private void createTimestampTable(Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { if (getDbType(connection).equals(DBType.ORACLE)) { createTimestampTableIgnoringAlreadyExistsError(statement); } else { statement.execute(String.format("CREATE TABLE IF NOT EXISTS %s ( last_allocated int8 NOT NULL )", prefixedTimestampTableName())); } } }
AgnosticLightResultSet selectLightResultSet(Connection c, FinalSQLString finalSql, Object... vs) throws PalantirSqlException { return basicSql.selectLightResultSetSpecifyingDBType( c, finalSql, vs, DBType.getTypeFromConnection(c), null); }
/** * Looks up a DBType by name. Names are not case-sensitive. * * @param strName the name of the type to lookup, typically corresponds * to the type name, e.g. DBType.ORACLE.toString(); * @return the property DBType, or null if none exists */ @Nullable public static DBType getTypeByName(@Nullable String strName) { if (strName == null) { return null; } return DBType.valueOf(strName.toUpperCase()); }
static FinalSQLString getByKey(String key, Connection connection) throws PalantirSqlException { DBType type = DBType.getTypeFromConnection(connection); return getByKey(key, type); }
private void createTimestampTable(Connection connection) throws SQLException { try (Statement statement = connection.createStatement()) { if (getDbType(connection).equals(DBType.ORACLE)) { createTimestampTableIgnoringAlreadyExistsError(statement); } else { statement.execute(String.format("CREATE TABLE IF NOT EXISTS %s ( last_allocated int8 NOT NULL )", prefixedTimestampTableName())); } } }
/** * Looks up a DBType by name. Names are not case-sensitive. * * @param strName the name of the type to lookup, typically corresponds * to the type name, e.g. DBType.ORACLE.toString(); * @return the property DBType, or null if none exists */ @Nullable public static DBType getTypeByName(@Nullable String strName) { if (strName == null) { return null; } return DBType.valueOf(strName.toUpperCase()); }
/** * Sets the specified joda {@link DateTime} on the prepared statement. */ private static void setDateTime(Connection c, PreparedStatement ps, int i, DateTime dt) throws PalantirSqlException { // This method no longer attempts to store timezone information. Any // attempts to do so _must_ deal specifically with daylight savings time // (which caused issues for us before--see QA-14416 and QA-14625, and // the corresponding SVN revisions). long millis = dt.getMillis(); if (DBType.getTypeFromConnection(c) == DBType.POSTGRESQL) { //postgres has a smaller range of allowable timestamps if (millis < POSTGRES_BEGIN_RANGE) { millis = POSTGRES_BEGIN_RANGE; } if (millis > POSTGRES_END_RANGE) { millis = POSTGRES_END_RANGE; } } PreparedStatements.setTimestamp(ps, i, new Timestamp(millis)); }
AgnosticLightResultSet selectLightResultSetUnregisteredQueryWithFetchSize(Connection c, String sql, @Nullable Integer fetchSize, Object... vs) { return basicSql.selectLightResultSetSpecifyingDBType( c, SQLString.getUnregisteredQuery(sql), vs, DBType.getTypeFromConnection(c), fetchSize); } AgnosticLightResultSet selectLightResultSet(Connection c, String key, Object... vs)
AgnosticResultSet selectResultSetUnregisteredQuery(Connection c, String sql, Object... vs) throws PalantirSqlException, PalantirInterruptedException { return basicSql.selectResultSetSpecifyingDBType( c, SQLString.getUnregisteredQuery(sql), vs, DBType.getTypeFromConnection(c)); }
AgnosticResultSet selectResultSet(Connection c, String key, Object... vs) throws PalantirSqlException, PalantirInterruptedException { DBType dbType = DBType.getTypeFromConnection(c); return basicSql.selectResultSetSpecifyingDBType( c, SQLString.getByKey(key, dbType), vs, dbType); }
private void setOracleStructArray(Connection c, PreparedStatement ps, int paramIndex, ArrayHandler array) { Preconditions.checkArgument(DBType.getTypeFromConnection(c) == DBType.ORACLE); try { PreparedStatements.setObject(ps, paramIndex, array.toOracleArray(c)); } catch (SQLException e) { throw BasicSQL.handleInterruptions(0, e); } }
AgnosticLightResultSet selectLightResultSet(Connection c, RegisteredSQLString sql, Object... vs) throws PalantirSqlException, PalantirInterruptedException { DBType dbType = DBType.getTypeFromConnection(c); return basicSql.selectLightResultSetSpecifyingDBType( c, SQLString.getByKey(sql.getKey(), dbType), vs, dbType, null); }
assert DBType.getTypeFromConnection(c) != DBType.ORACLE : "numInsertedForRow: " + numInsertedForRow; //$NON-NLS-1$ return false;
if (DBType.getTypeFromConnection(c) == DBType.POSTGRESQL && is.getLength() > SQL.POSTGRES_BLOB_WRITE_LIMIT) { Validate.isTrue(false, "Postgres only supports blobs up to 1G"); //$NON-NLS-1$ return null; } else { DBType dbType = DBType.getTypeFromConnection(c); Validate.isTrue(dbType == DBType.ORACLE, "We only support blobs over 2GB on oracle (postgres only supports blobs up to 1G)"); //$NON-NLS-1$ BlobHandler blobHandler;
AgnosticLightResultSet selectLightResultSet(Connection c, FinalSQLString finalSql, Object... vs) throws PalantirSqlException { return basicSql.selectLightResultSetSpecifyingDBType( c, finalSql, vs, DBType.getTypeFromConnection(c), null); }
static FinalSQLString getByKey(String key, Connection connection) throws PalantirSqlException { DBType type = DBType.getTypeFromConnection(connection); return getByKey(key, type); }
/** * Sets the specified joda {@link DateTime} on the prepared statement. */ private static void setDateTime(Connection c, PreparedStatement ps, int i, DateTime dt) throws PalantirSqlException { // This method no longer attempts to store timezone information. Any // attempts to do so _must_ deal specifically with daylight savings time // (which caused issues for us before--see QA-14416 and QA-14625, and // the corresponding SVN revisions). long millis = dt.getMillis(); if (DBType.getTypeFromConnection(c) == DBType.POSTGRESQL) { //postgres has a smaller range of allowable timestamps if (millis < POSTGRES_BEGIN_RANGE) { millis = POSTGRES_BEGIN_RANGE; } if (millis > POSTGRES_END_RANGE) { millis = POSTGRES_END_RANGE; } } PreparedStatements.setTimestamp(ps, i, new Timestamp(millis)); }
AgnosticLightResultSet selectLightResultSetUnregisteredQueryWithFetchSize(Connection c, String sql, @Nullable Integer fetchSize, Object... vs) { return basicSql.selectLightResultSetSpecifyingDBType( c, SQLString.getUnregisteredQuery(sql), vs, DBType.getTypeFromConnection(c), fetchSize); } AgnosticLightResultSet selectLightResultSet(Connection c, String key, Object... vs)
AgnosticResultSet selectResultSetUnregisteredQuery(Connection c, String sql, Object... vs) throws PalantirSqlException, PalantirInterruptedException { return basicSql.selectResultSetSpecifyingDBType( c, SQLString.getUnregisteredQuery(sql), vs, DBType.getTypeFromConnection(c)); }
AgnosticResultSet selectResultSet(Connection c, String key, Object... vs) throws PalantirSqlException, PalantirInterruptedException { DBType dbType = DBType.getTypeFromConnection(c); return basicSql.selectResultSetSpecifyingDBType( c, SQLString.getByKey(key, dbType), vs, dbType); }