use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class DB2TableReferenceCache method fetchObjectRow.
@Nullable
@Override
protected DB2TableKeyColumn[] fetchObjectRow(JDBCSession session, DB2Table db2Table, DB2TableReference db2TableReference, JDBCResultSet dbResult) throws SQLException, DBException {
String colName = JDBCUtils.safeGetString(dbResult, "COLNAME");
DB2TableColumn tableColumn = db2Table.getAttribute(session.getProgressMonitor(), colName);
if (tableColumn == null) {
log.debug("DB2TableReferenceCache : Column '" + colName + "' not found in table '" + db2Table.getName() + "' ??");
return null;
} else {
return new DB2TableKeyColumn[] { new DB2TableKeyColumn(db2TableReference, tableColumn, JDBCUtils.safeGetInt(dbResult, "COLSEQ")) };
}
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class TableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<MySQLTable> getScriptListener() {
return new SQLScriptStatusDialog<MySQLTable>(getShell(), getTitle() + " progress", null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText("Message");
}
@Override
public void processObjectResults(@NotNull MySQLTable object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (resultSet == null) {
return;
}
Map<String, String> statusMap = new LinkedHashMap<>();
while (resultSet.nextRow()) {
statusMap.put(CommonUtils.toString(resultSet.getAttributeValue("Msg_type")), CommonUtils.toString(resultSet.getAttributeValue("Msg_text")));
}
TreeItem treeItem = getTreeItem(object);
if (treeItem != null && !statusMap.isEmpty()) {
if (statusMap.size() == 1) {
treeItem.setText(1, statusMap.values().iterator().next());
} else {
String statusText = statusMap.get("status");
if (!CommonUtils.isEmpty(statusText)) {
treeItem.setText(1, statusText);
}
for (Map.Entry<String, String> status : statusMap.entrySet()) {
if (!status.getKey().equals("status")) {
TreeItem subItem = new TreeItem(treeItem, SWT.NONE);
subItem.setText(0, status.getKey());
subItem.setText(1, status.getValue());
}
}
treeItem.setExpanded(true);
}
}
}
};
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class TableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText("Message");
}
@Override
public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (statement == null) {
return;
}
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
try {
int warnNum = 0;
SQLWarning warning = ((JDBCStatement) statement).getWarnings();
while (warning != null) {
if (warnNum == 0) {
treeItem.setText(1, warning.getMessage());
} else {
TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
warnItem.setText(0, "");
warnItem.setText(1, warning.getMessage());
}
warnNum++;
warning = warning.getNextWarning();
}
if (warnNum == 0) {
treeItem.setText(1, "Done");
}
} catch (SQLException e) {
// ignore
}
treeItem.setExpanded(true);
}
}
@Override
public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
super.endObjectProcessing(object, error);
if (error != null) {
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
treeItem.setText(1, error.getMessage());
}
}
}
};
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class DBObjectNameCaseTransformer method transformName.
@Nullable
public static String transformName(@NotNull DBPDataSource dataSource, @Nullable String value) {
if (value == null) {
return null;
}
final boolean isNameCaseSensitive = dataSource.getContainer().getPreferenceStore().getBoolean(ModelPreferences.META_CASE_SENSITIVE);
if (isNameCaseSensitive || !(dataSource instanceof SQLDataSource)) {
return value;
}
final SQLDialect dialect = ((SQLDataSource) dataSource).getSQLDialect();
if (DBUtils.isQuotedIdentifier(dataSource, value)) {
if (dialect.supportsQuotedMixedCase()) {
return value;
}
}
if (dialect.supportsUnquotedMixedCase()) {
return value;
}
String xName = dialect.storesUnquotedCase().transform(value);
if (!DBUtils.getQuotedIdentifier(dataSource, xName).equals(xName)) {
// Name contains special characters and has to be quoted - leave it as is
return value;
}
return xName;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class DataSourcePropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof DBPContextProvider)) {
return false;
}
DBPContextProvider contextProvider = (DBPContextProvider) receiver;
@Nullable DBCExecutionContext context = contextProvider.getExecutionContext();
switch(property) {
case PROP_CONNECTED:
boolean isConnected;
if (context != null) {
isConnected = context.getDataSource().getContainer().isConnected();
} else if (receiver instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) receiver).getDataSourceContainer();
isConnected = container != null && container.isConnected();
} else {
isConnected = false;
}
boolean checkConnected = Boolean.TRUE.equals(expectedValue);
return checkConnected ? isConnected : !isConnected;
case PROP_TRANSACTIONAL:
if (context == null) {
return false;
}
if (!context.isConnected()) {
return Boolean.FALSE.equals(expectedValue);
}
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
try {
return txnManager != null && Boolean.valueOf(!txnManager.isAutoCommit()).equals(expectedValue);
} catch (DBCException e) {
log.debug("Error checking auto-commit state", e);
return false;
}
case PROP_TRANSACTION_ACTIVE:
if (context != null && context.isConnected()) {
boolean active = QMUtils.isTransactionActive(context);
return Boolean.valueOf(active).equals(expectedValue);
}
return Boolean.FALSE.equals(expectedValue);
}
return false;
}
Aggregations