Package com.dci.intellij.dbn.object

Examples of com.dci.intellij.dbn.object.DBColumn


        DBDataset dataset = getDataset();
        StringBuilder selectStatement = new StringBuilder();
        selectStatement.append("select ");
        Iterator<DBColumn> iterator = dataset.getColumns().iterator();
        while (iterator.hasNext()) {
            DBColumn column = iterator.next();
            selectStatement.append(column.getName());
            if (iterator.hasNext()) {
                selectStatement.append(", ");
            }
        }

        selectStatement.append(" from ");
        selectStatement.append(dataset.getQualifiedName());
        selectStatement.append(" where ");

        iterator = filterInput.getColumns().iterator();
        while (iterator.hasNext()) {
            DBColumn column = iterator.next();
            selectStatement.append(column.getName());
            selectStatement.append(" = ? ");
            if (iterator.hasNext()) {
                selectStatement.append(" and ");
            }
        }

        Connection connection = dataset.getConnectionHandler().getPoolConnection();
        PreparedStatement statement = connection.prepareStatement(selectStatement.toString());

        int index = 1;
        iterator = filterInput.getColumns().iterator();
        while (iterator.hasNext()) {
            DBColumn column = iterator.next();
            Object value = filterInput.getColumnValue(column);
            column.getDataType().setValueToPreparedStatement(statement, index, value);
            index++;
        }

        resultSet = statement.executeQuery();
        if (resultSet.next()) {
            index = 1;

            for (DBColumn column : dataset.getColumns()) {
                Object value = column.getDataType().getValueFromResultSet(resultSet, index);
                values.put(column.getName(), value);
                index++;
            }
        }
    }
