@Override public List<GenericSequence> loadSequences( @NotNull DBRProgressMonitor monitor, @NotNull GenericStructContainer container) throws DBException { try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read sequences")) { try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM INFORMATION_SCHEMA.SEQUENCES")) { List<GenericSequence> result = new ArrayList<>(); try (JDBCResultSet dbResult = dbStat.executeQuery()) { while (dbResult.next()) { String name = JDBCUtils.safeGetString(dbResult, "SEQUENCE_NAME"); if (name == null) { continue; } String description = JDBCUtils.safeGetString(dbResult, "REMARKS"); GenericSequence sequence = new GenericSequence( container, name, description, JDBCUtils.safeGetLong(dbResult, "CURRENT_VALUE"), JDBCUtils.safeGetLong(dbResult, "MIN_VALUE"), JDBCUtils.safeGetLong(dbResult, "MAX_VALUE"), JDBCUtils.safeGetLong(dbResult, "INCREMENT")); result.add(sequence); } } return result; } } catch (SQLException e) { throw new DBException(e, container.getDataSource()); } }
@Override public void bindParameter( JDBCSession session, JDBCPreparedStatement preparedStatement, DBSTypedObject columnType, int paramIndex) throws DBCException { try { if (storage != null) { try (InputStream streamReader = storage.getContentStream()) { final Object xmlObject = createXmlObject(session, streamReader); preparedStatement.setObject(paramIndex, xmlObject); } } else { preparedStatement.setNull(paramIndex, java.sql.Types.SQLXML); } } catch (SQLException e) { throw new DBCException(e, session.getDataSource()); } catch (IOException e) { throw new DBCException("IO error while reading XML", e); } }
@Override public String getViewDDL(DBRProgressMonitor monitor, GenericTable sourceObject) throws DBException { GenericDataSource dataSource = sourceObject.getDataSource(); try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read H2 view source")) { try (JDBCPreparedStatement dbStat = session.prepareStatement( "SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS " + "WHERE TABLE_SCHEMA=? AND TABLE_NAME=?")) { dbStat.setString(1, sourceObject.getContainer().getName()); dbStat.setString(2, sourceObject.getName()); try (JDBCResultSet dbResult = dbStat.executeQuery()) { if (dbResult.nextRow()) { return dbResult.getString(1); } return "-- H2 view definition not found"; } } } catch (SQLException e) { throw new DBException(e, dataSource); } }
public static boolean logObjectErrors( JDBCSession session, DBCCompileLog compileLog, OracleSourceObject unit, OracleObjectType objectType) { try { try (JDBCPreparedStatement dbStat = session.prepareStatement( "SELECT * FROM SYS.ALL_ERRORS WHERE OWNER=? AND NAME=? AND TYPE=? ORDER BY SEQUENCE")) { dbStat.setString(1, unit.getSchema().getName()); dbStat.setString(2, unit.getName()); dbStat.setString(3, objectType.getTypeName()); try (ResultSet dbResult = dbStat.executeQuery()) { boolean hasErrors = false; while (dbResult.next()) { DBCCompileError error = new DBCCompileError( "ERROR".equals(dbResult.getString("ATTRIBUTE")), dbResult.getString("TEXT"), dbResult.getInt("LINE"), dbResult.getInt("POSITION")); hasErrors = true; if (error.isError()) { compileLog.error(error); } else { compileLog.warn(error); } } return !hasErrors; } } } catch (Exception e) { log.error("Can't read user errors", e); return false; } }
// ------------------------ // Constructors // ------------------------ public DB2CurrentUserPrivileges( DBRProgressMonitor monitor, JDBCSession session, String currentAuthId, DB2DataSource db2DataSource) throws SQLException { // DF: There is no easy way to get this information from DB2 v9.1 // WE consider the user has no system authorities listAuthorities = new ArrayList<>(); if (db2DataSource.isAtLeastV9_5()) { try (JDBCPreparedStatement dbStat = session.prepareStatement(SEL_AUTHORITIES)) { dbStat.setString(1, currentAuthId); try (JDBCResultSet dbResult = dbStat.executeQuery()) { while (dbResult.next()) { listAuthorities.add(dbResult.getString(1)); } } } } listObjectPrivileges = new ArrayList<>(); try (JDBCPreparedStatement dbStat = session.prepareStatement(SEL_OBJECTS)) { dbStat.setString(1, currentAuthId); dbStat.setString(2, currentAuthId); try (JDBCResultSet dbResult = dbStat.executeQuery()) { while (dbResult.next()) { listObjectPrivileges.add(dbResult.getString(1)); } } } // Cache Authorities userIsAuthorisedForApplications = computeUserIsAuthorisedForApplications(); userIsAuthorisedForDBCFG = computeUserIsAuthorisedForDBCFG(); userIsAuthorisedForAdminister = userIsAuthorisedForApplications || userIsAuthorisedForDBCFG; userIsAuthorisedForContainers = computeUserIsAuthorisedForContainers(); }