private DefaultResultSetProvider(DataSource dataSource, ILayer layer) { this.dataSource = dataSource; this.layer = layer; try(Connection conn = dataSource.getConnection()) { pkName = MetaData.getPkName(conn, layer.getTableReference(), true); } catch (SQLException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } }
public static void createTableFromRowPkSelection(DataSource dataSource, String tableName, Set<Long> selectedRows, String newName, ProgressMonitor pm) throws SQLException { // Populate the new source try(Connection connection = dataSource.getConnection(); Statement st = connection.createStatement()) { DatabaseMetaData meta = connection.getMetaData(); // Find an unique name to register if (newName == null) { newName = MetaData.getNewUniqueName(tableName,meta,"selection"); } // Create row id table String tempTableName = CreateTable.createIndexTempTable(connection, pm, selectedRows,"ROWID", INSERT_BATCH_SIZE); PropertyChangeListener listener = EventHandler.create(PropertyChangeListener.class, st, "cancel"); pm.addPropertyChangeListener(ProgressMonitor.PROP_CANCEL, listener); // Copy content using pk String primaryKeyName = MetaData.getPkName(connection, tableName, true); StringBuilder pkEquality = new StringBuilder("a.%s = "); if (!primaryKeyName.equals(MetaData.POSTGRE_ROW_IDENTIFIER)) { pkEquality.append("b.ROWID"); } else { pkEquality.append(MetaData.castLongToTid("b.ROWID")); } st.execute(String.format("CREATE TABLE %s AS SELECT a.* FROM %s a,%s b " + "WHERE "+pkEquality, TableLocation.parse(newName), TableLocation.parse(tableName),tempTableName, primaryKeyName)); pm.removePropertyChangeListener(listener); } } }
public Object getUserValue() throws ParseException { String userInput = getValue(); return MetaData.castToSQLType(userInput, fieldType); } }
String pkName = MetaData.getPkName(connection, tableName, true); StringBuilder pkEquality = new StringBuilder("t1." + pkName + " = "); if (!pkName.equals(MetaData.POSTGRE_ROW_IDENTIFIER)) { pkEquality.append("t2.pk"); } else { pkEquality.append(MetaData.castLongToTid("t2.pk"));
tempTableName = MetaData.getNewUniqueName(tempTableName, connection.getMetaData(), ""); st.execute(String.format("CREATE LOCAL TEMPORARY TABLE %s("+columnName+" bigint primary key)", tempTableName));
/** * Show the selected field information */ public void onMenuShowInformation() { int col = popupCellAdress.x + 1; try(Connection connection = dataSource.getConnection()) { DatabaseMetaData meta = connection.getMetaData(); LOGGER.info(MetaData.getColumnInformations(meta, tableEditableElement.getTableReference(), col)); } catch( SQLException ex) { LOGGER.error(ex.getLocalizedMessage(),ex); } }
/** * Get the comparator to be used to retrieve the values sorted the best way. * @return A comparator that can be used with the keys of the associated mapping. */ public Comparator<String> getComparator(){ String fieldName = getFieldName(); try(Connection connection = getDataSource().getConnection()) { int type = MetaData.getFieldType(connection, getTable(), fieldName); return AbstractRecodedLegend.getComparator(type); } catch (SQLException e) { LOGGER.warn(I18N.tr("Can't build the analysis with an accurate comparator."),e); } return null; }
String pkName = MetaData.getPkName(connection, tableName, true); StringBuilder pkEquality = new StringBuilder("t1." + pkName + " = "); if (!pkName.equals(MetaData.POSTGRE_ROW_IDENTIFIER)) { pkEquality.append("t2.pk"); } else { pkEquality.append(MetaData.castLongToTid("t2.pk"));
tempTableName = MetaData.getNewUniqueName(tempTableName, connection.getMetaData(), ""); st.execute(String.format("CREATE LOCAL TEMPORARY TABLE %s("+columnName+" bigint primary key)", tempTableName));
/** * Show known column meta data using JDBC * @param meta DatabaseMetaData instance * @param tableReference Table identifier * @param colName Column name * @return Localised column information * @throws SQLException */ public static String getColumnInformationsByName(DatabaseMetaData meta, String tableReference, String colName) throws SQLException { TableLocation table = TableLocation.parse(tableReference); StringBuilder infos = new StringBuilder(); try(ResultSet rs = meta.getColumns(table.getCatalog(), table.getSchema(), table.getTable(), null)) { while (rs.next()) { String str = rs.getString("COLUMN_NAME"); if(str != null && str.equals(colName)){ infos.append(getColumnInformations(meta, tableReference, rs.getInt("ORDINAL_POSITION"))); } } } return infos.toString(); }
try(Connection connection = layer.getDataManager().getDataSource().getConnection()) { String f = leg.getLookupFieldName(); int type = MetaData.getFieldType(connection, table, f); leg.setComparator(AbstractRecodedLegend.getComparator(type)); } catch (SQLException e) {
this.pk_name = MetaData.getPkName(connection, location.toString(), true);
public static void createTableFromRowPkSelection(DataSource dataSource, String tableName, Set<Long> selectedRows, String newName, ProgressMonitor pm) throws SQLException { // Populate the new source try(Connection connection = dataSource.getConnection(); Statement st = connection.createStatement()) { DatabaseMetaData meta = connection.getMetaData(); // Find an unique name to register if (newName == null) { newName = MetaData.getNewUniqueName(tableName,meta,"selection"); } // Create row id table String tempTableName = CreateTable.createIndexTempTable(connection, pm, selectedRows,"ROWID", INSERT_BATCH_SIZE); PropertyChangeListener listener = EventHandler.create(PropertyChangeListener.class, st, "cancel"); pm.addPropertyChangeListener(ProgressMonitor.PROP_CANCEL, listener); // Copy content using pk String primaryKeyName = MetaData.getPkName(connection, tableName, true); StringBuilder pkEquality = new StringBuilder("a.%s = "); if (!primaryKeyName.equals(MetaData.POSTGRE_ROW_IDENTIFIER)) { pkEquality.append("b.ROWID"); } else { pkEquality.append(MetaData.castLongToTid("b.ROWID")); } st.execute(String.format("CREATE TABLE %s AS SELECT a.* FROM %s a,%s b " + "WHERE "+pkEquality, TableLocation.parse(newName), TableLocation.parse(tableName),tempTableName, primaryKeyName)); pm.removePropertyChangeListener(listener); } } }
parent, message.getText(), MetaData.getNewUniqueName(sourceTable, meta, TableLocation.capsIdentifier(I18N.tr("selection"), isH2)));
public Object getUserValue() throws ParseException { String userInput = getValue(); return MetaData.castToSQLType(userInput, fieldType); } }
this.pk_name = MetaData.getPkName(connection, location.toString(), true);
parent, message.getText(), MetaData.getNewUniqueName(sourceTable, meta, TableLocation.capsIdentifier(I18N.tr("selection"), isH2)));
/** * Get all fields * @return A valid row * @throws ParseException If the type conversion failed */ public Object[] getRow() throws ParseException { Object[] ret = new Object[fieldCount]; for (int i = 0; i < ret.length; i++) { String input = getInput("f" + i); ret[i] = MetaData.castToSQLType(input, types.get(i)); } return ret; }
String pkName = MetaData.getPkName(connection, tableLocation.toString(), true); boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); if(!pkName.isEmpty()) {
/** * Get all fields * @return A valid row * @throws ParseException If the type conversion failed */ public Object[] getRow() throws ParseException { Object[] ret = new Object[fieldCount]; for (int i = 0; i < ret.length; i++) { String input = getInput("f" + i); ret[i] = MetaData.castToSQLType(input, types.get(i)); } return ret; }