Package org.jboss.as.cmp.jdbc.bridge

Examples of org.jboss.as.cmp.jdbc.bridge.JDBCCMRFieldBridge


        StringBuffer buf = (StringBuffer) data;

        // setup compare to vars first, so we can compre types in from vars
        ASTPath toPath = (ASTPath) node.jjtGetChild(1);

        JDBCCMRFieldBridge toCMRField = (JDBCCMRFieldBridge) toPath.getCMRField();

        JDBCEntityBridge toChildEntity = (JDBCEntityBridge) toPath.getEntity();

        String pathStr = toPath.getPath(toPath.size() - 2);
        String toParentAlias = aliasManager.getAlias(pathStr);
        String toChildAlias = aliasManager.getAlias(toPath.getPath());
        String relationTableAlias = null;
        if (toCMRField.getRelationMetaData().isTableMappingStyle()) {
            relationTableAlias = aliasManager.getRelationTableAlias(toPath.getPath());
        }

        // setup from variables
        String fromAlias = null;
        int fromParamNumber = -1;
        if (node.jjtGetChild(0) instanceof ASTParameter) {
            ASTParameter fromParam = (ASTParameter) node.jjtGetChild(0);

            // can only compare like kind entities
            verifyParameterEntityType(fromParam.number, toChildEntity);

            fromParamNumber = fromParam.number;
        } else {
            ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
            addJoinPath(fromPath);

            JDBCEntityBridge fromEntity = (JDBCEntityBridge) fromPath.getEntity();
            fromAlias = aliasManager.getAlias(fromPath.getPath());

            // can only compare like kind entities
            if (!fromEntity.equals(toChildEntity)) {
                throw new IllegalStateException("Only like types can be " +
                        "compared: from entity=" +
                        fromEntity.getEntityName() +
                        " to entity=" + toChildEntity.getEntityName());
            }
        }

        // add the path to the list of paths to left join
        addLeftJoinPath(pathStr, toPath);

        // first part makes toChild not in toParent.child
        if (!subquerySupported) {
            addJoinPath(toPath);

            // subquery not supported; use a left join and is not null
            if (node.not) {
                buf.append(SQLUtil.NOT);
            }
            buf.append('(');

            if (relationTableAlias == null) {
                SQLUtil.getIsNullClause(true, toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
            } else {
                SQLUtil.getIsNullClause(true, toCMRField.getTableKeyFields(), relationTableAlias, buf);
            }
        } else {
            // subquery supported; use exists subquery
            if (node.not) {
                buf.append(SQLUtil.NOT);
            }

            buf.append(SQLUtil.EXISTS).append('(');

            if (relationTableAlias == null) {
                buf.append(SQLUtil.SELECT);
                SQLUtil.getColumnNamesClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf)
                        .append(SQLUtil.FROM)
                        .append(toChildEntity.getQualifiedTableName())
                        .append(' ')
                        .append(toChildAlias)
                        .append(SQLUtil.WHERE);
                SQLUtil.getJoinClause(toCMRField, toParentAlias, toChildAlias, buf);
            } else {
                buf.append(SQLUtil.SELECT);
                SQLUtil.getColumnNamesClause(toCMRField.getRelatedCMRField().getTableKeyFields(), relationTableAlias, buf)
                        .append(SQLUtil.FROM)
                        .append(toCMRField.getQualifiedTableName())
                        .append(' ')
                        .append(relationTableAlias)
                        .append(SQLUtil.WHERE);
                SQLUtil.getRelationTableJoinClause(toCMRField, toParentAlias, relationTableAlias, buf);
            }
        }

        buf.append(SQLUtil.AND);

        // second part makes fromNode equal toChild
        if (fromAlias != null) {
            // compre pk to pk
            if (relationTableAlias == null) {
                SQLUtil.getSelfCompareWhereClause(toChildEntity.getPrimaryKeyFields(),
                        toChildAlias,
                        fromAlias,
                        buf);
            } else {
                SQLUtil.getRelationTableJoinClause(toCMRField.getRelatedCMRField(),
                        fromAlias,
                        relationTableAlias,
                        buf);
            }
        } else {
            // add the parameters
            inputParameters.addAll(QueryParameter.createParameters(fromParamNumber - 1,
                    toChildEntity));

            // compare pk to parameter
            if (relationTableAlias == null) {
                SQLUtil.getWhereClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
            } else {
                SQLUtil.getWhereClause(toCMRField.getRelatedCMRField().getTableKeyFields(),
                        relationTableAlias,
                        buf);
            }
        }
