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

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


/* 126 */     return createSQL(relationData, keys);
/*     */   }
/*     */
/*     */   private static String createSQL(RelationData relationData, int keysInDelete)
/*     */   {
/* 131 */     JDBCCMRFieldBridge left = relationData.getLeftCMRField();
/* 132 */     JDBCCMRFieldBridge right = relationData.getRightCMRField();
/*     */
/* 134 */     StringBuffer sql = new StringBuffer(300);
/* 135 */     sql.append("DELETE FROM ").append(left.getQualifiedTableName()).append(" WHERE ");
/*     */
/* 139 */     StringBuffer whereClause = new StringBuffer(20);
/* 140 */     whereClause.append('(');
/*     */
/* 142 */     SQLUtil.getWhereClause(left.getTableKeyFields(), whereClause).append(" AND ");
/*     */
/* 145 */     SQLUtil.getWhereClause(right.getTableKeyFields(), whereClause).append(')');
/*     */
/* 147 */     String whereClauseStr = whereClause.toString();
/* 148 */     sql.append(whereClauseStr);
/* 149 */     for (int i = 1; i < keysInDelete; i++)
/*     */     {
View Full Code Here


/*     */     {
/*  93 */       return getNext().invoke(mi);
/*     */     }
/*     */
/*  97 */     EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext();
/*  98 */     JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)mi.getArguments()[0];
/*     */
/* 100 */     if (CMRMessage.GET_RELATED_ID == relationshipMessage)
/*     */     {
/* 103 */       if (this.log.isTraceEnabled())
/*     */       {
/* 105 */         this.log.trace("Getting related id: field=" + cmrField.getFieldName() + " id=" + ctx.getId());
/*     */       }
/* 107 */       return cmrField.getRelatedId(ctx);
/*     */     }
/*     */
/* 110 */     if (CMRMessage.ADD_RELATION == relationshipMessage)
/*     */     {
/* 113 */       Object relatedId = mi.getArguments()[1];
/* 114 */       if (this.log.isTraceEnabled())
/*     */       {
/* 116 */         this.log.trace("Add relation: field=" + cmrField.getFieldName() + " id=" + ctx.getId() + " relatedId=" + relatedId);
/*     */       }
/*     */
/* 121 */       cmrField.addRelation(ctx, relatedId);
/*     */
/* 123 */       return null;
/*     */     }
/*     */
/* 126 */     if (CMRMessage.REMOVE_RELATION == relationshipMessage)
/*     */     {
/* 129 */       Object relatedId = mi.getArguments()[1];
/* 130 */       if (this.log.isTraceEnabled())
/*     */       {
/* 132 */         this.log.trace("Remove relation: field=" + cmrField.getFieldName() + " id=" + ctx.getId() + " relatedId=" + relatedId);
/*     */       }
/*     */
/* 137 */       cmrField.removeRelation(ctx, relatedId);
/*     */
/* 139 */       return null;
/*     */     }
/* 141 */     if (CMRMessage.SCHEDULE_FOR_CASCADE_DELETE == relationshipMessage)
/*     */     {
/* 143 */       JDBCEntityBridge entity = (JDBCEntityBridge)cmrField.getEntity();
/* 144 */       entity.scheduleForCascadeDelete(ctx);
/* 145 */       return null;
/*     */     }
/* 147 */     if (CMRMessage.SCHEDULE_FOR_BATCH_CASCADE_DELETE == relationshipMessage)
/*     */     {
/* 149 */       JDBCEntityBridge entity = (JDBCEntityBridge)cmrField.getEntity();
/* 150 */       entity.scheduleForBatchCascadeDelete(ctx);
/* 151 */       return null;
/*     */     }
/*     */
/* 156 */     throw new EJBException("Unknown cmp2.0-relationship-message=" + relationshipMessage);
View Full Code Here

/*  64 */     this.log = Logger.getLogger(getClass().getName() + "." + manager.getMetaData().getName());
/*     */   }
/*     */
/*     */   public Collection execute(JDBCCMRFieldBridge cmrField, Object pk)
/*     */   {
/*  72 */     JDBCCMRFieldBridge relatedCMRField = (JDBCCMRFieldBridge)cmrField.getRelatedCMRField();
/*     */
/*  75 */     ReadAheadCache readAheadCache = this.manager.getReadAheadCache();
/*  76 */     ReadAheadCache relatedReadAheadCache = cmrField.getRelatedManager().getReadAheadCache();
/*     */
/*  79 */     ReadAheadCache.EntityReadAheadInfo info = readAheadCache.getEntityReadAheadInfo(pk);
/*  80 */     List loadKeys = info.getLoadKeys();
/*     */
/*  82 */     Connection con = null;
/*  83 */     PreparedStatement ps = null;
/*  84 */     ResultSet rs = null;
/*     */     try
/*     */     {
/*  88 */       boolean[] preloadMask = getPreloadMask(cmrField);
/*  89 */       String sql = getSQL(cmrField, preloadMask, loadKeys.size());
/*     */
/*  92 */       if (this.log.isDebugEnabled()) {
/*  93 */         this.log.debug("load relation SQL: " + sql);
/*     */       }
/*     */
/*  96 */       con = cmrField.getDataSource().getConnection();
/*  97 */       ps = con.prepareStatement(sql.toString());
/*     */
/* 100 */       if (this.entity.getFetchSize() > 0)
/*     */       {
/* 102 */         ps.setFetchSize(this.entity.getFetchSize());
/*     */       }
/*     */
/* 106 */       JDBCCMPFieldBridge[] myKeyFields = getMyKeyFields(cmrField);
/* 107 */       JDBCCMPFieldBridge[] relatedKeyFields = getRelatedKeyFields(cmrField);
/*     */
/* 110 */       int paramIndex = 1;
/* 111 */       for (int i = 0; i < loadKeys.size(); i++)
/*     */       {
/* 113 */         Object key = loadKeys.get(i);
/* 114 */         for (int j = 0; j < myKeyFields.length; j++) {
/* 115 */           paramIndex = myKeyFields[j].setPrimaryKeyParameters(ps, paramIndex, key);
/*     */         }
/*     */       }
/*     */
/* 119 */       rs = ps.executeQuery();
/*     */
/* 122 */       Map resultsMap = new HashMap(loadKeys.size());
/* 123 */       for (int i = 0; i < loadKeys.size(); i++)
/*     */       {
/* 125 */         resultsMap.put(loadKeys.get(i), new ArrayList());
/*     */       }
/*     */
/* 129 */       Object[] ref = new Object[1];
/* 130 */       while (rs.next())
/*     */       {
/* 133 */         int index = 1;
/*     */
/* 136 */         ref[0] = null;
/*     */
/* 139 */         Object loadedPk = pk;
/* 140 */         if (loadKeys.size() > 1)
/*     */         {
/* 143 */           for (int i = 0; i < myKeyFields.length; i++)
/*     */           {
/* 145 */             index = myKeyFields[i].loadPrimaryKeyResults(rs, index, ref);
/* 146 */             if (ref[0] == null)
/*     */             {
/*     */               break;
/*     */             }
/*     */           }
/* 151 */           loadedPk = ref[0];
/*     */         }
/*     */
/* 155 */         ref[0] = null;
/* 156 */         for (int i = 0; i < relatedKeyFields.length; i++)
/*     */         {
/* 158 */           index = relatedKeyFields[i].loadPrimaryKeyResults(rs, index, ref);
/* 159 */           if (ref[0] == null)
/*     */           {
/*     */             break;
/*     */           }
/*     */         }
/* 164 */         Object loadedFk = ref[0];
/*     */
/* 166 */         if (loadedFk != null)
/*     */         {
/* 169 */           List results = (List)resultsMap.get(loadedPk);
/* 170 */           results.add(loadedFk);
/*     */
/* 174 */           if (relatedCMRField.isSingleValued())
/*     */           {
/* 176 */             relatedReadAheadCache.addPreloadData(loadedFk, relatedCMRField, Collections.singletonList(loadedPk));
/*     */           }
/*     */
/* 183 */           if (preloadMask != null)
/*     */           {
/* 185 */             JDBCFieldBridge[] relatedFields = cmrField.getRelatedJDBCEntity().getTableFields();
/* 186 */             for (int i = 0; i < relatedFields.length; i++)
/*     */             {
/* 188 */               if (preloadMask[i] == 0)
/*     */                 continue;
/* 190 */               JDBCFieldBridge field = relatedFields[i];
/* 191 */               ref[0] = null;
/*     */
/* 194 */               index = field.loadArgumentResults(rs, index, ref);
/* 195 */               relatedReadAheadCache.addPreloadData(loadedFk, field, ref[0]);
/*     */             }
/*     */           }
/*     */
/*     */         }
/*     */
/*     */       }
/*     */
/* 203 */       JDBCReadAheadMetaData readAhead = relatedCMRField.getReadAhead();
/* 204 */       for (iter = resultsMap.keySet().iterator(); iter.hasNext(); )
/*     */       {
/* 206 */         Object key = iter.next();
/*     */
/* 209 */         List results = (List)resultsMap.get(key);
View Full Code Here

/*      */     {
/*  441 */       List leftJoinCMRNodes = new ArrayList();
/*  442 */       while (leftJoinIter.hasNext())
/*      */       {
/*  444 */         JDBCLeftJoinMetaData leftJoin = (JDBCLeftJoinMetaData)leftJoinIter.next();
/*  445 */         JDBCCMRFieldBridge cmrField = entity.getCMRFieldByName(leftJoin.getCmrField());
/*  446 */         if (cmrField == null)
/*      */         {
/*  448 */           throw new DeploymentException("cmr-field in left-join was not found: cmr-field=" + leftJoin.getCmrField() + ", entity=" + entity.getEntityName());
/*      */         }
/*      */
/*  453 */         JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
/*  454 */         String childPath = path + '.' + cmrField.getFieldName();
/*  455 */         if (declaredPaths != null)
/*      */         {
/*  457 */           declaredPaths.add(childPath);
/*      */         }
/*      */
View Full Code Here

/*      */   public static final void leftJoinCMRNodes(String alias, List onFindCMRNodes, AliasManager aliasManager, StringBuffer sb)
/*      */   {
/*  480 */     for (int i = 0; i < onFindCMRNodes.size(); i++)
/*      */     {
/*  482 */       LeftJoinCMRNode node = (LeftJoinCMRNode)onFindCMRNodes.get(i);
/*  483 */       JDBCCMRFieldBridge cmrField = node.cmrField;
/*  484 */       JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
/*  485 */       String relatedAlias = aliasManager.getAlias(node.path);
/*      */
/*  487 */       JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();
/*  488 */       if (relation.isTableMappingStyle())
/*      */       {
/*  490 */         String relTableAlias = aliasManager.getRelationTableAlias(node.path);
/*  491 */         sb.append(" LEFT OUTER JOIN ").append(cmrField.getQualifiedTableName()).append(' ').append(relTableAlias).append(" ON ");
/*      */
/*  496 */         SQLUtil.getRelationTableJoinClause(cmrField, alias, relTableAlias, sb);
/*      */
/*  498 */         sb.append(" LEFT OUTER JOIN ").append(relatedEntity.getQualifiedTableName()).append(' ').append(relatedAlias).append(" ON ");
/*      */
/*  503 */         SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), relatedAlias, relTableAlias, sb);
/*      */       }
/*      */       else
/*      */       {
/*  508 */         sb.append(" LEFT OUTER JOIN ").append(relatedEntity.getQualifiedTableName()).append(' ').append(relatedAlias).append(" ON ");
/*      */
View Full Code Here

/*      */   public static final void appendLeftJoinCMRColumnNames(List onFindCMRNodes, AliasManager aliasManager, StringBuffer sb)
/*      */   {
/*  531 */     for (int i = 0; i < onFindCMRNodes.size(); i++)
/*      */     {
/*  533 */       LeftJoinCMRNode node = (LeftJoinCMRNode)onFindCMRNodes.get(i);
/*  534 */       JDBCCMRFieldBridge cmrField = node.cmrField;
/*  535 */       JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
/*  536 */       String childAlias = aliasManager.getAlias(node.path);
/*      */
/*  539 */       SQLUtil.appendColumnNamesClause(relatedEntity.getPrimaryKeyFields(), childAlias, sb);
/*      */
/*  544 */       if (node.eagerLoadMask != null)
View Full Code Here

/*      */   {
/*  562 */     Object[] ref = new Object[1];
/*  563 */     for (int nodeInd = 0; nodeInd < onFindCMRNodes.size(); nodeInd++)
/*      */     {
/*  565 */       LeftJoinCMRNode node = (LeftJoinCMRNode)onFindCMRNodes.get(nodeInd);
/*  566 */       JDBCCMRFieldBridge cmrField = node.cmrField;
/*  567 */       ReadAheadCache myCache = cmrField.getJDBCStoreManager().getReadAheadCache();
/*  568 */       JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
/*  569 */       ReadAheadCache relatedCache = cmrField.getRelatedManager().getReadAheadCache();
/*      */
/*  572 */       ref[0] = null;
/*  573 */       index = relatedEntity.loadPrimaryKeyResults(rs, index, ref);
/*  574 */       Object relatedId = ref[0];
/*  575 */       boolean cacheRelatedData = relatedId != null;
/*      */
/*  577 */       if (pk != null)
/*      */       {
/*  579 */         if (cmrField.getMetaData().getRelatedRole().isMultiplicityOne())
/*      */         {
/*  582 */           myCache.addPreloadData(pk, cmrField, relatedId == null ? Collections.EMPTY_LIST : Collections.singletonList(relatedId));
/*      */         }
/*      */         else
/*      */         {
View Full Code Here

/*     */     }
/*     */
/* 336 */     boolean cleanReadAhead = this.manager.getMetaData().isCleanReadAheadOnLoad();
/*     */
/* 338 */     boolean loaded = false;
/* 339 */     JDBCCMRFieldBridge onlyOneSingleValuedCMR = null;
/*     */
/* 342 */     Iterator iter = preloadDataMap.entrySet().iterator();
/* 343 */     while (iter.hasNext())
/*     */     {
/* 345 */       Map.Entry entry = (Map.Entry)iter.next();
/* 346 */       Object field = entry.getKey();
/*     */
/* 349 */       Object value = entry.getValue();
/*     */
/* 352 */       if (value == null)
/*     */       {
/* 354 */         throw new IllegalStateException("Preloaded value not found");
/*     */       }
/*     */
/* 357 */       if (cleanReadAhead)
/*     */       {
/* 360 */         iter.remove();
/*     */       }
/*     */
/* 364 */       if (value == NULL_VALUE)
/*     */       {
/* 366 */         value = null;
/*     */       }
/*     */
/* 369 */       if ((field instanceof JDBCCMPFieldBridge))
/*     */       {
/* 371 */         JDBCCMPFieldBridge cmpField = (JDBCCMPFieldBridge)field;
/*     */
/* 373 */         if (!cmpField.isLoaded(ctx))
/*     */         {
/* 375 */           if (this.log.isTraceEnabled())
/*     */           {
/* 377 */             this.log.trace("Preloading data: entity=" + this.manager.getEntityBridge().getEntityName() + " pk=" + ctx.getId() + " cmpField=" + cmpField.getFieldName());
/*     */           }
/*     */
/* 384 */           cmpField.setInstanceValue(ctx, value);
/*     */
/* 387 */           cmpField.setClean(ctx);
/*     */
/* 389 */           loaded = true;
/*     */         }
/* 393 */         else if (this.log.isTraceEnabled())
/*     */         {
/* 395 */           this.log.trace("CMPField already loaded: entity=" + this.manager.getEntityBridge().getEntityName() + " pk=" + ctx.getId() + " cmpField=" + cmpField.getFieldName());
/*     */         }
/*     */
/*     */       }
/* 402 */       else if ((field instanceof JDBCCMRFieldBridge))
/*     */       {
/* 404 */         JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)field;
/*     */
/* 406 */         if (!cmrField.isLoaded(ctx))
/*     */         {
/* 408 */           if (this.log.isTraceEnabled())
/*     */           {
/* 410 */             this.log.trace("Preloading data: entity=" + this.manager.getEntityBridge().getEntityName() + " pk=" + ctx.getId() + " cmrField=" + cmrField.getFieldName());
/*     */           }
/*     */
/* 417 */           cmrField.load(ctx, (List)value);
/*     */
/* 420 */           JDBCStoreManager relatedManager = (JDBCStoreManager)cmrField.getRelatedCMRField().getManager();
/* 421 */           ReadAheadCache relatedReadAheadCache = relatedManager.getReadAheadCache();
/*     */
/* 423 */           relatedReadAheadCache.addFinderResults((List)value, cmrField.getReadAhead());
/*     */
/* 426 */           if (!loaded)
/*     */           {
/* 429 */             if ((cmrField.isSingleValued()) && (onlyOneSingleValuedCMR == null))
/*     */             {
/* 431 */               onlyOneSingleValuedCMR = cmrField;
/*     */             }
/*     */             else
/*     */             {
/* 435 */               loaded = true;
/*     */             }
/*     */
/*     */           }
/*     */
/*     */         }
/* 441 */         else if (this.log.isTraceEnabled())
/*     */         {
/* 443 */           this.log.trace("CMRField already loaded: entity=" + this.manager.getEntityBridge().getEntityName() + " pk=" + ctx.getId() + " cmrField=" + cmrField.getFieldName());
/*     */         }
/*     */
/*     */       }
/*     */
/*     */     }
View Full Code Here

/*     */     }
/*     */
/*  56 */     Connection con = null;
/*  57 */     PreparedStatement ps = null;
/*     */
/*  59 */     JDBCCMRFieldBridge cmrField = relationData.getLeftCMRField();
/*     */     try
/*     */     {
/*  62 */       String sql = getSQL(relationData);
/*  63 */       boolean debug = this.log.isDebugEnabled();
/*  64 */       if (debug) {
/*  65 */         this.log.debug("Executing SQL: " + sql);
/*     */       }
/*     */
/*  68 */       DataSource dataSource = cmrField.getDataSource();
/*  69 */       con = dataSource.getConnection();
/*     */
/*  72 */       ps = con.prepareStatement(sql);
/*     */
/*  74 */       Iterator pairs = relationData.addedRelations.iterator();
/*     */       int rowsAffected;
/*  75 */       while (pairs.hasNext()) {
/*  76 */         RelationPair pair = (RelationPair)pairs.next();
/*     */
/*  79 */         setParameters(ps, relationData, pair);
/*     */
/*  81 */         rowsAffected = ps.executeUpdate();
/*     */       }
/*     */     } catch (Exception e) {
/*  84 */       throw new EJBException("Could insert relations into " + cmrField.getQualifiedTableName(), e);
/*     */     }
/*     */     finally {
/*  87 */       JDBCUtil.safeClose(ps);
/*  88 */       JDBCUtil.safeClose(con);
/*     */     }
View Full Code Here

/*  88 */       JDBCUtil.safeClose(con);
/*     */     }
/*     */   }
/*     */
/*     */   protected static String getSQL(RelationData relationData) {
/*  93 */     JDBCCMRFieldBridge left = relationData.getLeftCMRField();
/*  94 */     JDBCCMRFieldBridge right = relationData.getRightCMRField();
/*     */
/*  96 */     StringBuffer sql = new StringBuffer(200);
/*  97 */     sql.append("INSERT INTO ").append(left.getQualifiedTableName());
/*     */
/*  99 */     sql.append('(');
/* 100 */     SQLUtil.getColumnNamesClause(left.getTableKeyFields(), sql);
/* 101 */     sql.append(", ");
/* 102 */     SQLUtil.getColumnNamesClause(right.getTableKeyFields(), sql);
/* 103 */     sql.append(')');
/*     */
/* 105 */     sql.append(" VALUES ").append('(');
/* 106 */     SQLUtil.getValuesClause(left.getTableKeyFields(), sql);
/* 107 */     sql.append(", ");
/* 108 */     SQLUtil.getValuesClause(right.getTableKeyFields(), sql);
/* 109 */     sql.append(')');
/* 110 */     return sql.toString();
/*     */   }
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.