Package nexj.core.meta.persistence.sql

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


   /**
    * Sets up the locking attribute, if available.
    */
   public final void setupLocking()
   {
      RelationalMapping relMapping = (RelationalMapping)m_mapping;
      Attribute lockAttribute = relMapping.getLockingAttribute();

      if (lockAttribute != null)
      {
         Object value = m_instance.getValueDirect(lockAttribute.getOrdinal());

         if (value != Undefined.VALUE)
         {
            Column column = ((RelationalPrimitiveMapping)relMapping
               .getAttributeMapping(lockAttribute)).getColumn();
           
            value = column.getValueType().convert(value);
            setLockingColumn(column);
            setValue(column, value);
View Full Code Here


    */
   protected Column findSource(Column column)
   {
      if (column.isDenormalized())
      {
         RelationalMapping mapping = (RelationalMapping)m_mapping;

         for (int i = 0, n = mapping.getDenormCount(); i < n; ++i)
         {
            RelationalDenorm denorm = mapping.getDenorm(i);

            if (denorm.getTable() == m_table)
            {
               Column src = denorm.findSource(column);

View Full Code Here

   public void testGetPersistenceMapping()
   {
      assertNotNull(m_contact.getPersistenceMapping());

      RelationalMapping hrRequestMapping = (RelationalMapping)m_hrRequest.getPersistenceMapping();

      assertNotNull(hrRequestMapping);
      assertNotNull(hrRequestMapping.getLockingAttribute());
      assertEquals("version", hrRequestMapping.getLockingAttribute().getName());

      RelationalPrimitiveMapping versionMapping =
         (RelationalPrimitiveMapping)hrRequestMapping.getAttributeMapping(m_hrRequest.getAttribute("version"));

      assertNotNull(versionMapping);
      assertEquals("version", versionMapping.getColumn().getName());
      assertEquals("test.HRRequest", versionMapping.getColumn().getTable().getName());

      RelationalMapping principalRefMapping = (RelationalMapping)m_principalRef.getPersistenceMapping();

      assertNotNull(principalRefMapping);
      assertNotNull(principalRefMapping.getLockingAttribute());
      assertEquals("version", principalRefMapping.getLockingAttribute().getName());

      versionMapping = (RelationalPrimitiveMapping)principalRefMapping
         .getAttributeMapping(m_principalRef.getAttribute("version"));

      assertNotNull(versionMapping);
      assertEquals("version", versionMapping.getColumn().getName());
      assertEquals("PrincipalRef", versionMapping.getColumn().getTable().getName());

      RelationalClassMapping principalMapping = (RelationalClassMapping)principalRefMapping
         .getAttributeMapping(m_principalRef.getAttribute("principal"));

      assertNotNull(principalMapping);
      assertEquals("PrincipalRef.FK_Usr", principalMapping.getSourceKey().getName());
      assertEquals("Usr.PK", ((Index)principalMapping.getDestinationKey()).getName());
      assertEquals(1, principalMapping.getDenormCount());
      assertEquals("PrincipalExt.FK_Usr", ((RelationalClassDenorm)principalMapping.getDenorm(0)).getSourceKey().getName());

      principalMapping = (RelationalClassMapping)principalRefMapping
         .getAttributeMapping(m_principalRef.getAttribute("principal2"));

      assertNotNull(principalMapping);
      assertEquals("PrincipalRef.PK", principalMapping.getSourceKey().getName());
      assertEquals("Usr.PK", ((Index)principalMapping.getDestinationKey()).getName());
      assertEquals(0, principalMapping.getDenormCount());

      RelationalPrimitiveMapping principalIdMapping = (RelationalPrimitiveMapping)principalRefMapping
         .getAttributeMapping(m_principalRef.getAttribute("principalId"));

      assertNotNull(principalIdMapping);
      assertEquals("principalId", principalIdMapping.getColumn().getName());
      assertEquals("PrincipalRef", principalIdMapping.getColumn().getTable().getName());
View Full Code Here

         SQLAdapter adapter = (SQLAdapter)instance.getAdapter();
         Object obj = instance.getValueDirect(m_variablesAttribute.getOrdinal());

         if (!(obj instanceof Undefined))
         {
            RelationalMapping mapping = (RelationalMapping)instance.getPersistenceMapping();
            RelationalPrimitiveMapping attrMapping = (RelationalPrimitiveMapping)mapping
               .getAttributeMapping(m_serializedVariablesAttribute);

            SQLWork work = (SQLWork)adapter.addPrimitiveWork(uow, instance,
               adapter.findWork(uow, instance, mapping.getPrimaryTable()),
               attrMapping, (obj == null) ? null : "");

            if (work != null)
            {
               work.setValue(attrMapping.getColumn(), null);
View Full Code Here

    * @see nexj.core.persistence.GenericPersistenceAdapter#addPrimitiveWork(nexj.core.runtime.UnitOfWork, nexj.core.runtime.Instance, nexj.core.persistence.Work, nexj.core.meta.persistence.AttributeMapping, java.lang.Object)
    */
   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));
      }

View Full Code Here

    * @param uow The unit of work.
    * @param instance The instance for which to add the work items.
    */
   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();
View Full Code Here

    * @param uow The unit of work.
    * @param instance The instance for which to add the work items.
    */
   protected void addUpdate(UnitOfWork uow, Instance instance)
   {
      RelationalMapping relMapping = (RelationalMapping)instance.getPersistenceMapping();
      Table primaryTable = relMapping.getPrimaryTable();
      SQLUpdate work = (SQLUpdate)getWork(uow, SQLWork.UPDATE, instance, primaryTable);

      work.setupLocking();

      addUpdateDependencies(uow, instance, work);
View Full Code Here

    */
   protected void addDelete(UnitOfWork uow, Instance instance)
   {
      assert instance.getOID() != null;

      RelationalMapping relMapping = (RelationalMapping)instance.getPersistenceMapping();
      SQLWork primaryWork = getWork(uow, SQLWork.DELETE, instance, relMapping.getPrimaryTable());

      primaryWork.setOID();
      primaryWork.setupLocking();

      int nCount = relMapping.getTableCount();

      for (int i = 1; i < nCount; ++i)
      {
         SQLWork work = getWork(uow, SQLWork.DELETE, instance, relMapping.getTable(i));

         work.setOID();
         primaryWork.addSuccessor(work, null, null);
      }
   }
View Full Code Here

TOP

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

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.