View Full Code Here


    private void existsClause(ASTPath path, StringBuffer buf, boolean not) {
        if (!path.isCMRField()) {
            throw MESSAGES.pathMustBeCmrField();
        }

        JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
        String pathStr = path.getPath(path.size() - 2);
        String parentAlias = aliasManager.getAlias(pathStr);

        // if exists is not supported we use a left join and is null
        if (!subquerySupported) {
            // add the path to the list of paths to left join
            addLeftJoinPath(pathStr, path);
            forceDistinct = true;

            addJoinPath(path);

            if (cmrField.getRelationMetaData().isForeignKeyMappingStyle()) {
                JDBCEntityBridge childEntity = (JDBCEntityBridge) cmrField.getRelatedEntity();
                String childAlias = aliasManager.getAlias(path.getPath());
                SQLUtil.getIsNullClause(!not, childEntity.getPrimaryKeyFields(), childAlias, buf);
            } else {
                String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
                SQLUtil.getIsNullClause(!not, cmrField.getTableKeyFields(), relationTableAlias, buf);
            }
            return;
        }

        if (not) {
            buf.append(SQLUtil.NOT);
        }
        buf.append(SQLUtil.EXISTS).append('(');

        if (cmrField.getRelationMetaData().isForeignKeyMappingStyle()) {
            JDBCEntityBridge childEntity = (JDBCEntityBridge) cmrField.getRelatedEntity();
            String childAlias = aliasManager.getAlias(path.getPath());

            buf.append(SQLUtil.SELECT);

            SQLUtil.getColumnNamesClause(childEntity.getPrimaryKeyFields(), childAlias, buf)
                    .append(SQLUtil.FROM)
                    .append(childEntity.getQualifiedTableName()).append(' ').append(childAlias)
                    .append(SQLUtil.WHERE);
            SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
        } else {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
            buf.append(SQLUtil.SELECT);
            SQLUtil.getColumnNamesClause(cmrField.getTableKeyFields(), relationTableAlias, buf)
                    .append(SQLUtil.FROM)
                    .append(cmrField.getQualifiedTableName())
                    .append(' ')
                    .append(relationTableAlias)
                    .append(SQLUtil.WHERE);
            SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf);
        }
View Full Code Here

    private void declareTables(ASTPath path, int i, StringBuffer buf) {
        if (!path.isCMRField(i) || declaredPaths.contains(path.getPath(i))) {
            return;
        }

        JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField(i);
        JDBCEntityBridge entity = (JDBCEntityBridge) path.getEntity(i);

        buf.append(SQLUtil.COMMA)
                .append(entity.getQualifiedTableName())
                .append(' ')
                .append(aliasManager.getAlias(path.getPath(i)));
        leftJoins(path.getPath(i), buf);

        if (cmrField.getRelationMetaData().isTableMappingStyle()) {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath(i));
            buf.append(SQLUtil.COMMA)
                    .append(cmrField.getQualifiedTableName())
                    .append(' ')
                    .append(relationTableAlias);
        }

        declaredPaths.add(path.getPath(i));
