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

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


   public boolean isSelectField()
   {
      boolean result;
      if(selectObject instanceof JDBCFieldBridge)
      {
         JDBCFieldBridge field = (JDBCFieldBridge) selectObject;
         result = field.isCMPField();
      }
      else
      {
         result = false;
      }
View Full Code Here


         path = (ASTPath) child0;

         if(path.isCMPField())
         {
            // set the select object
            JDBCFieldBridge selectField = (JDBCFieldBridge) path.getCMPField();
            selectManager = selectField.getManager();
            selectObject = selectField;
            setTypeFactory(selectManager.getJDBCTypeFactory());

            // todo inner or left?
            //addLeftJoinPath(path);
            addInnerJoinPath(path);

            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
         {
View Full Code Here

      if(child0 instanceof ASTPath)
      {
         ASTPath path = (ASTPath) child0;
         addLeftJoinPath(path);

         JDBCFieldBridge field = (JDBCFieldBridge) path.getField();

         if(field instanceof JDBCAbstractCMRFieldBridge)
         {
            JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge)field;
            final String alias;
View Full Code Here

      {
         throw new IllegalStateException("Can only visit cmp valued path node. "
            + "Should have been handled at a higher level.");
      }

      JDBCFieldBridge cmpField = (JDBCFieldBridge) node.getCMPField();

      // make sure this is mapped to a single column
      switch(node.type)
      {
         case EJBQLTypes.ENTITY_TYPE:
         case EJBQLTypes.VALUE_CLASS_TYPE:
            if(cmpField.getJDBCType().hasMapper() ||
               cmpField.getJDBCType().getParameterSetter() != null)
            {
               break;
            }
         case EJBQLTypes.UNKNOWN_TYPE:
            throw new IllegalStateException("Can not visit multi-column path " +
View Full Code Here

/*  115 */         ArrayList newNames = new ArrayList();
/*  116 */         JDBCFieldBridge[] fields = this.entity.getTableFields();
/*  117 */         String tableName = this.entity.getQualifiedTableName();
/*  118 */         for (int i = 0; i < fields.length; i++)
/*      */         {
/*  120 */           JDBCFieldBridge field = fields[i];
/*  121 */           JDBCType jdbcType = field.getJDBCType();
/*  122 */           String[] columnNames = jdbcType.getColumnNames();
/*  123 */           String[] sqlTypes = jdbcType.getSQLTypes();
/*  124 */           boolean[] notNull = jdbcType.getNotNull();
/*      */
/*  126 */           for (int j = 0; j < columnNames.length; j++)
/*      */           {
/*  128 */             String name = columnNames[j];
/*  129 */             String ucName = name.toUpperCase();
/*      */
/*  131 */             newNames.add(ucName);
/*      */
/*  133 */             int oldIndex = oldNames.indexOf(ucName);
/*  134 */             if (oldIndex == -1)
/*      */             {
/*  137 */               StringBuffer buf = new StringBuffer(sqlTypes[j]);
/*  138 */               if (notNull[j] != 0)
/*      */               {
/*  140 */                 buf.append(" NOT ").append("NULL");
/*      */               }
/*  142 */               alterTable(this.entity.getDataSource(), this.entityMetaData.getTypeMapping().getAddColumnTemplate(), tableName, name, buf.toString());
/*      */             }
/*      */             else
/*      */             {
/*  150 */               String type = (String)oldTypes.get(oldIndex);
/*  151 */               if ((!type.equals("CHAR")) && (!type.equals("VARCHAR"))) {
/*      */                 continue;
/*      */               }
/*      */               try
/*      */               {
/*  156 */                 String l = sqlTypes[j];
/*  157 */                 l = l.substring(l.indexOf('(') + 1, l.length() - 1);
/*  158 */                 Integer oldLength = (Integer)oldSizes.get(oldIndex);
/*  159 */                 if (Integer.parseInt(l) > oldLength.intValue())
/*      */                 {
/*  161 */                   alterTable(this.entity.getDataSource(), this.entityMetaData.getTypeMapping().getAlterColumnTemplate(), tableName, name, sqlTypes[j]);
/*      */                 }
/*      */
/*      */               }
/*      */               catch (Exception e)
/*      */               {
/*  168 */                 this.log.warn("EXCEPTION ALTER :" + e.toString());
/*      */               }
/*      */
/*      */             }
/*      */
/*      */           }
/*      */
/*  175 */           JDBCCMPFieldMetaData fieldMD = this.entity.getMetaData().getCMPFieldByName(field.getFieldName());
/*  176 */           if ((fieldMD == null) || (!fieldMD.isIndexed()))
/*      */             continue;
/*  178 */           if (oldIndexes == null)
/*      */           {
/*  180 */             oldIndexes = SQLUtil.getOldIndexes(this.entity.getQualifiedTableName(), this.entity.getDataSource());
/*  181 */             this.idxCount = oldIndexes.getIndexNames().size();
/*      */           }
/*  183 */           if (hasIndex(oldIndexes, field))
/*      */             continue;
/*  185 */           createCMPIndex(this.entity.getDataSource(), field, oldIndexes.getIndexNames());
/*      */         }
/*      */
/*  192 */         Iterator it = oldNames.iterator();
/*  193 */         while (it.hasNext())
/*      */         {
/*  195 */           String name = (String)(String)it.next();
/*  196 */           if (!newNames.contains(name))
/*      */           {
/*  198 */             alterTable(this.entity.getDataSource(), this.entityMetaData.getTypeMapping().getDropColumnTemplate(), tableName, name, "");
/*      */           }
/*      */
/*      */         }
/*      */
/*      */       }
/*      */
/*      */     }
/*      */
/*  208 */     Set createdTables = getCreatedTables(this.manager);
/*      */
/*  210 */     if ((this.entityMetaData.getCreateTable()) && (!createdTables.contains(this.entity.getEntityName())))
/*      */     {
/*  212 */       DataSource dataSource = this.entity.getDataSource();
/*  213 */       createTable(dataSource, this.entity.getQualifiedTableName(), getEntityCreateTableSQL(dataSource));
/*      */
/*  216 */       if (!tableExisted)
/*      */       {
/*  218 */         createCMPIndices(dataSource, SQLUtil.getOldIndexes(this.entity.getQualifiedTableName(), this.entity.getDataSource()).getIndexNames());
/*      */       }
/*  224 */       else if (this.log.isDebugEnabled())
/*      */       {
/*  226 */         this.log.debug("Indices for table " + this.entity.getQualifiedTableName() + "not created as table existed");
/*      */       }
/*      */
/*  232 */       if (!tableExisted)
/*      */       {
/*  234 */         issuePostCreateSQL(dataSource, this.entity.getMetaData().getDefaultTablePostCreateCmd(), this.entity.getQualifiedTableName());
/*      */       }
/*      */
/*  239 */       createdTables.add(this.entity.getEntityName());
/*      */     }
/*      */     else
/*      */     {
/*  243 */       this.log.debug("Table not create as requested: " + this.entity.getQualifiedTableName());
/*      */     }
/*      */
/*  247 */     JDBCAbstractCMRFieldBridge[] cmrFields = this.entity.getCMRFields();
/*  248 */     for (int i = 0; i < cmrFields.length; i++)
/*      */     {
/*  250 */       JDBCAbstractCMRFieldBridge cmrField = cmrFields[i];
/*  251 */       JDBCRelationMetaData relationMetaData = cmrField.getMetaData().getRelationMetaData();
/*      */
/*  254 */       EntityBridge relatedEntity = cmrField.getRelatedEntity();
/*  255 */       if ((!relationMetaData.isTableMappingStyle()) || (!createdTables.contains(relatedEntity.getEntityName())))
/*      */         continue;
/*  257 */       DataSource dataSource = relationMetaData.getDataSource();
/*      */
/*  259 */       boolean relTableExisted = SQLUtil.tableExists(cmrField.getQualifiedTableName(), this.entity.getDataSource());
/*      */
/*  261 */       if (relTableExisted)
/*      */       {
/*  263 */         if (relationMetaData.getAlterTable())
/*      */         {
/*  265 */           ArrayList oldNames = SQLUtil.getOldColumns(cmrField.getQualifiedTableName(), dataSource).getColumnNames();
/*  266 */           ArrayList newNames = new ArrayList();
/*  267 */           JDBCFieldBridge[] leftKeys = cmrField.getTableKeyFields();
/*  268 */           JDBCFieldBridge[] rightKeys = cmrField.getRelatedCMRField().getTableKeyFields();
/*  269 */           JDBCFieldBridge[] fields = new JDBCFieldBridge[leftKeys.length + rightKeys.length];
/*  270 */           System.arraycopy(leftKeys, 0, fields, 0, leftKeys.length);
/*  271 */           System.arraycopy(rightKeys, 0, fields, leftKeys.length, rightKeys.length);
/*      */
/*  274 */           boolean different = false;
/*  275 */           for (int j = 0; j < fields.length; j++)
/*      */           {
/*  277 */             JDBCFieldBridge field = fields[j];
/*      */
/*  279 */             String name = field.getJDBCType().getColumnNames()[0].toUpperCase();
/*  280 */             newNames.add(name);
/*      */
/*  282 */             if (oldNames.contains(name))
/*      */               continue;
/*  284 */             different = true;
View Full Code Here

/*      */
/*  806 */     boolean comma = false;
/*  807 */     JDBCFieldBridge[] fields = this.entity.getTableFields();
/*  808 */     for (int i = 0; i < fields.length; i++)
/*      */     {
/*  810 */       JDBCFieldBridge field = fields[i];
/*  811 */       JDBCType type = field.getJDBCType();
/*  812 */       if (comma)
/*      */       {
/*  814 */         sql.append(", ");
/*      */       }
/*      */       else
View Full Code Here

/*      */     throws DeploymentException
/*      */   {
/*  858 */     JDBCFieldBridge[] cmpFields = this.entity.getTableFields();
/*  859 */     for (int i = 0; i < cmpFields.length; i++)
/*      */     {
/*  861 */       JDBCFieldBridge field = cmpFields[i];
/*  862 */       JDBCCMPFieldMetaData fieldMD = this.entity.getMetaData().getCMPFieldByName(field.getFieldName());
/*      */
/*  864 */       if ((fieldMD == null) || (!fieldMD.isIndexed()))
/*      */         continue;
/*  866 */       createCMPIndex(dataSource, field, indexNames);
/*      */     }
View Full Code Here

/*      */   {
/*      */     boolean result;
/*      */     boolean result;
/*  212 */     if ((this.selectObject instanceof JDBCFieldBridge))
/*      */     {
/*  214 */       JDBCFieldBridge field = (JDBCFieldBridge)this.selectObject;
/*  215 */       result = field.isCMPField();
/*      */     }
/*      */     else
/*      */     {
/*  219 */       result = false;
/*      */     }
View Full Code Here

/*      */     {
/*  443 */       ASTPath path = (ASTPath)child0;
/*      */
/*  445 */       if (path.isCMPField())
/*      */       {
/*  448 */         JDBCFieldBridge selectField = path.getCMPField();
/*  449 */         this.selectManager = selectField.getManager();
/*  450 */         this.selectObject = selectField;
/*  451 */         setTypeFactory(this.selectManager.getJDBCTypeFactory());
/*      */
/*  455 */         addInnerJoinPath(path);
/*      */
/*  457 */         String alias = this.aliasManager.getAlias(path.getPath(path.size() - 2));
/*  458 */         SQLUtil.getColumnNamesClause(selectField, alias, sql);
/*      */       }
/*      */       else
/*      */       {
/*  462 */         JDBCAbstractEntityBridge selectEntity = (JDBCAbstractEntityBridge)path.getEntity();
/*  463 */         this.selectManager = selectEntity.getManager();
/*  464 */         this.selectObject = selectEntity;
/*  465 */         setTypeFactory(selectEntity.getManager().getJDBCTypeFactory());
/*      */
/*  467 */         String alias = this.aliasManager.getAlias(path.getPath());
/*  468 */         if (select.distinct)
/*      */         {
/*  470 */           SQLUtil.getSearchableColumnNamesClause(selectEntity.getTableFields(), alias, sql);
/*      */         }
/*      */         else
/*      */         {
/*  474 */           SQLUtil.getColumnNamesClause(selectEntity.getTableFields(), alias, sql);
/*      */         }
/*      */
/*  491 */         addLeftJoinPath(path);
/*      */       }
/*      */
/*      */     }
/*      */     else
/*      */     {
/*  497 */       ASTPath path = getPathFromChildren(child0);
/*      */
/*  499 */       if (path == null)
/*      */       {
/*  501 */         throw new IllegalStateException("The function in SELECT clause does not contain a path expression.");
/*      */       }
/*      */
/*  504 */       if (path.isCMPField())
/*      */       {
/*  506 */         JDBCFieldBridge selectField = path.getCMPField();
/*  507 */         this.selectManager = selectField.getManager();
/*  508 */         setTypeFactory(this.selectManager.getJDBCTypeFactory());
/*      */       }
/*  510 */       else if (path.isCMRField())
/*      */       {
/*  512 */         JDBCFieldBridge cmrField = (JDBCFieldBridge)path.getCMRField();
/*  513 */         this.selectManager = cmrField.getManager();
/*  514 */         setTypeFactory(this.selectManager.getJDBCTypeFactory());
/*  515 */         addLeftJoinPath(path);
/*      */       }
/*      */       else
/*      */       {
View Full Code Here

/*  646 */     if ((child0 instanceof ASTPath))
/*      */     {
/*  648 */       ASTPath path = (ASTPath)child0;
/*  649 */       addLeftJoinPath(path);
/*      */
/*  651 */       JDBCFieldBridge field = (JDBCFieldBridge)path.getField();
/*      */
/*  653 */       if ((field instanceof JDBCAbstractCMRFieldBridge))
/*      */       {
/*  655 */         JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge)field;
/*      */         JDBCFieldBridge[] keyFields;
View Full Code Here

TOP

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

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.