use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class SQLUtils method getColumnTypeModifiers.
public static String getColumnTypeModifiers(@NotNull DBSTypedObject column, @NotNull String typeName, @NotNull DBPDataKind dataKind) {
typeName = typeName.toUpperCase(Locale.ENGLISH);
if (column instanceof DBSObject) {
// If type is UDT (i.e. we can find it in type list) and type precision == column precision
// then do not use explicit precision in column definition
final DBSDataType dataType = DBUtils.getLocalDataType(((DBSObject) column).getDataSource(), column.getTypeName());
if (dataType != null && dataType.getScale() == column.getScale() && ((dataType.getPrecision() > 0 && dataType.getPrecision() == column.getPrecision()) || (dataType.getMaxLength() > 0 && dataType.getMaxLength() == column.getMaxLength()))) {
return null;
}
}
if (dataKind == DBPDataKind.STRING) {
if (typeName.indexOf('(') == -1) {
final long maxLength = column.getMaxLength();
if (maxLength > 0) {
return "(" + maxLength + ")";
}
}
} else if (dataKind == DBPDataKind.CONTENT && !typeName.contains("LOB")) {
final long maxLength = column.getMaxLength();
if (maxLength > 0) {
return "(" + maxLength + ')';
}
} else if (dataKind == DBPDataKind.NUMERIC) {
if (typeName.equals("DECIMAL") || typeName.equals("NUMERIC") || typeName.equals("NUMBER")) {
int scale = column.getScale();
int precision = column.getPrecision();
if (precision == 0) {
precision = (int) column.getMaxLength();
}
if (scale >= 0 && precision >= 0 && !(scale == 0 && precision == 0)) {
return "(" + precision + ',' + scale + ')';
}
} else if (typeName.equals("BIT")) {
// Bit string?
int precision = column.getPrecision();
if (precision > 1) {
return "(" + precision + ')';
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class DataImportHandler method chooseProducer.
@Override
protected IDataTransferProducer chooseProducer(ExecutionEvent event, IDataTransferConsumer consumer) {
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
final DBNNode rootNode = DBeaverCore.getInstance().getLiveProjects().size() == 1 ? navigatorModel.getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject()) : navigatorModel.getRoot();
DBNNode node = BrowseObjectDialog.selectObject(HandlerUtil.getActiveShell(event), "Select source container for '" + consumer.getTargetName() + "'", rootNode, null, new Class[] { DBSObjectContainer.class, DBSDataContainer.class }, new Class[] { DBSDataContainer.class });
if (node instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (object instanceof DBSDataContainer) {
return new DatabaseTransferProducer((DBSDataContainer) object);
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class DataExporterSQL method exportHeader.
@Override
public void exportHeader(DBCSession session) throws DBException, IOException {
columns = getSite().getAttributes();
DBPNamedObject source = getSite().getSource();
if (source instanceof DBSObject) {
tableName = omitSchema ? DBUtils.getQuotedIdentifier((DBSObject) source) : DBUtils.getObjectFullName(source, DBPEvaluationContext.UI);
} else {
throw new DBException("SQL export may be done only from table object");
}
rowCount = 0;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class NavigatorHandlerObjectOpen method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object element = iter.next();
DBNNode node = null;
if (element instanceof IResource) {
openResource((IResource) element, HandlerUtil.getActiveWorkbenchWindow(event));
continue;
} else if (element instanceof DBNNode) {
node = (DBNNode) element;
} else {
DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
if (object != null) {
node = getNodeByObject(object);
}
}
if (node != null) {
NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event));
}
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.
the class NavigatorHandlerObjectRename method renameDatabaseObject.
public static boolean renameDatabaseObject(IWorkbenchWindow workbenchWindow, DBNDatabaseNode node, String newName) {
try {
if (node.getParentNode() instanceof DBNContainer) {
final DBNContainer container = (DBNContainer) node.getParentNode();
DBSObject object = node.getObject();
if (object != null) {
DBEObjectRenamer objectRenamer = EntityEditorsRegistry.getInstance().getObjectManager(object.getClass(), DBEObjectRenamer.class);
if (objectRenamer != null) {
CommandTarget commandTarget = getCommandTarget(workbenchWindow, container, object.getClass(), false);
objectRenamer.renameObject(commandTarget.getContext(), object, newName);
if (object.isPersisted() && commandTarget.getEditor() == null) {
if (!showScript(workbenchWindow, commandTarget.getContext(), "Rename script")) {
commandTarget.getContext().resetChanges();
return false;
} else {
ObjectSaver renamer = new ObjectSaver(commandTarget.getContext());
TasksJob.runTask("Rename object '" + object.getName() + "'", renamer);
}
} else {
for (DBECommand command : commandTarget.getContext().getFinalCommands()) {
//System.out.println(command);
}
}
return true;
}
}
}
} catch (Throwable e) {
UIUtils.showErrorDialog(workbenchWindow.getShell(), "Rename object", "Can't rename object '" + node.getNodeName() + "'", e);
return false;
}
return false;
}
Aggregations