View Javadoc
1   package fr.ifremer.quadrige2.synchro.service.referential;
2   
3   /*-
4    * #%L
5    * Quadrige2 Core :: Quadrige2 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.SynchroContext;
28  import fr.ifremer.common.synchro.service.SynchroResult;
29  import fr.ifremer.quadrige2.synchro.service.SynchroDirection;
30  import org.springframework.transaction.annotation.Propagation;
31  import org.springframework.transaction.annotation.Transactional;
32  
33  import java.io.File;
34  import java.sql.Timestamp;
35  import java.util.Map;
36  import java.util.Properties;
37  import java.util.Set;
38  
39  /**
40   * <p>
41   * ReferentialSynchroService interface.
42   * </p>
43   * 
44   */
45  @Transactional(propagation = Propagation.SUPPORTS)
46  public interface ReferentialSynchroService {
47  
48  	/**
49  	 * Create a synchro context, from a source database directory (HSQLDB only), and with a last synchronization date.
50  	 * This use local connection properties as source properties, but change JDBC URL to use the given directory
51  	 * 
52  	 * @param sourceDbDirectory
53  	 *            a directory with a HSQLDB directory.
54  	 * @param lastSynchronizationDate
55  	 *            the last synchro date
56  	 * @param enableDelete
57  	 *            a boolean.
58  	 * @param enableInsertUpdate
59  	 *            a boolean.
60  	 * @return a new context for synchronization
61  	 * @param direction
62  	 *            a {@link fr.ifremer.quadrige2.synchro.service.SynchroDirection} object.
63  	 * @param userId
64  	 *            a int.
65  	 * @param statusCodeIncludes
66  	 *            a {@link java.util.Set} object.
67  	 */
68  	ReferentialSynchroContext createSynchroContext(File sourceDbDirectory,
69  			Timestamp lastSynchronizationDate,
70  			boolean enableDelete,
71  			boolean enableInsertUpdate,
72  			SynchroDirection direction,
73  			int userId,
74  			Set<String> statusCodeIncludes);
75  
76  	/**
77  	 * Create a synchro context, using configuration properties for target and source properties, and with a last
78  	 * synchronization date.
79  	 * 
80  	 * @param sourceConnectionProperties
81  	 *            Properties to use as source connection (could be Oracle, HSQLDB...)
82  	 * @param lastSynchronizationDate
83  	 *            the last synchro date
84  	 * @param enableDelete
85  	 *            a boolean.
86  	 * @param enableInsertUpdate
87  	 *            a boolean.
88  	 * @param statusCodeIncludes
89  	 *            status codes to include. Or null for 'all'
90  	 * @return a new context for synchronization
91  	 * @param direction
92  	 *            a {@link fr.ifremer.quadrige2.synchro.service.SynchroDirection} object.
93  	 * @param userId
94  	 *            a int.
95  	 */
96  	ReferentialSynchroContext createSynchroContext(Properties sourceConnectionProperties,
97  			Timestamp lastSynchronizationDate,
98  			boolean enableDelete,
99  			boolean enableInsertUpdate,
100 			SynchroDirection direction,
101 			int userId,
102 			Set<String> statusCodeIncludes);
103 
104 	/**
105 	 * Prepare the synchronize operation from the target data database supported
106 	 * by this service, says just compute nb rows to update for each table and
107 	 * update the result model.
108 	 * <p/>
109 	 * This method use Propagation.REQUIRES_NEW, because the transaction will be mark as rollbackOnly. (could not be set
110 	 * as readOnly, because of insertions into TEMP_QUERY_PARAMETER table)
111 	 * 
112 	 * @param context
113 	 *            Context of synchronization
114 	 */
115 	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
116 	void prepare(SynchroContext context);
117 
118 	/**
119 	 * <p>
120 	 * synchronize.
121 	 * </p>
122 	 * 
123 	 * @param context
124 	 *            a {@link fr.ifremer.common.synchro.service.SynchroContext} object.
125 	 */
126 	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
127 	void synchronize(SynchroContext context);
128 
129 	/**
130 	 * <p>
131 	 * getSourceLastUpdateDate.
132 	 * </p>
133 	 * 
134 	 * @param synchroContext
135 	 *            a {@link fr.ifremer.common.synchro.service.SynchroContext} object.
136 	 * @return a {@link java.sql.Timestamp} object.
137 	 */
138 	@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
139 	Timestamp getSourceLastUpdateDate(SynchroContext synchroContext);
140 
141 	/**
142 	 * <p>
143 	 * finish.
144 	 * </p>
145 	 * 
146 	 * @param synchroContext
147 	 *            a {@link fr.ifremer.common.synchro.service.SynchroContext} object.
148 	 * @param resultWithPendingOperation
149 	 *            a {@link fr.ifremer.common.synchro.service.SynchroResult} object.
150 	 * @param rejectStrategies
151 	 *            a {@link java.util.Map} object.
152 	 */
153 	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
154 	void finish(SynchroContext synchroContext, SynchroResult resultWithPendingOperation,
155 			Map<RejectedRow.Cause, RejectedRow.ResolveStrategy> rejectStrategies);
156 }