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

Examples of org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractEntityBridge


      JDBCEntityPersistenceStore manager,
      Class intf,
      String fieldName)
   {
      Catalog catalog = manager.getCatalog();
      JDBCAbstractEntityBridge entityBridge = (JDBCAbstractEntityBridge)catalog.getEntityByInterface(intf);
      if(entityBridge == null)
      {
         throw new IllegalArgumentException("Entity not found in application " +
            "catalog with interface=" + intf.getName());
      }

      JDBCFieldBridge cmpField = (JDBCFieldBridge)entityBridge.getFieldByName(fieldName);
      if(cmpField == null)
      {
         throw new IllegalArgumentException("cmpField not found:" +
            " cmpFieldName=" + fieldName +
            " entityName=" + entityBridge.getEntityName());
      }
      return cmpField;
   }
View Full Code Here


               cmrField.getEntity().getPrimaryKeyFields());

         }
         else if(cmrField.hasForeignKey())
         {
            JDBCAbstractEntityBridge relatedEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();
            addForeignKeyConstraint(cmrField.getEntity().getDataSource(),
               cmrField.getEntity().getQualifiedTableName(),
               cmrField.getFieldName(),
               cmrField.getForeignKeyFields(),
               relatedEntity.getQualifiedTableName(),
               relatedEntity.getPrimaryKeyFields());
         }
      }
      else
      {
         log.debug("Foreign key constraint not added as requested: relationshipRolename=" + metaData.getRelationshipRoleName());
View Full Code Here

            String alias = aliasManager.getAlias(path.getPath(path.size() - 2));
            SQLUtil.getColumnNamesClause(selectField, alias, sql);
         }
         else
         {
            JDBCAbstractEntityBridge selectEntity = (JDBCAbstractEntityBridge) path.getEntity();
            selectManager = selectEntity.getManager();
            selectObject = selectEntity;
            setTypeFactory(selectEntity.getManager().getJDBCTypeFactory());

            final String alias = aliasManager.getAlias(path.getPath());
            if(select.distinct)
            {
               SQLUtil.getSearchableColumnNamesClause(selectEntity.getTableFields(), alias, sql);
            }
            else
            {
               SQLUtil.getColumnNamesClause(selectEntity.getTableFields(), alias, sql);
            }

            /*
            if(readAhead.isOnFind())
            {
               String eagerLoadGroupName = readAhead.getEagerLoadGroup();
               boolean[] loadGroupMask = selectEntity.getLoadGroupMask(eagerLoadGroupName);
               SQLUtil.appendColumnNamesClause(
                  selectEntity.getTableFields(),
                  loadGroupMask,
                  alias,
                  sql
               );
            }
            */

            addLeftJoinPath(path);
         }
      }
      else
      {
         // the function should take a path expresion as a parameter
         path = getPathFromChildren(child0);

         if(path == null)
         {
            throw new IllegalStateException("The function in SELECT clause does not contain a path expression.");
         }

         if(path.isCMPField())
         {
            JDBCFieldBridge selectField = (JDBCFieldBridge) path.getCMPField();
            selectManager = selectField.getManager();
            setTypeFactory(selectManager.getJDBCTypeFactory());
         }
         else if(path.isCMRField())
         {
            JDBCFieldBridge cmrField = (JDBCFieldBridge) path.getCMRField();
            selectManager = cmrField.getManager();
            setTypeFactory(selectManager.getJDBCTypeFactory());
            addLeftJoinPath(path);
         }
         else
         {
            final JDBCAbstractEntityBridge entity = (JDBCAbstractEntityBridge) path.getEntity();
            selectManager = entity.getManager();
            setTypeFactory(selectManager.getJDBCTypeFactory());
            addLeftJoinPath(path);
         }

         selectObject = child0;
View Full Code Here

      addLeftJoinPath(path);

      StringBuffer sql = (StringBuffer) data;
      JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField();
      JDBCAbstractEntityBridge relatedEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();
      String alias = aliasManager.getAlias(path.getPath());
      SQLUtil.getIsNullClause(node.not, relatedEntity.getPrimaryKeyFields(), alias, sql);

      return data;
   }
