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

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


      if(!path.isCMRField(i) || declaredPaths.contains(path.getPath(i)))
      {
         return;
      }

      JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField(i);
      JDBCEntityBridge entity = (JDBCEntityBridge) path.getEntity(i);

      buf.append(SQLUtil.COMMA)
         .append(entity.getQualifiedTableName())
         .append(' ')
         .append(aliasManager.getAlias(path.getPath(i)));
      leftJoins(path.getPath(i), buf);

      if(cmrField.getRelationMetaData().isTableMappingStyle())
      {
         String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath(i));
         buf.append(SQLUtil.COMMA)
            .append(cmrField.getQualifiedTableName())
            .append(' ')
            .append(relationTableAlias);
      }

      declaredPaths.add(path.getPath(i));
View Full Code Here


      for(Iterator iter = paths.iterator(); iter.hasNext();)
      {
         ASTPath path = (ASTPath) iter.next();

         JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
         String parentAlias = aliasManager.getAlias(parentPath);

         if(cmrField.getRelationMetaData().isForeignKeyMappingStyle())
         {
            JDBCEntityBridge childEntity = (JDBCEntityBridge) cmrField.getRelatedEntity();
            String childAlias = aliasManager.getAlias(path.getPath());

            buf.append(SQLUtil.LEFT_JOIN)
               .append(childEntity.getQualifiedTableName())
               .append(' ')
               .append(childAlias)
               .append(SQLUtil.ON);
            SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
         }
         else
         {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
            buf.append(SQLUtil.LEFT_JOIN)
               .append(cmrField.getQualifiedTableName())
               .append(' ')
               .append(relationTableAlias)
               .append(SQLUtil.ON);
            SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf);
         }
View Full Code Here

      if(!path.isCMRField(i) || joinedAliases.contains(childAlias))
      {
         return;
      }

      JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField(i);
      String parentAlias = aliasManager.getAlias(path.getPath(i - 1));

      if(joinedAliases.size() > 0)
      {
         buf.append(SQLUtil.AND);
      }

      if(cmrField.getRelationMetaData().isForeignKeyMappingStyle())
      {
         SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
      }
      else
      {
         String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath(i));

         // parent to relation table
         SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf)
            .append(SQLUtil.AND);
         // child to relation table
         SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), childAlias, relationTableAlias, buf);
      }

      joinedAliases.add(childAlias);
   }
View Full Code Here

         buf.append(onFindCMRJoin);
         onFindCMRJoin = null;
      }

      // add the relation-table
      JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
      if(cmrField.getRelationMetaData().isTableMappingStyle())
      {
         String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
         buf.append(SQLUtil.COMMA)
            .append(cmrField.getQualifiedTableName())
            .append(' ')
            .append(relationTableAlias);
      }

      return buf;
