@Override public Object getLastAutoGeneratedValue( String schemaName, String tableName, String columnName, Connection cx) throws SQLException { Statement st = cx.createStatement(); try { String sql = "SELECT last_insert_id()"; dataStore.getLogger().fine(sql); ResultSet rs = st.executeQuery(sql); try { if (rs.next()) { return rs.getLong(1); } } finally { dataStore.closeSafe(rs); } } finally { dataStore.closeSafe(st); } return null; }
/** * Creates a new database index * * @param index * @throws IOException */ public void createIndex(Index index) throws IOException { SimpleFeatureType schema = getSchema(index.typeName); Connection cx = null; try { cx = getConnection(Transaction.AUTO_COMMIT); dialect.createIndex(cx, schema, databaseSchema, index); } catch (SQLException e) { throw new IOException("Failed to create index", e); } finally { closeSafe(cx); } }
MBTilesFile(JDBCDataStore dataStore) { this.dataStore = dataStore; this.connPool = dataStore.getDataSource(); }
if (jstore.getVirtualTables().containsValue(vt)) { ft = jstore.getSchema(vt.getName()); if (!jstore.getVirtualTables().containsValue(vt)) { ft = null; jstore.createVirtualTable(new VirtualTable(temporaryName.getLocalPart(), vt)); return true; } else { jstore.createVirtualTable(vt);
/** Checks whether the tableName corresponds to a view */ boolean isView(DatabaseMetaData metaData, String databaseSchema, String tableName) throws SQLException { ResultSet tables = null; try { tables = metaData.getTables( null, escapeNamePattern(metaData, databaseSchema), escapeNamePattern(metaData, tableName), new String[] {"VIEW"}); return tables.next(); } finally { closeSafe(tables); } }
private void setIsLimitOffsetSupported() { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = dataStore.getDataSource().getConnection(); ps = con.prepareStatement(SELECT_LIMITOFFSET); rs = ps.executeQuery(); if (rs.next()) isLimitOffsetSupported = Boolean.TRUE; LOGGER.info(LIMITOFFSET_MESSAGE); } catch (SQLException ex) { isLimitOffsetSupported = Boolean.FALSE; } finally { try { if (rs != null) rs.close(); } catch (SQLException ex1) { } try { if (ps != null) ps.close(); } catch (SQLException ex1) { } try { if (con != null) con.close(); } catch (SQLException ex1) { } } }
Connection con = null; try { con = dataStore.getDataSource().getConnection(); DB2DialectInfo di = ((DB2SQLDialectPrepared) dataStore.getSQLDialect()).getDb2DialectInfo(); DB2SQLDialectPrepared dialect = (DB2SQLDialectPrepared) dataStore.getSQLDialect(); Boolean loose = (Boolean) LOOSEBBOX.lookUp(params); dialect.setLooseBBOXEnabled(loose == null || Boolean.TRUE.equals(loose)); dialect.setUseSelectivity(Boolean.TRUE.equals(selectivity)); di.setProductVersion(md.getDatabaseProductVersion()); if (dataStore.getDatabaseSchema() == null) { ps = con.prepareStatement(GetCurrentSchema); rs = ps.executeQuery(); rs.next(); dataStore.setDatabaseSchema(rs.getString(1)); rs.close(); ps.close(); throw new IOException(e.getMessage()); dataStore.closeSafe(con); return dataStore;
private Integer readIntegerFromStatement(Connection cx, String sql, List<String> parameters) throws SQLException { PreparedStatement userSdoStatement = null; ResultSet userSdoResult = null; try { LOGGER.log( Level.FINE, "SRID check; {0} [ parameters = {1} ]", new Object[] {sql, parameters}); userSdoStatement = cx.prepareStatement(sql); for (int i = 0; i < parameters.size(); i++) { userSdoStatement.setString(i + 1, parameters.get(i)); } userSdoResult = userSdoStatement.executeQuery(); if (userSdoResult.next()) { Object intValue = userSdoResult.getObject(1); if (intValue != null) { return ((Number) intValue).intValue(); } } } finally { dataStore.closeSafe(userSdoResult); dataStore.closeSafe(userSdoStatement); } return null; }
+ " ind.type_desc = 'SPATIAL'\n" + " and t.name = '" + featureType.getTypeName() + "'"; ResultSet indexInfo = null; Map<String, Set<String>> indexes = new HashMap<String, Set<String>>(); try { st = cx.createStatement(); indexInfo = st.executeQuery(sql); while (indexInfo.next()) { String indexName = indexInfo.getString("index_name"); String columnName = indexInfo.getString("column_name"); Set<String> indexColumns = indexes.get(indexName); if (indexColumns == null) { dataStore.closeSafe(st); dataStore.closeSafe(indexInfo); if (columns.size() == 1) { String column = columns.iterator().next(); AttributeDescriptor descriptor = featureType.getDescriptor(column); if (descriptor instanceof GeometryDescriptor) { descriptor.getUserData().put(SPATIAL_INDEX_KEY, entry.getKey());
/** * Returns the PostGIS version * * @return */ public Version getVersion(Connection conn) throws SQLException { if (version == null) { Statement st = null; ResultSet rs = null; try { st = conn.createStatement(); rs = st.executeQuery("select PostGIS_Lib_Version()"); if (rs.next()) { version = new Version(rs.getString(1)); } } finally { dataStore.closeSafe(rs); dataStore.closeSafe(st); } } return version; }
@Override public Object getLastAutoGeneratedValue( String schemaName, String tableName, String columnName, Connection cx) throws SQLException { StringBuffer sql = new StringBuffer("SELECT TOP 1 "); encodeColumnName(columnName, sql); sql.append(" FROM "); encodeTableName(schemaName, tableName, sql); sql.append(" ORDER BY "); encodeColumnName(columnName, sql); sql.append(" DESC"); LOGGER.fine(sql.toString()); PreparedStatement ps = cx.prepareStatement(sql.toString()); try { ResultSet rs = ps.executeQuery(); try { if (rs.next()) { return rs.getInt(1); } } finally { dataStore.closeSafe(rs); } } finally { dataStore.closeSafe(ps); } return null; }
InProcessLockingManager lm = (InProcessLockingManager) getLockingManager(); Set<FeatureId> ids = getLockedIds(locks); Id lockFilter = getFilterFactory().id(ids); filter = getFilterFactory().and(filter, lockFilter); if (getSQLDialect() instanceof PreparedStatementSQLDialect) { st = selectSQLPS(featureType, query, cx); ((PreparedStatementSQLDialect) getSQLDialect()).onSelect(ps, cx, featureType); rs = ps.executeQuery(); } else { String sql = selectSQL(featureType, query); st = cx.createStatement(); st.setFetchSize(fetchSize); ((BasicSQLDialect) getSQLDialect()).onSelect(st, cx, featureType); PrimaryKey key = getPrimaryKey(featureType); while (rs.next()) { String fid = featureType.getTypeName() + "." + encodeFID(key, rs); lm.assertAccess(featureType.getTypeName(), fid, tx); closeSafe(rs); closeSafe(st);
@Override public boolean includeTable(String schemaName, String tableName, Connection cx) throws SQLException { Statement st = cx.createStatement(); try { ResultSet rs = st.executeQuery( String.format( "SELECT * FROM gpkg_contents WHERE" + " table_name = '%s' AND data_type = '%s'", tableName, DataType.Feature.value())); try { return rs.next(); } finally { rs.close(); } } finally { dataStore.closeSafe(st); } }
sql.append("."); sql.append(escape).append(schema.getTypeName()).append(escape); st = cx.createStatement(); st.execute(sql.toString()); if (!cx.getAutoCommit()) { cx.commit(); dataStore.closeSafe(cx);
@Override public void postDropTable(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException { PreparedStatement st = null; String tableName = featureType.getTypeName(); try { // remove all the geometry metadata (no need for schema as we can only play against // the current user's table) String sql = "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = ?"; st = cx.prepareStatement(sql); st.setString(1, tableName); LOGGER.log( Level.FINE, "Post drop table: {0} [ TABLE_NAME = {1} ]", new Object[] {sql, tableName}); st.execute(); } finally { dataStore.closeSafe(st); } }
@Override public void postDropTable(String schemaName, SimpleFeatureType featureType, Connection cx) throws SQLException { Statement st = cx.createStatement(); String tableName = featureType.getTypeName(); try { // remove all the geometry_column entries String sql = "DELETE FROM GEOMETRY_COLUMNS" + " WHERE f_table_catalog=''" // + " AND f_table_schema = '" + schemaName + "'" + " AND f_table_name = '" + tableName + "'"; LOGGER.fine(sql); st.execute(sql); } finally { dataStore.closeSafe(st); } }
Connection con = null; try { con = dataStore.getDataSource().getConnection(); int major = con.getMetaData().getDatabaseMajorVersion(); int minor = con.getMetaData().getDatabaseMinorVersion(); if (major > 5 || (major == 5 && minor > 6)) { isMySQLVersion56OrAbove = true; } finally { try { if (con != null && !con.isClosed()) { con.close();
public void onBorrow(JDBCDataStore store, Connection cx) throws SQLException { if (sqlOnBorrow != null && !"".equals(sqlOnBorrow)) { String command = sqlOnBorrow.evaluate(null, String.class); Statement st = null; try { st = cx.createStatement(); st.execute(command); } finally { store.closeSafe(st); } } }
/** Deletes an existing feature(s) in the database for a particular feature type / table. */ protected void delete(SimpleFeatureType featureType, Filter filter, Connection cx) throws IOException { Statement st = null; try { try { if (dialect instanceof PreparedStatementSQLDialect) { st = deleteSQLPS(featureType, filter, cx); PreparedStatement ps = (PreparedStatement) st; ((PreparedStatementSQLDialect) dialect).onDelete(ps, cx, featureType); ps.execute(); } else { String sql = deleteSQL(featureType, filter); st = cx.createStatement(); ((BasicSQLDialect) dialect).onDelete(st, cx, featureType); LOGGER.log(Level.FINE, "Removing feature(s): {0}", sql); st.execute(sql); } } finally { closeSafe(st); } } catch (SQLException e) { String msg = "Error occured during delete"; throw (IOException) new IOException(msg).initCause(e); } }
public JDBCFeatureReader( String sql, Connection cx, JDBCFeatureSource featureSource, SimpleFeatureType featureType, Query query) throws SQLException { init(featureSource, featureType, query); // create the result set this.cx = cx; st = cx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); st.setFetchSize(featureSource.getDataStore().getFetchSize()); ((BasicSQLDialect) featureSource.getDataStore().getSQLDialect()) .onSelect(st, cx, featureType); runQuery(() -> st.executeQuery(sql), st); }