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

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


    public Object visit(ASTRangeVariableDeclaration node, Object data) {
        StringBuffer buf = (StringBuffer) data;

        ASTAbstractSchema schema = (ASTAbstractSchema) node.jjtGetChild(0);
        JDBCEntityBridge entity = (JDBCEntityBridge) schema.entity;
        ASTIdentifier id = (ASTIdentifier) node.jjtGetChild(1);

        String alias = aliasManager.getAlias(id.identifier);
        buf.append(entity.getQualifiedTableName())
                .append(' ')
                .append(alias);
        leftJoins(id.identifier, buf);

        if (onFindCMRJoin != null && alias.equals(selectAlias)) {
View Full Code Here


                addJoinPath(path);
                selectAlias = aliasManager.getAlias(path.getPath(path.size() - 2));
                SQLUtil.getColumnNamesClause(selectField, selectAlias, buf);
            } else {
                // set the select object
                JDBCEntityBridge selectEntity = (JDBCEntityBridge) path.getEntity();
                selectManager = (JDBCStoreManager) selectEntity.getManager();
                selectObject = selectEntity;
                setTypeFactory(selectManager.getJDBCTypeFactory());
                selectEntity(path, node.distinct, buf);
            }
        } else {
            // the function should take a path expresion as a parameter
            path = getPathFromChildren(child0);

            if (path == null) {
                throw new IllegalStateException("The function in SELECT clause does not contain a path expression.");
            }

            if (path.isCMPField()) {
                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);
            }

            setTypeFactory(selectManager.getJDBCTypeFactory());
            selectObject = child0;
View Full Code Here

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

        Object[] args;
        final ASTPath cntPath = (ASTPath) node.jjtGetChild(0);
        if (cntPath.isCMPField()) {
            args = new Object[]{node.distinct, new NodeStringWrapper(cntPath)};
        } else {
            JDBCEntityBridge entity = (JDBCEntityBridge) cntPath.getEntity();
            final JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
            if (pkFields.length > 1) {
                countCompositePk = true;
                forceDistinct = node.distinct.length() > 0;
                selectEntity(cntPath, forceDistinct, buf);
                return buf;
View Full Code Here

        CMPFieldBridge cmpField = path.getCMPField();
        if (selectObject instanceof JDBCCMPFieldBridge && cmpField == selectObject) {
            selected = true;
        } else if (selectObject instanceof JDBCEntityBridge) {
            JDBCEntityBridge entity = (JDBCEntityBridge) selectObject;
            JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
            for (int pkInd = 0; pkInd < pkFields.length; ++pkInd) {
                if (pkFields[pkInd] == cmpField) {
                    selected = true;
                    break;
                }
View Full Code Here

        return selected;
    }

    private void selectEntity(ASTPath path, boolean distinct, StringBuffer buf) {
        JDBCEntityBridge selectEntity = (JDBCEntityBridge) path.getEntity();

        StringBuffer columnNamesClause = new StringBuffer(200);
        addJoinPath(path);
        selectAlias = aliasManager.getAlias(path.getPath());

        // get a list of all fields to be loaded
        // get the identifier for this field
        SQLUtil.getColumnNamesClause(selectEntity.getPrimaryKeyFields(), selectAlias, columnNamesClause);

        if (readAhead.isOnFind()) {
            String eagerLoadGroupName = readAhead.getEagerLoadGroup();
            boolean[] loadGroupMask = selectEntity.getLoadGroupMask(eagerLoadGroupName);
            if (distinct)
                SQLUtil.appendSearchableColumnNamesClause(selectEntity.getTableFields(), loadGroupMask, selectAlias, columnNamesClause);
            else
                SQLUtil.appendColumnNamesClause(selectEntity.getTableFields(), loadGroupMask, selectAlias, columnNamesClause);

            try {
                leftJoinCMRList = JDBCAbstractQueryCommand.getLeftJoinCMRNodes(
                        selectEntity, path.getPath(), readAhead.getLeftJoins(), declaredPaths);
            } catch (Exception e) {
View Full Code Here

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

        String fromAlias;
        JDBCEntityBridge fromEntity;
        ASTPath fromPath = (ASTPath) fromNode;
        addJoinPath(fromPath);
        fromAlias = aliasManager.getAlias(fromPath.getPath());
        fromEntity = (JDBCEntityBridge) fromPath.getEntity();

        if (toNode instanceof ASTParameter) {
            ASTParameter toParam = (ASTParameter) toNode;

            // can only compare like kind entities
            verifyParameterEntityType(toParam.number, fromEntity);

            inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromEntity));

            SQLUtil.getWhereClause(fromEntity.getPrimaryKeyFields(), fromAlias, buf);
        } else {
            String toAlias;
            JDBCEntityBridge toEntity;
            ASTPath toPath = (ASTPath) toNode;
            addJoinPath(toPath);
            toAlias = aliasManager.getAlias(toPath.getPath());
            toEntity = (JDBCEntityBridge) toPath.getEntity();

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

            SQLUtil.getSelfCompareWhereClause(fromEntity.getPrimaryKeyFields(), fromAlias, toAlias, buf);
        }
View Full Code Here

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

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

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

TOP

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

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.