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

Examples of org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge$TxSynchronization


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


      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.getId());
                  }
               }
               catch(Exception e)
               {
                  // no such object
               }
            }
         }
         else if(relatedCMRField.hasFKFieldsMappedToCMPFields())
         {
            cmrField.addRelatedPKsWaitedForMe(ctx);
         }
      }
      return null;
View Full Code Here

         manager.getMetaData().getName());
   }

   public Collection execute(JDBCCMRFieldBridge cmrField, Object pk)
   {
      JDBCCMRFieldBridge relatedCMRField = (JDBCCMRFieldBridge) cmrField.getRelatedCMRField();

      // get the read ahead cahces
      ReadAheadCache readAheadCache = manager.getReadAheadCache();
      ReadAheadCache relatedReadAheadCache = cmrField.getRelatedManager().getReadAheadCache();

      // get the finder results associated with this context, if it exists
      ReadAheadCache.EntityReadAheadInfo info = readAheadCache.getEntityReadAheadInfo(pk);
      List loadKeys = info.getLoadKeys();

      Connection con = null;
      PreparedStatement ps = null;
      ResultSet rs = null;
      try
      {
         // generate the sql
         boolean[] preloadMask = getPreloadMask(cmrField);
         String sql = getSQL(cmrField, preloadMask, loadKeys.size());

         // create the statement
         if(log.isDebugEnabled())
            log.debug("load relation SQL: " + sql);

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

         // Set the fetch size of the statement
         if(entity.getFetchSize() > 0)
         {
            ps.setFetchSize(entity.getFetchSize());
         }

         // get the load fields
         JDBCCMPFieldBridge[] myKeyFields = getMyKeyFields(cmrField);
         JDBCCMPFieldBridge[] relatedKeyFields = getRelatedKeyFields(cmrField);

         // set the parameters
         int paramIndex = 1;
         for(int i = 0; i < loadKeys.size(); i++)
         {
            Object key = loadKeys.get(i);
            for(int j = 0; j < myKeyFields.length; ++j)
               paramIndex = myKeyFields[j].setPrimaryKeyParameters(ps, paramIndex, key);
         }

         // execute statement
         rs = ps.executeQuery();

         // initialize the results map
         Map resultsMap = new HashMap(loadKeys.size());
         for(int i = 0; i < loadKeys.size(); ++i)
         {
            resultsMap.put(loadKeys.get(i), new ArrayList());
         }

         // load the results
         Object[] ref = new Object[1];
         while(rs.next())
         {
            // reset the column index for this row
            int index = 1;

            // ref must be reset to null before each load
            ref[0] = null;

            // if we are loading more then one entity, load the pk from the row
            Object loadedPk = pk;
            if(loadKeys.size() > 1)
            {
               // load the pk
               for(int i = 0; i < myKeyFields.length; ++i)
               {
                  index = myKeyFields[i].loadPrimaryKeyResults(rs, index, ref);
                  if(ref[0] == null)
                  {
                     break;
                  }
               }
               loadedPk = ref[0];
            }

            // load the fk
            ref[0] = null;
            for(int i = 0; i < relatedKeyFields.length; ++i)
            {
               index = relatedKeyFields[i].loadPrimaryKeyResults(rs, index, ref);
               if(ref[0] == null)
               {
                  break;
               }
            }
            Object loadedFk = ref[0];

            if(loadedFk != null)
            {
               // add this value to the list for loadedPk
               List results = (List)resultsMap.get(loadedPk);
               results.add(loadedFk);

               // if the related cmr field is single valued we can pre-load
               // the reverse relationship
               if(relatedCMRField.isSingleValued())
               {
                  relatedReadAheadCache.addPreloadData(
                     loadedFk,
                     relatedCMRField,
                     Collections.singletonList(loadedPk));
               }

               // read the preload fields
               if(preloadMask != null)
               {
                  JDBCFieldBridge[] relatedFields = cmrField.getRelatedJDBCEntity().getTableFields();
                  for(int i = 0; i < relatedFields.length; ++i)
                  {
                     if(preloadMask[i])
                     {
                        JDBCFieldBridge field = relatedFields[i];
                        ref[0] = null;

                        // read the value and store it in the readahead cache
                        index = field.loadArgumentResults(rs, index, ref);
                        relatedReadAheadCache.addPreloadData(loadedFk, field, ref[0]);
                     }
                  }
               }
            }
         }

         // set all of the preloaded values
         JDBCReadAheadMetaData readAhead = relatedCMRField.getReadAhead();
         for(Iterator iter = resultsMap.keySet().iterator(); iter.hasNext();)
         {
            Object key = iter.next();

            // get the results for this key
View Full Code Here

      {
         leftJoinCMRNodes = new ArrayList();
         while(leftJoinIter.hasNext())
         {
            JDBCLeftJoinMetaData leftJoin = (JDBCLeftJoinMetaData) leftJoinIter.next();
            JDBCCMRFieldBridge cmrField = entity.getCMRFieldByName(leftJoin.getCmrField());
            if(cmrField == null)
            {
               throw new DeploymentException("cmr-field in left-join was not found: cmr-field=" +
                  leftJoin.getCmrField() + ", entity=" + entity.getEntityName());
            }

            List subNodes;
            JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
            String childPath = path + '.' + cmrField.getFieldName();
            if(declaredPaths != null)
            {
               declaredPaths.add(childPath);
            }
View Full Code Here

                                             StringBuffer sb)
   {
      for(int i = 0; i < onFindCMRNodes.size(); ++i)
      {
         LeftJoinCMRNode node = (LeftJoinCMRNode) onFindCMRNodes.get(i);
         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 ")
View Full Code Here

                                                         StringBuffer sb)
   {
      for(int i = 0; i < onFindCMRNodes.size(); ++i)
      {
         LeftJoinCMRNode node = (LeftJoinCMRNode) onFindCMRNodes.get(i);
         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

   {
      Object[] ref = new Object[1];
      for(int nodeInd = 0; nodeInd < onFindCMRNodes.size(); ++nodeInd)
      {
         LeftJoinCMRNode node = (LeftJoinCMRNode) onFindCMRNodes.get(nodeInd);
         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));
View Full Code Here

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

         // get the connection
         DataSource dataSource = cmrField.getDataSource();
         con = dataSource.getConnection();
        
         // get a prepared statement
         ps = con.prepareStatement(sql);
        
         Iterator pairs = relationData.addedRelations.iterator();
         while(pairs.hasNext()) {
            RelationPair pair = (RelationPair)pairs.next();
           
            // set the parameters
            setParameters(ps, relationData, pair);
        
            int rowsAffected = ps.executeUpdate();
         }
      } catch(Exception e) {
         throw new EJBException("Could insert relations into " +
               cmrField.getQualifiedTableName(), e);
      } finally {
         JDBCUtil.safeClose(ps);
         JDBCUtil.safeClose(con);
      }
   }
View Full Code Here

         JDBCUtil.safeClose(con);
      }
   }
  
   protected static String getSQL(RelationData relationData) {
      JDBCCMRFieldBridge left = relationData.getLeftCMRField();
      JDBCCMRFieldBridge right = relationData.getRightCMRField();
     
      StringBuffer sql = new StringBuffer(200);
      sql.append(SQLUtil.INSERT_INTO).append(left.getQualifiedTableName());

      sql.append('(');
         SQLUtil.getColumnNamesClause(left.getTableKeyFields(), sql);
      sql.append(SQLUtil.COMMA);
         SQLUtil.getColumnNamesClause(right.getTableKeyFields(), sql);
      sql.append(')');

      sql.append(SQLUtil.VALUES).append('(');
            SQLUtil.getValuesClause(left.getTableKeyFields(), sql);
            sql.append(SQLUtil.COMMA);
            SQLUtil.getValuesClause(right.getTableKeyFields(), sql);
      sql.append(')');
      return sql.toString();
   }
View Full Code Here

/*  50 */     this.entity = ((JDBCEntityBridge)manager.getEntityBridge());
/*  51 */     JDBCFieldBridge[] cmrFields = this.entity.getCMRFields();
/*  52 */     List fkToCMPList = new ArrayList(4);
/*  53 */     for (int i = 0; i < cmrFields.length; i++)
/*     */     {
/*  55 */       JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)cmrFields[i];
/*  56 */       JDBCCMRFieldBridge relatedCMRField = (JDBCCMRFieldBridge)cmrField.getRelatedCMRField();
/*  57 */       if ((!cmrField.hasFKFieldsMappedToCMPFields()) && (!relatedCMRField.hasFKFieldsMappedToCMPFields())) {
/*     */         continue;
/*     */       }
/*  60 */       fkToCMPList.add(cmrField);
/*     */     }
/*     */
View Full Code Here

TOP

Related Classes of org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge$TxSynchronization

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.