public AskValidValue(DataSource ds,String tableReference, String fieldName) throws SQLException { super("Field '" + fieldName + "'", null, null); try(Connection connection = ds.getConnection()) { DatabaseMetaData meta = connection.getMetaData(); TableLocation location = TableLocation.parse(tableReference); try(ResultSet rs = meta.getColumns(location.getCatalog(), location.getSchema(), location.getTable(), fieldName)) { if(rs.next()) { this.fieldType = rs.getInt("DATA_TYPE"); } } } }
public AskValidValue(DataSource ds,String tableReference, String fieldName) throws SQLException { super("Field '" + fieldName + "'", null, null); try(Connection connection = ds.getConnection()) { DatabaseMetaData meta = connection.getMetaData(); TableLocation location = TableLocation.parse(tableReference); try(ResultSet rs = meta.getColumns(location.getCatalog(), location.getSchema(), location.getTable(), fieldName)) { if(rs.next()) { this.fieldType = rs.getInt("DATA_TYPE"); } } } }
@Override public boolean isTableExists(String tableName) throws SQLException { TableLocation tableLocation = TableLocation.parse(tableName); try (Connection connection = dataSource.getConnection(); ResultSet rs = connection.getMetaData().getTables(tableLocation.getCatalog(), tableLocation.getSchema(), tableLocation.getTable(), null)) { return rs.next(); } }
@Override public boolean isTableExists(String tableName) throws SQLException { TableLocation tableLocation = TableLocation.parse(tableName); try (Connection connection = dataSource.getConnection(); ResultSet rs = connection.getMetaData().getTables(tableLocation.getCatalog(), tableLocation.getSchema(), tableLocation.getTable(), null)) { return rs.next(); } }
private boolean isPrimaryKey(String columnName) throws SQLException { TableLocation tableLocation = TableLocation.parse(tableEditableElement.getTableReference()); try(Connection connection = dataSource.getConnection(); ResultSet rs = connection.getMetaData().getPrimaryKeys(tableLocation.getCatalog(null), tableLocation.getSchema(null), tableLocation.getTable())) { while (rs.next()) { // If the schema is not specified, public must be the schema if (!tableLocation.getSchema().isEmpty() || "public".equalsIgnoreCase(rs.getString("TABLE_SCHEM"))) { if (columnName.equals(rs.getString("COLUMN_NAME"))) { return true; } } } } return false; }
/** * Add the fields. */ private void addFields() { TableLocation tableLocation = TableLocation.parse(tableIdentifier); try(Connection connection = dataSource.getConnection(); ResultSet rs = connection.getMetaData().getColumns(tableLocation.getCatalog(), tableLocation.getSchema(), tableLocation.getTable(), null)) { while(rs.next()) { if (canAddField(rs.getInt("ORDINAL_POSITION"), rs.getInt("DATA_TYPE"), rs.getString("TYPE_NAME"))) { addItem(rs.getString("COLUMN_NAME")); } } } catch (SQLException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } }
/** * Suffix a TableLocation * * @param inputTable Input table * @param suffix Suffix * * @return suffixed TableLocation */ public static TableLocation suffixTableLocation(TableLocation inputTable, String suffix) { return new TableLocation(inputTable.getCatalog(), inputTable.getSchema(), inputTable.getTable() + suffix); }
/** * Find geometry fields name of a table. * @param connection Active connection * @param location Table location * @return A list of Geometry fields name * @throws SQLException */ public static List<String> getGeometryFields(Connection connection,TableLocation location) throws SQLException { return getGeometryFields(connection, location.getCatalog(), location.getSchema(), location.getTable()); }
/** * Find geometry fields name of a table. * @param connection Active connection * @param location Table location * @return A list of Geometry fields name * @throws SQLException */ public static List<String> getGeometryFields(Connection connection,TableLocation location) throws SQLException { return getGeometryFields(connection, location.getCatalog(), location.getSchema(), location.getTable()); }
private static String getH2TriggerName(String table) { TableLocation tableIdentifier = TableLocation.parse(table, true); return new TableLocation(tableIdentifier.getCatalog(), tableIdentifier.getSchema(), "DM_"+tableIdentifier.getTable()).toString(true); } @Override
/** * Suffix a TableLocation * * @param inputTable Input table * @param suffix Suffix * @return suffixed TableLocation */ public static TableLocation suffixTableLocation(TableLocation inputTable, String suffix) { return new TableLocation(inputTable.getCatalog(), inputTable.getSchema(), inputTable.getTable() + suffix); }
private static String getH2TriggerName(String table) { TableLocation tableIdentifier = TableLocation.parse(table, true); return new TableLocation(tableIdentifier.getCatalog(), tableIdentifier.getSchema(), "DM_"+tableIdentifier.getTable()).toString(true); } @Override
/** * Suffix a TableLocation * * @param inputTable Input table * @param suffix Suffix * @return suffixed TableLocation */ public static TableLocation suffixTableLocation(TableLocation inputTable, String suffix) { return new TableLocation(inputTable.getCatalog(), inputTable.getSchema(), inputTable.getTable() + suffix); } }
/** * Find geometry fields name of a table. * * @param connection Active connection * @param location Table location * * @return A list of Geometry fields name * * @throws SQLException */ public static List<String> getGeometryFields(Connection connection,TableLocation location) throws SQLException { return getGeometryFields(connection, location.getCatalog(), location.getSchema(), location.getTable()); }
@Override public String findUniqueTableName(String originalTableName) throws SQLException { TableLocation tableLocation = TableLocation.parse(originalTableName); String tableName = originalTableName; int offset = 0; while(isTableExists(tableName)) { tableName = new TableLocation(tableLocation.getCatalog(), tableLocation.getSchema(), tableLocation.getTable() + "_" + ++offset).toString(); } return tableName; }
private ResultSet getFunctionData(DatabaseMetaData metaData) throws SQLException { TableLocation functionLocation = TableLocation.parse(functionName); return metaData.getProcedureColumns( functionLocation.getCatalog(null), functionLocation.getSchema(null), functionLocation.getTable(), null); }
/** * Return the table identifier in the best fit depending on database type * * @param requestedTable Catalog and schema used * @param tableName Table without quotes * @param isH2 True if H2, false if PostGRES * @return Find table identifier */ private static String caseIdentifier(TableLocation requestedTable, String tableName, boolean isH2) { return new TableLocation(requestedTable.getCatalog(), requestedTable.getSchema(), TableLocation.parse(tableName, isH2).getTable()).toString(); }
/** * Return the table identifier in the best fit depending on database type * * @param requestedTable Catalog and schema used * @param tableName Table without quotes * @param isH2 True if H2, false if PostGRES * @return Find table identifier */ private static String caseIdentifier(TableLocation requestedTable, String tableName, boolean isH2) { return new TableLocation(requestedTable.getCatalog(), requestedTable.getSchema(), TableLocation.parse(tableName, isH2).getTable()).toString(); }
/** * Return the table identifier in the best fit depending on database type * * @param requestedTable Catalog and schema used * @param tableName Table without quotes * @param isH2 True if H2, false if PostGRES * @return Find table identifier */ public static String caseIdentifier(TableLocation requestedTable, String tableName, boolean isH2) { return new TableLocation(requestedTable.getCatalog(), requestedTable.getSchema(), TableLocation.parse(tableName, isH2).getTable()).toString(); } }
/** * Return the table identifier in the best fit depending on database type * * @param requestedTable Catalog and schema used * @param tableName Table without quotes * @param isH2 True if H2, false if PostGRES * * @return Find table identifier */ public static String caseIdentifier(TableLocation requestedTable, String tableName, boolean isH2) { return new TableLocation(requestedTable.getCatalog(), requestedTable.getSchema(), TableLocation.parse(tableName, isH2).getTable()).toString(); } }