use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class DB2PlanOperator method loadChildren.
// -------------
// Load children
// -------------
private void loadChildren(JDBCSession session) throws SQLException {
listArguments = new ArrayList<>();
try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_ARGUMENT", "ARGUMENT_TYPE"))) {
setQueryParameters(sqlStmt);
try (JDBCResultSet res = sqlStmt.executeQuery()) {
while (res.next()) {
listArguments.add(new DB2PlanOperatorArgument(res));
}
}
}
listPredicates = new ArrayList<>();
try (JDBCPreparedStatement sqlStmt = session.prepareStatement(String.format(SEL_BASE_SELECT, planTableSchema, "EXPLAIN_PREDICATE", "PREDICATE_ID"))) {
setQueryParameters(sqlStmt);
try (JDBCResultSet res = sqlStmt.executeQuery()) {
while (res.next()) {
listPredicates.add(new DB2PlanOperatorPredicate(res, this));
}
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class NetezzaMetaModel method getViewDDL.
public String getViewDDL(DBRProgressMonitor monitor, GenericTable sourceObject) throws DBException {
GenericDataSource dataSource = sourceObject.getDataSource();
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read Netezza view source")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT v.definition " + "FROM _v_view v, _v_objs_owned o " + "WHERE v.objid = o.objid AND o.DATABASE=? AND v.VIEWNAME=?")) {
dbStat.setString(1, sourceObject.getContainer().getName());
dbStat.setString(2, sourceObject.getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.nextRow()) {
return "CREATE OR REPLACE VIEW " + sourceObject.getName() + " AS\n" + dbResult.getString(1);
}
return "-- Netezza view definition not found";
}
}
} catch (SQLException e) {
throw new DBException(e, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class OracleDataType method getComponentType.
@Property(viewable = true, order = 8)
public OracleDataType getComponentType(@NotNull DBRProgressMonitor monitor) throws DBCException {
if (componentType != null) {
return componentType;
}
OracleSchema schema = getSchema();
if (schema == null || !TYPE_CODE_COLLECTION.equals(typeCode) || !getDataSource().isAtLeastV10()) {
return null;
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load collection types")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT ELEM_TYPE_OWNER,ELEM_TYPE_NAME,ELEM_TYPE_MOD FROM SYS.ALL_COLL_TYPES WHERE OWNER=? AND TYPE_NAME=?")) {
dbStat.setString(1, schema.getName());
dbStat.setString(2, getName());
try (JDBCResultSet dbResults = dbStat.executeQuery()) {
if (dbResults.next()) {
String compTypeSchema = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_OWNER");
String compTypeName = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_NAME");
//String compTypeMod = JDBCUtils.safeGetString(dbResults, "ELEM_TYPE_MOD");
componentType = OracleDataType.resolveDataType(monitor, getDataSource(), compTypeSchema, compTypeName);
} else {
log.warn("Can't resolve collection type [" + getName() + "]");
}
}
}
} catch (Exception e) {
log.warn("Error reading collection types", e);
}
return componentType;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class OracleStructureAssistant method searchAllObjects.
private void searchAllObjects(final JDBCSession session, final OracleSchema schema, String objectNameMask, DBSObjectType[] objectTypes, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
StringBuilder objectTypeClause = new StringBuilder(100);
final List<OracleObjectType> oracleObjectTypes = new ArrayList<>(objectTypes.length + 2);
for (DBSObjectType objectType : objectTypes) {
if (objectType instanceof OracleObjectType) {
oracleObjectTypes.add((OracleObjectType) objectType);
if (objectType == OracleObjectType.PROCEDURE) {
oracleObjectTypes.add(OracleObjectType.FUNCTION);
} else if (objectType == OracleObjectType.TABLE) {
oracleObjectTypes.add(OracleObjectType.VIEW);
oracleObjectTypes.add(OracleObjectType.MATERIALIZED_VIEW);
}
}
}
for (OracleObjectType objectType : oracleObjectTypes) {
if (objectTypeClause.length() > 0)
objectTypeClause.append(",");
objectTypeClause.append("'").append(objectType.getTypeName()).append("'");
}
if (objectTypeClause.length() == 0) {
return;
}
// Always search for synonyms
objectTypeClause.append(",'").append(OracleObjectType.SYNONYM.getTypeName()).append("'");
// Seek for objects (join with public synonyms)
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT " + OracleUtils.getSysCatalogHint((OracleDataSource) session.getDataSource()) + " DISTINCT OWNER,OBJECT_NAME,OBJECT_TYPE FROM (SELECT OWNER,OBJECT_NAME,OBJECT_TYPE FROM ALL_OBJECTS WHERE " + "OBJECT_TYPE IN (" + objectTypeClause + ") AND OBJECT_NAME LIKE ? " + (schema == null ? "" : " AND OWNER=?") + "UNION ALL\n" + "SELECT " + OracleUtils.getSysCatalogHint((OracleDataSource) session.getDataSource()) + " O.OWNER,O.OBJECT_NAME,O.OBJECT_TYPE\n" + "FROM ALL_SYNONYMS S,ALL_OBJECTS O\n" + "WHERE O.OWNER=S.TABLE_OWNER AND O.OBJECT_NAME=S.TABLE_NAME AND S.OWNER='PUBLIC' AND S.SYNONYM_NAME LIKE ?)" + "\nORDER BY OBJECT_NAME")) {
if (!caseSensitive) {
objectNameMask = objectNameMask.toUpperCase();
}
dbStat.setString(1, objectNameMask);
if (schema != null) {
dbStat.setString(2, schema.getName());
}
dbStat.setString(schema != null ? 3 : 2, objectNameMask);
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (objects.size() < maxResults && dbResult.next()) {
if (session.getProgressMonitor().isCanceled()) {
break;
}
final String schemaName = JDBCUtils.safeGetString(dbResult, "OWNER");
final String objectName = JDBCUtils.safeGetString(dbResult, "OBJECT_NAME");
final String objectTypeName = JDBCUtils.safeGetString(dbResult, "OBJECT_TYPE");
final OracleObjectType objectType = OracleObjectType.getByType(objectTypeName);
if (objectType != null && objectType != OracleObjectType.SYNONYM && objectType.isBrowsable() && oracleObjectTypes.contains(objectType)) {
OracleSchema objectSchema = dataSource.getSchema(session.getProgressMonitor(), schemaName);
if (objectSchema == null) {
log.debug("Schema '" + schemaName + "' not found. Probably was filtered");
continue;
}
objects.add(new AbstractObjectReference(objectName, objectSchema, null, objectType.getTypeClass(), objectType) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
OracleSchema tableSchema = (OracleSchema) getContainer();
DBSObject object = objectType.findObject(session.getProgressMonitor(), tableSchema, objectName);
if (object == null) {
throw new DBException(objectTypeName + " '" + objectName + "' not found in schema '" + tableSchema.getName() + "'");
}
return object;
}
});
}
}
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class OracleStructureAssistant method findConstraintsByMask.
private void findConstraintsByMask(JDBCSession session, final OracleSchema schema, String constrNameMask, DBSObjectType[] objectTypes, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
DBRProgressMonitor monitor = session.getProgressMonitor();
List<DBSObjectType> objectTypesList = Arrays.asList(objectTypes);
final boolean hasFK = objectTypesList.contains(OracleObjectType.FOREIGN_KEY);
final boolean hasConstraints = objectTypesList.contains(OracleObjectType.CONSTRAINT);
// Load tables
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT " + OracleUtils.getSysCatalogHint((OracleDataSource) session.getDataSource()) + " OWNER, TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE\n" + "FROM SYS.ALL_CONSTRAINTS\n" + "WHERE CONSTRAINT_NAME like ?" + (!hasFK ? " AND CONSTRAINT_TYPE<>'R'" : "") + (schema != null ? " AND OWNER=?" : ""))) {
dbStat.setString(1, constrNameMask);
if (schema != null) {
dbStat.setString(2, schema.getName());
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
int tableNum = maxResults;
while (dbResult.next() && tableNum-- > 0) {
if (monitor.isCanceled()) {
break;
}
final String schemaName = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_OWNER);
final String tableName = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_TABLE_NAME);
final String constrName = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_CONSTRAINT_NAME);
final String constrType = JDBCUtils.safeGetString(dbResult, OracleConstants.COL_CONSTRAINT_TYPE);
final DBSEntityConstraintType type = OracleTableConstraint.getConstraintType(constrType);
objects.add(new AbstractObjectReference(constrName, dataSource.getSchema(session.getProgressMonitor(), schemaName), null, type == DBSEntityConstraintType.FOREIGN_KEY ? OracleTableForeignKey.class : OracleTableConstraint.class, type == DBSEntityConstraintType.FOREIGN_KEY ? OracleObjectType.FOREIGN_KEY : OracleObjectType.CONSTRAINT) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
OracleSchema tableSchema = schema != null ? schema : dataSource.getSchema(monitor, schemaName);
if (tableSchema == null) {
throw new DBException("Constraint schema '" + schemaName + "' not found");
}
OracleTable table = tableSchema.getTable(monitor, tableName);
if (table == null) {
throw new DBException("Constraint table '" + tableName + "' not found in catalog '" + tableSchema.getName() + "'");
}
DBSObject constraint = null;
if (hasFK && type == DBSEntityConstraintType.FOREIGN_KEY) {
constraint = table.getForeignKey(monitor, constrName);
}
if (hasConstraints && type != DBSEntityConstraintType.FOREIGN_KEY) {
constraint = table.getConstraint(monitor, constrName);
}
if (constraint == null) {
throw new DBException("Constraint '" + constrName + "' not found in table '" + table.getFullyQualifiedName(DBPEvaluationContext.DDL) + "'");
}
return constraint;
}
});
}
}
}
}
Aggregations