Package nexj.core.persistence

Examples of nexj.core.persistence.PersistenceAdapter


            return this;
         }

         if ((nFlags & NORMALIZE_PERSISTENCE) != 0 && m_source != null)
         {
            PersistenceAdapter adapter = m_source.getAdapter();
            Field[] fieldArray = adapter.getFields(m_source);

            if (fieldArray != null)
            {
               int nCount = fieldArray.length;

               assert nCount > 0;

               if (nCount == 1)
               {
                  Field field = fieldArray[0];

                  first.setSource(field);
                  first.setType(field.getType());

                  for (int i = 1; i < m_nOperandCount; ++i)
                  {
                     Operator op = m_operandArray[i];

                     if (op.getValue() == null)
                     {
                        op.setType(null);
                     }
                     else
                     {
                        OID oid = ((OIDHolder)op.getValue()).getOID();

                        if (oid != null)
                        {
                           Object[] valueArray = adapter.getValues(oid, m_source);

                           if (valueArray.length != 1)
                           {
                              throw new TypeMismatchException(getSymbol());
                           }

                           op.setValue(valueArray[0]);
                           op.setType(Primitive.primitiveOf(op.getValue()));
                        }
                        else
                        {
                           removeOperand(i--);
                        }
                     }
                  }

                  return normalize(nFlags | NORMALIZE_NORECUR);
               }
               else
               {
                  OrOperator or = new OrOperator();

                  for (int i = 1; i < m_nOperandCount; ++i)
                  {
                     Operator op = m_operandArray[i];
                     Object[] valueArray = null;

                     if (op.getValue() != null)
                     {
                        OID oid = ((OIDHolder)op.getValue()).getOID();

                        if (oid != null)
                        {
                           valueArray = adapter.getValues(oid, m_source);

                           if (valueArray.length != nCount)
                           {
                              throw new TypeMismatchException(getSymbol());
                           }
View Full Code Here


      assert !isLazy();

      if (m_nState == NEW || m_nState == DIRTY)
      {
         PersistenceMapping persistenceMapping = getPersistenceMapping();
         PersistenceAdapter adapter = (persistenceMapping == null) ? null :
            (PersistenceAdapter)persistenceMapping.getDataSource()
               .getComponent().getInstance(m_context);
         ValidationException e = null;

         for (int i = 0, nCount = m_metaclass.getInstanceAttributeCount(); i != nCount; ++i)
         {
            Attribute attribute = m_metaclass.getInstanceAttribute(i);
            Object value = getValueDirect(i);

            if (value instanceof Undefined)
            {
               if ((m_nState == NEW || value == Invalid.VALUE) &&
                  (attribute.isPersistent() ||
                     (attribute.isRequired() ||
                        attribute.getValidationFunction() != null ||
                        m_nState == NEW && attribute.getInitializer() != Undefined.VALUE ||
                        attribute.isConstrained() && attribute.getEnumeration() != attribute.getType()) && bFull))
               {
                  value = getValue(i);
               }
               else
               {
                  continue;
               }
            }

            if (m_nState == DIRTY && !isDirty(i))
            {
               continue;
            }

            Type type = attribute.getType();

            if (attribute.isRequired())
            {
               boolean bMissing = (value == null);

               if (!bMissing)
               {
                  if (type.isPrimitive())
                  {
                     bMissing = (type == Primitive.STRING && value.equals(""));
                  }
                  else
                  {
                     bMissing = (attribute.isCollection() && ((InstanceList)value).isEmpty());
                  }
               }

               if (bMissing)
               {
                  e = createValidationException(e);

                  ValidationException x = new ValidationException("err.validation.requiredAttribute",
                     new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
                  e.addException(attribute.getName(), x);
               }
            }

            if (attribute.getMaxLength() > 0)
            {
               int nLength = 0;

               if (value instanceof String)
               {
                  nLength = ((String)value).length();
               }
               else if (value instanceof Binary)
               {
                  nLength = ((Binary)value).getData().length;
               }

               if (nLength > attribute.getMaxLength())
               {
                  e = createValidationException(e);

                  ValidationException x = new ValidationException("err.validation.maxDataLength",
                     new Object[]{Primitive.createInteger(attribute.getMaxLength()),
                        new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
                  e.addException(attribute.getName(), x);
               }
            }

            if (bFull)
            {
               if (attribute.isConstrained() &&
                  attribute.getEnumeration() != type &&
                  value != null && e == null)
               {
                  if (((InstanceList)attribute.getEnumeration().invoke("read",
                     new Object[]{null, (type.isPrimitive()) ?
                        Pair.attribute(Metaclass.ENUMERATION_VALUE).eq(value) :
                        new Pair(Symbol.AT).eq(value), null, Primitive.createInteger(-1),
                        Primitive.ZERO_INTEGER, Boolean.FALSE})).isEmpty())
                  {
                     e = createValidationException(e);

                     ValidationException x = new ValidationException("err.validation.enumerationValue",
                        new Object[]{new StringId(attribute.getEnumeration().getCaption()),
                           new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                     x.setClassName(m_metaclass.getName());
                     x.setOIDHolder(this);
                     e.addException(attribute.getName(), x);
                  }
               }

               if (attribute.getValidationFunction() != null && e == null)
               {
                  Object result = m_context.getMachine().invoke(attribute.getValidationFunction(), this, value, null);

                  if (result != null)
                  {
                     ValidationException x = null;

                     if (result instanceof Boolean)
                     {
                        if (!((Boolean)result).booleanValue())
                        {
                           x = new ValidationException("err.validation.valueRange",
                              new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});
                        }
                     }
                     else if (result instanceof String)
                     {
                        x = new ValidationException((String)result);
                     }
                     else if (result instanceof Pair)
                     {
                        x = new ValidationException((String)((Pair)result).getHead(),
                              Pair.toArray(((Pair)result).getNext()));
                     }

                     if (x != null)
                     {
                        x.setClassName(m_metaclass.getName());
                        x.setOIDHolder(this);
                        e = createValidationException(e);
                        e.addException(attribute.getName(), x);
                     }
                  }
               }
            }

            if (type.isPrimitive() && attribute.isPersistent() && adapter != null)
            {
               try
               {
                  adapter.validate(persistenceMapping.getAttributeMapping(attribute), value);
               }
               catch (ValidationException x)
               {
                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
View Full Code Here

            {
               Instance instance = (Instance)itr.next();

               if (instance.getPersistenceMapping() != null)
               {
                  PersistenceAdapter adapter = instance.getAdapter();

                  adapter.addWork(this, instance);

                  Component hook = instance.getPersistenceMapping().getHook();

                  if (hook != null)
                  {
View Full Code Here

         {
            return null;
         }
      }

      PersistenceAdapter adapter = (PersistenceAdapter)dataSource.getComponent().getInstance(m_context);

      return adapter.getVersion(dataSource.getSchema());
   }
View Full Code Here

            dataSource = su.getDataSource();

            if (dataSourceSet.contains(dataSource))
            {
               PersistenceAdapter adapter = (PersistenceAdapter)dataSource.getComponent().getInstance(m_context);

               adapter.upgrade(su, Upgrade.getState(stateMap, su), version);
            }
            else
            {
               su.apply(Upgrade.getState(stateMap, su));
            }
View Full Code Here

            return this;
         }

         if ((nFlags & NORMALIZE_PERSISTENCE) != 0 && m_source != null)
         {
            PersistenceAdapter adapter = m_source.getAdapter();
            Field[] leftFieldArray = adapter.getFields(m_left.getSource());

            if (leftFieldArray != null)
            {
               Field[] rightFieldArray = null;
               Object[] valueArray = null;

               if (m_right.isConstant())
               {
                  if (m_right.getValue() != null)
                  {
                     OID oid = ((OIDHolder)m_right.getValue()).getOID();

                     if (oid != null)
                     {
                        valueArray = adapter.getValues(oid, m_left.getSource());

                        if (leftFieldArray.length != valueArray.length)
                        {
                           throw new TypeMismatchException(getSymbol());
                        }
                     }
                     else if (isEquivalence())
                     {
                        setConstantValue(Boolean.valueOf(nullPredicate(false)));

                        return this;
                     }
                  }
               }
               else
               {
                  assert m_right.getOrdinal() == AttributeOperator.ORDINAL;

                  rightFieldArray = adapter.getFields((Query)m_right.getSource());

                  assert rightFieldArray != null;

                  if (leftFieldArray.length != rightFieldArray.length)
                  {
View Full Code Here

TOP

Related Classes of nexj.core.persistence.PersistenceAdapter

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.