use of org.jumpmind.symmetric.model.FileSnapshot in project symmetric-ds by JumpMind.
the class AbstractFileParsingRouter method deleteFileIfNecessary.
public void deleteFileIfNecessary(DataMetaData dataMetaData) {
Data data = dataMetaData.getData();
Table snapshotTable = dataMetaData.getTable();
if (data.getDataEventType() == DataEventType.INSERT || data.getDataEventType() == DataEventType.UPDATE) {
List<File> filesToDelete = new ArrayList<File>();
Map<String, String> columnData = data.toColumnNameValuePairs(snapshotTable.getColumnNames(), CsvData.ROW_DATA);
FileSnapshot fileSnapshot = new FileSnapshot();
fileSnapshot.setTriggerId(columnData.get("TRIGGER_ID"));
fileSnapshot.setRouterId(columnData.get("ROUTER_ID"));
fileSnapshot.setFileModifiedTime(Long.parseLong(columnData.get("FILE_MODIFIED_TIME")));
fileSnapshot.setFileName(columnData.get("FILE_NAME"));
fileSnapshot.setRelativeDir(columnData.get("RELATIVE_DIR"));
fileSnapshot.setLastEventType(LastEventType.fromCode(columnData.get("LAST_EVENT_TYPE")));
FileTriggerRouter triggerRouter = getEngine().getFileSyncService().getFileTriggerRouter(fileSnapshot.getTriggerId(), fileSnapshot.getRouterId());
if (triggerRouter != null) {
FileTrigger fileTrigger = triggerRouter.getFileTrigger();
if (fileTrigger.isDeleteAfterSync()) {
File file = fileTrigger.createSourceFile(fileSnapshot);
if (!file.isDirectory()) {
filesToDelete.add(file);
if (fileTrigger.isSyncOnCtlFile()) {
File ctlFile = getEngine().getFileSyncService().getControleFile(file);
filesToDelete.add(ctlFile);
}
}
} else if (getEngine().getParameterService().is(ParameterConstants.FILE_SYNC_DELETE_CTL_FILE_AFTER_SYNC, false)) {
File file = fileTrigger.createSourceFile(fileSnapshot);
if (!file.isDirectory()) {
if (fileTrigger.isSyncOnCtlFile()) {
File ctlFile = getEngine().getFileSyncService().getControleFile(file);
filesToDelete.add(ctlFile);
}
}
}
}
if (filesToDelete != null && filesToDelete.size() > 0) {
for (File file : filesToDelete) {
if (file != null && file.exists()) {
log.debug("Deleting the '{}' file", file.getAbsolutePath());
boolean deleted = FileUtils.deleteQuietly(file);
if (!deleted) {
log.warn("Failed to 'delete on sync' the {} file", file.getAbsolutePath());
}
}
file = null;
}
filesToDelete = null;
}
}
}
use of org.jumpmind.symmetric.model.FileSnapshot in project symmetric-ds by JumpMind.
the class FileSyncService method save.
public void save(List<FileSnapshot> changes) {
if (changes != null) {
ISqlTransaction sqlTransaction = null;
try {
sqlTransaction = sqlTemplate.startSqlTransaction();
for (FileSnapshot fileSnapshot : changes) {
save(sqlTransaction, fileSnapshot);
}
sqlTransaction.commit();
} catch (Error ex) {
if (sqlTransaction != null) {
sqlTransaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (sqlTransaction != null) {
sqlTransaction.rollback();
}
throw ex;
} finally {
close(sqlTransaction);
}
}
}
use of org.jumpmind.symmetric.model.FileSnapshot in project symmetric-ds by JumpMind.
the class FileSyncService method acknowledgeFiles.
public void acknowledgeFiles(OutgoingBatch outgoingBatch) {
log.debug("Acknowledging file_sync outgoing batch-{}", outgoingBatch.getBatchId());
ISqlReadCursor<Data> cursor = engine.getDataService().selectDataFor(outgoingBatch.getBatchId(), outgoingBatch.getChannelId());
Data data = null;
List<File> filesToDelete = new ArrayList<File>();
Table snapshotTable = platform.getTableFromCache(TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT), false);
for (int i = 0; i < outgoingBatch.getInsertEventCount(); i++) {
data = cursor.next();
if (data != null && (data.getDataEventType() == DataEventType.INSERT || data.getDataEventType() == DataEventType.UPDATE)) {
Map<String, String> columnData = data.toColumnNameValuePairs(snapshotTable.getColumnNames(), CsvData.ROW_DATA);
FileSnapshot fileSnapshot = new FileSnapshot();
fileSnapshot.setTriggerId(columnData.get("TRIGGER_ID"));
fileSnapshot.setRouterId(columnData.get("ROUTER_ID"));
fileSnapshot.setFileModifiedTime(Long.parseLong(columnData.get("FILE_MODIFIED_TIME")));
fileSnapshot.setFileName(columnData.get("FILE_NAME"));
fileSnapshot.setRelativeDir(columnData.get("RELATIVE_DIR"));
fileSnapshot.setLastEventType(LastEventType.fromCode(columnData.get("LAST_EVENT_TYPE")));
FileTriggerRouter triggerRouter = this.getFileTriggerRouter(fileSnapshot.getTriggerId(), fileSnapshot.getRouterId());
if (triggerRouter != null) {
FileTrigger fileTrigger = triggerRouter.getFileTrigger();
if (fileTrigger.isDeleteAfterSync()) {
File file = fileTrigger.createSourceFile(fileSnapshot);
if (!file.isDirectory()) {
filesToDelete.add(file);
if (fileTrigger.isSyncOnCtlFile()) {
filesToDelete.add(new File(file.getAbsolutePath() + ".ctl"));
}
}
}
}
}
}
if (cursor != null) {
cursor.close();
cursor = null;
}
if (filesToDelete != null && filesToDelete.size() > 0) {
for (File file : filesToDelete) {
if (file != null && file.exists()) {
log.debug("Deleting the '{}' file", file.getAbsolutePath());
boolean deleted = FileUtils.deleteQuietly(file);
if (!deleted) {
log.warn("Failed to 'delete on sync' the {} file", file.getAbsolutePath());
}
}
file = null;
}
filesToDelete = null;
}
}
use of org.jumpmind.symmetric.model.FileSnapshot in project symmetric-ds by JumpMind.
the class FileSyncZipDataWriter method start.
public void start(Batch batch) {
this.batch = batch;
this.statistics.put(batch, new Statistics());
this.snapshotEvents = new ArrayList<FileSnapshot>();
}
use of org.jumpmind.symmetric.model.FileSnapshot in project symmetric-ds by JumpMind.
the class FileTriggerTrackerTest method testTakeSnapshotRecursiveTestDelete.
@Test
public void testTakeSnapshotRecursiveTestDelete() throws Exception {
FileTrigger fileTrigger = new FileTrigger(directory.getAbsolutePath(), true, null, null);
Router router = new Router();
FileTriggerRouter fileTriggerRouter = new FileTriggerRouter(fileTrigger, router);
FileTriggerTracker tracker = new FileTriggerTracker(fileTriggerRouter, null);
tracker.trackChanges();
FileUtils.deleteQuietly(fileInDirectory1);
DirectorySnapshot snapshot = tracker.trackChanges();
assertEquals(1, snapshot.size());
FileSnapshot change = snapshot.get(0);
assertEquals(change.getFileName(), FileSyncUtils.getRelativePath(fileInDirectory1, directory));
assertEquals(change.getLastEventType(), LastEventType.DELETE);
}
Aggregations