use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class ExasolBaseTableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<ExasolTableBase> getScriptListener() {
final int nbExtraColumns = getNumberExtraResultingColumns();
return new SQLScriptStatusDialog<ExasolTableBase>(getShell(), getTitle() + " " + ExasolMessages.dialog_table_tools_progress, null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText(ExasolMessages.dialog_table_tools_result);
for (int i = 0; i < nbExtraColumns; i++) {
new TreeColumn(objectTree, SWT.NONE);
}
}
@Override
public void endObjectProcessing(@NotNull ExasolTableBase exasolTable, Exception exception) {
TreeItem treeItem = getTreeItem(exasolTable);
if (exception == null) {
treeItem.setText(1, ExasolMessages.dialog_table_tools_success_title);
} else {
treeItem.setText(1, exception.getMessage());
}
UIUtils.packColumns(treeItem.getParent(), false, null);
}
// DF: This method is for tools that return resultsets
@Override
public void processObjectResults(@NotNull ExasolTableBase exasolTable, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (resultSet == null) {
return;
}
// Retrieve column names
DBCResultSetMetaData rsMetaData = resultSet.getMeta();
try {
TreeItem treeItem = getTreeItem(exasolTable);
Font f = UIUtils.makeBoldFont(treeItem.getFont());
if (treeItem != null) {
// Display the column names
TreeItem subItem = null;
subItem = new TreeItem(treeItem, SWT.NONE);
subItem.setFont(f);
for (DBCAttributeMetaData column : rsMetaData.getAttributes()) {
subItem.setText(column.getOrdinalPosition(), column.getName());
subItem.setGrayed(true);
}
// Display the data for each row
while (resultSet.nextRow()) {
subItem = new TreeItem(treeItem, SWT.NONE);
for (int i = 0; i < rsMetaData.getAttributes().size(); i++) {
subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
i++;
}
}
treeItem.setExpanded(true);
}
} catch (Exception e) {
throw new DBCException(e.getMessage());
}
}
};
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class ForeignKeysCache method fetchObject.
@Nullable
@Override
protected GenericTableForeignKey fetchObject(JDBCSession session, GenericStructContainer owner, GenericTable parent, String fkName, JDBCResultSet dbResult) throws SQLException, DBException {
String pkTableCatalog = GenericUtils.safeGetStringTrimmed(foreignKeyObject, dbResult, JDBCConstants.PKTABLE_CAT);
String pkTableSchema = GenericUtils.safeGetStringTrimmed(foreignKeyObject, dbResult, JDBCConstants.PKTABLE_SCHEM);
String pkTableName = GenericUtils.safeGetStringTrimmed(foreignKeyObject, dbResult, JDBCConstants.PKTABLE_NAME);
String fkTableCatalog = GenericUtils.safeGetStringTrimmed(foreignKeyObject, dbResult, JDBCConstants.FKTABLE_CAT);
String fkTableSchema = GenericUtils.safeGetStringTrimmed(foreignKeyObject, dbResult, JDBCConstants.FKTABLE_SCHEM);
int keySeq = GenericUtils.safeGetInt(foreignKeyObject, dbResult, JDBCConstants.KEY_SEQ);
int updateRuleNum = GenericUtils.safeGetInt(foreignKeyObject, dbResult, JDBCConstants.UPDATE_RULE);
int deleteRuleNum = GenericUtils.safeGetInt(foreignKeyObject, dbResult, JDBCConstants.DELETE_RULE);
String pkName = GenericUtils.safeGetStringTrimmed(foreignKeyObject, dbResult, JDBCConstants.PK_NAME);
int defferabilityNum = GenericUtils.safeGetInt(foreignKeyObject, dbResult, JDBCConstants.DEFERRABILITY);
DBSForeignKeyModifyRule deleteRule = JDBCUtils.getCascadeFromNum(deleteRuleNum);
DBSForeignKeyModifyRule updateRule = JDBCUtils.getCascadeFromNum(updateRuleNum);
DBSForeignKeyDefferability defferability;
switch(defferabilityNum) {
case DatabaseMetaData.importedKeyInitiallyDeferred:
defferability = DBSForeignKeyDefferability.INITIALLY_DEFERRED;
break;
case DatabaseMetaData.importedKeyInitiallyImmediate:
defferability = DBSForeignKeyDefferability.INITIALLY_IMMEDIATE;
break;
case DatabaseMetaData.importedKeyNotDeferrable:
defferability = DBSForeignKeyDefferability.NOT_DEFERRABLE;
break;
default:
defferability = DBSForeignKeyDefferability.UNKNOWN;
break;
}
if (pkTableName == null) {
log.debug("Null PK table name");
return null;
}
String pkTableFullName = DBUtils.getSimpleQualifiedName(pkTableCatalog, pkTableSchema, pkTableName);
GenericTable pkTable = parent.getDataSource().findTable(session.getProgressMonitor(), pkTableCatalog, pkTableSchema, pkTableName);
if (pkTable == null) {
// Try to use FK catalog/schema
pkTable = parent.getDataSource().findTable(session.getProgressMonitor(), fkTableCatalog, fkTableSchema, pkTableName);
if (pkTable == null) {
log.warn("Can't find PK table " + pkTableName);
return null;
} else {
log.debug("PK table " + pkTableFullName + " was taken from FK container.");
}
}
// Find PK
GenericPrimaryKey pk = null;
if (!CommonUtils.isEmpty(pkName)) {
pk = DBUtils.findObject(pkTable.getConstraints(session.getProgressMonitor()), pkName);
if (pk == null) {
log.debug("Unique key '" + pkName + "' not found in table " + pkTable.getFullyQualifiedName(DBPEvaluationContext.DDL));
}
}
if (pk == null) {
String pkColumnName = GenericUtils.safeGetStringTrimmed(foreignKeyObject, dbResult, JDBCConstants.PKCOLUMN_NAME);
GenericTableColumn pkColumn = pkTable.getAttribute(session.getProgressMonitor(), pkColumnName);
if (pkColumn == null) {
log.warn("Can't find PK table " + pkTable.getFullyQualifiedName(DBPEvaluationContext.DDL) + " column " + pkColumnName);
return null;
}
Collection<GenericPrimaryKey> uniqueKeys = pkTable.getConstraints(session.getProgressMonitor());
if (uniqueKeys != null) {
for (GenericPrimaryKey pkConstraint : uniqueKeys) {
if (pkConstraint.getConstraintType().isUnique() && DBUtils.getConstraintAttribute(session.getProgressMonitor(), pkConstraint, pkColumn) != null) {
pk = pkConstraint;
break;
}
}
}
if (pk == null) {
log.warn("Can't find unique key for table " + pkTable.getFullyQualifiedName(DBPEvaluationContext.DDL) + " column " + pkColumn.getName());
// Too bad. But we have to create new fake PK for this FK
String pkFullName = pkTable.getFullyQualifiedName(DBPEvaluationContext.DDL) + "." + pkName;
pk = pkMap.get(pkFullName);
if (pk == null) {
pk = new GenericPrimaryKey(pkTable, pkName, null, DBSEntityConstraintType.PRIMARY_KEY, true);
pkMap.put(pkFullName, pk);
// Add this fake constraint to it's owner
pk.getTable().addUniqueKey(pk);
}
pk.addColumn(new GenericTableConstraintColumn(pk, pkColumn, keySeq));
}
}
if (CommonUtils.isEmpty(fkName)) {
// [JDBC] Some drivers return empty foreign key names
fkName = parent.getName().toUpperCase() + "_FK_" + pkTable.getName().toUpperCase(Locale.ENGLISH);
}
return new GenericTableForeignKey(parent, fkName, null, pk, deleteRule, updateRule, defferability, true);
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class IndexCache method fetchObject.
@Nullable
@Override
protected GenericTableIndex fetchObject(JDBCSession session, GenericStructContainer owner, GenericTable parent, String indexName, JDBCResultSet dbResult) throws SQLException, DBException {
boolean isNonUnique = GenericUtils.safeGetBoolean(indexObject, dbResult, JDBCConstants.NON_UNIQUE);
String indexQualifier = GenericUtils.safeGetStringTrimmed(indexObject, dbResult, JDBCConstants.INDEX_QUALIFIER);
long cardinality = GenericUtils.safeGetLong(indexObject, dbResult, JDBCConstants.INDEX_CARDINALITY);
int indexTypeNum = GenericUtils.safeGetInt(indexObject, dbResult, JDBCConstants.TYPE);
DBSIndexType indexType;
switch(indexTypeNum) {
case DatabaseMetaData.tableIndexStatistic:
// Table index statistic. Not a real index.
log.debug("Skip statistics index '" + indexName + "' in '" + DBUtils.getObjectFullName(parent, DBPEvaluationContext.DDL) + "'");
return null;
// indexType = DBSIndexType.STATISTIC; break;
case DatabaseMetaData.tableIndexClustered:
indexType = DBSIndexType.CLUSTERED;
break;
case DatabaseMetaData.tableIndexHashed:
indexType = DBSIndexType.HASHED;
break;
case DatabaseMetaData.tableIndexOther:
indexType = DBSIndexType.OTHER;
break;
default:
indexType = DBSIndexType.UNKNOWN;
break;
}
if (CommonUtils.isEmpty(indexName)) {
// [JDBC] Some drivers return empty index names
indexName = parent.getName().toUpperCase(Locale.ENGLISH) + "_INDEX";
}
return owner.getDataSource().getMetaModel().createIndexImpl(parent, isNonUnique, indexQualifier, cardinality, indexName, indexType, true);
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class DBVUtils method findAttributeTransformers.
@Nullable
public static DBDAttributeTransformer[] findAttributeTransformers(@NotNull DBDAttributeBinding binding, @Nullable Boolean custom) {
DBPDataSource dataSource = binding.getDataSource();
DBPDataSourceContainer container = dataSource.getContainer();
List<? extends DBDAttributeTransformerDescriptor> tdList = container.getPlatform().getValueHandlerRegistry().findTransformers(dataSource, binding.getAttribute(), custom);
if (tdList == null || tdList.isEmpty()) {
return null;
}
boolean filtered = false;
DBSEntityAttribute entityAttribute = binding.getEntityAttribute();
if (entityAttribute != null) {
DBVEntity vEntity = findVirtualEntity(entityAttribute.getParentObject(), false);
if (vEntity != null) {
DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(binding, false);
if (vAttr != null) {
final DBVTransformSettings transformSettings = getTransformSettings(vAttr, false);
if (transformSettings != null) {
filtered = transformSettings.filterTransformers(tdList);
}
}
}
}
if (!filtered) {
// Leave only default transformers
for (int i = 0; i < tdList.size(); ) {
if (tdList.get(i).isCustom() || !tdList.get(i).isApplicableByDefault()) {
tdList.remove(i);
} else {
i++;
}
}
}
if (tdList.isEmpty()) {
return null;
}
DBDAttributeTransformer[] result = new DBDAttributeTransformer[tdList.size()];
for (int i = 0; i < tdList.size(); i++) {
result[i] = tdList.get(i).getInstance();
}
return result;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class ContentUtils method convertPathToWorkspaceFile.
@Nullable
public static IFile convertPathToWorkspaceFile(IPath path) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = root.getFileForLocation(path);
if (file != null) {
return file;
}
// Probably we have a path to some linked resource
IPath folderPath = path.removeLastSegments(1);
URI folderURI = folderPath.toFile().toURI();
IContainer[] containers = root.findContainersForLocationURI(folderURI);
if (!ArrayUtils.isEmpty(containers)) {
IContainer container = containers[0];
file = container.getFile(path.removeFirstSegments(path.segmentCount() - 1));
}
return file;
}
Aggregations