use of org.jkiss.dbeaver.model.struct.DBSObjectType 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);
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectType in project dbeaver by dbeaver.
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);
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectType in project dbeaver by serge-rider.
the class DB2StructureAssistant method findObjectsByMask.
@NotNull
@Override
public List<DBSObjectReference> findObjectsByMask(@NotNull DBRProgressMonitor monitor, @NotNull DB2ExecutionContext executionContext, DBSObject parentObject, DBSObjectType[] objectTypes, String objectNameMask, boolean caseSensitive, boolean globalSearch, int maxResults) throws DBException {
List<DB2ObjectType> db2ObjectTypes = new ArrayList<>(objectTypes.length);
for (DBSObjectType dbsObjectType : objectTypes) {
db2ObjectTypes.add((DB2ObjectType) dbsObjectType);
}
DB2Schema schema = parentObject instanceof DB2Schema ? (DB2Schema) parentObject : null;
if (schema == null && !globalSearch) {
schema = executionContext.getContextDefaults().getDefaultSchema();
}
try (JDBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.META, "Find objects by name")) {
return searchAllObjects(session, schema, objectNameMask, db2ObjectTypes, caseSensitive, maxResults);
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectType in project dbeaver by serge-rider.
the class SQLServerStructureAssistant method searchAllObjects.
private void searchAllObjects(final JDBCSession session, final SQLServerDatabase database, final SQLServerSchema schema, String objectNameMask, DBSObjectType[] objectTypes, boolean caseSensitive, int maxResults, List<DBSObjectReference> objects) throws DBException {
final List<SQLServerObjectType> supObjectTypes = new ArrayList<>(objectTypes.length + 2);
for (DBSObjectType objectType : objectTypes) {
if (objectType instanceof SQLServerObjectType) {
supObjectTypes.add((SQLServerObjectType) objectType);
} else if (objectType == RelationalObjectType.TYPE_PROCEDURE) {
supObjectTypes.addAll(SQLServerObjectType.getTypesForClass(SQLServerProcedure.class));
} else if (objectType == RelationalObjectType.TYPE_TABLE) {
supObjectTypes.addAll(SQLServerObjectType.getTypesForClass(SQLServerTable.class));
} else if (objectType == RelationalObjectType.TYPE_CONSTRAINT) {
supObjectTypes.addAll(SQLServerObjectType.getTypesForClass(SQLServerTableCheckConstraint.class));
supObjectTypes.addAll(SQLServerObjectType.getTypesForClass(SQLServerTableForeignKey.class));
} else if (objectType == RelationalObjectType.TYPE_VIEW) {
supObjectTypes.addAll(SQLServerObjectType.getTypesForClass(SQLServerView.class));
}
}
if (supObjectTypes.isEmpty()) {
return;
}
StringBuilder objectTypeClause = new StringBuilder(100);
for (SQLServerObjectType objectType : supObjectTypes) {
if (objectTypeClause.length() > 0)
objectTypeClause.append(",");
objectTypeClause.append("'").append(objectType.getTypeID()).append("'");
}
if (objectTypeClause.length() == 0) {
return;
}
// Seek for objects (join with public synonyms)
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM " + SQLServerUtils.getSystemTableName(database, "all_objects") + " o " + "\nWHERE o.type IN (" + objectTypeClause.toString() + ") AND o.name LIKE ?" + (schema == null ? "" : " AND o.schema_id=? ") + "\nORDER BY o.name")) {
dbStat.setString(1, objectNameMask);
if (schema != null) {
dbStat.setLong(2, schema.getObjectId());
}
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (objects.size() < maxResults && dbResult.next()) {
if (session.getProgressMonitor().isCanceled()) {
break;
}
final long schemaId = JDBCUtils.safeGetLong(dbResult, "schema_id");
final String objectName = JDBCUtils.safeGetString(dbResult, "name");
final String objectTypeName = JDBCUtils.safeGetStringTrimmed(dbResult, "type");
final SQLServerObjectType objectType = SQLServerObjectType.valueOf(objectTypeName);
{
SQLServerSchema objectSchema = schemaId == 0 ? null : database.getSchema(session.getProgressMonitor(), schemaId);
objects.add(new AbstractObjectReference(objectName, objectSchema != null ? objectSchema : database, null, objectType.getTypeClass(), objectType) {
@Override
public DBSObject resolveObject(DBRProgressMonitor monitor) throws DBException {
DBSObject object = objectType.findObject(session.getProgressMonitor(), database, objectSchema, objectName);
if (object == null) {
throw new DBException(objectTypeName + " '" + objectName + "' not found");
}
return object;
}
});
}
}
}
} catch (Throwable e) {
throw new DBException("Error while searching in system catalog", e, dataSource);
}
}
use of org.jkiss.dbeaver.model.struct.DBSObjectType in project dbeaver by dbeaver.
the class SearchMetadataQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
List<DBSObjectType> objectTypes = params.getObjectTypes();
String objectNameMask = params.getObjectNameMask();
if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_STARTS_WITH) {
if (!objectNameMask.endsWith("%")) {
// $NON-NLS-1$
// $NON-NLS-1$
objectNameMask = objectNameMask + "%";
}
} else if (params.getMatchType() == SearchMetadataConstants.MATCH_INDEX_CONTAINS) {
if (!objectNameMask.startsWith("%")) {
// $NON-NLS-1$
// $NON-NLS-1$
objectNameMask = "%" + objectNameMask;
}
if (!objectNameMask.endsWith("%")) {
// $NON-NLS-1$
// $NON-NLS-1$
objectNameMask = objectNameMask + "%";
}
}
int totalObjects = 0;
DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
Collection<DBSObjectReference> objects = structureAssistant.findObjectsByMask(localMonitor, executionContext, params.getParentObject(), objectTypes.toArray(new DBSObjectType[0]), objectNameMask, params.isCaseSensitive(), true, params.getMaxResults());
for (DBSObjectReference reference : objects) {
if (monitor.isCanceled()) {
break;
}
try {
DBSObject object = reference.resolveObject(localMonitor);
if (object != null) {
DBNNode node = navigatorModel.getNodeByObject(localMonitor, object, false);
if (node != null) {
searchResult.addObjects(Collections.singletonList(node));
totalObjects++;
}
}
} catch (DBException e) {
log.error(e);
}
}
searchResult.fireChange(new AbstractSearchResult.DatabaseSearchFinishEvent(searchResult, totalObjects));
return Status.OK_STATUS;
} catch (DBException e) {
log.debug(e);
return GeneralUtils.makeExceptionStatus(e);
}
}
Aggregations