Je suis en train de mettre en place un outil de synchronisation entre plusieurs bases de donnees.

Mon soucis, c'est que je me retrouve au final avec 22 beans dans mon controlleur (11 tables a synchroniser), existe t-il un moyen de n'avoir au final que 2 beans (un pour la SOURCE et un pour la TARGET) ?

Voici des parties de mon code :

-- datasource.xml --
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd">
 
    <context:annotation-config />
 
    <bean id="sourceDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost/source"/>
        <!--<property name="url" value="jdbc:mysql://linkSource"/>-->
        <property name="username" value="username"/>
        <property name="password" value="password"/>
    </bean>
 
        <bean id="targetDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost/target"/>
        <!--<property name="url" value="jdbc:mysql://linkTarget"/>-->
        <property name="username" value="username"/>
        <property name="password" value="password"/>
    </bean>
 
</beans>
-- sync-servelt.xml --
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
        <!--sync query beans-->
        <bean id="sourceDatasetQueryBean" class="ds.sync.db.SyncDatasetQuery" name="sourceDatasetsQuery">
            <property name="dataSource" ref="sourceDataSource"/>
        </bean>
 
        <bean id="targetDatasetQueryBean" class="ds.sync.db.SyncDatasetQuery" name="targetDatasetsQuery">
            <property name="dataSource" ref="targetDataSource"/>
        </bean>
 
        <bean id="sourceDatasetDescriptionQueryBean" class="ds.sync.db.SyncDatasetDescriptionQuery" name="sourceDatasetsDescriptionQuery">
            <property name="dataSource" ref="sourceDataSource"/>
        </bean>
 
        <bean id="targetDatasetDescriptionQueryBean" class="ds.sync.db.SyncDatasetDescriptionQuery" name="targetDatasetsDescriptionQuery">
            <property name="dataSource" ref="targetDataSource"/>
        </bean>
...etc...
--dans mon controlleur--
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Autowired
 @Qualifier("sourceDatasetQueryBean")
 protected SyncDatasetQuery m_datasetQuerySource;
 
 @Autowired
 @Qualifier("targetDatasetQueryBean")
 protected SyncDatasetQuery m_datasetQueryTarget;
 
 @Autowired
 @Qualifier("sourceDatasetDescriptionQueryBean")
 protected SyncDatasetDescriptionQuery m_datasetDescriptionQuerySource;
 
 @Autowired
 @Qualifier("targetDatasetDescriptionQueryBean")
 protected SyncDatasetDescriptionQuery m_datasetDescriptionQueryTarget;
...etc...
Ensuite, je fais mes query de la sorte (pour vous donner une idee):

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
SyncDatasetItem ds = m_datasetQuerySource.getDataset(nDatasetID);
m_datasetQueryTarget.update(ds);
 
SyncDatasetDescriptionItem dsDescription = m_datasetDescriptionQuerySource.getDatasetDescription(nDatasetID);
m_datasetDescriptionQueryTarget.update(dsDescription);
...etc...
Ce qui serait bien, c'est de n'avoir que 2 beans (par exemple) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
@Autowired
 @Qualifier("sourceDataBean")
 protected SourceQuery m_dataQuerySource;
et
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
@Autowired
 @Qualifier("targetDataBean")
 protected TargetQuery m_dataQueryTarget;
Pour au final, avoir a juste faire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
SyncDatasetItem ds = m_dataQuerySource.getDataset(nDatasetID);
m_dataQueryTarget.update(ds);
 
SyncDatasetDescriptionItem dsDescription = m_dataQuerySource.getDatasetDescription(nDatasetID);
m_dataQueryTarget.update(dsDescription);
...etc...
Est-ce possible ?

Merci.