Package nexj.core.meta.persistence.sql

Examples of nexj.core.meta.persistence.sql.Column


   {
      if (op.isConstant())
      {
         Operator parent = op.getParent();
         Object value = op.getValue();
         Column column = null;
         Operator left = null;

         if (parent instanceof ComparisonOperator)
         {
            left = ((ComparisonOperator)op.getParent()).getLeft();

            if (parent.getOrdinal() == LikeOperator.ORDINAL && value != null)
            {
               value = m_adapter.getLikePattern((String)value);
            }
         }
         else if (parent instanceof InOperator)
         {
            left = ((InOperator)op.getParent()).getOperand(0);
         }

         if (left instanceof AttributeOperator)
         {
            AttributeOperator aop = (AttributeOperator)left;

            if (aop.getConverter() == null)
            {
               column = (Column)((Field)aop.getSource()).getItem();
            }
         }

         if (column != null)
         {
            if ((column.isLiteral() || m_adapter.isLiteral()) &&
               m_adapter.isLiteral(column.getType(), value) ||
               getBindCount() == m_adapter.getMaxBindCount())
            {
               if (column.isTimeZoned() && value != null)
               {
                  Timestamp ts = ((Timestamp)value);
                  long lTime = ts.getTime();

                  Timestamp tsLocal = new Timestamp(lTime + ((CalendarFactory)column.getConverter().getInstance(null))
                        .createCalendar().getTimeZone().getOffset(lTime));

                  tsLocal.setNanos(ts.getNanos());
                  value = tsLocal;
               }

               m_adapter.appendLiteral(buf, column.getType(), value);
            }
            else
            {
               m_adapter.appendBind(buf, getBindCount());
               addBind(m_adapter.getBind(column), m_adapter.toBind(column, value));
View Full Code Here


      if (op.getType() == Primitive.BOOLEAN &&
         (parent == null && (m_nGenMode == GEN_JOIN || m_nGenMode == GEN_WHERE || m_nGenMode == GEN_HAVING) ||
          parent instanceof Logical || parent instanceof IfOperator && op == ((IfOperator)parent).getCondition()))
      {
         Field field = (Field)op.getSource();
         Column column = (Column)field.getItem();
         Boolean value = Boolean.valueOf(bTrue);
         boolean bParen = (parent != null && parent.getPriority() >= EqualsOperator.PRIORITY);

         if (bParen)
         {
            buf.append('(');
         }

         appendField(buf, field);
         buf.append(" = ");

         if ((column.isLiteral() || m_adapter.isLiteral()) &&
            m_adapter.isLiteral(column.getType(), value) ||
            getBindCount() == m_adapter.getMaxBindCount())
         {
            m_adapter.appendLiteral(buf, column.getType(), value);
         }
         else
         {
            m_adapter.appendBind(buf, getBindCount());
View Full Code Here

      buf.append("create table ").append(sTable).append('(');

      for (int i = 0, nCount = primaryKey.getIndexColumnCount(); i < nCount; ++i) // add PK cols
      {
         Column col = table.getColumn(i);

         appendColumnDeclaration(buf, col, true, true, ", ");
         columns.append(col.getQuotedName());
         buf.append(','); // last one will be followed by PK declaration at end
         columns.append(','); // last one will be truncated later
      }

      appendPrimaryKey(buf, primaryKey);
View Full Code Here

         Index idx = table.getIndex(i);

         if (idx.getType() == Index.TEXT && idx != excludeIndex &&
             (includeIndex == null || idx == includeIndex))
         {
            Column col = idx.getIndexColumn(0).getColumn();

            if (primaryKey.findIndexColumn(col) == null) // add PK columns later
            {
               changedColumns.append("new.").append(col.getQuotedName());
               listingColumns.append(col.getQuotedName());
               updatedColumns.append(col.getQuotedName());
               updatedColumns.append(" = new.").append(col.getQuotedName());
               changedColumns.append(','); // followed by PrimaryKey columns
               listingColumns.append(','); // followed by PrimaryKey columns
               updatedColumns.append(','); // followed by PrimaryKey columns
            }
         }
      }

      for (int i = 0, nCount = primaryKey.getIndexColumnCount(); i < nCount; ++i) // add PK cols
      {
         if (i != 0)
         {
            changedColumns.append(',');
            listingColumns.append(',');
            matchedColumns.append(" and ");
            updatedColumns.append(',');
         }

         Column col = primaryKey.getIndexColumn(i).getColumn();

         changedColumns.append("new.").append(col.getQuotedName());
         listingColumns.append(col.getQuotedName());
         matchedColumns.append(col.getQuotedName());
         matchedColumns.append(" = old.").append(col.getQuotedName());
         updatedColumns.append(col.getQuotedName());
         updatedColumns.append(" = new.").append(col.getQuotedName());
      }

      StringBuffer buf = new StringBuffer(64);

      buf.append("create trigger ").append(table.getFullName(getOwner(), "$d", true));
View Full Code Here

         return;
      }

      String sTable = table.getFullName(getOwner(), "$", true);
      Column column = index.getIndexColumn(0).getColumn();
      Index primaryKey = table.getPrimaryKey();
      boolean bColInPK = primaryKey.findIndexColumn(column) != null;
      boolean bHaveMoreIndexes = false;
      StringBuffer buf = new StringBuffer(128);

      // determine if this is the first Full-Text index to be created (i.e. Full-Text table needed)
      for (int i = 0, nCount = table.getIndexCount(); i < nCount && !bHaveMoreIndexes; ++i)
      {
         Index idx = table.getIndex(i);

         bHaveMoreIndexes = idx != index && idx.getType() == Index.TEXT;
      }

      if (!bHaveMoreIndexes) // Need to create a new Full-Text table
      {
         createTextTable(table);
      }

      if (!bColInPK) // Existing Full-Text table to alter, column does not exist yet
      {
         buf.append("alter table ").append(sTable).append(" add column ");
         appendColumnDeclaration(buf, column, false, false, ", "); // take only first column
         m_appender.appendSQL(buf.toString());           // column nullable since rows can exist
         buf.setLength(0);
         dropTextTriggers(table);
         createTextTriggers(table, null, null);
         buf.append("update ").append(sTable).append(" dst inner join ");
         buf.append(table.getFullName(getOwner(), null, true)).append(" src on ");

         for (int i = 0, nCount = primaryKey.getIndexColumnCount(); i < nCount; ++i) // add PK cols
         {
            Column col = table.getColumn(i);

            if (i != 0)
            {
               buf.append("and ");
            }

            buf.append("dst.").append(col.getQuotedName());
            buf.append(" = src.").append(col.getQuotedName());
         }

         buf.append(" set dst.").append(column.getQuotedName());
         buf.append(" = src.").append(column.getQuotedName());
         m_appender.appendSQL(buf.toString()); // fill Full-Text column with data from source table
View Full Code Here

         buf.append(sTable);
         m_appender.appendSQL(buf.toString());
         buf.setLength(0);

         boolean bHaveMoreIndexes = false;
         Column column = index.getIndexColumn(0).getColumn(); // take only first column

         // see if if there are any more FullText indexes
         for (int i = 0, nCount = table.getIndexCount(); i < nCount && !bHaveMoreIndexes; ++i)
         {
            Index idx = table.getIndex(i);

            bHaveMoreIndexes = idx != index && idx.getType() == Index.TEXT; // ignore self
         }

         // the Full-Text column is part of PrimaryKey, so it is still needed for other Full-Text
         if (bHaveMoreIndexes &&                                                       // indexes
             table.getPrimaryKey().findIndexColumn(column) != null)
         {
            return; // done
         }

         dropTextTriggers(table);

         if (bHaveMoreIndexes) // Existing Full-Text table to alter
         {
            createTextTriggers(table, null, index);
            buf.append("alter table ");
            buf.append(sTable);
            buf.append(" drop column ");
            buf.append(column.getQuotedName());
         }
         else // no more need for the Full-Text table
         {
            buf.append("drop table ");
            buf.append(sTable);
View Full Code Here

      if (!instance.isDirty(m_objectAttribute.getOrdinal()))
      {
         return;
      }

      Column column = ((RelationalPrimitiveMapping)instance.getPersistenceMapping()
         .getAttributeMapping(m_binaryAttribute)).getColumn();
      SQLAdapter adapter = (SQLAdapter)instance.getAdapter();
      SQLWork work = adapter.findWork(uow, instance, column.getTable());

      if (work == null)
      {
         return;
      }
View Full Code Here

      if (!(symbol instanceof Symbol))
      {
         return;
      }

      Column column = ((RelationalPrimitiveMapping)instance.getPersistenceMapping()
         .getAttributeMapping(m_binaryAttribute)).getColumn();
      SQLWork sqlWork = (SQLWork)work;

      if (sqlWork.getTable() == column.getTable())
      {
         TransferObject tobj = (TransferObject)RPCUtil.transferState(
            instance.getValueDirect(m_objectAttribute.getOrdinal()), null, new HashTab(), RPCUtil.TF_ALL);

         Request request = new Request();
View Full Code Here

   protected Work addPrimitiveWork(UnitOfWork uow, Instance instance,
      Work primaryWork, AttributeMapping attributeMapping, Object value)
   {
      RelationalMapping mapping = (RelationalMapping)instance.getPersistenceMapping();
      RelationalPrimitiveMapping primitiveMapping = (RelationalPrimitiveMapping)attributeMapping;
      Column column = primitiveMapping.getColumn();
      int nType = primaryWork.getType();
      SQLWork work = null;

      if (nType == SQLWork.UPDATE || value != null || column.getTable() == mapping.getPrimaryTable())
      {
         work = findWork(uow, instance, column.getTable());

         if (work == null)
         {
            if (nType == SQLWork.UPDATE)
            {
               ((SQLUpdate)primaryWork).touch();
            }

            work = addWork(uow, nType, instance, column.getTable());
            primaryWork.addSuccessor(work, column.getTable().getPrimaryKey(), mapping.getObjectKey());
         }

         work.setValue(column, column.getValueType().convert(value));
      }

      return work;
   }
View Full Code Here

               AttributeMapping mapping = relMapping.getAttributeMapping(attribute);
               int nPrimaryColCount = primaryTable.getPrimaryKey().getIndexColumnCount();

               if (mapping instanceof RelationalPrimitiveMapping)
               {
                  Column column = ((RelationalPrimitiveMapping)mapping).getColumn();

                  if (column.isPrimary())
                  {
                     primaryWork.setValue(column, column.getValueType().convert(instance.getValue(i)));

                     if (++n >= nPrimaryColCount)
                     {
                        break;
                     }
                  }
               }
               else if (mapping instanceof RelationalClassMapping)
               {
                  Index index = ((RelationalClassMapping)mapping).getSourceKey();

                  if (index.isObjectKeyPart())
                  {
                     Object value = instance.getValue(i);

                     if (value instanceof OIDHolder)
                     {
                        oid = ((OIDHolder)value).getOID();

                        if (oid != null )
                        {
                           int nIndexColCount = index.getIndexColumnCount();

                           if (nIndexColCount == oid.getCount())
                           {
                              for (int k = 0; k < nIndexColCount; ++k)
                              {
                                 Column column = index.getIndexColumn(k).getColumn();

                                 if (column.isPrimary())
                                 {
                                    primaryWork.setValue(column, column.getValueType().convert(oid.getValue(k)));

                                    if (++n >= nPrimaryColCount)
                                    {
                                       break;
                                    }
View Full Code Here

TOP

Related Classes of nexj.core.meta.persistence.sql.Column

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.