public int getBatchSize() { return config.batchSize(); }
@Override public String getUpsertRowSql() { if (upsertRowSql == null) { if (metaData.isSegmentedDisabled()) { upsertRowSql = String.format("MERGE INTO %1$s (%2$s, %3$s, %4$s) KEY(%4$s) VALUES(?, ?, ?)", getTableName(), config.dataColumnName(), config.timestampColumnName(), config.idColumnName()); } else { upsertRowSql = String.format("MERGE INTO %1$s (%2$s, %3$s, %4$s, %5$s) KEY(%4$s) VALUES(?, ?, ?, ?)", getTableName(), config.dataColumnName(), config.timestampColumnName(), config.idColumnName(), config.segmentColumnName()); } } return upsertRowSql; }
public int getFetchSize() { return config.fetchSize(); }
@Override public String getUpdateRowSql() { if (updateRowSql == null) { updateRowSql = String.format("UPDATE %s SET %s = ? , %s = ? WHERE %s = cast(? as %s)", getTableName(), config.dataColumnName(), config.timestampColumnName(), config.idColumnName(), config.idColumnType()); } return updateRowSql; }
@Override public String getSelectRowSql() { if (selectRowSql == null) { selectRowSql = String.format("SELECT %s, %s FROM %s WHERE %s = cast(? as %s)", config.idColumnName(), config.dataColumnName(), getTableName(), config.idColumnName(), config.idColumnType()); } return selectRowSql; }
@Override public String getUpdateRowSql() { if (updateRowSql == null) { updateRowSql = String.format("UPDATE %s SET %s = ? , %s = ? WHERE %s = ?", getTableName(), config.timestampColumnName(), config.dataColumnName(), config.idColumnName()); } return updateRowSql; }
public void createTable(Connection conn) throws PersistenceException { if (cacheName == null || cacheName.trim().length() == 0) throw new PersistenceException("cacheName needed in order to create table"); String ddl; if (metaData.isSegmentedDisabled()) { ddl = String.format("CREATE TABLE %1$s (%2$s %3$s NOT NULL, %4$s %5$s NOT NULL, %6$s %7$s NOT NULL, PRIMARY KEY (%2$s))", getTableName(), config.idColumnName(), config.idColumnType(), config.dataColumnName(), config.dataColumnType(), config.timestampColumnName(), config.timestampColumnType()); } else { ddl = String.format("CREATE TABLE %1$s (%2$s %3$s NOT NULL, %4$s %5$s NOT NULL, %6$s %7$s NOT NULL, %8$s %9$s NOT NULL, PRIMARY KEY (%2$s))", getTableName(), config.idColumnName(), config.idColumnType(), config.dataColumnName(), config.dataColumnType(), config.timestampColumnName(), config.timestampColumnType(), config.segmentColumnName(), config.segmentColumnType()); } if (log.isTraceEnabled()) { log.tracef("Creating table with following DDL: '%s'.", ddl); } executeUpdateSql(conn, ddl); }
assert store.connectionFactory() instanceof PooledConnectionFactoryConfiguration; assert ((PooledConnectionFactoryConfiguration)store.connectionFactory()).connectionUrl().equals(JDBC_URL); assert store.table().tableNamePrefix().equals("STRINGS_"); assert store.table().idColumnName().equals("id"); assert store.table().idColumnType().equals("VARCHAR"); assert store.table().dataColumnName().equals("datum"); assert store.table().dataColumnType().equals("BINARY"); assert store.table().timestampColumnName().equals("version"); assert store.table().timestampColumnType().equals("BIGINT"); assert store.fetchPersistentState(); assert store.async().enabled(); assert store2.connectionFactory() instanceof PooledConnectionFactoryConfiguration; assert ((PooledConnectionFactoryConfiguration)store2.connectionFactory()).connectionUrl().equals(JDBC_URL); assert store2.table().tableNamePrefix().equals("STRINGS_"); assert store2.table().idColumnName().equals("id"); assert store2.table().idColumnType().equals("VARCHAR"); assert store2.table().dataColumnName().equals("datum"); assert store2.table().dataColumnType().equals("BINARY"); assert store2.table().timestampColumnName().equals("version"); assert store2.table().timestampColumnType().equals("BIGINT"); assert store2.fetchPersistentState(); assert store2.async().enabled();
@Override public String getSelectIdRowSql() { if (selectIdRowSql == null) { selectIdRowSql = String.format("SELECT %s FROM %s WHERE %s = cast(? as %s)", config.idColumnName(), getTableName(), config.idColumnName(), config.idColumnType()); } return selectIdRowSql; }
JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) cacheManager.getDefaultCacheConfiguration().persistence().stores().get(0); assertEquals(128, store.table().batchSize()); assertEquals(34, store.table().fetchSize()); assertEquals("BINARY", store.table().dataColumnType()); assertEquals("version", store.table().timestampColumnName()); assertTrue(store.async().enabled()); assertEquals("DummyKey2StringMapper", store.key2StringMapper());
@Override public String getUpsertRowSql() { if (upsertRowSql == null) { // Assumes that config.idColumnName is the primary key if (metaData.isSegmentedDisabled()) { upsertRowSql = String.format("%1$s ON DUPLICATE KEY UPDATE %2$s = VALUES(%2$s), %3$s = VALUES(%3$s)", getInsertRowSql(), config.dataColumnName(), config.timestampColumnName()); } else { upsertRowSql = String.format("%1$s ON DUPLICATE KEY UPDATE %2$s = VALUES(%2$s), %3$s = VALUES(%3$s), %4$s = VALUES(%4$s)", getInsertRowSql(), config.dataColumnName(), config.timestampColumnName(), config.segmentColumnName()); } } return upsertRowSql; } }
@Override public String getSelectRowSql() { if (selectRowSql == null) { selectRowSql = String.format("SELECT %s, %s FROM %s WHERE %s = ?", config.idColumnName(), config.dataColumnName(), getTableName(), config.idColumnName()); } return selectRowSql; }
@Override public void start() throws PersistenceException { if (config.createOnStart()) { Connection conn = null; try { conn = connectionFactory.getConnection(); if (!tableExists(conn)) { createTable(conn); } createIndex(conn, timestampIndexExt, config.timestampColumnName()); if (!metaData.isSegmentedDisabled()) { createIndex(conn, segmentIndexExt, config.segmentColumnName()); } } finally { connectionFactory.releaseConnection(conn); } } }
public void testTableProperties() { Properties props = new Properties(); props.put("createOnStart", "false"); props.put("dropOnExit", "true"); ConfigurationBuilder b = new ConfigurationBuilder(); b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class) .connectionPool().connectionUrl(JDBC_URL) .withProperties(props); Configuration stringConfiguration = b.build(); JdbcStringBasedStoreConfiguration stringStoreConfiguration = (JdbcStringBasedStoreConfiguration) stringConfiguration.persistence().stores().get(0); assertFalse(stringStoreConfiguration.table().createOnStart()); assertTrue(stringStoreConfiguration.table().dropOnExit()); } }
@Override public Builder<?> read(TableManipulationConfiguration template) { attributes.read(template.attributes()); return this; }
@Override public String getSelectIdRowSql() { if (selectIdRowSql == null) { selectIdRowSql = String.format("SELECT %s FROM %s WHERE %s = ?", config.idColumnName(), getTableName(), config.idColumnName()); } return selectIdRowSql; }
public TableName getTableName() { if (tableName == null) { tableName = new TableName(identifierQuoteString, config.tableNamePrefix(), cacheName); } return tableName; }
@Override public void stop() throws PersistenceException { if (config.dropOnExit()) { Connection conn = null; try { conn = connectionFactory.getConnection(); dropTable(conn); } finally { connectionFactory.releaseConnection(conn); } } }
@Override public String getUpsertRowSql() { if (upsertRowSql == null) { upsertRowSql = String.format("%1$s ON CONFLICT (%2$s) DO UPDATE SET %3$s = EXCLUDED.%3$s, %4$s = EXCLUDED.%4$s", getInsertRowSql(), config.idColumnName(), config.dataColumnName(), config.timestampColumnName()); } return upsertRowSql; } }
@Override public String getUpdateRowSql() { if (updateRowSql == null) { updateRowSql = String.format("UPDATE %s SET %s = ? , %s = ? WHERE %s = convert(%s,?)", getTableName(), config.dataColumnName(), config.timestampColumnName(), config.idColumnName(), config.idColumnType()); } return updateRowSql; }