View Full Code Here

   public Object visit(ASTMemberOf node, Object data)
   {
      Node member = node.jjtGetChild(0);
      ASTPath colPath = (ASTPath) node.jjtGetChild(1);
      JDBCAbstractEntityBridge colEntity = (JDBCAbstractEntityBridge) colPath.getEntity();

      StringBuffer sql = (StringBuffer) data;

      if(node.not)
      {
         sql.append(SQLUtil.NOT);
      }

      sql.append(SQLUtil.EXISTS).append('(').append(SQLUtil.SELECT);

      if(member instanceof ASTParameter)
      {
         ASTParameter toParam = (ASTParameter) member;
         verifyParameterEntityType(toParam.number, colEntity);
         inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, colEntity));

         String parentAlias = aliasManager.getAlias(colPath.getPath(0));
         String localParentAlias = aliasManager.getAlias(colPath.getPath(0) + "_local");
         JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) colPath.getEntity(0);
         SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), localParentAlias, sql);
         sql.append(SQLUtil.FROM)
            .append(parentEntity.getQualifiedTableName()).append(' ').append(localParentAlias);
         innerJoinPath(colPath, sql);

         sql.append(SQLUtil.WHERE);

         JDBCAbstractEntityBridge col0 = (JDBCAbstractEntityBridge)colPath.getEntity(0);
         SQLUtil.getSelfCompareWhereClause(col0.getPrimaryKeyFields(), parentAlias, localParentAlias, sql);
         sql.append(SQLUtil.AND);

         String localColAlias = aliasManager.getAlias(colPath.getPath() + "_local");
         SQLUtil.getWhereClause(colEntity.getPrimaryKeyFields(), localColAlias, sql);
      }
      else
      {
         ASTPath memberPath = (ASTPath) member;
         JDBCAbstractEntityBridge memberEntity = (JDBCAbstractEntityBridge) memberPath.getEntity();

         if(!memberEntity.equals(colEntity))
         {
            throw new IllegalStateException("Member must be if the same type as the collection, got: member="
               +
               memberEntity.getEntityName()
               + ", collection=" + colEntity.getEntityName());
         }

         String memberAlias = aliasManager.getAlias(memberPath.getPath());

         if(memberPath.size() > 1)
         {
            String parentAlias = aliasManager.getAlias(memberPath.getPath(0) + "_local");
            JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) memberPath.getEntity(0);
            SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
            sql.append(SQLUtil.FROM)
               .append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
            innerJoinPath(memberPath, sql);
            innerJoinPath(colPath, sql);
         }
         else if(colPath.size() > 1)
         {
            String parentAlias = aliasManager.getAlias(colPath.getPath(0) + "_local");
            JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) colPath.getEntity(0);
            SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
            sql.append(SQLUtil.FROM)
               .append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
            innerJoinPath(colPath, sql);
         }
         else
         {
            throw new IllegalStateException(
               "There should be collection valued path expression, not identification variable.");
         }

         sql.append(SQLUtil.WHERE);

         JDBCAbstractEntityBridge member0 = (JDBCAbstractEntityBridge)memberPath.getEntity(0);
         String colAliasLocal = aliasManager.getAlias(colPath.getPath() + "_local");
         if(memberPath.size() > 1)
         {
            String memberAliasLocal = aliasManager.getAlias(memberPath.getPath() + "_local");
            SQLUtil.getSelfCompareWhereClause(colEntity.getPrimaryKeyFields(),
               memberAliasLocal,
               colAliasLocal,
               sql);

            sql.append(SQLUtil.AND);

            String member0Alias = aliasManager.getAlias(memberPath.getPath(0));
            String member0AliasLocal = aliasManager.getAlias(memberPath.getPath(0) + "_local");
            SQLUtil.getSelfCompareWhereClause(member0.getPrimaryKeyFields(),
               member0Alias,
               member0AliasLocal,
               sql);
         }
         else
         {
            SQLUtil.getSelfCompareWhereClause(member0.getPrimaryKeyFields(), memberAlias, colAliasLocal, sql);

            sql.append(SQLUtil.AND);

            String col0Alias = aliasManager.getAlias(colPath.getPath(0));
            String col0AliasLocal = aliasManager.getAlias(colPath.getPath(0) + "_local");
View Full Code Here

      {
         String curPath = path.getPath(i);
         final String joinAlias = aliasManager.getAlias(curPath + "_local");

         final JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField(i);
         final JDBCAbstractEntityBridge joinEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();

         JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();

         String join = " INNER JOIN ";

         if(relation.isTableMappingStyle())
         {
            String relTableAlias = aliasManager.getRelationTableAlias(curPath + "_local");
            sql.append(join)
               .append(cmrField.getQualifiedTableName())
               .append(' ')
               .append(relTableAlias)
               .append(" ON ");
            SQLUtil.getRelationTableJoinClause(cmrField, leftAlias, relTableAlias, sql);

            sql.append(join)
               .append(joinEntity.getQualifiedTableName())
               .append(' ')
               .append(joinAlias)
               .append(" ON ");
            SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), joinAlias, relTableAlias, sql);
         }
         else
         {
            sql.append(join)
               .append(joinEntity.getQualifiedTableName())
               .append(' ')
               .append(joinAlias)
               .append(" ON ");

            SQLUtil.getJoinClause(cmrField, leftAlias, joinAlias, sql);
View Full Code Here

      {
         args = new Object[]{node.distinct, node.jjtGetChild(0).jjtAccept(this, new StringBuffer()).toString()};
      }
      else
      {
         JDBCAbstractEntityBridge entity = (JDBCAbstractEntityBridge) cntPath.getEntity();
         final JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
         if(pkFields.length > 1)
         {
            countCompositePk = true;
            forceDistinct = node.distinct.length() > 0;

            addLeftJoinPath(cntPath);

            String alias = aliasManager.getAlias(cntPath.getPath());
            SQLUtil.getColumnNamesClause(entity.getPrimaryKeyFields(),
               alias,
               buf);

            return buf;
         }
View Full Code Here

   }

   public Object visit(ASTRangeVariableDeclaration node, Object data)
   {
      ASTAbstractSchema schema = (ASTAbstractSchema) node.jjtGetChild(0);
      JDBCAbstractEntityBridge entity = (JDBCAbstractEntityBridge) schema.entity;
      ASTIdentifier id = (ASTIdentifier) node.jjtGetChild(1);
      declareTable(id.identifier, entity.getQualifiedTableName());
      return data;
   }
View Full Code Here

      }

      ASTPath fromPath = (ASTPath) fromNode;
      addLeftJoinPath(fromPath);
      String fromAlias = aliasManager.getAlias(fromPath.getPath());
      JDBCAbstractEntityBridge fromEntity = (JDBCAbstractEntityBridge) fromPath.getEntity();

      if(toNode instanceof ASTParameter)
      {
         ASTParameter toParam = (ASTParameter) toNode;

         // can only compare like kind entities
         verifyParameterEntityType(toParam.number, fromEntity);

         inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromEntity));

         SQLUtil.getWhereClause(fromEntity.getPrimaryKeyFields(), fromAlias, buf);
      }
      else
      {
         ASTPath toPath = (ASTPath) toNode;
         addLeftJoinPath(toPath);
         String toAlias = aliasManager.getAlias(toPath.getPath());
         JDBCAbstractEntityBridge toEntity = (JDBCAbstractEntityBridge) toPath.getEntity();

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

         SQLUtil.getSelfCompareWhereClause(fromEntity.getPrimaryKeyFields(), fromAlias, toAlias, buf);
      }