View Full Code Here


        }

    }

    protected void processMouseMotionEvent(MouseEvent e) {
        DBColumn column = getColumn();
        if (column != null && column.isForeignKey()) {
            if (e.isControlDown() && e.getID() != MouseEvent.MOUSE_DRAGGED && record.getColumnValue(column) != null) {
                setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                setToolTipText("<html>Show referenced <b>" + column.getForeignKeyColumn().getDataset().getQualifiedName() + "</b> record<html>");
            } else {
                super.processMouseMotionEvent(e);
                setCursor(Cursor.getDefaultCursor());
                setToolTipText(null);
            }
View Full Code Here

        }
    }
   
    @Nullable
    public DatasetFilterInput resolveForeignKeyRecord() {
        DBColumn column = getColumn();
        if (column != null) {
            for (DBConstraint constraint : column.getConstraints()) {
                if (constraint.isForeignKey()) {
                    DBConstraint foreignKeyConstraint = constraint.getForeignKeyConstraint();
                    if (foreignKeyConstraint != null) {
                        DBDataset foreignKeyDataset = foreignKeyConstraint.getDataset();
                        DatasetFilterInput filterInput = new DatasetFilterInput(foreignKeyDataset);

                        for (DBColumn constraintColumn : constraint.getColumns()) {
                            DBObject constraintCol = constraintColumn.getUndisposedElement();
                            if (constraintCol != null) {
                                DBColumn foreignKeyColumn = ((DBColumn) constraintCol).getForeignKeyColumn();
                                Object value = record.getColumnValue(column);
                                filterInput.setColumnValue(foreignKeyColumn, value);
                            }
                        }
                        return filterInput;
View Full Code Here

    }


    @Override
    public List<DBObject> getObjectList() {
        DBColumn column = (DBColumn) sourceObject;
        return new ArrayList<DBObject>(column.getReferencingColumns());
    }
View Full Code Here

        return "Referencing records";
    }

    @Override
    protected AnAction createObjectAction(DBObject object) {
        DBColumn column = (DBColumn) object;
        DatasetFilterInput filterInput = new DatasetFilterInput(column.getDataset());
        filterInput.setColumnValue(column, columnValue);
        String actionText = NamingUtil.enhanceNameForDisplay(column.getDataset().getName() + " - " + column.getName() + "");
        return new ShowRecordsAction(actionText, filterInput) {};
    }
View Full Code Here

        String operator = this.operator;
        String value = this.value;

        if (editorForm != null && !editorForm.isDisposed()) {
            conditionOperator = editorForm.getSelectedOperator();
            DBColumn selectedColumn = editorForm.getSelectedColumn();
            if (selectedColumn != null) {
                columnName = selectedColumn.getName();
                operator = conditionOperator == null ? " " : conditionOperator.getText();
                value = editorForm.getValue();
            }
        }

        DBColumn column = dataset.getColumn(columnName);

        if (conditionOperator != null &&
                conditionOperator.getValuePrefix() != null &&
                conditionOperator.getValuePostfix() != null) {
            value = conditionOperator.getValuePrefix() + value + conditionOperator.getValuePostfix();
        }
        else if (StringUtil.isNotEmptyOrSpaces(value)) {
            DBDataType dataType = column == null ? null : column.getDataType();
            if (dataType != null && dataType.isNative()) {
                ConnectionHandler connectionHandler = dataset.getConnectionHandler();
                RegionalSettings regionalSettings = RegionalSettings.getInstance(connectionHandler.getProject());
                GenericDataType genericDataType = dataType.getNativeDataType().getBasicDataType();
                if (genericDataType == GenericDataType.LITERAL) {
                    value = com.intellij.openapi.util.text.StringUtil.replace(value, "'", "''");
                    value = "'" + value + "'";
                } else if (genericDataType == GenericDataType.DATE_TIME) {
                    DatabaseMetadataInterface metadataInterface = connectionHandler.getInterfaceProvider().getMetadataInterface();
                    try {
                        Date date = regionalSettings.getFormatter().parseDateTime(value);
                        value = metadataInterface.createDateString(date);
                    } catch (ParseException e) {
                        try {
                            Date date = regionalSettings.getFormatter().parseDate(value);
                            value = metadataInterface.createDateString(date);
                        } catch (ParseException e1) {
                            // value can be something like "sysdate" => not parseable
                            //e1.printStackTrace();
                        }
                    }
                } else if (genericDataType == GenericDataType.NUMERIC) {
                    /*try {
                        regionalSettings.getFormatter().parseNumber(value);
                    } catch (ParseException e) {
                        e.printStackTrace();

                    }*/
                }
            }
        }
        buffer.append(column == null ? columnName : column.getQuotedName(false));
        buffer.append(" ");
        buffer.append(operator);
        buffer.append(" ");
        buffer.append(value);
    }
View Full Code Here

        if (sortingInstructions.size() > 0) {
            buffer.append(" order by ");
            boolean instructionAdded = false;
            for (SortingInstruction sortingInstruction : sortingInstructions) {
                SortDirection sortDirection = sortingInstruction.getDirection();
                DBColumn column = dataset.getColumn(sortingInstruction.getColumnName());
                if (column != null && !sortDirection.isIndefinite()) {
                    buffer.append(instructionAdded ? ", " : "");
                    buffer.append(column.getName());
                    buffer.append(" ");
                    buffer.append(sortDirection.getSqlToken());
                    instructionAdded = true;
                }
            }
View Full Code Here

                    Object psiElement = bucket.toArray()[0];
                    if (psiElement instanceof IdentifierPsiElement) {
                        IdentifierPsiElement columnPsiElement = (IdentifierPsiElement) psiElement;
                        DBObject object = columnPsiElement.resolveUnderlyingObject();
                        if (object != null && object instanceof DBColumn) {
                            DBColumn column = (DBColumn) object;
                            return column.getDataType();
                        }

                    }
                    return null;
                }
View Full Code Here

    @Override
    protected void processMouseMotionEvent(MouseEvent e) {
        if (e.isControlDown() && e.getID() != MouseEvent.MOUSE_DRAGGED && isNavigableCellAtMousePosition()) {
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            DatasetEditorModelCell cell = (DatasetEditorModelCell) getCellAtMouseLocation();
            DBColumn column = cell.getColumnInfo().getColumn();
            if (column != null) {
                boolean ensureDataLoaded = DatabaseLoadMonitor.isEnsureDataLoaded();
                DatabaseLoadMonitor.setEnsureDataLoaded(false);
                try {
                    DBColumn foreignKeyColumn = column.getForeignKeyColumn();
                    if (foreignKeyColumn != null) {
                        setToolTipText("<html>Show referenced <b>" + foreignKeyColumn.getDataset().getQualifiedName() + "</b> record<html>");
                    }
                } finally {
                    DatabaseLoadMonitor.setEnsureDataLoaded(ensureDataLoaded);
                }
            }
View Full Code Here

                    columnSetup.init(dataset);
                }

                int index = 0;
                for (DatasetColumnState columnState : columnStates) {
                    DBColumn column = dataset.getColumn(columnState.getName());
                    ColumnInfo columnInfo = new DatasetEditorColumnInfo(column, index, column.getPosition());
                    addColumnInfo(columnInfo);
                    index++;
                }
            } else {
                ResultSetMetaData metaData = resultSet.getMetaData();
                int columnCount = metaData.getColumnCount();
                for (int i = 0; i < columnCount; i++) {
                    String name = metaData.getColumnName(i+1);
                    DBColumn column = dataset.getColumn(name);
                    ColumnInfo columnInfo = new DatasetEditorColumnInfo(column, i, i+1);
                    addColumnInfo(columnInfo);
                }
            }
View Full Code Here

TOP

Related Classes of com.dci.intellij.dbn.object.DBColumn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.