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 void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress, boolean deleteTables) throws SQLException, IOException { if(deleteTables) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation requestedTable = TableLocation.parse(tableReference, isH2); String table = requestedTable.getTable(); Statement stmt = connection.createStatement(); stmt.execute("DROP TABLE IF EXISTS " + table); stmt.close(); } importFile(connection, tableReference, fileName, progress); }
@Override public void importFile(Connection connection, String tableReference, File fileName, ProgressVisitor progress, boolean deleteTables) throws SQLException, IOException { if(deleteTables) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation requestedTable = TableLocation.parse(tableReference, isH2); String table = requestedTable.getTable(); Statement stmt = connection.createStatement(); stmt.execute("DROP TABLE IF EXISTS " + table); stmt.close(); } importFile(connection, tableReference, fileName, progress); }
@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 static void checkGeometryType(Connection connection, TableLocation tableName, int spatialFieldIndex) throws SQLException { final String fieldName = JDBCUtilities.getFieldName(connection.getMetaData(), tableName.getTable(), spatialFieldIndex); int geomType = SFSUtilities.getGeometryType(connection, tableName, fieldName); if (geomType != GeometryTypeCodes.LINESTRING) { throw new IllegalArgumentException(TYPE_ERROR + SFSUtilities.getGeometryTypeNameFromCode(geomType)); } }
private static void checkGeometryType(Connection connection, TableLocation tableName, int spatialFieldIndex) throws SQLException { final String fieldName = JDBCUtilities.getFieldName(connection.getMetaData(), tableName.getTable(), spatialFieldIndex); int geomType = SFSUtilities.getGeometryType(connection, tableName, fieldName); if (geomType != GeometryTypeCodes.LINESTRING) { throw new IllegalArgumentException(TYPE_ERROR + SFSUtilities.getGeometryTypeNameFromCode(geomType)); } }
@Override public boolean hasTableEditListener(String tableIdentifier) { TableLocation table = TableLocation.parse(tableIdentifier, isH2); if("PUBLIC".equals(table.getSchema()) && !tableEditionListener.containsKey(table.toString(true))) { // Maybe schema is not given in listener table identifier table = new TableLocation("","",table.getTable()); } String parsedTable = table.toString(isH2); return tableEditionListener.containsKey(parsedTable); }
@Override public boolean hasTableEditListener(String tableIdentifier) { TableLocation table = TableLocation.parse(tableIdentifier, isH2); if("PUBLIC".equals(table.getSchema()) && !tableEditionListener.containsKey(table.toString(true))) { // Maybe schema is not given in listener table identifier table = new TableLocation("","",table.getTable()); } String parsedTable = table.toString(isH2); return tableEditionListener.containsKey(parsedTable); }
/** * 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()); }
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
/** * 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
@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(); } }