Package org.jboss.ejb.plugins.cmp.jdbc.bridge

Examples of org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMRFieldBridge


         JDBCFieldBridge field = (JDBCFieldBridge) path.getField();

         if(field instanceof JDBCAbstractCMRFieldBridge)
         {
            JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge)field;
            final String alias;
            final JDBCFieldBridge[] keyFields;

            if(cmrField.hasForeignKey())
            {
               alias = aliasManager.getAlias(path.getPath(path.size() - 2));
               keyFields = cmrField.getForeignKeyFields();
            }
            else
            {
               alias = aliasManager.getAlias(path.getPath());
               if(cmrField.getMetaData().getRelationMetaData().isTableMappingStyle())
               {
                  keyFields = cmrField.getRelatedCMRField().getEntity().getPrimaryKeyFields();
               }
               else
               {
                  keyFields = cmrField.getRelatedCMRField().getForeignKeyFields();
               }
            }

            SQLUtil.getIsNullClause(node.not, keyFields, alias, sql);
         }
View Full Code Here


      }

      addLeftJoinPath(path);

      StringBuffer sql = (StringBuffer) data;
      JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField();
      JDBCAbstractEntityBridge relatedEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();
      String alias = aliasManager.getAlias(path.getPath());
      SQLUtil.getIsNullClause(node.not, relatedEntity.getPrimaryKeyFields(), alias, sql);

      return data;
   }
View Full Code Here

      for(int i = 1; i < path.size(); ++i)
      {
         String curPath = path.getPath(i);
         final String joinAlias = aliasManager.getAlias(curPath + "_local");

         final JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField(i);
         final JDBCAbstractEntityBridge joinEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();

         JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();

         String join = " INNER JOIN ";

         if(relation.isTableMappingStyle())
         {
            String relTableAlias = aliasManager.getRelationTableAlias(curPath + "_local");
            sql.append(join)
               .append(cmrField.getQualifiedTableName())
               .append(' ')
               .append(relTableAlias)
               .append(" ON ");
            SQLUtil.getRelationTableJoinClause(cmrField, leftAlias, relTableAlias, sql);

            sql.append(join)
               .append(joinEntity.getQualifiedTableName())
               .append(' ')
               .append(joinAlias)
               .append(" ON ");
            SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), joinAlias, relTableAlias, sql);
         }
         else
         {
            sql.append(join)
               .append(joinEntity.getQualifiedTableName())
View Full Code Here

               final String curPath = path.getPath(i);
               final String joinAlias = aliasManager.getAlias(curPath);

               if(joinedAliases.add(joinAlias))
               {
                  final JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField(i);
                  final JDBCAbstractEntityBridge joinEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();

                  JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();

                  String join = (path.innerJoin ? " INNER JOIN " : " LEFT OUTER JOIN ");

                  if(relation.isTableMappingStyle())
                  {
                     String relTableAlias = aliasManager.getRelationTableAlias(curPath);
                     sql.append(join)
                        .append(cmrField.getQualifiedTableName())
                        .append(' ')
                        .append(relTableAlias)
                        .append(" ON ");
                     SQLUtil.getRelationTableJoinClause(cmrField, leftAlias, relTableAlias, sql);

                     sql.append(join)
                        .append(joinEntity.getQualifiedTableName())
                        .append(' ')
                        .append(joinAlias)
                        .append(" ON ");
                     SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), joinAlias, relTableAlias, sql);
                  }
                  else
                  {
                     sql.append(join)
                        .append(joinEntity.getQualifiedTableName())
View Full Code Here

      }

      addLeftJoinPath(path);

      StringBuffer sql = (StringBuffer) data;
      JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField();
      JDBCAbstractEntityBridge relatedEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();
      String alias = aliasManager.getAlias(path.getPath());
      SQLUtil.getIsNullClause(node.not, relatedEntity.getPrimaryKeyFields(), alias, sql);

      return data;
   }
View Full Code Here

      for(int i = 1; i < path.size(); ++i)
      {
         String curPath = path.getPath(i);
         final String joinAlias = aliasManager.getAlias(curPath + "_local");

         final JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField(i);
         final JDBCAbstractEntityBridge joinEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();

         JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();

         String join = " INNER JOIN ";

         if(relation.isTableMappingStyle())
         {
            String relTableAlias = aliasManager.getRelationTableAlias(curPath + "_local");
            sql.append(join)
               .append(cmrField.getQualifiedTableName())
               .append(' ')
               .append(relTableAlias)
               .append(" ON ");
            SQLUtil.getRelationTableJoinClause(cmrField, leftAlias, relTableAlias, sql);

            sql.append(join)
               .append(joinEntity.getQualifiedTableName())
               .append(' ')
               .append(joinAlias)
               .append(" ON ");
            SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), joinAlias, relTableAlias, sql);
         }
         else
         {
            sql.append(join)
               .append(joinEntity.getQualifiedTableName())
View Full Code Here

               final String curPath = path.getPath(i);
               final String joinAlias = aliasManager.getAlias(curPath);

               if(joinedAliases.add(joinAlias))
               {
                  final JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField(i);
                  final JDBCAbstractEntityBridge joinEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();

                  JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();

                  String join = (path.innerJoin ? " INNER JOIN " : " LEFT OUTER JOIN ");

                  if(relation.isTableMappingStyle())
                  {
                     String relTableAlias = aliasManager.getRelationTableAlias(curPath);
                     sql.append(join)
                        .append(cmrField.getQualifiedTableName())
                        .append(' ')
                        .append(relTableAlias)
                        .append(" ON ");
                     SQLUtil.getRelationTableJoinClause(cmrField, leftAlias, relTableAlias, sql);

                     sql.append(join)
                        .append(joinEntity.getQualifiedTableName())
                        .append(' ')
                        .append(joinAlias)
                        .append(" ON ");
                     SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), joinAlias, relTableAlias, sql);
                  }
                  else
                  {
                     sql.append(join)
                        .append(joinEntity.getQualifiedTableName())
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 = relationMetaData.getDataSource();

         // if the table for the related entity has been created
         final EntityBridge relatedEntity = cmrField.getRelatedEntity();
         if(relationMetaData.isTableMappingStyle() && createdTables.contains(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

      Set createdTables = getCreatedTables(manager);

      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() && (createdTables.contains(relatedEntity.getEntityName())))
         {
            createCMRIndex(((JDBCAbstractEntityBridge)relatedEntity).getDataSource(), cmrField);
         }
View Full Code Here

      final JDBCAbstractCMRFieldBridge[] cmrFields = entity.getCMRFields();
      if(cmrFields != null)
      {
         for(int i = 0; i < cmrFields.length; ++i)
         {
            JDBCAbstractCMRFieldBridge cmrField = cmrFields[i];
            if(cmrField.getRelatedCMRField().getMetaData().isIndexed())
            {
               final JDBCFieldBridge[] fkFields = cmrField.getForeignKeyFields();
               if(fkFields != null)
               {
                  for(int fkInd = 0; fkInd < fkFields.length; ++fkInd)
                  {
                     createCMPIndex(dataSource, fkFields[fkInd], indexNames);
View Full Code Here

TOP

Related Classes of org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMRFieldBridge

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.