use of org.jkiss.dbeaver.model.struct.DBSEntity in project dbeaver by serge-rider.
the class ResultSetFilterPanel method openEditorForActiveQuery.
private void openEditorForActiveQuery() {
DBSDataContainer dataContainer = viewer.getDataContainer();
String editorName;
if (dataContainer instanceof DBSEntity) {
editorName = dataContainer.getName();
} else {
editorName = "Query";
}
OpenHandler.openSQLConsole(DBeaverUI.getActiveWorkbenchWindow(), dataContainer == null ? null : dataContainer.getDataSource().getContainer(), editorName, getActiveQueryText());
}
use of org.jkiss.dbeaver.model.struct.DBSEntity in project dbeaver by serge-rider.
the class SQLAttributeResolver method resolveAll.
@Override
protected String[] resolveAll(final TemplateContext context) {
final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
if (executionContext == null) {
return super.resolveAll(context);
}
TemplateVariable tableVariable = ((SQLContext) context).getTemplateVariable("table");
final String tableName = tableVariable == null ? null : tableVariable.getDefaultValue();
if (!CommonUtils.isEmpty(tableName)) {
final List<DBSEntityAttribute> attributes = new ArrayList<>();
DBRRunnableWithProgress runnable = new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<DBSEntity> entities = new ArrayList<>();
SQLEntityResolver.resolveTables(monitor, executionContext, context, entities);
if (!CommonUtils.isEmpty(entities)) {
DBSEntity table = DBUtils.findObject(entities, tableName);
if (table != null) {
attributes.addAll(CommonUtils.safeCollection(table.getAttributes(monitor)));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
};
RuntimeUtils.runTask(runnable, "Resolve attributes", 1000);
if (!CommonUtils.isEmpty(attributes)) {
String[] result = new String[attributes.size()];
for (int i = 0; i < attributes.size(); i++) {
DBSEntityAttribute entity = attributes.get(i);
result[i] = entity.getName();
}
return result;
}
}
return super.resolveAll(context);
}
use of org.jkiss.dbeaver.model.struct.DBSEntity in project dbeaver by serge-rider.
the class MySQLTableManager method createDatabaseObject.
@Override
protected MySQLTable createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, MySQLCatalog parent, Object copyFrom) throws DBException {
final MySQLTable table;
if (copyFrom instanceof DBSEntity) {
table = new MySQLTable(monitor, parent, (DBSEntity) copyFrom);
table.setName(getTableName(monitor, parent, ((DBSEntity) copyFrom).getName()));
} else if (copyFrom == null) {
table = new MySQLTable(parent);
setTableName(monitor, parent, table);
final MySQLTable.AdditionalInfo additionalInfo = table.getAdditionalInfo(monitor);
additionalInfo.setEngine(parent.getDataSource().getDefaultEngine());
additionalInfo.setCharset(parent.getDefaultCharset());
additionalInfo.setCollation(parent.getDefaultCollation());
} else {
throw new DBException("Can't create MySQL table from '" + copyFrom + "'");
}
return table;
}
use of org.jkiss.dbeaver.model.struct.DBSEntity in project dbeaver by serge-rider.
the class ResultSetModel method updateColorMapping.
void updateColorMapping() {
colorMapping.clear();
DBSEntity entity = getSingleSource();
if (entity == null) {
return;
}
DBVEntity virtualEntity = DBVUtils.findVirtualEntity(entity, false);
if (virtualEntity != null) {
List<DBVColorOverride> coList = virtualEntity.getColorOverrides();
if (!CommonUtils.isEmpty(coList)) {
for (DBVColorOverride co : coList) {
DBDAttributeBinding binding = getAttributeBinding(entity, co.getAttributeName());
if (binding != null) {
List<AttributeColorSettings> cmList = colorMapping.get(binding);
if (cmList == null) {
cmList = new ArrayList<>();
colorMapping.put(binding, cmList);
}
cmList.add(new AttributeColorSettings(co));
}
}
}
}
updateRowColors(curRows);
}
use of org.jkiss.dbeaver.model.struct.DBSEntity in project dbeaver by serge-rider.
the class ResultSetPersister method prepareUpdateStatements.
private void prepareUpdateStatements() throws DBException {
// Make statements
for (ResultSetRow row : this.rowIdentifiers.keySet()) {
if (row.changes == null)
continue;
DBDRowIdentifier rowIdentifier = this.rowIdentifiers.get(row);
DBSEntity table = rowIdentifier.getEntity();
{
DataStatementInfo statement = new DataStatementInfo(DBSManipulationType.UPDATE, row, table);
// Updated columns
for (DBDAttributeBinding changedAttr : row.changes.keySet()) {
statement.updateAttributes.add(new DBDAttributeValue(changedAttr, model.getCellValue(changedAttr, row)));
}
// Key columns
List<DBDAttributeBinding> idColumns = rowIdentifier.getAttributes();
for (DBDAttributeBinding metaColumn : idColumns) {
Object keyValue = model.getCellValue(metaColumn, row);
// Try to find old key oldValue
if (row.changes != null && row.changes.containsKey(metaColumn)) {
keyValue = row.changes.get(metaColumn);
}
statement.keyAttributes.add(new DBDAttributeValue(metaColumn, keyValue));
}
updateStatements.add(statement);
}
}
}
Aggregations