View Full Code Here

        }

        for (Iterator iter = paths.iterator(); iter.hasNext(); ) {
            ASTPath path = (ASTPath) iter.next();

            JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
            String parentAlias = aliasManager.getAlias(parentPath);

            if (cmrField.getRelationMetaData().isForeignKeyMappingStyle()) {
                JDBCEntityBridge childEntity = (JDBCEntityBridge) cmrField.getRelatedEntity();
                String childAlias = aliasManager.getAlias(path.getPath());

                buf.append(SQLUtil.LEFT_JOIN)
                        .append(childEntity.getQualifiedTableName())
                        .append(' ')
                        .append(childAlias)
                        .append(SQLUtil.ON);
                SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
            } else {
                String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
                buf.append(SQLUtil.LEFT_JOIN)
                        .append(cmrField.getQualifiedTableName())
                        .append(' ')
                        .append(relationTableAlias)
                        .append(SQLUtil.ON);
                SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf);
            }
View Full Code Here

                                 StringBuffer buf) {
        if (!path.isCMRField(i) || joinedAliases.contains(childAlias)) {
            return;
        }

        JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField(i);
        String parentAlias = aliasManager.getAlias(path.getPath(i - 1));

        if (joinedAliases.size() > 0) {
            buf.append(SQLUtil.AND);
        }

        if (cmrField.getRelationMetaData().isForeignKeyMappingStyle()) {
            SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
        } else {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath(i));

            // parent to relation table
            SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf)
                    .append(SQLUtil.AND);
            // child to relation table
            SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), childAlias, relationTableAlias, buf);
        }

        joinedAliases.add(childAlias);
    }
View Full Code Here

            buf.append(onFindCMRJoin);
            onFindCMRJoin = null;
        }

        // add the relation-table
        JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
        if (cmrField.getRelationMetaData().isTableMappingStyle()) {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
            buf.append(SQLUtil.COMMA)
                    .append(cmrField.getQualifiedTableName())
                    .append(' ')
                    .append(relationTableAlias);
        }

        return buf;
