use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class JDBCObjectLookupCache method reloadObject.
protected OBJECT reloadObject(@NotNull DBRProgressMonitor monitor, @NotNull OWNER owner, @Nullable OBJECT object, @Nullable String objectName) throws DBException {
DBPDataSource dataSource = owner.getDataSource();
if (dataSource == null) {
throw new DBException("Not connected to database");
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, object == null ? "Load object '" + objectName + "' from " + owner.getName() : "Reload object '" + object + "' from " + owner.getName())) {
try (JDBCStatement dbStat = prepareLookupStatement(session, owner, object, objectName)) {
dbStat.setFetchSize(1);
dbStat.executeStatement();
JDBCResultSet dbResult = dbStat.getResultSet();
if (dbResult != null) {
try {
if (dbResult.next()) {
return fetchObject(session, owner, dbResult);
}
} finally {
dbResult.close();
}
}
return null;
}
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class JDBCStructCache method loadChildren.
/**
* Reads children objects from database
*
* @param monitor
* monitor
* @param forObject
* object for which to read children. If null then reads children for all objects in this container.
* @throws org.jkiss.dbeaver.DBException
* on error
*/
public synchronized void loadChildren(DBRProgressMonitor monitor, OWNER owner, @Nullable final OBJECT forObject) throws DBException {
if ((forObject == null && this.childrenCached) || (forObject != null && (!forObject.isPersisted() || isChildrenCached(forObject))) || monitor.isCanceled()) {
return;
}
if (forObject == null) {
// If we have some child objects read before that - do not clear them.
// We have to reuse them because there could be some references in cached model
//clearChildrenCache(null);
super.loadObjects(monitor, owner);
}
DBPDataSource dataSource = owner.getDataSource();
if (dataSource == null) {
throw new DBException("Not connected to database");
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Load child objects")) {
Map<OBJECT, List<CHILD>> objectMap = new HashMap<>();
// Load columns
try (JDBCStatement dbStat = prepareChildrenStatement(session, owner, forObject)) {
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
dbStat.executeStatement();
JDBCResultSet dbResult = dbStat.getResultSet();
if (dbResult != null) {
try {
while (dbResult.next()) {
if (monitor.isCanceled()) {
break;
}
String objectName;
if (objectNameColumn instanceof Number) {
objectName = JDBCUtils.safeGetString(dbResult, ((Number) objectNameColumn).intValue());
} else {
objectName = JDBCUtils.safeGetStringTrimmed(dbResult, objectNameColumn.toString());
}
if (objectName == null) {
log.debug("NULL object name in " + this);
continue;
}
OBJECT object = forObject;
if (object == null) {
object = super.getCachedObject(objectName);
if (object == null) {
log.debug("Object '" + objectName + "' not found");
continue;
}
}
if (isChildrenCached(object)) {
// Already read
continue;
}
CHILD child = fetchChild(session, owner, object, dbResult);
if (child == null) {
continue;
}
// Add to map
List<CHILD> children = objectMap.get(object);
if (children == null) {
children = new ArrayList<>();
objectMap.put(object, children);
}
children.add(child);
}
if (monitor.isCanceled()) {
return;
}
// All children are read. Now assign them to parents
for (Map.Entry<OBJECT, List<CHILD>> colEntry : objectMap.entrySet()) {
if (!isChildrenCached(colEntry.getKey())) {
// isChildrenCached may return true if the same cache was read in other thread
// just skip
cacheChildren(colEntry.getKey(), colEntry.getValue());
}
}
if (forObject == null) {
if (objectMap.isEmpty()) {
// Nothing was read. May be it means empty list of children
// but possibly this feature is not supported [JDBC: SQLite]
} else {
// Now set empty column list for other tables
for (OBJECT tmpObject : getAllObjects(monitor, owner)) {
if (!isChildrenCached(tmpObject) && !objectMap.containsKey(tmpObject)) {
cacheChildren(tmpObject, new ArrayList<CHILD>());
}
}
this.childrenCached = true;
}
} else if (!objectMap.containsKey(forObject)) {
cacheChildren(forObject, new ArrayList<CHILD>());
}
} finally {
dbResult.close();
}
}
}
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class DB2Utils method getListOfUsableTsForExplain.
// ------------------------
// EXPLAIN
// ------------------------
public static List<String> getListOfUsableTsForExplain(DBRProgressMonitor monitor, JDBCSession session) throws SQLException {
LOG.debug("Get List Of Usable Tablespaces For Explain Tables");
List<String> listTablespaces = new ArrayList<>();
try (JDBCPreparedStatement dbStat = session.prepareStatement(SEL_LIST_TS_EXPLAIN)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
listTablespaces.add(dbResult.getString(1));
}
}
}
return listTablespaces;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class DB2Utils method readXMLStrings.
public static List<DB2XMLString> readXMLStrings(DBRProgressMonitor monitor, JDBCSession session) throws SQLException {
LOG.debug("readXMLStrings");
List<DB2XMLString> listXMLStrings = new ArrayList<>();
try (JDBCPreparedStatement dbStat = session.prepareStatement(SEL_XMLSTRINGS)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
listXMLStrings.add(new DB2XMLString((DB2DataSource) session.getDataSource(), dbResult));
}
}
}
return listXMLStrings;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet in project dbeaver by serge-rider.
the class DB2IndexColumn method getDependentView.
// -----------------
// Helpers
// -----------------
private DB2View getDependentView(DBRProgressMonitor monitor, DB2DataSource db2DataSource, String indexSchema, String indexName) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, db2DataSource, "Read Index view dependency")) {
try (JDBCPreparedStatement stmtSel = session.prepareStatement(I_DEP)) {
stmtSel.setString(1, indexSchema);
stmtSel.setString(2, indexName);
JDBCResultSet dbResult = stmtSel.executeQuery();
if (dbResult.next()) {
String viewSchema = dbResult.getString("BSCHEMA").trim();
String viewName = dbResult.getString("BNAME");
return DB2Utils.findViewBySchemaNameAndName(monitor, db2DataSource, viewSchema, viewName);
} else {
return null;
}
}
} catch (SQLException e) {
throw new DBException(e, db2DataSource);
}
}
Aggregations