private static void upsertBaseColumnCountInHeaderRow(PhoenixConnection metaConnection, String tenantId, String schemaName, String viewOrTableName, int baseColumnCount) throws SQLException { try (PreparedStatement stmt = metaConnection.prepareStatement(UPSERT_BASE_COLUMN_COUNT_IN_HEADER_ROW)) { stmt.setString(1, tenantId); stmt.setString(2, schemaName); stmt.setString(3, viewOrTableName); stmt.setString(4, null); stmt.setString(5, null); stmt.setInt(6, baseColumnCount); stmt.executeUpdate(); } }
private void mutateBooleanProperty(String tenantId, String schemaName, String tableName, String propertyName, boolean propertyValue) throws SQLException { String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " + TENANT_ID + "," + TABLE_SCHEM + "," + TABLE_NAME + "," + propertyName + ") VALUES (?, ?, ?, ?)"; try (PreparedStatement tableBoolUpsert = connection.prepareStatement(updatePropertySql)) { tableBoolUpsert.setString(1, tenantId); tableBoolUpsert.setString(2, schemaName); tableBoolUpsert.setString(3, tableName); tableBoolUpsert.setBoolean(4, propertyValue); tableBoolUpsert.execute(); } }
private void mutateStringProperty(String tenantId, String schemaName, String tableName, String propertyName, String propertyValue) throws SQLException { String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " + TENANT_ID + "," + TABLE_SCHEM + "," + TABLE_NAME + "," + propertyName + ") VALUES (?, ?, ?, ?)"; try (PreparedStatement tableBoolUpsert = connection.prepareStatement(updatePropertySql)) { tableBoolUpsert.setString(1, tenantId); tableBoolUpsert.setString(2, schemaName); tableBoolUpsert.setString(3, tableName); tableBoolUpsert.setString(4, propertyValue); tableBoolUpsert.execute(); } }
@Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { checkOpen(); // Ignore autoGeneratedKeys, and just execute the statement. return prepareStatement(sql); }
@Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { checkOpen(); // Ignore columnIndexes, and just execute the statement. return prepareStatement(sql); }
@Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { checkOpen(); // Ignore columnNames, and just execute the statement. return prepareStatement(sql); }
@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { checkOpen(); if (resultSetHoldability != ResultSet.CLOSE_CURSORS_AT_COMMIT) { throw new SQLFeatureNotSupportedException(); } return prepareStatement(sql, resultSetType, resultSetConcurrency); }
@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) { throw new SQLFeatureNotSupportedException(); } return prepareStatement(sql); }
private void mutateByteProperty(String tenantId, String schemaName, String tableName, String propertyName, Byte propertyValue) throws SQLException { String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " + TENANT_ID + "," + TABLE_SCHEM + "," + TABLE_NAME + "," + propertyName + ") VALUES (?, ?, ?, ?)"; try (PreparedStatement tableBoolUpsert = connection.prepareStatement(updatePropertySql)) { tableBoolUpsert.setString(1, tenantId); tableBoolUpsert.setString(2, schemaName); tableBoolUpsert.setString(3, tableName); if (propertyValue == null) { tableBoolUpsert.setNull(4, Types.TINYINT); } else { tableBoolUpsert.setByte(4, propertyValue); } tableBoolUpsert.execute(); } }
private void mutateLongProperty(String tenantId, String schemaName, String tableName, String propertyName, Long propertyValue) throws SQLException { String updatePropertySql = "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " + TENANT_ID + "," + TABLE_SCHEM + "," + TABLE_NAME + "," + propertyName + ") VALUES (?, ?, ?, ?)"; try (PreparedStatement tableBoolUpsert = connection.prepareStatement(updatePropertySql)) { tableBoolUpsert.setString(1, tenantId); tableBoolUpsert.setString(2, schemaName); tableBoolUpsert.setString(3, tableName); if (propertyValue == null) { tableBoolUpsert.setNull(4, Types.BIGINT); } else { tableBoolUpsert.setLong(4, propertyValue); } tableBoolUpsert.execute(); } }
public static void deleteTask(PhoenixConnection conn, TaskType taskType, Timestamp ts, String tenantId, String schemaName, String tableName, boolean accessCheckEnabled) throws IOException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement("DELETE FROM " + PhoenixDatabaseMetaData.SYSTEM_TASK_NAME + " WHERE " + PhoenixDatabaseMetaData.TASK_TYPE + " = ? AND " + PhoenixDatabaseMetaData.TASK_TS + " = ? AND " + PhoenixDatabaseMetaData.TENANT_ID + (tenantId == null ? " IS NULL " : " = '" + tenantId + "'") + " AND " + PhoenixDatabaseMetaData.TABLE_SCHEM + (schemaName == null ? " IS NULL " : " = '" + schemaName + "'") + " AND " + PhoenixDatabaseMetaData.TABLE_NAME + " = ?"); stmt.setByte(1, taskType.getSerializedValue()); stmt.setTimestamp(2, ts); stmt.setString(3, tableName); } catch (SQLException e) { throw new IOException(e); } mutateSystemTaskTable(conn, stmt, accessCheckEnabled); }
public static void addTask(PhoenixConnection conn, TaskType taskType, String tenantId, String schemaName, String tableName, boolean accessCheckEnabled) throws IOException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement("UPSERT INTO " + PhoenixDatabaseMetaData.SYSTEM_TASK_NAME + " ( " + PhoenixDatabaseMetaData.TASK_TYPE + ", " + PhoenixDatabaseMetaData.TENANT_ID + ", " + PhoenixDatabaseMetaData.TABLE_SCHEM + ", " + PhoenixDatabaseMetaData.TABLE_NAME + " ) VALUES(?,?,?,?)"); stmt.setByte(1, taskType.getSerializedValue()); if (tenantId != null) { stmt.setString(2, tenantId); } else { stmt.setNull(2, Types.VARCHAR); } if (schemaName != null) { stmt.setString(3, schemaName); } else { stmt.setNull(3, Types.VARCHAR); } stmt.setString(4, tableName); } catch (SQLException e) { throw new IOException(e); } mutateSystemTaskTable(conn, stmt, accessCheckEnabled); }
private void upsertRows(PhoenixConnection conn, String fullTableName) throws SQLException { PreparedStatement stmt = conn.prepareStatement("upsert into " + fullTableName + " (organization_id, entity_id, score) values (?,?,?)"); for (int i = 0; i < 10000; i++) { stmt.setString(1, "AAAA" + i); stmt.setString(2, "BBBB" + i); stmt.setInt(3, 1); stmt.execute(); } }
private void upsertRows(PhoenixConnection conn, String fullTableName) throws SQLException { PreparedStatement stmt = conn.prepareStatement("upsert into " + fullTableName + " (organization_id, entity_id, score) values (?,?,?)"); for (int i = 0; i < 4; i++) { stmt.setString(1, "AAAA" + i); stmt.setString(2, "BBBB" + i); stmt.setInt(3, 1); stmt.execute(); } }
+ PhoenixDatabaseMetaData.COLUMN_NAME + "," + PhoenixDatabaseMetaData.NULLABLE + ") VALUES (null, ?, ?, ?, ?)"; PreparedStatement stmt = metaConnection.prepareStatement(dml); stmt.setString(1, schemaName); stmt.setString(2, tableName);
updateLinkSql += " AND TENANT_ID = ? "; PreparedStatement updateLinkStatment = conn.prepareStatement(updateLinkSql); updateLinkStatment.setString(1, schemaName.getString()); updateLinkStatment.setString(2, schemaName.getString()); deleteLinkSql += (" AND TENANT_ID = ? "); PreparedStatement deleteLinkStatment = conn.prepareStatement(deleteLinkSql); deleteLinkStatment.setString(1, schemaName.getString()); deleteLinkStatment.setString(2, schemaName.getString());
private static byte[] getRange(PhoenixConnection pconn, List<Object> startValues) throws SQLException { byte[] lowerRange; if (startValues == null) { lowerRange = KeyRange.UNBOUND; } else { String upsertValues = StringUtils.repeat("?,", startValues.size()).substring(0,startValues.size() * 2 - 1); String upsertStmt = "UPSERT INTO T VALUES(" + upsertValues + ")"; PreparedStatement stmt = pconn.prepareStatement(upsertStmt); for (int i = 0; i < startValues.size(); i++) { stmt.setObject(i+1, startValues.get(i)); } stmt.execute(); Cell startCell = PhoenixRuntime.getUncommittedDataIterator(pconn).next().getSecond().get(0); lowerRange = CellUtil.cloneRow(startCell); pconn.rollback(); } return lowerRange; }
PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next());
private static void assertUseStatsForQueryFlag(String tableName, PhoenixConnection conn, Boolean expected) throws TableNotFoundException, SQLException { assertEquals(expected, conn.unwrap(PhoenixConnection.class).getMetaDataCache() .getTableRef(new PTableKey(null, tableName)).getTable() .useStatsForParallelization()); String query = "SELECT USE_STATS_FOR_PARALLELIZATION FROM SYSTEM.CATALOG WHERE TABLE_NAME = ? AND COLUMN_NAME IS NULL AND COLUMN_FAMILY IS NULL AND TENANT_ID IS NULL"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, tableName); ResultSet rs = stmt.executeQuery(); rs.next(); boolean b = rs.getBoolean(1); if (expected == null) { assertTrue(rs.wasNull()); } else { assertEquals(expected, b); } }
.prepareStatement("SELECT ID, VALARRAY FROM ARRAY_TABLE"); ResultSet phoenixResultSet = statement.executeQuery(); assertTrue(phoenixResultSet.next());