View Javadoc
1   package fr.ifremer.quadrige2.synchro.intercept.administration;
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 com.google.common.base.Joiner;
27  import com.google.common.eventbus.Subscribe;
28  import fr.ifremer.common.synchro.dao.SynchroTableDao;
29  import fr.ifremer.common.synchro.intercept.SynchroInterceptorBase;
30  import fr.ifremer.common.synchro.intercept.SynchroOperationRepository;
31  import fr.ifremer.common.synchro.meta.SynchroTableMetadata;
32  import fr.ifremer.common.synchro.meta.event.CreateQueryEvent;
33  import fr.ifremer.common.synchro.query.SynchroQueryBuilder;
34  import fr.ifremer.common.synchro.query.SynchroQueryName;
35  import fr.ifremer.common.synchro.query.SynchroQueryOperator;
36  import fr.ifremer.quadrige2.synchro.intercept.referential.AbstractReferentialInterceptor;
37  import fr.ifremer.quadrige2.synchro.meta.DatabaseColumns;
38  import fr.ifremer.quadrige2.synchro.meta.administration.ProgramStrategySynchroTables;
39  import fr.ifremer.quadrige2.synchro.service.referential.ReferentialSynchroDatabaseConfiguration;
40  import org.apache.commons.collections4.CollectionUtils;
41  
42  import java.sql.SQLException;
43  import java.util.List;
44  import java.util.Set;
45  
46  /**
47   * Manage table STRATEGY :
48   * <ul>
49   * <li>Delete children tables (APPLIED_STRATEGY, PMFM_STRATEGY)
50   * </ul>
51   * 
52   * @author Benoit Lavenier <benoit.lavenier@e-is.pro>
53   * @since 1.0
54   */
55  public class StrategyInterceptor extends AbstractProgramStrategyInterceptor {
56  
57  	/**
58  	 * <p>
59  	 * Constructor for StrategyInterceptor.
60  	 * </p>
61  	 */
62  	public StrategyInterceptor() {
63  		super(ProgramStrategySynchroTables.STRATEGY.name());
64  		setEnableOnWrite(true);
65  	}
66  
67  	/** {@inheritDoc} */
68  	@Override
69  	protected void doOnDelete(List<Object> pk, SynchroTableDao sourceDao, SynchroTableDao targetDao, SynchroOperationRepository buffer)
70  			throws SQLException {
71  		// Getting the stratId
72  		Integer stratId = Integer.parseInt(pk.get(0).toString());
73  
74  		// Delete children tables : APPLIED_STRATEGY, PMFM_STRATEGY
75  		buffer.addChildToDeleteFromOneColumn(ProgramStrategySynchroTables.APPLIED_STRATEGY.name(), DatabaseColumns.STRAT_ID.name(), stratId);
76  		buffer.addChildToDeleteFromOneColumn(ProgramStrategySynchroTables.PMFM_STRATEGY.name(), DatabaseColumns.STRAT_ID.name(), stratId);
77  	}
78  }