private void loadDriver(String driverClass, ClassLoader classLoader) throws PersistenceException { if (log.isTraceEnabled()) log.tracef("Attempting to load driver %s", driverClass); Util.getInstance(driverClass, classLoader); }
public boolean tableExists(Connection connection, TableName tableName) throws PersistenceException { Objects.requireNonNull(tableName, "table name is mandatory"); ResultSet rs = null; try { // we need to make sure, that (even if the user has extended permissions) only the tables in current schema are checked // explicit set of the schema to the current user one to make sure only tables of the current users are requested DatabaseMetaData metaData = connection.getMetaData(); String schemaPattern = tableName.getSchema(); rs = metaData.getTables(null, schemaPattern, tableName.getName(), new String[]{"TABLE"}); return rs.next(); } catch (SQLException e) { if (log.isTraceEnabled()) log.tracef(e, "SQLException occurs while checking the table %s", tableName); return false; } finally { JdbcUtil.safeClose(rs); } }
@Override public boolean tableExists(Connection connection, TableName tableName) throws PersistenceException { Objects.requireNonNull(tableName, "table name is mandatory"); ResultSet rs = null; try { DatabaseMetaData metaData = connection.getMetaData(); String schemaPattern = tableName.getSchema() == null ? metaData.getUserName() : tableName.getSchema(); rs = metaData.getTables(null, schemaPattern, tableName.getName(), new String[]{"TABLE"}); return rs.next(); } catch (SQLException e) { if (LOG.isTraceEnabled()) LOG.tracef(e, "SQLException occurs while checking the table %s", tableName); return false; } finally { JdbcUtil.safeClose(rs); } }
protected void dropIndex(Connection conn, String indexName) throws PersistenceException { if (!indexExists(getIndexName(true, indexName), conn)) return; String dropIndexDdl = getDropTimestampSql(indexName); if (log.isTraceEnabled()) { log.tracef("Dropping timestamp index with '%s'", dropIndexDdl); } executeUpdateSql(conn, dropIndexDdl); }
private void createIndex(Connection conn, String indexExt, String columnName) throws PersistenceException { if (metaData.isIndexingDisabled()) return; boolean indexExists = indexExists(getIndexName(false, indexExt), conn); if (!indexExists) { String ddl = String.format("CREATE INDEX %s ON %s (%s)", getIndexName(true, indexExt), getTableName(), columnName); if (log.isTraceEnabled()) { log.tracef("Adding index with following DDL: '%s'.", ddl); } executeUpdateSql(conn, ddl); } }
@Override public void clear() { Connection conn = null; Statement statement = null; try { String sql = tableManager.getDeleteAllRowsSql(); conn = connectionFactory.getConnection(); statement = conn.createStatement(); int result = statement.executeUpdate(sql); if (log.isTraceEnabled()) { log.tracef("Successfully removed %d rows.", result); } } catch (SQLException ex) { log.failedClearingJdbcCacheStore(ex); throw new PersistenceException("Failed clearing cache store", ex); } finally { JdbcUtil.safeClose(statement); connectionFactory.releaseConnection(conn); } }
@Override public void clear(IntSet segments) { Connection conn = null; PreparedStatement ps = null; try { String sql = tableManager.getDeleteRowsSqlForSegments(segments.size()); conn = connectionFactory.getConnection(); ps = conn.prepareStatement(sql); int offset = 0; for (PrimitiveIterator.OfInt segIter = segments.iterator(); segIter.hasNext(); ) { ps.setInt(++offset, segIter.nextInt()); } int result = ps.executeUpdate(); if (log.isTraceEnabled()) { log.tracef("Successfully removed %d rows.", result); } } catch (SQLException ex) { log.failedClearingJdbcCacheStore(ex); throw new PersistenceException("Failed clearing cache store when using segments " + segments, ex); } finally { JdbcUtil.safeClose(ps); connectionFactory.releaseConnection(conn); } }
public void dropTable(Connection conn) throws PersistenceException { dropIndex(conn, timestampIndexExt); dropIndex(conn, segmentIndexExt); String clearTable = "DELETE FROM " + getTableName(); executeUpdateSql(conn, clearTable); String dropTableDdl = "DROP TABLE " + getTableName(); if (log.isTraceEnabled()) { log.tracef("Dropping table with following DDL '%s'", dropTableDdl); } executeUpdateSql(conn, dropTableDdl); }
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); }