protected void notifyFiltersEarlyCommit() { List<IDatabaseWriterFilter> filters = this.writerSettings.getDatabaseWriterFilters(); if (filters != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.FILTERMILLIS); for (IDatabaseWriterFilter filter : filters) { filter.earlyCommit(context); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.FILTERMILLIS); } } }
protected void notifyFiltersBatchRolledback() { List<IDatabaseWriterFilter> filters = this.writerSettings.getDatabaseWriterFilters(); if (filters != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.FILTERMILLIS); for (IDatabaseWriterFilter filter : filters) { filter.batchRolledback(context); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.FILTERMILLIS); } } }
protected void rollback() { if (transaction != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); this.transaction.rollback(); notifyFiltersBatchRolledback(); } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS); } } uncommittedCount = 0; }
protected void filterAfter(CsvData data) { List<IDatabaseWriterFilter> filters = this.writerSettings.getDatabaseWriterFilters(); if (filters != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.FILTERMILLIS); for (IDatabaseWriterFilter filter : filters) { filter.afterWrite(this.context, this.sourceTable, data); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.FILTERMILLIS); } } }
protected void notifyFiltersBatchCommitted() { List<IDatabaseWriterFilter> filters = this.writerSettings.getDatabaseWriterFilters(); if (filters != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.FILTERMILLIS); for (IDatabaseWriterFilter filter : filters) { filter.batchCommitted(context); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.FILTERMILLIS); } } }
protected void notifyFiltersBatchComplete() { List<IDatabaseWriterFilter> filters = this.writerSettings.getDatabaseWriterFilters(); if (filters != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.FILTERMILLIS); for (IDatabaseWriterFilter filter : filters) { filter.batchComplete(context); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.FILTERMILLIS); } } }
protected boolean filterError(CsvData data, Exception ex) { boolean process = true; List<IDatabaseWriterErrorHandler> filters = this.writerSettings .getDatabaseWriterErrorHandlers(); if (filters != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.FILTERMILLIS); for (IDatabaseWriterErrorHandler filter : filters) { process &= filter.handleError(context, targetTable, data, ex); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.FILTERMILLIS); } } return process; }
protected void commit(boolean earlyCommit) { if (transaction != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); this.transaction.commit(); if (!earlyCommit) { notifyFiltersBatchCommitted(); } else { notifyFiltersEarlyCommit(); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS); } } uncommittedCount = 0; }
protected void flush() { if (copyIn != null) { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); try { copyIn.flushCopy(); } catch (SQLException ex) { throw getPlatform().getSqlTemplate().translate(ex); } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS); } } }
protected boolean script(CsvData data) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); String script = data.getParsedData(CsvData.ROW_DATA)[0]; Map<String, Object> variables = new HashMap<String, Object>();
protected boolean sql(CsvData data) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); String script = data.getParsedData(CsvData.ROW_DATA)[0]; List<String> sqlStatements = getSqlStatements(script); long count = 0; for (String sql : sqlStatements) { sql = preprocessSqlStatement(sql); transaction.prepare(sql); if (log.isDebugEnabled()) { log.debug("About to run: {}", sql); } count += transaction.prepareAndExecute(sql); if (log.isDebugEnabled()) { log.debug("{} rows updated when running: {}", count, sql); } } statistics.get(batch).increment(DataWriterStatisticConstants.SQLCOUNT); statistics.get(batch).increment(DataWriterStatisticConstants.SQLROWSAFFECTEDCOUNT, count); return true; } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS); } }
protected void flush() { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); try { if (rowArrays.size() > 0) {
protected boolean create(CsvData data) { String xml = null; try { transaction.commit(); statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); xml = data.getParsedData(CsvData.ROW_DATA)[0]; log.info("About to create table using the following definition: {}", xml); StringReader reader = new StringReader(xml); Database db = DatabaseXmlUtil.read(reader, false); if (writerSettings.isCreateTableAlterCaseToMatchDatabaseDefault()) { platform.alterCaseToMatchDatabaseDefaultCase(db); } if (writerSettings.isAlterTable()) { platform.alterDatabase(db, !writerSettings.isCreateTableFailOnError()); } else { platform.createDatabase(db, writerSettings.isCreateTableDropFirst(), !writerSettings.isCreateTableFailOnError()); } platform.resetCachedTableModel(); statistics.get(batch).increment(DataWriterStatisticConstants.CREATECOUNT); return true; } catch (RuntimeException ex) { log.error("Failed to alter table using the following xml: {}", xml); throw ex; } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS); } }
statistics.get(batch).increment(DataWriterStatisticConstants.STATEMENTCOUNT); statistics.get(batch).increment(DataWriterStatisticConstants.LINENUMBER); statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); try { String formattedData = CsvUtils.escapeCsvData(
protected boolean filterBefore(CsvData data) { boolean process = true; List<IDatabaseWriterFilter> filters = this.writerSettings.getDatabaseWriterFilters(); if (filters != null) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.FILTERMILLIS); for (IDatabaseWriterFilter filter : filters) { process &= filter.beforeWrite(this.context, this.sourceTable, data); } // re-lookup target table in case the source table has changed Table oldTargetTable = targetTable; if (this.sourceTable!=null) { targetTable = lookupTableAtTarget(this.sourceTable); } if (targetTable!=null && !targetTable.equals(oldTargetTable)) { // allow for auto increment columns to be inserted into if appropriate String quote = getPlatform().getDatabaseInfo().getDelimiterToken(); if (oldTargetTable!=null) { transaction.allowInsertIntoAutoIncrementColumns(false, oldTargetTable, quote); } transaction.allowInsertIntoAutoIncrementColumns(true, targetTable, quote); } } finally { statistics.get(batch).stopTimer(DataWriterStatisticConstants.FILTERMILLIS); } } return process; }
protected LoadStatus update(CsvData data, boolean applyChangesOnly, boolean useConflictDetection) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); String[] rowData = getRowData(data, CsvData.ROW_DATA); String[] oldData = getRowData(data, CsvData.OLD_DATA);
protected LoadStatus delete(CsvData data, boolean useConflictDetection) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); Conflict conflict = writerSettings.pickConflict(this.targetTable, batch); Map<String, String> lookupDataMap = null;
protected LoadStatus insert(CsvData data) { try { statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS); if (requireNewStatement(DmlType.INSERT, data, false, true, null)) { this.lastUseConflictDetection = true;