use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by dbeaver.
the class GreenplumTableTest method mockResults.
private JDBCResultSet mockResults(DBRProgressMonitor monitor) throws SQLException {
JDBCSession mockSession = Mockito.mock(JDBCSession.class);
JDBCStatement mockStatement = Mockito.mock(JDBCStatement.class);
JDBCResultSet mockDCResults = Mockito.mock(JDBCResultSet.class);
Mockito.when(mockContext.openSession(Mockito.eq(monitor), Mockito.eq(DBCExecutionPurpose.META), Mockito.anyString())).thenReturn(mockSession);
Mockito.when(mockSession.createStatement()).thenReturn(mockStatement);
Mockito.when(mockStatement.executeQuery(Mockito.anyString())).thenReturn(mockDCResults);
return mockDCResults;
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by dbeaver.
the class MySQLCatalog method collectObjectStatistics.
@Override
public void collectObjectStatistics(DBRProgressMonitor monitor, boolean totalSizeOnly, boolean forceRefresh) throws DBException {
if (hasStatistics && !forceRefresh) {
return;
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load table status")) {
try (JDBCStatement dbStat = session.createStatement()) {
try (JDBCResultSet dbResult = dbStat.executeQuery("SHOW TABLE STATUS FROM " + DBUtils.getQuotedIdentifier(this))) {
while (dbResult.next()) {
String tableName = dbResult.getString("Name");
MySQLTableBase table = tableCache.getObject(monitor, this, tableName);
if (table instanceof MySQLTable) {
((MySQLTable) table).fetchAdditionalInfo(dbResult);
}
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getExecutionContext());
}
} finally {
hasStatistics = true;
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by dbeaver.
the class JDBCStructLookupCache 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(ModelMessages.error_not_connected_to_database);
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, owner, 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 {
while (dbResult.next()) {
OBJECT remoteObject = fetchObject(session, owner, dbResult);
if (isValidObject(monitor, owner, remoteObject)) {
return remoteObject;
}
}
} finally {
dbResult.close();
}
}
return null;
}
} catch (SQLException ex) {
throw new DBException("Error loading object metadata from database", ex, dataSource);
}
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by dbeaver.
the class JDBCObjectCache method loadObjects.
protected synchronized void loadObjects(DBRProgressMonitor monitor, OWNER owner) throws DBException {
if (isFullyCached() || monitor.isCanceled()) {
return;
}
List<OBJECT> tmpObjectList = new ArrayList<>();
DBPDataSource dataSource = owner.getDataSource();
if (dataSource == null) {
throw new DBException(ModelMessages.error_not_connected_to_database);
}
if (owner.isPersisted()) {
// Load cache from database only for persisted objects
try {
try (JDBCSession session = DBUtils.openMetaSession(monitor, owner, "Load objects from " + owner.getName())) {
try (JDBCStatement dbStat = prepareObjectsStatement(session, owner)) {
monitor.subTask("Load " + getCacheName());
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
dbStat.executeStatement();
JDBCResultSet dbResult = dbStat.getResultSet();
if (dbResult != null) {
try {
while (dbResult.next()) {
if (monitor.isCanceled()) {
return;
}
OBJECT object = fetchObject(session, owner, dbResult);
if (object == null || !isValidObject(monitor, owner, object)) {
continue;
}
tmpObjectList.add(object);
// monitor.subTask(object.getName());
if (tmpObjectList.size() == maximumCacheSize) {
log.warn("Maximum cache size exceeded (" + maximumCacheSize + ") in " + this);
break;
}
}
} finally {
dbResult.close();
}
}
}
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
} catch (DBException ex) {
throw ex;
} catch (Exception ex) {
throw new DBException("Internal driver error", ex);
}
} catch (Exception e) {
if (!handleCacheReadError(e)) {
throw e;
}
}
}
addCustomObjects(tmpObjectList);
Comparator<OBJECT> comparator = getListOrderComparator();
if (comparator != null) {
tmpObjectList.sort(comparator);
}
detectCaseSensitivity(owner);
mergeCache(tmpObjectList);
this.invalidateObjects(monitor, owner, new CacheIterator());
}
use of org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement in project dbeaver by dbeaver.
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(ModelMessages.error_not_connected_to_database);
}
try (JDBCSession session = DBUtils.openMetaSession(monitor, owner, 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);
}
}
Aggregations