use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class FireBirdMetaModel method loadSequences.
@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 RDB$GENERATOR_NAME,RDB$DESCRIPTION FROM RDB$GENERATORS")) {
List<GenericSequence> result = new ArrayList<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, 1);
if (name == null) {
continue;
}
name = name.trim();
String description = JDBCUtils.safeGetString(dbResult, 2);
GenericSequence sequence = new GenericSequence(container, name, description, -1, 0, -1, 1);
result.add(sequence);
}
}
// Obtain sequence values
for (GenericSequence sequence : result) {
try (JDBCPreparedStatement dbSeqStat = session.prepareStatement("SELECT GEN_ID(" + sequence.getName() + ", 0) from RDB$DATABASE")) {
try (JDBCResultSet seqResults = dbSeqStat.executeQuery()) {
seqResults.next();
sequence.setLastValue(JDBCUtils.safeGetLong(seqResults, 1));
}
}
}
return result;
}
} catch (SQLException e) {
throw new DBException(e, container.getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class InformixMetaModel method loadTriggers.
@Override
public List<? extends GenericTrigger> loadTriggers(DBRProgressMonitor monitor, @NotNull GenericStructContainer container, @Nullable GenericTable table) throws DBException {
assert table != null;
try (JDBCSession session = DBUtils.openMetaSession(monitor, container.getDataSource(), "Read triggers")) {
String query = "SELECT T1.trigname \n" + "FROM informix.systriggers AS T1, informix.systables AS T2 \n" + "WHERE T2.tabid = T1.tabid AND T2.tabname = ?";
try (JDBCPreparedStatement dbStat = session.prepareStatement(query)) {
dbStat.setString(2, table.getName());
List<GenericTrigger> result = new ArrayList<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, 1);
if (name == null) {
continue;
}
name = name.trim();
GenericTrigger trigger = new GenericTrigger(container, table, name, null);
result.add(trigger);
}
}
return result;
}
} catch (SQLException e) {
throw new DBException(e, container.getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class SQLServerMetaModel method extractSource.
private String extractSource(DBRProgressMonitor monitor, GenericDataSource dataSource, String catalog, String schema, String name) throws DBException {
ServerType serverType = getServerType(monitor, dataSource);
String systemSchema = getSystemSchema(serverType);
catalog = DBUtils.getQuotedIdentifier(dataSource, catalog);
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read source code")) {
String mdQuery = serverType == ServerType.SQL_SERVER ? catalog + "." + systemSchema + ".sp_helptext '" + schema + "." + name + "'" : "SELECT sc.text\n" + "FROM " + catalog + "." + systemSchema + ".sysobjects so\n" + "INNER JOIN " + catalog + "." + systemSchema + ".syscomments sc on sc.id = so.id\n" + "WHERE user_name(so.uid)=? AND so.name=?";
try (JDBCPreparedStatement dbStat = session.prepareStatement(mdQuery)) {
if (serverType == ServerType.SYBASE) {
dbStat.setString(1, schema);
dbStat.setString(2, name);
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
StringBuilder sql = new StringBuilder();
while (dbResult.nextRow()) {
sql.append(dbResult.getString(1));
}
return sql.toString();
}
}
} catch (SQLException e) {
throw new DBException(e, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class HSQLMetaModel method loadSequences.
@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 WHERE SEQUENCE_SCHEMA=?")) {
dbStat.setString(1, container.getName());
List<GenericSequence> result = new ArrayList<>();
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String name = JDBCUtils.safeGetString(dbResult, "SEQUENCE_NAME");
if (name == null) {
continue;
}
GenericSequence sequence = new GenericSequence(container, name, null, JDBCUtils.safeGetLong(dbResult, "NEXT_VALUE"), JDBCUtils.safeGetLong(dbResult, "MINIMUM_VALUE"), JDBCUtils.safeGetLong(dbResult, "MAXIMUM_VALUE"), JDBCUtils.safeGetLong(dbResult, "INCREMENT"));
result.add(sequence);
}
}
return result;
}
} catch (SQLException e) {
throw new DBException(e, container.getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCSession in project dbeaver by serge-rider.
the class ExasolStructureAssistant method findObjectsByMask.
@NotNull
@Override
public List<DBSObjectReference> findObjectsByMask(DBRProgressMonitor monitor, DBSObject parentObject, DBSObjectType[] objectTypes, String objectNameMask, boolean caseSensitive, boolean globalSearch, int maxResults) throws DBException {
LOG.debug(objectNameMask);
List<ExasolObjectType> exasolObjectTypes = new ArrayList<>(objectTypes.length);
for (DBSObjectType dbsObjectType : objectTypes) {
exasolObjectTypes.add((ExasolObjectType) dbsObjectType);
}
ExasolSchema schema = parentObject instanceof ExasolSchema ? (ExasolSchema) parentObject : null;
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Find objects by name")) {
return searchAllObjects(session, schema, objectNameMask, exasolObjectTypes, caseSensitive, maxResults);
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
}
}
Aggregations