Package org.jboss.as.cmp.jdbc.metadata

Examples of org.jboss.as.cmp.jdbc.metadata.JDBCRelationMetaData


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


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

        // create relation tables
        JDBCAbstractCMRFieldBridge[] cmrFields = entity.getCMRFields();
        for (int i = 0; i < cmrFields.length; ++i) {
            JDBCAbstractCMRFieldBridge cmrField = cmrFields[i];
            JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();
            DataSource dataSource = manager.getDataSource(relationMetaData.getDataSourceName());

            // if the table for the related entity has been created
            final EntityBridge relatedEntity = cmrField.getRelatedEntity();
            if (relationMetaData.isTableMappingStyle() && manager.hasCreateTable(relatedEntity.getEntityName())) {
                boolean relTableExisted = SQLUtil.tableExists(cmrField.getQualifiedTableName(), entity.getDataSource());

                if (relTableExisted) {
                    if (relationMetaData.getAlterTable()) {
                        ArrayList oldNames = SQLUtil.getOldColumns(cmrField.getQualifiedTableName(), dataSource).getColumnNames();
                        ArrayList newNames = new ArrayList();
                        JDBCFieldBridge[] leftKeys = cmrField.getTableKeyFields();
                        JDBCFieldBridge[] rightKeys = cmrField.getRelatedCMRField().getTableKeyFields();
                        JDBCFieldBridge[] fields = new JDBCFieldBridge[leftKeys.length + rightKeys.length];
                        System.arraycopy(leftKeys, 0, fields, 0, leftKeys.length);
                        System.arraycopy(rightKeys, 0, fields, leftKeys.length, rightKeys.length);
                        // have to append field names to leftKeys, rightKeys...

                        boolean different = false;
                        for (int j = 0; j < fields.length; j++) {
                            JDBCFieldBridge field = fields[j];

                            String name = field.getJDBCType().getColumnNames()[0].toUpperCase();
                            newNames.add(name);

                            if (!oldNames.contains(name)) {
                                different = true;
                                break;
                            }
                        } // for int j;

                        if (!different) {
                            Iterator it = oldNames.iterator();
                            while (it.hasNext()) {
                                String name = (String) (it.next());
                                if (!newNames.contains(name)) {
                                    different = true;
                                    break;
                                }
                            }
                        }

                        if (different) {
                            // only log, don't drop table is this can cause data loss
                            CmpLogger.ROOT_LOGGER.incorrectCmrTableStructure(cmrField.getQualifiedTableName());

                            //SQLUtil.dropTable(entity.getDataSource(), cmrField.getQualifiedTableName());
                        }

                    } // if alter-table

                } // if existed

                // create the relation table
                if (relationMetaData.isTableMappingStyle() && !relationMetaData.isTableCreated()) {
                    if (relationMetaData.getCreateTable()) {
                        createTable(dataSource, cmrField.getQualifiedTableName(),
                                getRelationCreateTableSQL(cmrField, dataSource));
                    } else {
                        log.debug("Relation table not created as requested: " + cmrField.getQualifiedTableName());
                    }

                    // create Indices if needed
                    createCMRIndex(dataSource, cmrField);

                    if (relationMetaData.getCreateTable()) {
                        issuePostCreateSQL(dataSource,
                                relationMetaData.getDefaultTablePostCreateCmd(),
                                cmrField.getQualifiedTableName());
                    }
                }
            }
        }