View Full Code Here

                JDBCCMPFieldBridge selectField = (JDBCCMPFieldBridge) path.getCMPField();
                selectManager = (JDBCStoreManager) selectField.getManager();
                if (selectField.getJDBCType().hasMapper())
                    this.functionJDBCType = selectField.getJDBCType();
            } else if (path.isCMRField()) {
                JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
                selectManager = (JDBCStoreManager) cmrField.getEntity().getManager();
                addJoinPath(path);
            } else {
                final JDBCEntityBridge entity = (JDBCEntityBridge) path.getEntity();
                selectManager = (JDBCStoreManager) entity.getManager();
                addJoinPath(path);
View Full Code Here

        final Node child0 = node.jjtGetChild(0);
        if (child0 instanceof ASTPath) {
            ASTPath path = (ASTPath) child0;

            if (path.isCMRField()) {
                JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
                if (cmrField.getRelationMetaData().isTableMappingStyle()) {
                    existsClause(path, buf, !node.not);
                    return buf;
                }
            }
View Full Code Here

        StringBuffer buf = (StringBuffer) data;

        // setup compare to vars first, so we can compare types in from vars
        ASTPath toPath = (ASTPath) node.jjtGetChild(1);

        JDBCCMRFieldBridge toCMRField = (JDBCCMRFieldBridge) toPath.getCMRField();

        JDBCEntityBridge toChildEntity = (JDBCEntityBridge) toPath.getEntity();

        String pathStr = toPath.getPath(toPath.size() - 2);
        String toParentAlias = aliasManager.getAlias(pathStr);
        String toChildAlias = aliasManager.getAlias(toPath.getPath());
        String relationTableAlias = null;
        if (toCMRField.getRelationMetaData().isTableMappingStyle()) {
            relationTableAlias = aliasManager.getRelationTableAlias(toPath.getPath());
        }

        // setup from variables
        String fromAlias = null;
        int fromParamNumber = -1;
        if (node.jjtGetChild(0) instanceof ASTParameter) {
            ASTParameter fromParam = (ASTParameter) node.jjtGetChild(0);

            // can only compare like kind entities
            verifyParameterEntityType(fromParam.number, toChildEntity);

            fromParamNumber = fromParam.number;
        } else {
            ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
            addJoinPath(fromPath);

            JDBCEntityBridge fromEntity = (JDBCEntityBridge) fromPath.getEntity();
            fromAlias = aliasManager.getAlias(fromPath.getPath());

            // can only compare like kind entities
            if (!fromEntity.equals(toChildEntity)) {
                throw CmpMessages.MESSAGES.onlyLikeTypesCanBeCompared(fromEntity.getEntityName(), toChildEntity.getEntityName());
            }
        }

        // add the path to the list of paths to left join
        addLeftJoinPath(pathStr, toPath);

        // first part makes toChild not in toParent.child
        if (!subquerySupported) {
            addJoinPath(toPath);

            // subquery not supported; use a left join and is not null
            if (node.not) {
                buf.append(SQLUtil.NOT);
            }
            buf.append('(');

            if (relationTableAlias == null) {
                SQLUtil.getIsNullClause(true, toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
            } else {
                SQLUtil.getIsNullClause(true, toCMRField.getTableKeyFields(), relationTableAlias, buf);
            }
        } else {
            // subquery supported; use exists subquery
            if (node.not) {
                buf.append(SQLUtil.NOT);
            }

            buf.append(SQLUtil.EXISTS).append('(');

            if (relationTableAlias == null) {
                buf.append(SQLUtil.SELECT);
                SQLUtil.getColumnNamesClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf)
                        .append(SQLUtil.FROM)
                        .append(toChildEntity.getQualifiedTableName())
                        .append(' ')
                        .append(toChildAlias)
                        .append(SQLUtil.WHERE);
                SQLUtil.getJoinClause(toCMRField, toParentAlias, toChildAlias, buf);
            } else {
                buf.append(SQLUtil.SELECT);
                SQLUtil.getColumnNamesClause(toCMRField.getRelatedCMRField().getTableKeyFields(), relationTableAlias, buf)
                        .append(SQLUtil.FROM)
                        .append(toCMRField.getQualifiedTableName())
                        .append(' ')
                        .append(relationTableAlias)
                        .append(SQLUtil.WHERE);
                SQLUtil.getRelationTableJoinClause(toCMRField, toParentAlias, relationTableAlias, buf);
            }
        }

        buf.append(SQLUtil.AND);

        // second part makes fromNode equal toChild
        if (fromAlias != null) {
            // compare pk to pk
            if (relationTableAlias == null) {
                SQLUtil.getSelfCompareWhereClause(toChildEntity.getPrimaryKeyFields(),
                        toChildAlias,
                        fromAlias,
                        buf);
            } else {
                SQLUtil.getRelationTableJoinClause(toCMRField.getRelatedCMRField(),
                        fromAlias,
                        relationTableAlias,
                        buf);
            }
        } else {
            // add the parameters
            inputParameters.addAll(QueryParameter.createParameters(fromParamNumber - 1,
                    toChildEntity));

            // compare pk to parameter
            if (relationTableAlias == null) {
                SQLUtil.getWhereClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
            } else {
                SQLUtil.getWhereClause(toCMRField.getRelatedCMRField().getTableKeyFields(),
                        relationTableAlias,
                        buf);
            }
        }
View Full Code Here

    public JDBCPostCreateEntityCommand(JDBCStoreManager manager) {
        entity = (JDBCEntityBridge) manager.getEntityBridge();
        JDBCFieldBridge[] cmrFields = entity.getCMRFields();
        List fkToCMPList = new ArrayList(4);
        for (int i = 0; i < cmrFields.length; ++i) {
            JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) cmrFields[i];
            JDBCCMRFieldBridge relatedCMRField = (JDBCCMRFieldBridge) cmrField.getRelatedCMRField();
            if (cmrField.hasFKFieldsMappedToCMPFields()
                    || relatedCMRField.hasFKFieldsMappedToCMPFields()) {
                fkToCMPList.add(cmrField);
            }
        }
        if (fkToCMPList.isEmpty())
            cmrWithFKMappedToCMP = null;
View Full Code Here

TOP

Related Classes of org.jboss.as.cmp.jdbc.bridge.JDBCCMRFieldBridge

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.