use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class PostgreStructureAssistant method findConstraintsByMask.
private void findConstraintsByMask(JDBCSession session, @Nullable final List<PostgreSchema> schema, String constrNameMask, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
DBRProgressMonitor monitor = session.getProgressMonitor();
// Load constraints
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT x.oid,x.conname,x.connamespace FROM pg_catalog.pg_constraint x " + "WHERE x.conname " + (caseSensitive ? "LIKE" : "ILIKE") + " ? " + (CommonUtils.isEmpty(schema) ? "" : " AND x.connamespace IN (" + SQLUtils.generateParamList(schema.size()) + ")") + " ORDER BY x.conname LIMIT " + maxResults)) {
dbStat.setString(1, constrNameMask);
if (!CommonUtils.isEmpty(schema)) {
PostgreUtils.setArrayParameter(dbStat, 2, schema);
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
int tableNum = maxResults;
while (dbResult.next() && tableNum-- > 0) {
if (monitor.isCanceled()) {
break;
}
final long schemaId = JDBCUtils.safeGetLong(dbResult, "connamespace");
final long constrId = JDBCUtils.safeGetLong(dbResult, "oid");
final String constrName = JDBCUtils.safeGetString(dbResult, "conname");
final PostgreSchema constrSchema = dataSource.getDefaultInstance().getSchema(session.getProgressMonitor(), schemaId);
objects.add(new AbstractObjectReference(constrName, constrSchema, null, PostgreTableConstraintBase.class, RelationalObjectType.TYPE_TABLE) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
final PostgreTableConstraintBase constraint = PostgreUtils.getObjectById(monitor, constrSchema.constraintCache, constrSchema, constrId);
if (constraint == null) {
throw new DBException("Constraint '" + constrName + "' not found in schema '" + constrSchema.getName() + "'");
}
return constraint;
}
});
}
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class PostgreStructureAssistant method findProceduresByMask.
private void findProceduresByMask(JDBCSession session, @Nullable final List<PostgreSchema> schema, String procNameMask, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws SQLException, DBException {
DBRProgressMonitor monitor = session.getProgressMonitor();
// Load procedures
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT DISTINCT x.oid,x.proname,x.pronamespace FROM pg_catalog.pg_proc x " + "WHERE x.proname " + (caseSensitive ? "LIKE" : "ILIKE") + " ? " + (CommonUtils.isEmpty(schema) ? "" : " AND x.pronamespace IN (" + SQLUtils.generateParamList(schema.size()) + ")") + " ORDER BY x.proname LIMIT " + maxResults)) {
dbStat.setString(1, procNameMask);
if (!CommonUtils.isEmpty(schema)) {
PostgreUtils.setArrayParameter(dbStat, 2, schema);
}
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
int tableNum = maxResults;
while (dbResult.next() && tableNum-- > 0) {
if (monitor.isCanceled()) {
break;
}
final long schemaId = JDBCUtils.safeGetLong(dbResult, "pronamespace");
final String procName = JDBCUtils.safeGetString(dbResult, "proname");
final long procId = JDBCUtils.safeGetLong(dbResult, "oid");
final PostgreSchema procSchema = dataSource.getDefaultInstance().getSchema(session.getProgressMonitor(), schemaId);
objects.add(new AbstractObjectReference(procName, procSchema, null, PostgreProcedure.class, RelationalObjectType.TYPE_PROCEDURE) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
PostgreProcedure procedure = procSchema.getProcedure(monitor, procId);
if (procedure == null) {
throw new DBException("Procedure '" + procName + "' not found in schema '" + procSchema.getName() + "'");
}
return procedure;
}
});
}
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class DBVModel method findEntity.
/**
* Search for virtual entity descriptor
*
* @param entity entity
* @param createNew create new entity if missing
* @return entity virtual entity
*/
public DBVEntity findEntity(DBSEntity entity, boolean createNew) {
DBSObject[] path = DBUtils.getObjectPath(entity, false);
if (path.length == 0) {
log.warn("Empty entity path");
return null;
}
if (path[0] != dataSourceContainer) {
log.warn("Entity's root must be datasource container '" + dataSourceContainer.getName() + "'");
return null;
}
DBVContainer container = this;
for (int i = 1; i < path.length; i++) {
DBSObject item = path[i];
container = container.getContainer(item.getName(), createNew);
if (container == null) {
return null;
}
}
return container.getEntity(entity.getName(), createNew);
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class DiagramCreateWizard method performFinish.
@Override
public boolean performFinish() {
try {
Collection<DBNNode> initialContent = pageContent.getInitialContent();
List<DBSObject> rootObjects = new ArrayList<>();
for (DBNNode node : initialContent) {
if (node instanceof DBNDatabaseNode) {
rootObjects.add(((DBNDatabaseNode) node).getObject());
}
}
DiagramCreator creator = new DiagramCreator(rootObjects);
DBeaverUI.run(getContainer(), true, true, creator);
NavigatorHandlerObjectOpen.openResource(creator.diagramFile, DBeaverUI.getActiveWorkbenchWindow());
} catch (InterruptedException ex) {
return false;
} catch (InvocationTargetException ex) {
DBUserInterface.getInstance().showError("Create error", "Cannot create diagram", ex.getTargetException());
return false;
}
return true;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by dbeaver.
the class DebugCore method resolveDatabaseContext.
public static Map<String, Object> resolveDatabaseContext(DBSObject databaseObject) {
Map<String, Object> result = new HashMap<String, Object>();
if (databaseObject == null) {
return result;
}
DBPDataSource dataSource = databaseObject.getDataSource();
if (dataSource == null) {
return result;
}
DBGResolver finder = Adapters.adapt(dataSource.getContainer(), DBGResolver.class);
if (finder == null) {
return result;
}
Map<String, Object> context = finder.resolveContext(databaseObject);
result.putAll(context);
return result;
}
Aggregations