use of org.jkiss.dbeaver.ext.db2.model.DB2TableColumn in project dbeaver by serge-rider.
the class DB2Utils method findColumnBySchemaNameAndTableNameAndName.
public static DB2TableColumn findColumnBySchemaNameAndTableNameAndName(DBRProgressMonitor monitor, DB2DataSource db2DataSource, String db2SchemaName, String db2TableName, String db2ColumnName) throws DBException {
DB2Schema db2Schema = db2DataSource.getSchema(monitor, db2SchemaName);
if (db2Schema == null) {
return null;
}
DB2Table db2Table = db2Schema.getTable(monitor, db2TableName);
if (db2Table == null) {
return null;
}
return db2Table.getAttribute(monitor, db2ColumnName);
}
use of org.jkiss.dbeaver.ext.db2.model.DB2TableColumn in project dbeaver by serge-rider.
the class DB2TableColumnManager method addObjectRenameActions.
@Override
protected void addObjectRenameActions(List<DBEPersistAction> actions, ObjectRenameCommand command) {
final DB2TableColumn column = command.getObject();
actions.add(new SQLDatabasePersistAction("Rename column", "ALTER TABLE " + column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " RENAME COLUMN " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getOldName()) + " TO " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getNewName())));
}
use of org.jkiss.dbeaver.ext.db2.model.DB2TableColumn in project dbeaver by serge-rider.
the class DB2TableForeignKeyCache method fetchObjectRow.
@Nullable
@Override
protected DB2TableKeyColumn[] fetchObjectRow(JDBCSession session, DB2Table db2Table, DB2TableForeignKey object, JDBCResultSet dbResult) throws SQLException, DBException {
String colName = JDBCUtils.safeGetString(dbResult, "COLNAME");
DB2TableColumn tableColumn = db2Table.getAttribute(session.getProgressMonitor(), colName);
if (tableColumn == null) {
log.debug("DB2TableForeignKeyCache : Column '" + colName + "' not found in table '" + db2Table.getFullyQualifiedName(DBPEvaluationContext.UI) + "' ??");
return null;
} else {
return new DB2TableKeyColumn[] { new DB2TableKeyColumn(object, tableColumn, JDBCUtils.safeGetInt(dbResult, "COLSEQ")) };
}
}
use of org.jkiss.dbeaver.ext.db2.model.DB2TableColumn in project dbeaver by serge-rider.
the class DB2GranteeAuthCache method fetchObject.
@Override
protected DB2AuthBase fetchObject(@NotNull JDBCSession session, @NotNull DB2Grantee db2Grantee, @NotNull JDBCResultSet resultSet) throws SQLException, DBException {
DB2DataSource db2DataSource = db2Grantee.getDataSource();
DBRProgressMonitor monitor = session.getProgressMonitor();
String objectSchemaName = JDBCUtils.safeGetStringTrimmed(resultSet, "OBJ_SCHEMA");
String objectName = JDBCUtils.safeGetStringTrimmed(resultSet, "OBJ_NAME");
DB2ObjectType objectType = CommonUtils.valueOf(DB2ObjectType.class, JDBCUtils.safeGetString(resultSet, "OBJ_TYPE"));
switch(objectType) {
case COLUMN:
String columnName = JDBCUtils.safeGetStringTrimmed(resultSet, "USAGEAUTH");
DB2TableColumn db2TableColumn = DB2Utils.findColumnBySchemaNameAndTableNameAndName(monitor, db2DataSource, objectSchemaName, objectName, columnName);
return new DB2AuthColumn(monitor, db2Grantee, db2TableColumn, resultSet);
case INDEX:
DB2Index db2Index = DB2Utils.findIndexBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthIndex(monitor, db2Grantee, db2Index, resultSet);
case MODULE:
DB2Module db2Module = DB2Utils.findModuleBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthModule(monitor, db2Grantee, db2Module, resultSet);
case PACKAGE:
DB2Package db2Package = DB2Utils.findPackageBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthPackage(monitor, db2Grantee, db2Package, resultSet);
case PROCEDURE:
// Can be a Function or a Procedure
DB2RoutineType routineType = CommonUtils.valueOf(DB2RoutineType.class, JDBCUtils.safeGetStringTrimmed(resultSet, "USAGEAUTH"));
switch(routineType) {
case F:
DB2Routine db2Udf = DB2Utils.findUDFBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthUDF(monitor, db2Grantee, db2Udf, resultSet);
case M:
DB2Routine db2Method = DB2Utils.findMethodBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthMethod(monitor, db2Grantee, db2Method, resultSet);
case P:
DB2Routine db2Procedure = DB2Utils.findProcedureBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthProcedure(monitor, db2Grantee, db2Procedure, resultSet);
default:
throw new DBException(routineType + " is not a valid DB2RoutineType");
}
case SCHEMA:
DB2Schema db2Schema = db2DataSource.getSchema(monitor, objectName);
return new DB2AuthSchema(monitor, db2Grantee, db2Schema, resultSet);
case SEQUENCE:
DB2Sequence db2Sequence = DB2Utils.findSequenceBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthSequence(monitor, db2Grantee, db2Sequence, resultSet);
case TABLE:
// Can be a Table, a View or an MQT..
DB2TableBase db2TableBase = DB2Utils.findTableBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
if (db2TableBase != null) {
return new DB2AuthTable(monitor, db2Grantee, db2TableBase, resultSet);
} else {
db2TableBase = DB2Utils.findViewBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
if (db2TableBase != null) {
return new DB2AuthView(monitor, db2Grantee, db2TableBase, resultSet);
} else {
db2TableBase = DB2Utils.findMQTBySchemaNameAndName(monitor, db2DataSource, objectSchemaName, objectName);
return new DB2AuthMaterializedQueryTable(monitor, db2Grantee, db2TableBase, resultSet);
}
}
case TABLESPACE:
DB2Tablespace db2Tablespace = db2DataSource.getTablespace(monitor, objectName);
return new DB2AuthTablespace(monitor, db2Grantee, db2Tablespace, resultSet);
case VARIABLE:
DB2Variable db2Variable = db2DataSource.getVariable(monitor, objectName);
return new DB2AuthVariable(monitor, db2Grantee, db2Variable, resultSet);
case XML_SCHEMA:
Long xmlSchemaId = Long.valueOf(objectName);
DB2XMLSchema db2XmlSchema = DB2Utils.findXMLSchemaByById(monitor, db2DataSource, xmlSchemaId);
return new DB2AuthXMLSchema(monitor, db2Grantee, db2XmlSchema, resultSet);
default:
throw new DBException("Programming error: " + objectType + " is not supported yet and the SELECT statement must exclude it");
}
}
use of org.jkiss.dbeaver.ext.db2.model.DB2TableColumn in project dbeaver by serge-rider.
the class DB2TableColumnManager method computeDeltaSQL.
// -------
// Helpers
// -------
private String computeDeltaSQL(ObjectChangeCommand command) {
if (command.getProperties().isEmpty() || (command.getProperties().size() == 1 && command.getProperty("description") != null)) {
return "";
}
/*
if (log.isDebugEnabled()) {
for (Map.Entry<Object, Object> entry : command.getProperties().entrySet()) {
log.debug(entry.getKey() + "=" + entry.getValue());
}
}
*/
DB2TableColumn column = command.getObject();
StringBuilder sb = new StringBuilder(128);
sb.append(column.getName());
Boolean required = (Boolean) command.getProperty("required");
if (required != null) {
sb.append(LINE_SEPARATOR);
if (required) {
sb.append(CLAUSE_SET_NULL);
} else {
sb.append(CLAUSE_DROP_NULL);
}
}
String type = (String) command.getProperty("type");
if (type != null) {
sb.append(LINE_SEPARATOR);
sb.append(CLAUSE_SET_TYPE);
sb.append(type);
}
return sb.toString();
}
Aggregations