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

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


/*  73 */     if (this.cmrWithFKMappedToCMP == null) {
/*  74 */       return null;
/*     */     }
/*  76 */     for (int i = 0; i < this.cmrWithFKMappedToCMP.length; i++)
/*     */     {
/*  78 */       JDBCCMRFieldBridge cmrField = this.cmrWithFKMappedToCMP[i];
/*  79 */       JDBCCMRFieldBridge relatedCMRField = (JDBCCMRFieldBridge)cmrField.getRelatedCMRField();
/*  80 */       if (cmrField.hasFKFieldsMappedToCMPFields())
/*     */       {
/*  82 */         Object relatedId = cmrField.getRelatedIdFromContext(ctx);
/*  83 */         if (relatedId != null)
/*     */         {
/*     */           try
/*     */           {
/*  87 */             if (cmrField.isForeignKeyValid(relatedId))
/*     */             {
/*  89 */               cmrField.createRelationLinks(ctx, relatedId);
/*     */             }
/*     */             else
/*     */             {
/*  93 */               relatedCMRField.addRelatedPKWaitingForMyPK(relatedId, ctx.getId());
/*     */             }
/*     */           }
/*     */           catch (Exception e)
/*     */           {
/*     */           }
/*     */         }
/*     */       }
/*     */       else {
/* 102 */         if (!relatedCMRField.hasFKFieldsMappedToCMPFields())
/*     */           continue;
/* 104 */         cmrField.addRelatedPKsWaitedForMe(ctx);
/*     */       }
/*     */     }
/* 107 */     return null;
View Full Code Here


/*  437 */     if (!path.isCMRField())
/*      */     {
/*  439 */       throw new IllegalArgumentException("path must be a cmr field");
/*      */     }
/*      */
/*  442 */     JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)path.getCMRField();
/*  443 */     String pathStr = path.getPath(path.size() - 2);
/*  444 */     String parentAlias = this.aliasManager.getAlias(pathStr);
/*      */
/*  447 */     if (!this.subquerySupported)
/*      */     {
/*  450 */       addLeftJoinPath(pathStr, path);
/*  451 */       this.forceDistinct = true;
/*      */
/*  453 */       addJoinPath(path);
/*      */
/*  455 */       if (cmrField.getRelationMetaData().isForeignKeyMappingStyle())
/*      */       {
/*  457 */         JDBCEntityBridge childEntity = (JDBCEntityBridge)cmrField.getRelatedEntity();
/*  458 */         String childAlias = this.aliasManager.getAlias(path.getPath());
/*  459 */         SQLUtil.getIsNullClause(!not, childEntity.getPrimaryKeyFields(), childAlias, buf);
/*      */       }
/*      */       else
/*      */       {
/*  463 */         String relationTableAlias = this.aliasManager.getRelationTableAlias(path.getPath());
/*  464 */         SQLUtil.getIsNullClause(!not, cmrField.getTableKeyFields(), relationTableAlias, buf);
/*      */       }
/*  466 */       return;
/*      */     }
/*      */
/*  469 */     if (not)
/*      */     {
/*  471 */       buf.append(" NOT ");
/*      */     }
/*  473 */     buf.append("EXISTS ").append('(');
/*      */
/*  475 */     if (cmrField.getRelationMetaData().isForeignKeyMappingStyle())
/*      */     {
/*  477 */       JDBCEntityBridge childEntity = (JDBCEntityBridge)cmrField.getRelatedEntity();
/*  478 */       String childAlias = this.aliasManager.getAlias(path.getPath());
/*      */
/*  480 */       buf.append("SELECT ");
/*      */
/*  482 */       SQLUtil.getColumnNamesClause(childEntity.getPrimaryKeyFields(), childAlias, buf).append(" FROM ").append(childEntity.getQualifiedTableName()).append(' ').append(childAlias).append(" WHERE ");
/*      */
/*  486 */       SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
/*      */     }
/*      */     else
/*      */     {
/*  490 */       String relationTableAlias = this.aliasManager.getRelationTableAlias(path.getPath());
/*  491 */       buf.append("SELECT ");
/*  492 */       SQLUtil.getColumnNamesClause(cmrField.getTableKeyFields(), relationTableAlias, buf).append(" FROM ").append(cmrField.getQualifiedTableName()).append(' ').append(relationTableAlias).append(" WHERE ");
/*      */
/*  498 */       SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf);
/*      */     }
/*      */
/*  501 */     buf.append(')');
View Full Code Here

