use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
the class ExasolTableForeignKeyCache method prepareObjectsStatement.
@SuppressWarnings("rawtypes")
@NotNull
@Override
protected JDBCStatement prepareObjectsStatement(JDBCSession session, ExasolSchema exasolSchema, ExasolTable forTable) throws SQLException {
String sql;
if (forTable != null) {
sql = String.format(SQL_FK_TAB, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forTable.getName()));
} else {
sql = String.format(SQL_FK_ALL, ExasolUtils.quoteString(exasolSchema.getName()));
}
JDBCStatement dbStat = session.createStatement();
((JDBCStatementImpl) dbStat).setQueryString(sql);
return dbStat;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
the class ExasolViewCache method prepareObjectsStatement.
@SuppressWarnings("rawtypes")
@Override
protected JDBCStatement prepareObjectsStatement(@NotNull JDBCSession session, @NotNull ExasolSchema exasolSchema) throws SQLException {
JDBCStatement dbStat = session.createStatement();
String sql = String.format(SQL_VIEWS, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(exasolSchema.getName()));
((JDBCStatementImpl) dbStat).setQueryString(sql);
return dbStat;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
the class ExasolViewCache method prepareChildrenStatement.
@SuppressWarnings("rawtypes")
@Override
protected JDBCStatement prepareChildrenStatement(@NotNull JDBCSession session, @NotNull ExasolSchema exasolSchema, @Nullable ExasolView forView) throws SQLException {
String sql;
if (forView != null) {
sql = String.format(SQL_COLS_VIEW, ExasolUtils.quoteString(exasolSchema.getName()), ExasolUtils.quoteString(forView.getName()));
} else {
sql = String.format(SQL_COLS_ALL, ExasolUtils.quoteString(exasolSchema.getName()));
}
JDBCStatement dbStat = session.createStatement();
((JDBCStatementImpl) dbStat).setQueryString(sql);
return dbStat;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
the class ExasolStructureAssistant method searchTables.
// --------------
// Helper Classes
// --------------
private void searchTables(JDBCSession session, ExasolSchema schema, String searchObjectNameMask, List<ExasolObjectType> exasolObjectTypes, int maxResults, List<DBSObjectReference> objects, int nbResults) throws SQLException, DBException {
String sql;
if (schema != null) {
sql = String.format(SQL_TABLES_SCHEMA, ExasolUtils.quoteString(schema.getName()), ExasolUtils.quoteString(searchObjectNameMask), buildTableTypes(exasolObjectTypes));
} else {
sql = String.format(SQL_TABLES_ALL, ExasolUtils.quoteString(searchObjectNameMask), buildTableTypes(exasolObjectTypes));
}
try (JDBCStatement dbStat = session.createStatement()) {
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
String schemaName;
String objectName;
ExasolSchema exasolSchema;
ExasolObjectType objectType;
try (JDBCResultSet dbResult = dbStat.executeQuery(sql)) {
while (dbResult.next()) {
if (session.getProgressMonitor().isCanceled()) {
break;
}
if (nbResults++ >= maxResults) {
break;
}
schemaName = JDBCUtils.safeGetStringTrimmed(dbResult, "TABLE_SCHEM");
objectName = JDBCUtils.safeGetString(dbResult, "TABLE_NAME");
exasolSchema = dataSource.getSchema(session.getProgressMonitor(), schemaName);
if (exasolSchema == null) {
LOG.debug("Schema '" + schemaName + "' not found. Probably was filtered");
continue;
}
objectType = ExasolObjectType.TABLE;
objects.add(new ExasolObjectReference(objectName, exasolSchema, objectType));
}
}
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by serge-rider.
the class JDBCCompositeCache method loadObjects.
protected synchronized void loadObjects(DBRProgressMonitor monitor, OWNER owner, PARENT forParent) throws DBException {
synchronized (objectCache) {
if ((forParent == null && isFullyCached()) || (forParent != null && (!forParent.isPersisted() || objectCache.containsKey(forParent)))) {
return;
}
}
// Load tables and columns first
if (forParent == null) {
parentCache.loadObjects(monitor, owner);
parentCache.loadChildren(monitor, owner, null);
}
Map<PARENT, Map<String, ObjectInfo>> parentObjectMap = new LinkedHashMap<>();
// Load index columns
DBPDataSource dataSource = owner.getDataSource();
assert (dataSource != null);
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Load composite objects")) {
JDBCStatement dbStat = prepareObjectsStatement(session, owner, forParent);
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
try {
dbStat.executeStatement();
JDBCResultSet dbResult = dbStat.getResultSet();
if (dbResult != null)
try {
while (dbResult.next()) {
if (monitor.isCanceled()) {
break;
}
String parentName = parentColumnName instanceof Number ? JDBCUtils.safeGetString(dbResult, ((Number) parentColumnName).intValue()) : JDBCUtils.safeGetString(dbResult, parentColumnName.toString());
String objectName = objectColumnName instanceof Number ? JDBCUtils.safeGetString(dbResult, ((Number) objectColumnName).intValue()) : JDBCUtils.safeGetString(dbResult, objectColumnName.toString());
if (CommonUtils.isEmpty(objectName)) {
// Use default name
objectName = getDefaultObjectName(dbResult, parentName);
}
if (forParent == null && CommonUtils.isEmpty(parentName)) {
// No parent - can't evaluate it
log.debug("Empty parent name in " + this);
continue;
}
PARENT parent = forParent;
if (parent == null) {
parent = parentCache.getObject(monitor, owner, parentName, parentType);
if (parent == null) {
log.debug("Object '" + objectName + "' owner '" + parentName + "' not found");
continue;
}
}
synchronized (objectCache) {
if (objectCache.containsKey(parent)) {
// Already cached
continue;
}
}
// Add to map
Map<String, ObjectInfo> objectMap = parentObjectMap.get(parent);
if (objectMap == null) {
objectMap = new TreeMap<>();
parentObjectMap.put(parent, objectMap);
}
ObjectInfo objectInfo = objectMap.get(objectName);
if (objectInfo == null) {
OBJECT object = fetchObject(session, owner, parent, objectName, dbResult);
if (object == null) {
// Can't fetch object
continue;
}
objectName = object.getName();
objectInfo = new ObjectInfo(object);
objectMap.put(objectName, objectInfo);
}
ROW_REF[] rowRef = fetchObjectRow(session, parent, objectInfo.object, dbResult);
if (rowRef == null || rowRef.length == 0) {
// At least one of rows is broken.
// So entire object is broken, let's just skip it.
objectInfo.broken = true;
//log.debug("Object '" + objectName + "' metadata corrupted - NULL child returned");
continue;
}
Collections.addAll(objectInfo.rows, rowRef);
}
} finally {
dbResult.close();
}
} finally {
dbStat.close();
}
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
}
if (monitor.isCanceled()) {
return;
}
// Fill global cache
synchronized (this) {
synchronized (objectCache) {
if (forParent != null || !parentObjectMap.isEmpty()) {
if (forParent == null) {
// Cache global object list
List<OBJECT> globalCache = new ArrayList<>();
for (Map<String, ObjectInfo> objMap : parentObjectMap.values()) {
if (objMap != null) {
for (ObjectInfo info : objMap.values()) {
if (!info.broken) {
globalCache.add(info.object);
}
}
}
}
// Save precached objects in global cache
for (List<OBJECT> objects : objectCache.values()) {
globalCache.addAll(objects);
}
// Add precached objects to global cache too
super.setCache(globalCache);
this.invalidateObjects(monitor, owner, new CacheIterator());
}
}
// All objects are read. Now assign them to parents
for (Map.Entry<PARENT, Map<String, ObjectInfo>> colEntry : parentObjectMap.entrySet()) {
if (colEntry.getValue() == null || objectCache.containsKey(colEntry.getKey())) {
// Do not overwrite this object's cache
continue;
}
Collection<ObjectInfo> objectInfos = colEntry.getValue().values();
ArrayList<OBJECT> objects = new ArrayList<>(objectInfos.size());
for (ObjectInfo objectInfo : objectInfos) {
objectInfo.needsCaching = true;
objects.add(objectInfo.object);
}
objectCache.put(colEntry.getKey(), objects);
}
// Now set empty object list for other parents
if (forParent == null) {
for (PARENT tmpParent : parentCache.getTypedObjects(monitor, owner, parentType)) {
if (!parentObjectMap.containsKey(tmpParent) && !objectCache.containsKey(tmpParent)) {
objectCache.put(tmpParent, new ArrayList<OBJECT>());
}
}
} else if (!parentObjectMap.containsKey(forParent) && !objectCache.containsKey(forParent)) {
objectCache.put(forParent, new ArrayList<OBJECT>());
}
}
// Cache children lists (we do it in the end because children caching may operate with other model objects)
for (Map.Entry<PARENT, Map<String, ObjectInfo>> colEntry : parentObjectMap.entrySet()) {
for (ObjectInfo objectInfo : colEntry.getValue().values()) {
if (objectInfo.needsCaching) {
cacheChildren(monitor, objectInfo.object, objectInfo.rows);
}
}
}
for (Map.Entry<PARENT, Map<String, ObjectInfo>> colEntry : parentObjectMap.entrySet()) {
for (ObjectInfo objectInfo : colEntry.getValue().values()) {
if (objectInfo.needsCaching) {
cacheChildren2(monitor, objectInfo.object, objectInfo.rows);
}
}
}
}
}
Aggregations