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

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


      if(!path.isCMRField())
      {
         throw new IllegalArgumentException("path must be a cmr field");
      }

      JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
      String pathStr = path.getPath(path.size() - 2);
      String parentAlias = aliasManager.getAlias(pathStr);

      // if exists is not supported we use a left join and is null
      if(!subquerySupported)
      {
         // add the path to the list of paths to left join
         addLeftJoinPath(pathStr, path);
         forceDistinct = true;

         addJoinPath(path);

         if(cmrField.getRelationMetaData().isForeignKeyMappingStyle())
         {
            JDBCEntityBridge childEntity = (JDBCEntityBridge) cmrField.getRelatedEntity();
            String childAlias = aliasManager.getAlias(path.getPath());
            SQLUtil.getIsNullClause(!not, childEntity.getPrimaryKeyFields(), childAlias, buf);
         }
         else
         {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
            SQLUtil.getIsNullClause(!not, cmrField.getTableKeyFields(), relationTableAlias, buf);
         }
         return;
      }

      if(not)
      {
         buf.append(SQLUtil.NOT);
      }
      buf.append(SQLUtil.EXISTS).append('(');

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

         buf.append(SQLUtil.SELECT);

         SQLUtil.getColumnNamesClause(childEntity.getPrimaryKeyFields(), childAlias, buf)
            .append(SQLUtil.FROM)
            .append(childEntity.getQualifiedTableName()).append(' ').append(childAlias)
            .append(SQLUtil.WHERE);
         SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
      }
      else
      {
         String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
         buf.append(SQLUtil.SELECT);
         SQLUtil.getColumnNamesClause(cmrField.getTableKeyFields(), relationTableAlias, buf)
            .append(SQLUtil.FROM)
            .append(cmrField.getQualifiedTableName())
            .append(' ')
            .append(relationTableAlias)
            .append(SQLUtil.WHERE);
         SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf);
      }
View Full Code Here


      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

            if(selectField.getJDBCType().hasMapper())
               this.functionJDBCType = selectField.getJDBCType();
         }
         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

      }

      boolean cleanReadAhead = manager.getMetaData().isCleanReadAheadOnLoad();

      boolean loaded = false;
      JDBCCMRFieldBridge onlyOneSingleValuedCMR = null;

      // iterate over the keys in the preloaded map
      Iterator iter = preloadDataMap.entrySet().iterator();
      while(iter.hasNext())
      {
         Map.Entry entry = (Map.Entry) iter.next();
         Object field = entry.getKey();

         // get the value that was preloaded for this field
         Object value = entry.getValue();

         // if we didn't get a value something is seriously hosed
         if(value == null)
         {
            throw new IllegalStateException("Preloaded value not found");
         }

         if(cleanReadAhead)
         {
            // remove this value from the preload cache as it is about to be loaded
            iter.remove();
         }

         // check for null value standin
         if(value == NULL_VALUE)
         {
            value = null;
         }

         if(field instanceof JDBCCMPFieldBridge)
         {
            JDBCCMPFieldBridge cmpField = (JDBCCMPFieldBridge) field;

            if(!cmpField.isLoaded(ctx))
            {
               if(log.isTraceEnabled())
               {
                  log.trace("Preloading data:" +
                     " entity=" + manager.getEntityBridge().getEntityName() +
                     " pk=" + ctx.getId() +
                     " cmpField=" + cmpField.getFieldName());
               }

               // set the value
               cmpField.setInstanceValue(ctx, value);

               // mark this field clean as it's value was just loaded
               cmpField.setClean(ctx);

               loaded = true;
            }
            else
            {
               if(log.isTraceEnabled())
               {
                  log.trace("CMPField already loaded:" +
                     " entity=" + manager.getEntityBridge().getEntityName() +
                     " pk=" + ctx.getId() +
                     " cmpField=" + cmpField.getFieldName());
               }
            }
         }
         else if(field instanceof JDBCCMRFieldBridge)
         {
            JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) field;

            if(!cmrField.isLoaded(ctx))
            {
               if(log.isTraceEnabled())
               {
                  log.trace("Preloading data:" +
                     " entity=" + manager.getEntityBridge().getEntityName() +
                     " pk=" + ctx.getId() +
                     " cmrField=" + cmrField.getFieldName());
               }

               // set the value
               cmrField.load(ctx, (List) value);

               // add the loaded list to the related entity's readahead cache
               JDBCStoreManager relatedManager = (JDBCStoreManager) cmrField.getRelatedCMRField().getManager();
               ReadAheadCache relatedReadAheadCache =
                  relatedManager.getReadAheadCache();
               relatedReadAheadCache.addFinderResults(
                  (List) value, cmrField.getReadAhead());

               if(!loaded)
               {
                  // this is a hack to fix on-load read-ahead for 1:m relationships
                  if(cmrField.isSingleValued() && onlyOneSingleValuedCMR == null)
                  {
                     onlyOneSingleValuedCMR = cmrField;
                  }
                  else
                  {
                     loaded = true;
                  }
               }
            }
            else
            {
               if(log.isTraceEnabled())
               {
                  log.trace("CMRField already loaded:" +
                     " entity=" + manager.getEntityBridge().getEntityName() +
                     " pk=" + ctx.getId() +
                     " cmrField=" + cmrField.getFieldName());
               }
            }
         }
      }
View Full Code Here

      if(!path.isCMRField())
      {
         throw new IllegalArgumentException("path must be a cmr field");
      }

      JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
      String pathStr = path.getPath(path.size() - 2);
      String parentAlias = aliasManager.getAlias(pathStr);

      // if exists is not supported we use a left join and is null
      if(!subquerySupported)
      {
         // add the path to the list of paths to left join
         addLeftJoinPath(pathStr, path);
         forceDistinct = true;

         addJoinPath(path);

         if(cmrField.getRelationMetaData().isForeignKeyMappingStyle())
         {
            JDBCEntityBridge childEntity = (JDBCEntityBridge) cmrField.getRelatedEntity();
            String childAlias = aliasManager.getAlias(path.getPath());
            SQLUtil.getIsNullClause(!not, childEntity.getPrimaryKeyFields(), childAlias, buf);
         }
         else
         {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
            SQLUtil.getIsNullClause(!not, cmrField.getTableKeyFields(), relationTableAlias, buf);
         }
         return;
      }

      if(not)
      {
         buf.append(SQLUtil.NOT);
      }
      buf.append(SQLUtil.EXISTS).append('(');

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

         buf.append(SQLUtil.SELECT);

         SQLUtil.getColumnNamesClause(childEntity.getPrimaryKeyFields(), childAlias, buf)
            .append(SQLUtil.FROM)
            .append(childEntity.getQualifiedTableName()).append(' ').append(childAlias)
            .append(SQLUtil.WHERE);
         SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
      }
      else
      {
         String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
         buf.append(SQLUtil.SELECT);
         SQLUtil.getColumnNamesClause(cmrField.getTableKeyFields(), relationTableAlias, buf)
            .append(SQLUtil.FROM)
            .append(cmrField.getQualifiedTableName())
            .append(' ')
            .append(relationTableAlias)
            .append(SQLUtil.WHERE);
         SQLUtil.getRelationTableJoinClause(cmrField, parentAlias, relationTableAlias, buf);
      }
View Full Code Here

TOP

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

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.