Package nexj.core.meta.persistence.sql

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


      if (mapping instanceof RelationalPrimitiveMapping)
      {
         for (int i = 0, n = mapping.getDenormCount(); i < n; ++i)
         {
            RelationalPrimitiveDenorm denorm = (RelationalPrimitiveDenorm)mapping.getDenorm(i);
            Column column = denorm.getColumn();
            SQLWork work = findWork(uow, instance, column.getTable());

            if (work != null)
            {
               work.setValue(column, value);
            }
View Full Code Here


    */
   public Object getValue(OID oid, Source source)
   {
      if (source instanceof Field)
      {
         Column column = null;
         Field field = (Field)source;
         RelationalPrimitiveMapping mapping = (RelationalPrimitiveMapping)field.getAttributeMapping();

         if (mapping != null)
         {
            column = mapping.getColumn();
         }
         else if (field.getItem() instanceof Column)
         {
            column = (Column)field.getItem();
         }

         if (column != null && column.isPrimary())
         {
            IndexColumn indexColumn = ((Index)((RelationalMapping)source.getQuery()
               .getPersistenceMapping()).getObjectKey()).findIndexColumn(column);

            if (indexColumn != null && indexColumn.getOrdinal() < oid.getCount())
View Full Code Here

         }
      }

      if (source instanceof Field)
      {
         Column column = null;
         RelationalPrimitiveMapping primitiveMapping = (RelationalPrimitiveMapping)source.getAttributeMapping();

         if (primitiveMapping != null)
         {
            column = primitiveMapping.getColumn();
         }
         else
         {
            Object item = source.getItem();

            if (item instanceof Column)
            {
               column = (Column)item;
            }
            else if (item instanceof Field[])
            {
               Object[] valueArray = null;
               Field[] fieldArray = (Field[])item;

               for (int i = 0; i < fieldArray.length; ++i)
               {
                  Object value = getValue(instance, fieldArray[i]);

                  if (value == Undefined.VALUE)
                  {
                     valueArray = null;

                     break;
                  }

                  if (valueArray == null)
                  {
                     valueArray = new Object[fieldArray.length];
                  }

                  valueArray[i] = value;
               }

               if (valueArray != null)
               {
                  return new OID(valueArray);
               }
            }
         }

         if (column != null)
         {
            PersistenceMapping persistenceMapping = ((SQLJoin)source.getMapping()).query.getPersistenceMapping();

            if (persistenceMapping != null)
            {
               Metaclass metaclass = persistenceMapping.getMetaclass();

               assert metaclass.isUpcast(m_context.getMetadata().getMetaclass(instance.getClassName()));

               // TODO: Optimize with precomputed metadata

               for (int nAttrOrdinal = 0, nAttrCount = metaclass.getInstanceAttributeCount();
                  nAttrOrdinal < nAttrCount; ++nAttrOrdinal)
               {
                  attribute = metaclass.getInstanceAttribute(nAttrOrdinal);

                  AttributeMapping mapping = persistenceMapping.getAttributeMapping(attribute);

                  if (mapping instanceof RelationalPrimitiveMapping)
                  {
                     if (column == ((RelationalPrimitiveMapping)mapping).getColumn())
                     {
                        Object value = instance.findValue(attribute.getName(), Undefined.VALUE);

                        if (value != Undefined.VALUE)
                        {
                           return column.getValueType().convert(value);
                        }
                     }
                  }
                  else if (mapping instanceof RelationalClassMapping)
                  {
View Full Code Here

    */
   public void validate(AttributeMapping mapping, Object value) throws ValidationException
   {
      if (mapping instanceof RelationalPrimitiveMapping && value != null)
      {
         Column column = ((RelationalPrimitiveMapping)mapping).getColumn();
         int nPrecision;

         switch (column.getType().getOrdinal())
         {
            case Primitive.INTEGER_ORDINAL:
               nPrecision = column.getPrecision();

               switch (nPrecision)
               {
                  case 1:
                     int nValue = ((Number)toBind(column, column.getValueType().convert(value))).intValue();

                     if (nValue < 0 || nValue > 255)
                     {
                        throw new ValidationException("err.validation.numberRange",
                           new Object[]
                           {
                              new StringId(mapping.getAttribute().getCaption()),
                              new StringId(mapping.getAttribute().getMetaclass().getCaption()),
                              Primitive.ZERO_INTEGER,
                              Primitive.createInteger(255)
                           });
                     }

                     break;

                  case 2:
                     nValue = ((Number)toBind(column, column.getValueType().convert(value))).intValue();

                     if (nValue < Short.MIN_VALUE || nValue > Short.MAX_VALUE)
                     {
                        throw new ValidationException("err.validation.numberRange",
                           new Object[]
                           {
                              new StringId(mapping.getAttribute().getCaption()),
                              new StringId(mapping.getAttribute().getMetaclass().getCaption()),
                              Primitive.createInteger(Short.MIN_VALUE),
                              Primitive.createInteger(Short.MAX_VALUE)
                           });
                     }

                     break;
               }

               break;

            case Primitive.DECIMAL_ORDINAL:
               nPrecision = column.getPrecision(getMaxDecimalPrecision());

               int nScale = column.getScale(getMaxDecimalPrecision());
               BigDecimal decMax = BigDecimal.TEN.pow(nPrecision - nScale);

               if (((BigDecimal)toBind(column, column.getValueType().convert(value))).abs().setScale(nScale,
                  RoundingMode.HALF_UP).compareTo(decMax) >= 0)
               {
                  if (nScale > 0)
                  {
                     decMax = decMax.subtract(BigDecimal.ONE.divide(BigDecimal.TEN.pow(nScale)));
                  }

                  throw new ValidationException("err.validation.numberRange",
                     new Object[]
                     {
                        new StringId(mapping.getAttribute().getCaption()),
                        new StringId(mapping.getAttribute().getMetaclass().getCaption()),
                        decMax.negate(),
                        decMax
                     });
               }

               break;

            case Primitive.TIMESTAMP_ORDINAL:
               long lTime = ((Timestamp)toBind(column, column.getValueType().convert(value))).getTime();

               if (lTime < getMinTime() || lTime > getMaxTime())
               {
                  throw new ValidationException("err.validation.dateRange",
                     new Object[]
View Full Code Here

      if (metadata.getNamespace() == null || table == null)
      {
         return null;
      }

      Column namespaceColumn = table.getColumn("namespace");
      Column versionColumn = table.getColumn("version");
      Column stepColumn = table.getColumn("step");
      Column upgradableColumn = table.getColumn("upgradable");
      Column testColumn = table.getColumn("test");
      StringBuffer buf = new StringBuffer(128);

      buf.append("select ");
      buf.append(namespaceColumn.getQuotedName());
      buf.append(", ");
      buf.append(versionColumn.getQuotedName());
      buf.append(", ");
      buf.append(stepColumn.getQuotedName());
      buf.append(", ");
      buf.append(upgradableColumn.getQuotedName());
      buf.append(", ");
      buf.append(testColumn.getQuotedName());
      buf.append(" from ");
      buf.append(table.getQuotedName());

      String sSQL = buf.toString();
      SQLConnection connection = null;
View Full Code Here

      if (table == null)
      {
         return;
      }

      Column namespaceColumn = table.getColumn("namespace");
      Column versionColumn = table.getColumn("version");
      Column stepColumn = table.getColumn("step");
      StringBuffer buf = new StringBuffer(128);

      buf.append("update ");
      buf.append(table.getQuotedName());
      buf.append(" set ");
      buf.append(versionColumn.getQuotedName());
      buf.append(" = ");
      appendBind(buf, 0);
      buf.append(", ");
      buf.append(stepColumn.getQuotedName());
      buf.append(" = ");
      appendBind(buf, 1);
      buf.append(" where ");
      buf.append(namespaceColumn.getQuotedName());
      buf.append(" = ");
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.