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

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


            return Collections.emptyList();
        }

        final List<LeftJoinCMRNode> leftJoinCMRNodes = new ArrayList<LeftJoinCMRNode>();
        for (JDBCLeftJoinMetaData leftJoin : leftJoins) {
            JDBCCMRFieldBridge cmrField = entity.getCMRFieldByName(leftJoin.getCmrField());
            if (cmrField == null) {
                throw new RuntimeException("cmr-field in left-join was not found: cmr-field=" +
                        leftJoin.getCmrField() + ", entity=" + entity.getEntityName());
            }

            List<LeftJoinCMRNode> subNodes;
            JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
            String childPath = path + '.' + cmrField.getFieldName();
            if (declaredPaths != null) {
                declaredPaths.add(childPath);
            }

            subNodes = getLeftJoinCMRNodes(relatedEntity, childPath, leftJoin.getLeftJoins(), declaredPaths);
View Full Code Here


        return leftJoinCMRNodes;
    }

    public static final void leftJoinCMRNodes(String alias, List<LeftJoinCMRNode> onFindCMRNodes, AliasManager aliasManager, StringBuffer sb) {
        for (LeftJoinCMRNode node : onFindCMRNodes) {
            JDBCCMRFieldBridge cmrField = node.cmrField;
            JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
            String relatedAlias = aliasManager.getAlias(node.path);

            JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();
            if (relation.isTableMappingStyle()) {
                String relTableAlias = aliasManager.getRelationTableAlias(node.path);
                sb.append(" LEFT OUTER JOIN ")
                        .append(cmrField.getQualifiedTableName())
                        .append(' ')
                        .append(relTableAlias)
                        .append(" ON ");
                SQLUtil.getRelationTableJoinClause(cmrField, alias, relTableAlias, sb);

                sb.append(" LEFT OUTER JOIN ")
                        .append(relatedEntity.getQualifiedTableName())
                        .append(' ')
                        .append(relatedAlias)
                        .append(" ON ");
                SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), relatedAlias, relTableAlias, sb);
            } else {
                // foreign key mapping style
                sb.append(" LEFT OUTER JOIN ")
                        .append(relatedEntity.getQualifiedTableName())
                        .append(' ')
View Full Code Here

    public static final void appendLeftJoinCMRColumnNames(List<LeftJoinCMRNode> onFindCMRNodes,
                                                          AliasManager aliasManager,
                                                          StringBuffer sb) {
        for (LeftJoinCMRNode node : onFindCMRNodes) {
            JDBCCMRFieldBridge cmrField = node.cmrField;
            JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
            String childAlias = aliasManager.getAlias(node.path);

            // primary key fields
            SQLUtil.appendColumnNamesClause(relatedEntity.getPrimaryKeyFields(),
                    childAlias,
View Full Code Here

    }

    private static int loadOnFindCMRFields(Object pk, List<LeftJoinCMRNode> onFindCMRNodes, ResultSet rs, int index, Logger log) {
        Object[] ref = new Object[1];
        for (LeftJoinCMRNode node : onFindCMRNodes) {
            JDBCCMRFieldBridge cmrField = node.cmrField;
            ReadAheadCache myCache = cmrField.getJDBCStoreManager().getReadAheadCache();
            JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
            ReadAheadCache relatedCache = cmrField.getRelatedManager().getReadAheadCache();

            // load related id
            ref[0] = null;
            index = relatedEntity.loadPrimaryKeyResults(rs, index, ref);
            Object relatedId = ref[0];
            boolean cacheRelatedData = relatedId != null;

            if (pk != null) {
                if (cmrField.getMetaData().getRelatedRole().isMultiplicityOne()) {
                    // cacheRelatedData the value
                    myCache.addPreloadData(pk,
                            cmrField,
                            relatedId == null ? Collections.EMPTY_LIST : Collections.singletonList(relatedId));
                } else {
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

    public Object execute(Method m, Object[] args, CmpEntityBeanContext ctx) {
        if (cmrWithFKMappedToCMP == null)
            return null;

        for (int i = 0; i < cmrWithFKMappedToCMP.length; ++i) {
            JDBCCMRFieldBridge cmrField = cmrWithFKMappedToCMP[i];
            JDBCCMRFieldBridge relatedCMRField = (JDBCCMRFieldBridge) cmrField.getRelatedCMRField();
            if (cmrField.hasFKFieldsMappedToCMPFields()) {
                Object relatedId = cmrField.getRelatedIdFromContext(ctx);
                if (relatedId != null) {
                    try {
                        if (cmrField.isForeignKeyValid(relatedId)) {
                            cmrField.createRelationLinks(ctx, relatedId);
                        } else {
                            relatedCMRField.addRelatedPKWaitingForMyPK(relatedId, ctx.getPrimaryKey());
                        }
                    } catch (Exception e) {
                        // no such object
                    }
                }
            } else if (relatedCMRField.hasFKFieldsMappedToCMPFields()) {
                cmrField.addRelatedPKsWaitedForMe(ctx);
            }
        }
        return null;
    }
View Full Code Here

        while (i < relationData.removedRelations.size()) {
            String sql = getSQL(relationData, relationData.removedRelations.size() - i);

            Connection con = null;
            PreparedStatement ps = null;
            JDBCCMRFieldBridge cmrField = relationData.getLeftCMRField();
            try {
                // create the statement
                if (log.isDebugEnabled()) {
                    log.debug("Executing SQL: " + sql);
                }

                // get the connection
                DataSource dataSource = cmrField.getDataSource();
                con = dataSource.getConnection();
                ps = con.prepareStatement(sql);

                // set the parameters
                setParameters(ps, relationData, pairs);

                // execute statement
                int rowsAffected = ps.executeUpdate();
                if (log.isDebugEnabled()) {
                    log.debug("Rows affected = " + rowsAffected);
                }

                i += (maxKeysInDelete > 0 ? maxKeysInDelete : relationData.removedRelations.size());
            } catch (Exception e) {
                throw CmpMessages.MESSAGES.couldNotDeleteRelations(cmrField.getQualifiedTableName(), e);
            } finally {
                JDBCUtil.safeClose(ps);
                JDBCUtil.safeClose(con);
            }
        }
View Full Code Here

        }
        return createSQL(relationData, keys);
    }

    private static String createSQL(RelationData relationData, int keysInDelete) {
        JDBCCMRFieldBridge left = relationData.getLeftCMRField();
        JDBCCMRFieldBridge right = relationData.getRightCMRField();

        StringBuffer sql = new StringBuffer(300);
        sql.append(SQLUtil.DELETE_FROM)
                .append(left.getQualifiedTableName())
                .append(SQLUtil.WHERE);

        StringBuffer whereClause = new StringBuffer(20);
        whereClause.append('(');
        // left keys
        SQLUtil.getWhereClause(left.getTableKeyFields(), whereClause)
                .append(SQLUtil.AND);
        // right keys
        SQLUtil.getWhereClause(right.getTableKeyFields(), whereClause)
                .append(')');
        String whereClauseStr = whereClause.toString();
        sql.append(whereClauseStr);
        for (int i = 1; i < keysInDelete; ++i) {
            sql.append(SQLUtil.OR).append(whereClauseStr);
View Full Code Here

            return Collections.emptyList();
        }

        final List<LeftJoinCMRNode> leftJoinCMRNodes = new ArrayList<LeftJoinCMRNode>();
        for (JDBCLeftJoinMetaData leftJoin : leftJoins) {
            JDBCCMRFieldBridge cmrField = entity.getCMRFieldByName(leftJoin.getCmrField());
            if (cmrField == null) {
                throw CmpMessages.MESSAGES.cmrFieldInJoinNotFound(leftJoin.getCmrField(), entity.getEntityName());
            }

            List<LeftJoinCMRNode> subNodes;
            JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
            String childPath = path + '.' + cmrField.getFieldName();
            if (declaredPaths != null) {
                declaredPaths.add(childPath);
            }

            subNodes = getLeftJoinCMRNodes(relatedEntity, childPath, leftJoin.getLeftJoins(), declaredPaths);
View Full Code Here

        return leftJoinCMRNodes;
    }

    public static final void leftJoinCMRNodes(String alias, List<LeftJoinCMRNode> onFindCMRNodes, AliasManager aliasManager, StringBuffer sb) {
        for (LeftJoinCMRNode node : onFindCMRNodes) {
            JDBCCMRFieldBridge cmrField = node.cmrField;
            JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
            String relatedAlias = aliasManager.getAlias(node.path);

            JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();
            if (relation.isTableMappingStyle()) {
                String relTableAlias = aliasManager.getRelationTableAlias(node.path);
                sb.append(" LEFT OUTER JOIN ")
                        .append(cmrField.getQualifiedTableName())
                        .append(' ')
                        .append(relTableAlias)
                        .append(" ON ");
                SQLUtil.getRelationTableJoinClause(cmrField, alias, relTableAlias, sb);

                sb.append(" LEFT OUTER JOIN ")
                        .append(relatedEntity.getQualifiedTableName())
                        .append(' ')
                        .append(relatedAlias)
                        .append(" ON ");
                SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), relatedAlias, relTableAlias, sb);
            } else {
                // foreign key mapping style
                sb.append(" LEFT OUTER JOIN ")
                        .append(relatedEntity.getQualifiedTableName())
                        .append(' ')
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.