protected boolean doesTriggerExistOnPlatform(String catalogName, String schema, String tableName, String triggerName) { return platform.getSqlTemplate().queryForInt( "select count(*) from sqlite_master where type='trigger' and name=? and tbl_name=?", triggerName, tableName) > 0; }
public void resetDataSource() { if (dataSource instanceof BasicDataSource) { BasicDataSource dbcp = (BasicDataSource) dataSource; try { dbcp.close(); } catch (SQLException e) { throw sqlTemplate.translate(e); } } }
public void saveRegistrationRedirect(String externalIdToRedirect, String nodeIdToRedirectTo) { int count = sqlTemplate.update(getSql("updateRegistrationRedirectUrlSql"), new Object[] { nodeIdToRedirectTo, externalIdToRedirect }, new int[] { Types.VARCHAR, Types.VARCHAR }); if (count == 0) { sqlTemplate.update(getSql("insertRegistrationRedirectUrlSql"), new Object[] { nodeIdToRedirectTo, externalIdToRedirect }, new int[] { Types.VARCHAR, Types.VARCHAR }); } }
public AbstractSymmetricDialect(IParameterService parameterService, IDatabasePlatform platform) { this.parameterService = parameterService; this.platform = platform; log.info("The DbDialect being used is {}", this.getClass().getName()); buildSqlReplacementTokens(); ISqlTemplate sqlTemplate = this.platform.getSqlTemplate(); this.databaseMajorVersion = sqlTemplate.getDatabaseMajorVersion(); this.databaseMinorVersion = sqlTemplate.getDatabaseMinorVersion(); this.databaseName = sqlTemplate.getDatabaseProductName(); this.databaseProductVersion = sqlTemplate.getDatabaseProductVersion(); this.driverName = sqlTemplate.getDriverName(); this.driverVersion = sqlTemplate.getDriverVersion(); }
public void insertNodeGroup(String groupId, String description) { if (sqlTemplate.queryForInt(getSql("doesNodeGroupExistSql"), groupId) == 0) { sqlTemplate.update(getSql("insertNodeGroupSql"), description, groupId); } }
public List<Data> listData(long batchId, String nodeId, long startDataId, String channelId, final int maxRowsToRetrieve) { return sqlTemplate.query(getDataSelectSql(batchId, startDataId, channelId), maxRowsToRetrieve, this.dataMapper, batchId, nodeId, startDataId); }
private long[] queryForMinMax(String sql, Object... params) { long[] minMax = sqlTemplate.queryForObject(sql, new ISqlRowMapper<long[]>() { public long[] mapRow(Row rs) { return new long[] { rs.getLong("min_id"), rs.getLong("max_id") }; } }, params); return minMax; }
public void open(DataContext context) { this.context = context; this.transaction = platform.getSqlTemplate().startSqlTransaction(); }
protected void startNewCursor() { String sql = String.format("select * from %s %s", table.getFullyQualifiedTableName(platform .getDatabaseInfo().getDelimiterToken()), StringUtils.isNotBlank(whereClause) ? " where " + whereClause : ""); this.cursor = platform.getSqlTemplate().queryForCursor(sql, new ISqlRowMapper<CsvData>() { public CsvData mapRow(Row row) { return new CsvData(DataEventType.INSERT, toStringData(row, table.getPrimaryKeyColumns()), toStringData(row, table.getColumns())); } }); }
protected boolean isMariaDbDriver() { if (mariaDbDriver == null) { mariaDbDriver = "mariadb-jdbc".equals(getPlatform().getSqlTemplate().getDriverName()); } return mariaDbDriver; }
public MsSqlDatabasePlatform(DataSource dataSource, SqlTemplateSettings settings) { super(dataSource, settings); // override the ddl builder based on the version if (this.sqlTemplate.getDatabaseMajorVersion() >= 10) { this.ddlBuilder = new MsSql10DdlBuilder(); } else { this.ddlBuilder = new MsSqlDdlBuilder(); } }
public List<ConflictNodeGroupLink> getConflictSettingsNodeGroupLinks() { List<ConflictNodeGroupLink> list = new ArrayList<DataLoaderService.ConflictNodeGroupLink>(); list = sqlTemplate.query(getSql("selectConflictSettingsSql"), new ConflictSettingsNodeGroupLinkMapper()); return list; }
protected void buildBulkDataType(int typeCode) { String typeName = getTypeName(typeCode); if (platform.getSqlTemplate().queryForInt( "select count(*) from user_types where type_name=?", typeName) == 0) { final String DDL = "create or replace type %s is table of %s"; platform.getSqlTemplate().update( String.format(DDL, getTypeName(typeCode), getMappedType(typeCode))); } }
public String getDefaultSchema() { if (StringUtils.isBlank(defaultSchema)) { defaultSchema = (String) getSqlTemplate().queryForObject("select SCHEMA()", String.class); } return defaultSchema; }
public boolean setInitialLoadEnabled(String nodeId, boolean initialLoadEnabled, boolean syncChange, long loadId, String createBy) { ISqlTransaction transaction = null; try { transaction = sqlTemplate.startSqlTransaction(); boolean updated = setInitialLoadEnabled(transaction, nodeId, initialLoadEnabled, syncChange, loadId, createBy); transaction.commit(); return updated; } catch (Error ex) { if (transaction != null) { transaction.rollback(); } throw ex; } catch (RuntimeException ex) { if (transaction != null) { transaction.rollback(); } throw ex; } finally { close(transaction); } }
public ISqlReadCursor<Data> selectDataFor(Batch batch) { return sqlTemplate .queryForCursor(getDataSelectSql(batch.getBatchId(), -1l, batch.getChannelId()), dataMapper, new Object[] { batch.getBatchId(), batch.getTargetNodeId() }, new int[] { Types.NUMERIC }); }
public boolean isUnsentDataOnChannelForNode(String channelId, String nodeId) { int unsentCount = sqlTemplate.queryForInt(getSql("unsentBatchesForNodeIdChannelIdSql"), new Object[] { nodeId, channelId }); if (unsentCount > 0) { return true; } // Do we need to check for unbatched data? return false; }
protected boolean unlock(String action, String serverId) { String lastLockingServerId = serverId.equals(Lock.STOPPED) ? null : serverId; return sqlTemplate.update(getSql("releaseLockSql"), new Object[] { new Date(), lastLockingServerId, action, serverId }) > 0; }
/** * Get a list of trigger histories that are currently active */ public List<TriggerHistory> getActiveTriggerHistories() { return sqlTemplate.query(getSql("allTriggerHistSql", "activeTriggerHistSql"), new TriggerHistoryMapper()); }
public String getDefaultCatalog() { if (StringUtils.isBlank(defaultCatalog)) { defaultCatalog = (String) getSqlTemplate().queryForObject("select DATABASE()", String.class); } return defaultCatalog; }