@Service(value="referentialSynchroService") @Lazy public class ReferentialSynchroServiceImpl extends SynchroBaseService implements ReferentialSynchroService
batchSize, config, daoInterceptors, dataSource
Constructor and Description |
---|
ReferentialSynchroServiceImpl() |
ReferentialSynchroServiceImpl(DataSource dataSource,
SynchroConfiguration config) |
Modifier and Type | Method and Description |
---|---|
protected void |
closeSilently(Connection connection) |
protected Connection |
createConnection(Properties connectionProperties) |
protected Connection |
createConnection(String jdbcUrl,
String user,
String password) |
SynchroContext |
createSynchroContext(File sourceDbDirectory)
Create a synchro context, from a source database directory (HSQLDB only).
|
SynchroContext |
createSynchroContext(Properties sourceConnectionProperties)
Create a synchro context, using configuration properties for target and source properties.
|
void |
prepare(SynchroContext synchroContext)
Prepare the synchronize operation from the local data database supported
by this service, says just compute nb rows to update for each table and
update the result model.
|
protected void |
prepareSynch(Connection connection) |
protected void |
prepareTable(SynchroTableMetadata sourceTable,
SynchroTableMetadata targetTable,
SynchroContext context,
Connection targetConnection,
Connection sourceConnection,
SynchroResult result) |
protected void |
releaseSynch(Connection connection) |
protected void |
reportProgress(SynchroResult result,
SynchroTableDao dao,
int countR,
String tablePrefix) |
void |
synchronize(SynchroContext synchroContext)
Launch the synchronize operation from the local data database supported
by this service.
|
protected void |
synchronizeTable(SynchroTableMetadata table,
Connection targetConnection,
Connection sourceConnection,
SynchroResult result) |
protected void |
updateBigTable(SynchroTableDao targetDao,
SynchroTableDao sourceDao,
ResultSet incomingData,
SynchroResult result)
To update the content of the given
table (with a lot of rows) on
the target db, from the given incomingData of the source db. |
protected void |
updateTable(SynchroTableDao targetDao,
ResultSet incomingData,
SynchroResult result)
To update the content of the given
table on the target db,
from the given incomingData of the source db. |
getInterceptor, getInterceptors
@Autowired public ReferentialSynchroServiceImpl(DataSource dataSource, SynchroConfiguration config)
public ReferentialSynchroServiceImpl()
public SynchroContext createSynchroContext(File sourceDbDirectory)
ReferentialSynchroService
createSynchroContext
in interface ReferentialSynchroService
sourceDbDirectory
- a directory with a HSQLDB directory.public SynchroContext createSynchroContext(Properties sourceConnectionProperties)
ReferentialSynchroService
createSynchroContext
in interface ReferentialSynchroService
sourceConnectionProperties
- Properties to use as source connection (could be Oracle, HSQLDB...)public void prepare(SynchroContext synchroContext)
ReferentialSynchroService
prepare
in interface ReferentialSynchroService
synchroContext
- context of synchro operationpublic void synchronize(SynchroContext synchroContext)
ReferentialSynchroService
synchronize
in interface ReferentialSynchroService
synchroContext
- context of synchro operationprotected void prepareTable(SynchroTableMetadata sourceTable, SynchroTableMetadata targetTable, SynchroContext context, Connection targetConnection, Connection sourceConnection, SynchroResult result) throws SQLException
SQLException
protected void synchronizeTable(SynchroTableMetadata table, Connection targetConnection, Connection sourceConnection, SynchroResult result) throws SQLException
SQLException
protected void updateTable(SynchroTableDao targetDao, ResultSet incomingData, SynchroResult result) throws SQLException
table
on the target db,
from the given incomingData
of the source db.
The algorithm is pretty simple, for each row of the incomingData
, if exists on target table, then do an
update, otherwise do a insert.
As an update query is more expensive, we won't use this method for table with a lot of rows, we will prefer to
use the updateBigTable
method instead.targetDao
- connection on the target dbincomingData
- data to update from the source dbresult
- where to store operation resultsSQLException
- if any sql errorsprotected void updateBigTable(SynchroTableDao targetDao, SynchroTableDao sourceDao, ResultSet incomingData, SynchroResult result) throws SQLException
table
(with a lot of rows) on
the target db, from the given incomingData
of the source db.
We can't use the simple algorithm, since update queries cost too much and is not acceptable when talking on huge
numbers of rows.
Here is what to do :
dbMetas
- targetDao
- connection on the target dbsourceDao
- connection on the target dbincomingData
- data to update from the source dbinterceptor
- result
- where to store operation results @throws SQLException if any sql errorsSQLException
protected void reportProgress(SynchroResult result, SynchroTableDao dao, int countR, String tablePrefix)
reportProgress
in class SynchroBaseService
protected Connection createConnection(Properties connectionProperties) throws SQLException
SQLException
protected Connection createConnection(String jdbcUrl, String user, String password) throws SQLException
SQLException
protected void closeSilently(Connection connection)
protected void prepareSynch(Connection connection) throws SQLException
SQLException
protected void releaseSynch(Connection connection) throws SQLException
SQLException
Copyright © 2012–2014 IFREMER. All rights reserved.