View Full Code Here

               final String joinAlias = aliasManager.getAlias(curPath);

               if(joinedAliases.add(joinAlias))
               {
                  final JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField(i);
                  final JDBCAbstractEntityBridge joinEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();

                  JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();

                  String join = (path.innerJoin ? " INNER JOIN " : " LEFT OUTER JOIN ");

                  if(relation.isTableMappingStyle())
                  {
                     String relTableAlias = aliasManager.getRelationTableAlias(curPath);
                     sql.append(join)
                        .append(cmrField.getQualifiedTableName())
                        .append(' ')
                        .append(relTableAlias)
                        .append(" ON ");
                     SQLUtil.getRelationTableJoinClause(cmrField, leftAlias, relTableAlias, sql);

                     sql.append(join)
                        .append(joinEntity.getQualifiedTableName())
                        .append(' ')
                        .append(joinAlias)
                        .append(" ON ");
                     SQLUtil.getRelationTableJoinClause(cmrField.getRelatedCMRField(), joinAlias, relTableAlias, sql);
                  }
                  else
                  {
                     sql.append(join)
                        .append(joinEntity.getQualifiedTableName())
                        .append(' ')
                        .append(joinAlias)
                        .append(" ON ");

                     SQLUtil.getJoinClause(cmrField, leftAlias, joinAlias, sql);
View Full Code Here

TOP

Related Classes of org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractEntityBridge

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.