View Full Code Here

    public void addForeignKeyConstraints() {
        JDBCAbstractCMRFieldBridge[] cmrFields = entity.getCMRFields();
        for (int i = 0; i < cmrFields.length; ++i) {
            JDBCAbstractCMRFieldBridge cmrField = cmrFields[i];
            EntityBridge relatedEntity = cmrField.getRelatedEntity();
            JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();

            if (relationMetaData.isForeignKeyMappingStyle() && (manager.hasCreateTable(relatedEntity.getEntityName()))) {
                createCMRIndex(((JDBCAbstractEntityBridge) relatedEntity).getDataSource(), cmrField);
            }

            // Create fk constraint
            addForeignKeyConstraint(cmrField);
View Full Code Here

        createIndex(dataSource, entity.getQualifiedTableName(), indexName, sql.toString());
    }

    private void createCMRIndex(DataSource dataSource, JDBCAbstractCMRFieldBridge field) {
        JDBCRelationMetaData rmd;
        String tableName;

        rmd = field.getMetaData().getRelationMetaData();

        if (rmd.isTableMappingStyle()) {
            tableName = rmd.getDefaultTableName();
            createFKIndex(rmd.getLeftRelationshipRole(), dataSource, tableName);
            createFKIndex(rmd.getRightRelationshipRole(), dataSource, tableName);
        } else if (field.hasForeignKey()) {
            tableName = field.getEntity().getQualifiedTableName();
            createFKIndex(field.getRelatedCMRField().getMetaData(), dataSource, tableName);
        }
    }
View Full Code Here

                .append(" (")
                        // add field declaration
                .append(SQLUtil.getCreateTableColumnsClause(fieldsArr));

        // add a pk constraint
        final JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();
        if (relationMetaData.hasPrimaryKeyConstraint()) {
            JDBCFunctionMappingMetaData pkConstraint =
                    manager.getMetaData().getTypeMapping().getPkConstraintTemplate();
            if (pkConstraint == null) {
                throw MESSAGES.pkConstraintNotAllowed();
            }

            String name = "pk_" + relationMetaData.getDefaultTableName();
            name = SQLUtil.fixConstraintName(name, dataSource);
            String[] args = new String[]{
                    name,
                    SQLUtil.getColumnNamesClause(fieldsArr, new StringBuffer(100).toString(), new StringBuffer()).toString()
            };
View Full Code Here

        // create relation tables
        JDBCAbstractCMRFieldBridge[] cmrFields = entity.getCMRFields();
        for (int i = 0; i < cmrFields.length; ++i) {
            JDBCAbstractCMRFieldBridge cmrField = cmrFields[i];
            JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();
            DataSource dataSource = manager.getDataSource(relationMetaData.getDataSourceName());

            // if the table for the related entity has been created
            final EntityBridge relatedEntity = cmrField.getRelatedEntity();
            if (relationMetaData.isTableMappingStyle() && manager.hasCreateTable(relatedEntity.getEntityName())) {
                boolean relTableExisted = SQLUtil.tableExists(cmrField.getQualifiedTableName(), entity.getDataSource());

                if (relTableExisted) {
                    if (relationMetaData.getAlterTable()) {
                        ArrayList oldNames = SQLUtil.getOldColumns(cmrField.getQualifiedTableName(), dataSource).getColumnNames();
                        ArrayList newNames = new ArrayList();
                        JDBCFieldBridge[] leftKeys = cmrField.getTableKeyFields();
                        JDBCFieldBridge[] rightKeys = cmrField.getRelatedCMRField().getTableKeyFields();
                        JDBCFieldBridge[] fields = new JDBCFieldBridge[leftKeys.length + rightKeys.length];
                        System.arraycopy(leftKeys, 0, fields, 0, leftKeys.length);
                        System.arraycopy(rightKeys, 0, fields, leftKeys.length, rightKeys.length);
                        // have to append field names to leftKeys, rightKeys...

                        boolean different = false;
                        for (int j = 0; j < fields.length; j++) {
                            JDBCFieldBridge field = fields[j];

                            String name = field.getJDBCType().getColumnNames()[0].toUpperCase();
                            newNames.add(name);

                            if (!oldNames.contains(name)) {
                                different = true;
                                break;
                            }
                        } // for int j;

                        if (!different) {
                            Iterator it = oldNames.iterator();
                            while (it.hasNext()) {
                                String name = (String) (it.next());
                                if (!newNames.contains(name)) {
                                    different = true;
                                    break;
                                }
                            }
                        }

                        if (different) {
                            // only log, don't drop table is this can cause data loss
                            log.error("CMR table structure is incorrect for " + cmrField.getQualifiedTableName());
                            //SQLUtil.dropTable(entity.getDataSource(), cmrField.getQualifiedTableName());
                        }

                    } // if alter-table

                } // if existed

                // create the relation table
                if (relationMetaData.isTableMappingStyle() && !relationMetaData.isTableCreated()) {
                    if (relationMetaData.getCreateTable()) {
                        createTable(dataSource, cmrField.getQualifiedTableName(),
                                getRelationCreateTableSQL(cmrField, dataSource));
                    } else {
                        log.debug("Relation table not created as requested: " + cmrField.getQualifiedTableName());
                    }

                    // create Indices if needed
                    createCMRIndex(dataSource, cmrField);

                    if (relationMetaData.getCreateTable()) {
                        issuePostCreateSQL(dataSource,
                                relationMetaData.getDefaultTablePostCreateCmd(),
                                cmrField.getQualifiedTableName());
                    }
                }
            }
        }
View Full Code Here

    public void addForeignKeyConstraints() {
        JDBCAbstractCMRFieldBridge[] cmrFields = entity.getCMRFields();
        for (int i = 0; i < cmrFields.length; ++i) {
            JDBCAbstractCMRFieldBridge cmrField = cmrFields[i];
            EntityBridge relatedEntity = cmrField.getRelatedEntity();
            JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();

            if (relationMetaData.isForeignKeyMappingStyle() && (manager.hasCreateTable(relatedEntity.getEntityName()))) {
                createCMRIndex(((JDBCAbstractEntityBridge) relatedEntity).getDataSource(), cmrField);
            }

            // Create fk constraint
            addForeignKeyConstraint(cmrField);
View Full Code Here

        createIndex(dataSource, entity.getQualifiedTableName(), indexName, sql.toString());
    }

    private void createCMRIndex(DataSource dataSource, JDBCAbstractCMRFieldBridge field) {
        JDBCRelationMetaData rmd;
        String tableName;

        rmd = field.getMetaData().getRelationMetaData();

        if (rmd.isTableMappingStyle()) {
            tableName = rmd.getDefaultTableName();
            createFKIndex(rmd.getLeftRelationshipRole(), dataSource, tableName);
            createFKIndex(rmd.getRightRelationshipRole(), dataSource, tableName);
        } else if (field.hasForeignKey()) {
            tableName = field.getEntity().getQualifiedTableName();
            createFKIndex(field.getRelatedCMRField().getMetaData(), dataSource, tableName);
        }
    }
View Full Code Here

                .append(" (")
                        // add field declaration
                .append(SQLUtil.getCreateTableColumnsClause(fieldsArr));

        // add a pk constraint
        final JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();
        if (relationMetaData.hasPrimaryKeyConstraint()) {
            JDBCFunctionMappingMetaData pkConstraint =
                    manager.getMetaData().getTypeMapping().getPkConstraintTemplate();
            if (pkConstraint == null) {
                throw new IllegalStateException("Primary key constraint is not allowed for this type of data store");
            }

            String name = "pk_" + relationMetaData.getDefaultTableName();
            name = SQLUtil.fixConstraintName(name, dataSource);
            String[] args = new String[]{
                    name,
                    SQLUtil.getColumnNamesClause(fieldsArr, new StringBuffer(100).toString(), new StringBuffer()).toString()
            };
View Full Code Here

TOP

Related Classes of org.jboss.as.cmp.jdbc.metadata.JDBCRelationMetaData

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.