View Full Code Here

            JDBCCMPFieldBridge selectField = (JDBCCMPFieldBridge) path.getCMPField();
            selectManager = (JDBCStoreManager) selectField.getManager();
         }
         else if(path.isCMRField())
         {
            JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
            selectManager = (JDBCStoreManager) cmrField.getEntity().getManager();
            addJoinPath(path);
         }
         else
         {
            final JDBCEntityBridge entity = (JDBCEntityBridge) path.getEntity();
View Full Code Here

      {
         ASTPath path = (ASTPath) child0;

         if(path.isCMRField())
         {
            JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
            if(cmrField.getRelationMetaData().isTableMappingStyle())
            {
               existsClause(path, buf, !node.not);
               return buf;
            }
         }
View Full Code Here

      StringBuffer buf = (StringBuffer) data;

      // setup compare to vars first, so we can compre types in from vars
      ASTPath toPath = (ASTPath) node.jjtGetChild(1);

      JDBCCMRFieldBridge toCMRField = (JDBCCMRFieldBridge) toPath.getCMRField();

      JDBCEntityBridge toChildEntity = (JDBCEntityBridge) toPath.getEntity();

      String pathStr = toPath.getPath(toPath.size() - 2);
      String toParentAlias = aliasManager.getAlias(pathStr);
      String toChildAlias = aliasManager.getAlias(toPath.getPath());
      String relationTableAlias = null;
      if(toCMRField.getRelationMetaData().isTableMappingStyle())
      {
         relationTableAlias = aliasManager.getRelationTableAlias(toPath.getPath());
      }

      // setup from variables
      String fromAlias = null;
      int fromParamNumber = -1;
      if(node.jjtGetChild(0) instanceof ASTParameter)
      {
         ASTParameter fromParam = (ASTParameter) node.jjtGetChild(0);

         // can only compare like kind entities
         verifyParameterEntityType(fromParam.number, toChildEntity);

         fromParamNumber = fromParam.number;
      }
      else
      {
         ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
         addJoinPath(fromPath);

         JDBCEntityBridge fromEntity = (JDBCEntityBridge) fromPath.getEntity();
         fromAlias = aliasManager.getAlias(fromPath.getPath());

         // can only compare like kind entities
         if(!fromEntity.equals(toChildEntity))
         {
            throw new IllegalStateException("Only like types can be " +
               "compared: from entity=" +
               fromEntity.getEntityName() +
               " to entity=" + toChildEntity.getEntityName());
         }
      }

      // add the path to the list of paths to left join
      addLeftJoinPath(pathStr, toPath);

      // first part makes toChild not in toParent.child
      if(!subquerySupported)
      {
         addJoinPath(toPath);

         // subquery not supported; use a left join and is not null
         if(node.not)
         {
            buf.append(SQLUtil.NOT);
         }
         buf.append('(');

         if(relationTableAlias == null)
         {
            SQLUtil.getIsNullClause(true, toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
         }
         else
         {
            SQLUtil.getIsNullClause(true, toCMRField.getTableKeyFields(), relationTableAlias, buf);
         }
      }
      else
      {
         // subquery supported; use exists subquery
         if(node.not)
         {
            buf.append(SQLUtil.NOT);
         }

         buf.append(SQLUtil.EXISTS).append('(');

         if(relationTableAlias == null)
         {
            buf.append(SQLUtil.SELECT);
            SQLUtil.getColumnNamesClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf)
               .append(SQLUtil.FROM)
               .append(toChildEntity.getQualifiedTableName())
               .append(' ')
               .append(toChildAlias)
               .append(SQLUtil.WHERE);
            SQLUtil.getJoinClause(toCMRField, toParentAlias, toChildAlias, buf);
         }
         else
         {
            buf.append(SQLUtil.SELECT);
            SQLUtil.getColumnNamesClause(toCMRField.getRelatedCMRField().getTableKeyFields(), relationTableAlias, buf)
               .append(SQLUtil.FROM)
               .append(toCMRField.getQualifiedTableName())
               .append(' ')
               .append(relationTableAlias)
               .append(SQLUtil.WHERE);
            SQLUtil.getRelationTableJoinClause(toCMRField, toParentAlias, relationTableAlias, buf);
         }
      }

      buf.append(SQLUtil.AND);

      // second part makes fromNode equal toChild
      if(fromAlias != null)
      {
         // compre pk to pk
         if(relationTableAlias == null)
         {
            SQLUtil.getSelfCompareWhereClause(toChildEntity.getPrimaryKeyFields(),
               toChildAlias,
               fromAlias,
               buf);
         }
         else
         {
            SQLUtil.getRelationTableJoinClause(toCMRField.getRelatedCMRField(),
               fromAlias,
               relationTableAlias,
               buf);
         }
      }
      else
      {
         // add the parameters
         inputParameters.addAll(QueryParameter.createParameters(fromParamNumber - 1,
            toChildEntity));

         // compare pk to parameter
         if(relationTableAlias == null)
         {
            SQLUtil.getWhereClause(toChildEntity.getPrimaryKeyFields(), toChildAlias, buf);
         }
         else
         {
            SQLUtil.getWhereClause(toCMRField.getRelatedCMRField().getTableKeyFields(),
               relationTableAlias,
               buf);
         }
      }
View Full Code Here

      {
         String sql = getSQL(relationData, relationData.removedRelations.size() - i);

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

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

            // set the parameters
            setParameters(ps, relationData, pairs);

            // execute statement
            int rowsAffected = ps.executeUpdate();
            if(log.isDebugEnabled())
            {
               log.debug("Rows affected = " + rowsAffected);
            }

            i += (maxKeysInDelete > 0 ? maxKeysInDelete : relationData.removedRelations.size());
         }
         catch(Exception e)
         {
            throw new EJBException("Could not delete relations from " +
               cmrField.getQualifiedTableName(), e
            );
         }
         finally
         {
            JDBCUtil.safeClose(ps);
View Full Code Here

      return createSQL(relationData, keys);
   }

   private static String createSQL(RelationData relationData, int keysInDelete)
   {
      JDBCCMRFieldBridge left = relationData.getLeftCMRField();
      JDBCCMRFieldBridge right = relationData.getRightCMRField();

      StringBuffer sql = new StringBuffer(300);
      sql.append(SQLUtil.DELETE_FROM)
         .append(left.getQualifiedTableName())
         .append(SQLUtil.WHERE);

      StringBuffer whereClause = new StringBuffer(20);
      whereClause.append('(');
      // left keys
      SQLUtil.getWhereClause(left.getTableKeyFields(), whereClause)
         .append(SQLUtil.AND);
      // right keys
      SQLUtil.getWhereClause(right.getTableKeyFields(), whereClause)
         .append(')');
      String whereClauseStr = whereClause.toString();
      sql.append(whereClauseStr);
      for(int i = 1; i < keysInDelete; ++i)
      {
View Full Code Here

         return getNext().invoke(mi);
      }

      // We are going to work with the context a lot
      EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext();
      JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)mi.getArguments()[0];

      if(CMRMessage.GET_RELATED_ID == relationshipMessage)
      {
         // call getRelateId
         if(log.isTraceEnabled())
         {
            log.trace("Getting related id: field=" + cmrField.getFieldName() + " id=" + ctx.getId());
         }
         return cmrField.getRelatedId(ctx);

      }
      else if(CMRMessage.ADD_RELATION == relationshipMessage)
      {
         // call addRelation
         Object relatedId = mi.getArguments()[1];
         if(log.isTraceEnabled())
         {
            log.trace("Add relation: field=" + cmrField.getFieldName() +
               " id=" + ctx.getId() +
               " relatedId=" + relatedId);
         }

         cmrField.addRelation(ctx, relatedId);

         return null;

      }
      else if(CMRMessage.REMOVE_RELATION == relationshipMessage)
      {
         // call removeRelation
         Object relatedId = mi.getArguments()[1];
         if(log.isTraceEnabled())
         {
            log.trace("Remove relation: field=" + cmrField.getFieldName() +
               " id=" + ctx.getId() +
               " relatedId=" + relatedId);
         }

         cmrField.removeRelation(ctx, relatedId);

         return null;
      }
      else if(CMRMessage.SCHEDULE_FOR_CASCADE_DELETE == relationshipMessage)
      {
         JDBCEntityBridge entity = (JDBCEntityBridge)cmrField.getEntity();
         entity.scheduleForCascadeDelete(ctx);
         return null;
      }
      else if(CMRMessage.SCHEDULE_FOR_BATCH_CASCADE_DELETE == relationshipMessage)
      {
         JDBCEntityBridge entity = (JDBCEntityBridge)cmrField.getEntity();
         entity.scheduleForBatchCascadeDelete(ctx);
         return null;
      }
      else
      {
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.