Package com.dci.intellij.dbn.connection

Examples of com.dci.intellij.dbn.connection.ConnectionHandler


import java.util.List;

public class DatasetEditorUtils {
    public static List<String> loadDistinctColumnValues(DBColumn column) {
        List<String> list = new ArrayList<String>();
        ConnectionHandler connectionHandler = column.getConnectionHandler();
        Connection connection = null;
        ResultSet resultSet = null;
        try {
            connection = connectionHandler.getPoolConnection();
            resultSet = connectionHandler.getInterfaceProvider().getMetadataInterface().getDistinctValues(
                column.getDataset().getSchema().getName(),
                column.getDataset().getName(),
                column.getName(), connection);

            while (resultSet.next()) {
                String value = resultSet.getString(1);
                list.add(value);
            }
        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            ConnectionUtil.closeResultSet(resultSet);
            connectionHandler.freePoolConnection(connection);
        }
        return list;
    }
View Full Code Here


    }

    private void buildElementRelativeVariants(LeafPsiElement element, CodeCompletionLookupConsumer consumer) throws ConsumerStoppedException {

        CodeCompletionContext context = consumer.getContext();
        ConnectionHandler connectionHandler = context.getConnectionHandler();

        CodeCompletionFilterSettings filterSettings = context.getCodeCompletionFilterSettings();
        Map<String, LeafElementType> nextPossibleLeafs = new THashMap<String, LeafElementType>();
        DBObject parentObject = null;
        if (element.getParent() instanceof QualifiedIdentifierPsiElement) {
            QualifiedIdentifierPsiElement qualifiedIdentifier = (QualifiedIdentifierPsiElement) element.getParent();
            ElementType separator = qualifiedIdentifier.getElementType().getSeparatorToken();

            if (element.getElementType() == separator){
                BasePsiElement parentPsiElement = element.getPrevElement();
                if (parentPsiElement != null && parentPsiElement instanceof IdentifierPsiElement) {
                    IdentifierPsiElement identifierPsiElement = (IdentifierPsiElement) parentPsiElement;
                    parentObject = identifierPsiElement.resolveUnderlyingObject();

                    if (parentObject != null) {
                        for (QualifiedIdentifierVariant parseVariant : qualifiedIdentifier.getParseVariants()){
                            boolean match = parseVariant.matchesPsiElement(qualifiedIdentifier);
                            if (match) {
                                int index = qualifiedIdentifier.getIndexOf(identifierPsiElement);
                                LeafElementType leafElementType = parseVariant.getLeaf(index + 1);
                                if (leafElementType != null) {
                                    nextPossibleLeafs.put(getLeafUniqueKey(leafElementType), leafElementType);
                                }
                            }
                        }
                    }
                }
            }
        }

        if (nextPossibleLeafs.size() == 0) {
            LeafElementType elementType = (LeafElementType) element.getElementType();
            PathNode pathNode = new ASTPathNode(element.getNode());
            for (LeafElementType leafElementType : elementType.getNextPossibleLeafs(pathNode, filterSettings)) {
                String leafUniqueKey = getLeafUniqueKey(leafElementType);
                if (leafUniqueKey != null) {
                    nextPossibleLeafs.put(leafUniqueKey, leafElementType);   
                }
            }
        }

        for (LeafElementType nextPossibleLeaf : nextPossibleLeafs.values()) {
            consumer.check();
            //boolean addParenthesis =
            //        nextPossibleLeaf.getLookupCache().getNextRequiredTokens().contains(
            //                element.getLanguage().getSharedTokenTypes().getLeftParenthesis());
            //consumer.setAddParenthesis(addParenthesis);

            if (nextPossibleLeaf instanceof TokenElementType) {
                TokenElementType tokenElementType = (TokenElementType) nextPossibleLeaf;
                //consumer.setAddParenthesis(addParenthesis && tokenType.isFunction());
                if (filterSettings.acceptReservedWord(tokenElementType.getTokenTypeCategory())) {
                    consumer.consume(tokenElementType);
                }
            }
            else if (nextPossibleLeaf instanceof IdentifierElementType) {
                IdentifierElementType identifierElementType = (IdentifierElementType) nextPossibleLeaf;
                if (identifierElementType.isReference()) {
                    DBObjectType objectType = identifierElementType.getObjectType();
                    if (identifierElementType.isObject()) {
                        PsiLookupAdapter lookupAdapter = new ObjectDefinitionLookupAdapter(null, objectType,  null);
                        Set<BasePsiElement> objectDefinitions = lookupAdapter.collectInParentScopeOf(element);
                        if (objectDefinitions != null) {
                            for (BasePsiElement psiElement : objectDefinitions) {
                                if (psiElement instanceof IdentifierPsiElement) {
                                    IdentifierPsiElement identifierPsiElement = (IdentifierPsiElement) psiElement;
                                    PsiElement referencedPsiElement = identifierPsiElement.resolve();
                                    if (referencedPsiElement instanceof DBObject) {
                                        DBObject object = (DBObject) referencedPsiElement;
                                        LookupItemFactory lookupItemFactory = object.getLookupItemFactory(identifierElementType.getLanguage());
                                        lookupItemFactory.createLookupItem(object, consumer);
                                    }
                                }
                            }
                        }
                       
                        if (connectionHandler != null && !connectionHandler.isVirtual()) {
                            if (parentObject == null) {
                                BasePsiElement scope = element.getEnclosingScopePsiElement();
                                collectObjectMatchingScope(consumer, identifierElementType, filterSettings, scope, context);
                            } else {
                                for (DBObject object : parentObject.getChildObjects(identifierElementType.getObjectType())) {
View Full Code Here

            ObjectTypeFilter filter,
            BasePsiElement sourceScope,
            CodeCompletionContext context) throws ConsumerStoppedException {
        DBObjectType objectType = identifierElementType.getObjectType();
        PsiElement sourceElement = context.getElementAtCaret();
        ConnectionHandler connectionHandler = context.getConnectionHandler();

        if (connectionHandler != null ) {
            DBObjectBundle objectBundle = connectionHandler.getObjectBundle();
            if (sourceElement.getParent() instanceof QualifiedIdentifierPsiElement && sourceElement.getParent().getFirstChild() != sourceElement) {
                QualifiedIdentifierPsiElement qualifiedIdentifierPsiElement = (QualifiedIdentifierPsiElement) sourceElement.getOriginalElement().getParent();
                DBObject parentObject = qualifiedIdentifierPsiElement.lookupParentObjectFor(identifierElementType);
                if (parentObject != null) {
                    DBSchema currentSchema = PsiUtil.getCurrentSchema(sourceScope);
View Full Code Here

    public JComponent getPreferredFocusedComponent() {
        return selectConnectionForm.getConnectionsList();
    }

    protected void doOKAction() {
        ConnectionHandler activeConnection = selectConnectionForm.getSelectedConnection();
        DBSchema currentSchema = selectConnectionForm.getSelectedSchema();
        file.setActiveConnection(activeConnection);
        file.setCurrentSchema(currentSchema);
        Editor editor = EditorUtil.getSelectedEditor(file.getProject());
        DocumentUtil.touchDocument(editor);
View Full Code Here

    private SelectCurrentSchemaForm selectCurrentSchemaForm;

    public SelectCurrentSchemaDialog(DBLanguageFile file) {
        super(file.getProject(), "Select Current Schema", true);
        this.file = file;
        ConnectionHandler activeConnection = file.getActiveConnection();
        selectCurrentSchemaForm = new SelectCurrentSchemaForm(file, activeConnection);
        selectCurrentSchemaForm.setHintMessage(null);
        init();
    }
View Full Code Here

            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 {
View Full Code Here

            method.readConfiguration(methodElement);
        }
    }

    public void writeConfiguration(Element element) throws WriteExternalException {
        ConnectionHandler connectionHandler = getConnectionHandler();
        if (connectionHandler != null) element.setAttribute("connection-id", connectionHandler.getId());
        if (schemaName != null) element.setAttribute("schema", schemaName);
        if(method != null) {
            Element methodElement = new Element("selected-method");
            method.writeConfiguration(methodElement);
            element.addContent(methodElement);
View Full Code Here

        }
    }

    @NotNull
    protected DefaultActionGroup createPopupActionGroup(JComponent jComponent) {
        ConnectionHandler connectionHandler = executionInput.getConnectionHandler();
        DefaultActionGroup actionGroup = new DefaultActionGroup();
        for (DBSchema schema : connectionHandler.getObjectBundle().getSchemas()){
            actionGroup.add(new SetExecutionSchemaAction(executionInput, schema));
        }
        return actionGroup;
    }
View Full Code Here

        if (!CommonUtil.safeEqual(userValue, getUserValue()) || hasError()) {
            DatasetEditorModelRow row = getRow();
            DatasetEditorError error = new DatasetEditorError(errorMessage, getColumnInfo().getColumn());
            getRow().notifyError(error, true, true);
            setUserValue(userValue);
            ConnectionHandler connectionHandler = getConnectionHandler();
            if (!row.isInsert() && !connectionHandler.isAutoCommit()) {
                isModified = true;
                row.setModified(true);
                connectionHandler.ping(false);
            }
        }
    }
View Full Code Here

        }
        return underlyingObject;
    }

    public char getIdentifierQuotesChar() {
        ConnectionHandler activeConnection = getActiveConnection();
        if (activeConnection != null) {
            return DatabaseCompatibilityInterface.getInstance(activeConnection).getIdentifierQuotes();
        }
        return '"';
    }
View Full Code Here

TOP

Related Classes of com.dci.intellij.dbn.connection.ConnectionHandler

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.