Package nexj.core.persistence

Examples of nexj.core.persistence.OID


         mrsh.marshal(tobj.getEventName(),
                      null, XML.BASE_PREFIX + "event", STRING_MSH, MF_LITERAL);
         mrsh.marshal(tobj.getVersion(), null, XML.BASE_PREFIX + "version");

         OID oid = tobj.getOID();

         if (oid == null)
         {
            mrsh.marshal("@" + mrsh.getObjectId(obj),
                         null, XML.BASE_PREFIX + "oid", STRING_MSH, MF_LITERAL);
View Full Code Here


          */
         public void marshalContents(Object obj, SOAPMarshaller msh) throws IOException
         {
            XMLMarshaller mrsh = (XMLMarshaller)msh;
            TransferObject tobj = (TransferObject)obj;
            OID oid = tobj.getOID();

            mrsh.marshal(tobj.getClassName(), null, XML.BASE_PREFIX + "class", STRING_MSH, MF_LITERAL);

            mrsh.marshal((oid != null) ? (Object)oid : ("@" + mrsh.getObjectId(obj)), null,
               XML.BASE_PREFIX + "oid", (oid != null) ? OID_MSH : STRING_MSH, MF_LITERAL);
View Full Code Here

    */
   protected Object unmarshal(Metaclass metaclass, String sContext) throws IOException, RequestException
   {
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(m_context);
      String sMethod = getMethod();
      OID oid = null;
      Event event = null;

      if (sContext.length() != 0)
      {
         int i = sContext.indexOf('/');
View Full Code Here

         Object obj = itr.next();

         if (obj instanceof Instance)
         {
            Instance instance = (Instance)obj;
            OID oid = instance.getOID();

            if (oid != null)
            {
               Metaclass metaclass = instance.getLazyMetaclass().getPersistenceRoot();
               Set oidSet = (Set)whereMap.get(metaclass);
View Full Code Here

      {
         TransferObject tobj = (TransferObject)list.get(i);

         if (tobj.getClassName().equals(Metadata.VERSION_CLASS_NAME))
         {
            tobj.setOID(new OID(new Object[] {sNamespace}));
            tobj.setValue("namespace", sNamespace);
            tobj.setValue("version", sVersion);
         }
      }
View Full Code Here

   protected void addInsert(UnitOfWork uow, Instance instance)
   {
      RelationalMapping relMapping = (RelationalMapping)instance.getPersistenceMapping();
      Table primaryTable = relMapping.getPrimaryTable();
      SQLWork primaryWork = getWork(uow, SQLWork.INSERT, instance, primaryTable);
      OID oid = instance.getOID();

      if (oid != null)
      {
         primaryWork.setOID();
      }
      else
      {
         Component component = relMapping.getKeyGenerator();

         if (component == RelationalMapping.KEY_GEN_IDENTITY)
         {
            primaryWork.setIdentity(true);
         }
         else if (component != null)
         {
            oid = ((OIDGenerator)component.getInstance(uow.getInvocationContext())).generateOID(instance, this);

            Object[] values = oid.getValueArray();
            Index pk = primaryTable.getPrimaryKey();
            int nCount = pk.getIndexColumnCount();

            if (nCount != values.length)
            {
               throw new PersistenceException("err.persistence.oidValueCount",
                  new Object[]{component.getName(), Primitive.createInteger(nCount),
                     Primitive.createInteger(values.length)});
            }

            for (int i = 0; i < nCount; ++i)
            {
               values[i] = pk.getIndexColumn(i).getColumn().getValueType().convert(values[i]);
            }

            instance.setOID(oid);
            primaryWork.setOID();
         }
         else
         {
            Metaclass metaclass = instance.getMetaclass();

            for (int i = 0, n = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
            {
               Attribute attribute = metaclass.getInstanceAttribute(i);
               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

                  }

                  valueArray[i] = oid.getValue(nOrdinal);
               }

               return new OID(valueArray);
            }
         }
      }

      return Undefined.VALUE;
View Full Code Here

    */
   public Object getValue(PropertyMap instance, Source source)
   {
      if (instance instanceof OIDHolder)
      {
         OID oid = ((OIDHolder)instance).getOID();

         if (oid == null)
         {
            return Undefined.VALUE;
         }

         Object value = getValue(oid, source);

         if (value != Undefined.VALUE)
         {
            return value;
         }
      }

      Attribute attribute = source.getAttribute();

      if (attribute != null && !source.isInverse())
      {
         Object value = instance.findValue(attribute.getName(), Undefined.VALUE);

         if (value != Undefined.VALUE)
         {
            return value;
         }
      }

      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)
                  {
                     RelationalClassMapping classMapping = (RelationalClassMapping)mapping;

                     if (classMapping.isInner())
                     {
                        IndexColumn indexColumn = classMapping.getSourceKey().findIndexColumn(column);

                        if (indexColumn != null)
                        {
                           Object value = instance.findValue(attribute.getName(), Undefined.VALUE);

                           if (value == null)
                           {
                              return null;
                           }

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

                              if (oid != null && indexColumn.getOrdinal() < oid.getCount())
                              {
                                 return oid.getValue(indexColumn.getOrdinal());
                              }
                           }
                        }
                     }
                  }
View Full Code Here

         {
            return null;
         }
      }

      return new OID(valueArray);
   }
View Full Code Here

         return ((Symbol)element).getName();
      }

      if (element instanceof OIDHolder)
      {
         OID oid = ((OIDHolder)element).getOID();

         if (oid == null)
         {
            return null;
         }

         Object[] valueArray = oid.getValueArray();

         if (valueArray.length > 0 && valueArray[0] instanceof String)
         {
            return (String)valueArray[0];
         }
View Full Code Here

TOP

Related Classes of nexj.core.persistence.OID

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.