use of org.jkiss.dbeaver.ext.generic.model.GenericTableBase in project dbeaver by serge-rider.
the class SQLiteTableColumnManager method addObjectDeleteActions.
@Override
protected void addObjectDeleteActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectDeleteCommand command, Map<String, Object> options) throws DBException {
final GenericTableColumn column = command.getObject();
final GenericTableBase table = column.getTable();
final List<? extends GenericTableColumn> attributes = table.getAttributes(monitor);
if (CommonUtils.isEmpty(attributes)) {
throw new DBException("Table was deleted");
}
final String tableColumns = attributes.stream().filter(x -> !x.getName().equals(column.getName()) && x.isPersisted()).map(DBUtils::getQuotedIdentifier).collect(Collectors.joining(",\n "));
final String tableName = DBUtils.getQuotedIdentifier(table);
actions.add(new SQLDatabasePersistActionComment(table.getDataSource(), "Drop column " + DBUtils.getQuotedIdentifier(column)));
actions.add(new SQLDatabasePersistAction("Create temporary table from original table", "CREATE TEMPORARY TABLE temp AS\nSELECT\n " + tableColumns + "\nFROM " + tableName));
actions.add(new SQLDatabasePersistAction("Drop original table", "\nDROP TABLE " + tableName + ";\n"));
actions.add(new SQLDatabasePersistAction("Create new table", DBStructUtils.generateTableDDL(monitor, table, Collections.emptyMap(), false)));
actions.add(new SQLDatabasePersistAction("Insert values from temporary table to new table", "INSERT INTO " + tableName + "\n (" + tableColumns + ")\nSELECT\n " + tableColumns + "\nFROM temp"));
actions.add(new SQLDatabasePersistAction("Drop temporary table", "\nDROP TABLE temp"));
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableBase in project dbeaver by serge-rider.
the class GenericForeignKeyManager method createDatabaseObject.
@Override
protected GenericTableForeignKey createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, final Object container, Object from, Map<String, Object> options) {
GenericTableBase tableBase = (GenericTableBase) container;
GenericTableForeignKey foreignKey = new GenericTableForeignKey(tableBase, null, null, null, DBSForeignKeyModifyRule.NO_ACTION, DBSForeignKeyModifyRule.NO_ACTION, DBSForeignKeyDeferability.NOT_DEFERRABLE, false);
foreignKey.setName(getNewConstraintName(monitor, foreignKey));
return foreignKey;
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableBase in project dbeaver by serge-rider.
the class ClickhouseSchema method collectObjectStatistics.
@Override
public void collectObjectStatistics(DBRProgressMonitor monitor, boolean totalSizeOnly, boolean forceRefresh) throws DBException {
if (hasStatistics && !forceRefresh) {
return;
}
try (DBCSession session = DBUtils.openMetaSession(monitor, this, "Read relation statistics")) {
try (JDBCPreparedStatement dbStat = ((JDBCSession) session).prepareStatement("select table," + "sum(bytes) as table_size, " + "sum(rows) as table_rows, " + "max(modification_time) as latest_modification," + "min(min_date) AS min_date," + "max(max_date) AS max_date," + "any(engine) as engine\n" + "FROM system.parts\n" + "WHERE database=? AND active\n" + "GROUP BY table")) {
dbStat.setString(1, getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
String tableName = dbResult.getString(1);
GenericTableBase table = getTable(monitor, tableName);
if (table instanceof ClickhouseTable) {
((ClickhouseTable) table).fetchStatistics(dbResult);
}
}
}
} catch (SQLException e) {
throw new DBCException("Error reading schema statistics", e);
}
} finally {
hasStatistics = true;
}
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableBase in project dbeaver by serge-rider.
the class GenericTableIndexConfigurator method configureObject.
@Override
public GenericTableIndex configureObject(DBRProgressMonitor monitor, Object table, GenericTableIndex index) {
GenericTableBase tableBase = (GenericTableBase) table;
boolean supportUniqueIndexes = tableBase.supportUniqueIndexes();
Collection<DBSIndexType> tableIndexTypes = tableBase.getTableIndexTypes();
return new UITask<GenericTableIndex>() {
@Override
protected GenericTableIndex runTask() {
EditIndexPage editPage = new EditIndexPage("Create index", index, tableIndexTypes, supportUniqueIndexes);
if (!editPage.edit()) {
return null;
}
index.setIndexType(editPage.getIndexType());
StringBuilder idxName = new StringBuilder(64);
idxName.append(CommonUtils.escapeIdentifier(index.getTable().getName()));
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
if (colIndex == 1) {
idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName()));
}
index.addColumn(new GenericTableIndexColumn(index, (GenericTableColumn) tableColumn, colIndex++, !Boolean.TRUE.equals(editPage.getAttributeProperty(tableColumn, EditIndexPage.PROP_DESC))));
}
idxName.append("_IDX");
index.setName(DBObjectNameCaseTransformer.transformObjectName(index, idxName.toString()));
index.setUnique(editPage.isUnique());
return index;
}
}.execute();
}
use of org.jkiss.dbeaver.ext.generic.model.GenericTableBase in project dbeaver by serge-rider.
the class GenericTableColumnManager method createDatabaseObject.
@Override
protected GenericTableColumn createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, Object container, Object copyFrom, Map<String, Object> options) throws DBException {
GenericTableBase tableBase = (GenericTableBase) container;
DBSDataType columnType = findBestDataType(tableBase.getDataSource(), DBConstants.DEFAULT_DATATYPE_NAMES);
int columnSize = columnType != null && columnType.getDataKind() == DBPDataKind.STRING ? 100 : 0;
GenericTableColumn column = tableBase.getDataSource().getMetaModel().createTableColumnImpl(monitor, null, tableBase, getNewColumnName(monitor, context, tableBase), columnType == null ? "INTEGER" : columnType.getName(), columnType == null ? Types.INTEGER : columnType.getTypeID(), columnType == null ? Types.INTEGER : columnType.getTypeID(), -1, columnSize, columnSize, null, null, 10, false, null, null, false, false);
column.setPersisted(false);
return column;
}
Aggregations