/*  771 */     if ((!path.isCMRField(i)) || (this.declaredPaths.contains(path.getPath(i))))
/*      */     {
/*  773 */       return;
/*      */     }
/*      */
/*  776 */     JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)path.getCMRField(i);
/*  777 */     JDBCEntityBridge entity = (JDBCEntityBridge)path.getEntity(i);
/*      */
/*  779 */     buf.append(", ").append(entity.getQualifiedTableName()).append(' ').append(this.aliasManager.getAlias(path.getPath(i)));
/*      */
/*  783 */     leftJoins(path.getPath(i), buf);
/*      */
/*  785 */     if (cmrField.getRelationMetaData().isTableMappingStyle())
/*      */     {
/*  787 */       String relationTableAlias = this.aliasManager.getRelationTableAlias(path.getPath(i));
/*  788 */       buf.append(", ").append(cmrField.getQualifiedTableName()).append(' ').append(relationTableAlias);
/*      */     }
/*      */
/*  794 */     this.declaredPaths.add(path.getPath(i));
/*      */   }
View Full Code Here

/*      */
/*  805 */     for (Iterator iter = paths.iterator(); iter.hasNext(); )
/*      */     {
/*  807 */       ASTPath path = (ASTPath)iter.next();
/*      */
/*  809 */       JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)path.getCMRField();
/*  810 */       String parentAlias = this.aliasManager.getAlias(parentPath);
/*      */
/*  812 */       if (cmrField.getRelationMetaData().isForeignKeyMappingStyle())
/*      */       {
/*  814 */         JDBCEntityBridge childEntity = (JDBCEntityBridge)cmrField.getRelatedEntity();
/*  815 */         String childAlias = this.aliasManager.getAlias(path.getPath());
/*      */
/*  817 */         buf.append(" LEFT JOIN ").append(childEntity.getQualifiedTableName()).append(' ').append(childAlias).append(" ON ");
/*      */
/*  822 */         SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
/*      */       }
/*      */       else
/*      */       {
/*  826 */         String relationTableAlias = this.aliasManager.getRelationTableAlias(path.getPath());
/*  827 */         buf.append(" LEFT JOIN ").append(cmrField.getQualifiedTableName()).append(' ').append(relationTableAlias).append(" ON ");
/*      */
/*  832 */         SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf);
/*      */       }
/*      */     }
/*      */   }
View Full Code Here

/*  910 */     if ((!path.isCMRField(i)) || (joinedAliases.contains(childAlias)))
/*      */     {
/*  912 */       return;
/*      */     }
/*      */
/*  915 */     JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)path.getCMRField(i);
/*  916 */     String parentAlias = this.aliasManager.getAlias(path.getPath(i - 1));
/*      */
/*  918 */     if (joinedAliases.size() > 0)
/*      */     {
/*  920 */       buf.append(" AND ");
/*      */     }
/*      */
/*  923 */     if (cmrField.getRelationMetaData().isForeignKeyMappingStyle())
/*      */     {
/*  925 */       SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
/*      */     }
/*      */     else
/*      */     {
/*  929 */       String relationTableAlias = this.aliasManager.getRelationTableAlias(path.getPath(i));
/*      */
/*  932 */       SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf).append(" AND ");
/*      */
/*  935 */       SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), childAlias, relationTableAlias, buf);
/*      */     }
/*      */
/*  938 */     joinedAliases.add(childAlias);
/*      */   }
View Full Code Here

/*      */     {
/*  974 */       buf.append(this.onFindCMRJoin);
/*  975 */       this.onFindCMRJoin = null;
/*      */     }
/*      */
/*  979 */     JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)path.getCMRField();
/*  980 */     if (cmrField.getRelationMetaData().isTableMappingStyle())
/*      */     {
/*  982 */       String relationTableAlias = this.aliasManager.getRelationTableAlias(path.getPath());
/*  983 */       buf.append(", ").append(cmrField.getQualifiedTableName()).append(' ').append(relationTableAlias);
/*      */     }
/*      */
/*  989 */     return buf;
/*      */   }
View Full Code Here

