View Javadoc
1   package fr.ifremer.quadrige3.synchro.service.referential;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Synchro Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.common.synchro.service.RejectedRow;
27  import fr.ifremer.common.synchro.service.SynchroResult;
28  import fr.ifremer.quadrige3.synchro.service.SynchroDirection;
29  import org.springframework.transaction.annotation.Propagation;
30  import org.springframework.transaction.annotation.Transactional;
31  
32  import java.io.File;
33  import java.sql.Timestamp;
34  import java.util.Map;
35  import java.util.Properties;
36  import java.util.Set;
37  
38  /**
39   * <p>
40   * ReferentialSynchroService interface.
41   * </p>
42   * 
43   */
44  @Transactional(propagation = Propagation.SUPPORTS)
45  public interface ReferentialSynchroService {
46  
47  	/**
48  	 * Create a synchro context, from a source database directory (HSQLDB only), and with a last synchronization date.
49  	 * This use local connection properties as source properties, but change JDBC URL to use the given directory
50  	 * 
51  	 * @param sourceDbDirectory
52  	 *            a directory with a HSQLDB directory.
53  	 * @param lastSynchronizationDate
54  	 *            the last synchro date
55  	 * @param enableDelete
56  	 *            a boolean.
57  	 * @param enableInsertUpdate
58  	 *            a boolean.
59  	 * @return a new context for synchronization
60  	 * @param direction
61  	 *            a {@link fr.ifremer.quadrige3.synchro.service.SynchroDirection} object.
62  	 * @param userId
63  	 *            a int.
64  	 * @param statusCodeIncludes
65  	 *            a {@link java.util.Set} object.
66  	 */
67  	ReferentialSynchroContext createSynchroContext(File sourceDbDirectory,
68  			Timestamp lastSynchronizationDate,
69  			boolean enableDelete,
70  			boolean enableInsertUpdate,
71  			SynchroDirection direction,
72  			int userId,
73  			Set<String> statusCodeIncludes);
74  
75  	/**
76  	 * Create a synchro context, using configuration properties for target and source properties, and with a last
77  	 * synchronization date.
78  	 * 
79  	 * @param sourceConnectionProperties
80  	 *            Properties to use as source connection (could be Oracle, HSQLDB...)
81  	 * @param lastSynchronizationDate
82  	 *            the last synchro date
83  	 * @param enableDelete
84  	 *            a boolean.
85  	 * @param enableInsertUpdate
86  	 *            a boolean.
87  	 * @param statusCodeIncludes
88  	 *            status codes to include. Or null for 'all'
89  	 * @return a new context for synchronization
90  	 * @param direction
91  	 *            a {@link fr.ifremer.quadrige3.synchro.service.SynchroDirection} object.
92  	 * @param userId
93  	 *            a int.
94  	 */
95  	ReferentialSynchroContext createSynchroContext(Properties sourceConnectionProperties,
96  			Timestamp lastSynchronizationDate,
97  			boolean enableDelete,
98  			boolean enableInsertUpdate,
99  			SynchroDirection direction,
100 			int userId,
101 			Set<String> statusCodeIncludes);
102 
103 	/**
104 	 * Prepare the synchronize operation from the target data database supported
105 	 * by this service, says just compute nb rows to update for each table and
106 	 * update the result model.
107 	 * <p/>
108 	 * This method use Propagation.REQUIRES_NEW, because the transaction will be mark as rollbackOnly. (could not be set
109 	 * as readOnly, because of insertions into TEMP_QUERY_PARAMETER table)
110 	 * 
111 	 * @param context
112 	 *            Context of synchronization
113 	 */
114 	@Transactional(propagation = Propagation.REQUIRED)
115 	void prepare(ReferentialSynchroContext context);
116 
117 	/**
118 	 * <p>
119 	 * synchronize.
120 	 * </p>
121 	 * 
122 	 * @param context
123 	 *            a {@link fr.ifremer.common.synchro.service.SynchroContext} object.
124 	 */
125 	@Transactional(propagation = Propagation.REQUIRED)
126 	void synchronize(ReferentialSynchroContext context);
127 
128 	/**
129 	 * <p>
130 	 * getSourceLastUpdateDate.
131 	 * </p>
132 	 * 
133 	 * @param synchroContext
134 	 *            a {@link fr.ifremer.common.synchro.service.SynchroContext} object.
135 	 * @return a {@link java.sql.Timestamp} object.
136 	 */
137 	@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
138 	Timestamp getSourceLastUpdateDate(ReferentialSynchroContext synchroContext);
139 
140 	/**
141 	 * <p>
142 	 * finish.
143 	 * </p>
144 	 *
145 	 * @param synchroContext
146 	 *            a {@link fr.ifremer.common.synchro.service.SynchroContext} object.
147 	 * @param resultWithPendingOperation
148 	 *            a {@link fr.ifremer.common.synchro.service.SynchroResult} object.
149 	 * @param rejectStrategies
150 	 *            a {@link java.util.Map} object.
151 	 */
152 	@Transactional(propagation = Propagation.REQUIRED)
153 	void finish(ReferentialSynchroContext synchroContext, SynchroResult resultWithPendingOperation,
154 			Map<RejectedRow.Cause, RejectedRow.ResolveStrategy> rejectStrategies);
155 }