/* 1059 */         JDBCCMPFieldBridge selectField = (JDBCCMPFieldBridge)path.getCMPField();
/* 1060 */         this.selectManager = ((JDBCStoreManager)selectField.getManager());
/*      */       }
/* 1062 */       else if (path.isCMRField())
/*      */       {
/* 1064 */         JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)path.getCMRField();
/* 1065 */         this.selectManager = ((JDBCStoreManager)cmrField.getEntity().getManager());
/* 1066 */         addJoinPath(path);
/*      */       }
/*      */       else
/*      */       {
/* 1070 */         JDBCEntityBridge entity = (JDBCEntityBridge)path.getEntity();
View Full Code Here

/*      */     {
/* 1099 */       ASTPath path = (ASTPath)child0;
/*      */
/* 1101 */       if (path.isCMRField())
/*      */       {
/* 1103 */         JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)path.getCMRField();
/* 1104 */         if (cmrField.getRelationMetaData().isTableMappingStyle())
/*      */         {
/* 1106 */           existsClause(path, buf, !node.not);
/* 1107 */           return buf;
/*      */         }
/*      */       }
View Full Code Here

/*      */   {
/* 1177 */     StringBuffer buf = (StringBuffer)data;
/*      */
/* 1180 */     ASTPath toPath = (ASTPath)node.jjtGetChild(1);
/*      */
/* 1182 */     JDBCCMRFieldBridge toCMRField = (JDBCCMRFieldBridge)toPath.getCMRField();
/*      */
/* 1184 */     JDBCEntityBridge toChildEntity = (JDBCEntityBridge)toPath.getEntity();
/*      */
/* 1186 */     String pathStr = toPath.getPath(toPath.size() - 2);
/* 1187 */     String toParentAlias = this.aliasManager.getAlias(pathStr);
/* 1188 */     String toChildAlias = this.aliasManager.getAlias(toPath.getPath());
/* 1189 */     String relationTableAlias = null;
/* 1190 */     if (toCMRField.getRelationMetaData().isTableMappingStyle())
/*      */     {
/* 1192 */       relationTableAlias = this.aliasManager.getRelationTableAlias(toPath.getPath());
/*      */     }
/*      */
/* 1196 */     String fromAlias = null;
/* 1197 */     int fromParamNumber = -1;
/* 1198 */     if ((node.jjtGetChild(0) instanceof ASTParameter))
/*      */     {
/* 1200 */       ASTParameter fromParam = (ASTParameter)node.jjtGetChild(0);
/*      */
/* 1203 */       verifyParameterEntityType(fromParam.number, toChildEntity);
/*      */
/* 1205 */       fromParamNumber = fromParam.number;
/*      */     }
/*      */     else
/*      */     {
/* 1209 */       ASTPath fromPath = (ASTPath)node.jjtGetChild(0);
/* 1210 */       addJoinPath(fromPath);
/*      */
/* 1212 */       JDBCEntityBridge fromEntity = (JDBCEntityBridge)fromPath.getEntity();
/* 1213 */       fromAlias = this.aliasManager.getAlias(fromPath.getPath());
/*      */
/* 1216 */       if (!fromEntity.equals(toChildEntity))
/*      */       {
/* 1218 */         throw new IllegalStateException("Only like types can be compared: from entity=" + fromEntity.getEntityName() + " to entity=" + toChildEntity.getEntityName());
/*      */       }
/*      */
/*      */     }
/*      */
/* 1226 */     addLeftJoinPath(pathStr, toPath);
/*      */
/* 1229 */     if (!this.subquerySupported)
/*      */     {
/* 1231 */       addJoinPath(toPath);
/*      */
/* 1234 */       if (node.not)
/*      */       {
/* 1236 */         buf.append(" NOT ");
/*      */       }
/* 1238 */       buf.append('(');
/*      */
/* 1240 */       if (relationTableAlias == null)
/*      */       {
/* 1242 */         SQLUtil.getIsNullClause(true, toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
/*      */       }
/*      */       else
/*      */       {
/* 1246 */         SQLUtil.getIsNullClause(true, toCMRField.getTableKeyFields(), relationTableAlias, buf);
/*      */       }
/*      */
/*      */     }
/*      */     else
/*      */     {
/* 1252 */       if (node.not)
/*      */       {
/* 1254 */         buf.append(" NOT ");
/*      */       }
/*      */
/* 1257 */       buf.append("EXISTS ").append('(');
/*      */
/* 1259 */       if (relationTableAlias == null)
/*      */       {
/* 1261 */         buf.append("SELECT ");
/* 1262 */         SQLUtil.getColumnNamesClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf).append(" FROM ").append(toChildEntity.getQualifiedTableName()).append(' ').append(toChildAlias).append(" WHERE ");
/*      */
/* 1268 */         SQLUtil.getJoinClause(toCMRField, toParentAlias, toChildAlias, buf);
/*      */       }
/*      */       else
/*      */       {
/* 1272 */         buf.append("SELECT ");
/* 1273 */         SQLUtil.getColumnNamesClause(toCMRField.getRelatedCMRField().getTableKeyFields(), relationTableAlias, buf).append(" FROM ").append(toCMRField.getQualifiedTableName()).append(' ').append(relationTableAlias).append(" WHERE ");
/*      */
/* 1279 */         SQLUtil.getRelationTableJoinClause(toCMRField, toParentAlias, relationTableAlias, buf);
/*      */       }
/*      */     }
/*      */
/* 1283 */     buf.append(" AND ");
/*      */
/* 1286 */     if (fromAlias != null)
/*      */     {
/* 1289 */       if (relationTableAlias == null)
/*      */       {
/* 1291 */         SQLUtil.getSelfCompareWhereClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, fromAlias, buf);
/*      */       }
/*      */       else
/*      */       {
/* 1298 */         SQLUtil.getRelationTableJoinClause(toCMRField.getRelatedCMRField(), fromAlias, relationTableAlias, buf);
/*      */       }
/*      */
/*      */     }
/*      */     else
/*      */     {
/* 1307 */       this.inputParameters.addAll(QueryParameter.createParameters(fromParamNumber - 1, toChildEntity));
/*      */
/* 1311 */       if (relationTableAlias == null)
/*      */       {
/* 1313 */         SQLUtil.getWhereClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
/*      */       }
/*      */       else
/*      */       {
/* 1317 */         SQLUtil.getWhereClause(toCMRField.getRelatedCMRField().getTableKeyFields(), relationTableAlias, buf);
/*      */       }
/*      */
/*      */     }
/*      */
/* 1323 */     buf.append(')');
View Full Code Here

/*     */     {
/*  72 */       String sql = getSQL(relationData, relationData.removedRelations.size() - i);
/*     */
/*  74 */       Connection con = null;
/*  75 */       PreparedStatement ps = null;
/*  76 */       JDBCCMRFieldBridge cmrField = relationData.getLeftCMRField();
/*     */       try
/*     */       {
/*  80 */         if (this.log.isDebugEnabled())
/*     */         {
/*  82 */           this.log.debug("Executing SQL: " + sql);
/*     */         }
/*     */
/*  86 */         DataSource dataSource = cmrField.getDataSource();
/*  87 */         con = dataSource.getConnection();
/*  88 */         ps = con.prepareStatement(sql);
/*     */
/*  91 */         setParameters(ps, relationData, pairs);
/*     */
/*  94 */         int rowsAffected = ps.executeUpdate();
/*  95 */         if (this.log.isDebugEnabled())
/*     */         {
/*  97 */           this.log.debug("Rows affected = " + rowsAffected);
/*     */         }
/*     */
/* 100 */         i += (this.maxKeysInDelete > 0 ? this.maxKeysInDelete : relationData.removedRelations.size());
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 104 */         throw new EJBException("Could not delete relations from " + cmrField.getQualifiedTableName(), e);
/*     */       }
/*     */       finally
/*     */       {
/* 110 */         JDBCUtil.safeClose(ps);
/* 111 */         JDBCUtil.safeClose(con);
View Full Code Here

TOP

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

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.