Package org.datanucleus.api

Examples of org.datanucleus.api.ApiAdapter


        {
            throw new NucleusException(failureMessage("setObject")).setFatal();
        }

        ObjectProvider[] sms = null;
        ApiAdapter api = ec.getApiAdapter();
        if (value != null)
        {
            Collection smsColl = null;
            if (value instanceof java.util.Collection)
            {
                Iterator elementsIter = ((java.util.Collection)value).iterator();
                while (elementsIter.hasNext())
                {
                    Object elem = elementsIter.next();
                    if (api.isPersistable(elem))
                    {
                        ObjectProvider sm = ec.findObjectProvider(elem);
                        if (sm != null)
                        {
                            if (smsColl == null)
                            {
                                smsColl = new HashSet();
                            }
                            smsColl.add(sm);
                        }
                    }
                }
            }
            else if (value instanceof java.util.Map)
            {
                Iterator entriesIter = ((java.util.Map)value).entrySet().iterator();
                while (entriesIter.hasNext())
                {
                    Map.Entry entry = (Map.Entry)entriesIter.next();
                    Object key = entry.getKey();
                    Object val = entry.getValue();
                    if (api.isPersistable(key))
                    {
                        ObjectProvider sm = ec.findObjectProvider(key);
                        if (sm != null)
                        {
                            if (smsColl == null)
                            {
                                smsColl = new HashSet();
                            }
                            smsColl.add(sm);
                        }
                    }
                    if (api.isPersistable(val))
                    {
                        ObjectProvider sm = ec.findObjectProvider(val);
                        if (sm != null)
                        {
                            if (smsColl == null)
View Full Code Here


    public Object getObject(ExecutionContext ec, final Object rs, int[] param)
    {
        Object value = super.getObject(ec, rs, param);
        if (value != null)
        {
            ApiAdapter api = ec.getApiAdapter();
            return api.getIdForObject(value);
        }
        return null;
    }
View Full Code Here

        {
            getDatastoreMapping(0).setObject(ps, param[0], null);
        }
        else
        {
            ApiAdapter api = ec.getApiAdapter();
            OID oid;
            if (api.isPersistable(value))
            {
                oid = (OID) api.getIdForObject(value);
                if (oid == null)
                {
                    if (ec.isInserting(value))
                    {
                        // Object is in the process of being inserted, but has no id yet so provide a null for now
                        // The "NotYetFlushedException" is caught by ParameterSetter and processed as an update being required.
                        getDatastoreMapping(0).setObject(ps, param[0], null);
                        throw new NotYetFlushedException(value);
                    }
                    else
                    {
                        // Object is not persist, nor in the process of being made persistent
                        ec.persistObjectInternal(value, null, -1, ObjectProvider.PC);
                        ec.flushInternal(false);
                    }
                }
                oid = (OID) api.getIdForObject(value);
            }
            else
            {
                oid = (OID) value;
            }
View Full Code Here

                mmd != null ? mmd.getFullFieldName() : "", getType(), value.getClass().getName()));
        }

        if (value != null)
        {
            ApiAdapter api = ec.getApiAdapter();
            ClassLoaderResolver clr = ec.getClassLoaderResolver();

            // Make sure the value is persisted if it is persistable in its own right
            if (!ec.isInserting(value))
            {
                // Object either already exists, or is not yet being inserted.
                Object id = api.getIdForObject(value);

                // Check if the PersistenceCapable exists in this datastore
                boolean requiresPersisting = false;
                if (ec.getApiAdapter().isDetached(value) && ownerSM != null)
                {
                    // Detached object that needs attaching (or persisting if detached from a different datastore)
                    requiresPersisting = true;
                }
                else if (id == null)
                {
                    // Transient object, so we need to persist it
                    requiresPersisting = true;
                }
                else
                {
                    ExecutionContext valueEC = api.getExecutionContext(value);
                    if (valueEC != null && ec != valueEC)
                    {
                        throw new NucleusUserException(LOCALISER.msg("041015"), id);
                    }
                }

                if (requiresPersisting)
                {
                    // The object is either not yet persistent or is detached and so needs attaching
                    Object pcNew = ec.persistObjectInternal(value, null, -1, ObjectProvider.PC);
                    ec.flushInternal(false);
                    id = api.getIdForObject(pcNew);
                    if (ec.getApiAdapter().isDetached(value) && ownerSM != null)
                    {
                        // Update any detached reference to refer to the attached variant
                        ownerSM.replaceFieldMakeDirty(ownerFieldNumber, pcNew);
                        RelationType relationType = mmd.getRelationType(clr);
View Full Code Here

     * @param fieldName The full field name (for logging only)
     * @return The mapping class for the class
     **/
    protected Class getMappingClass(Class c, boolean serialised, boolean embedded, String fieldName)
    {
        ApiAdapter api = storeMgr.getApiAdapter();
        if (api.isPersistable(c))
        {
            // Persistence Capable field
            if (serialised)
            {
                // Serialised PC field
                return SerialisedPCMapping.class;
            }
            else if (embedded)
            {
                // Embedded PC field
                return EmbeddedPCMapping.class;
            }
            else
            {
                // PC field
                return PersistableMapping.class;
            }
        }

        if (c.isInterface() && !storeMgr.getMappedTypeManager().isSupportedMappedType(c.getName()))
        {
            // Interface field
            if (serialised)
            {
                // Serialised Interface field
                return SerialisedReferenceMapping.class;
            }
            else if (embedded)
            {
                // Embedded interface field - just default to an embedded PCMapping!
                return EmbeddedPCMapping.class;
            }
            else
            {
                // Interface field
                return InterfaceMapping.class;
            }
        }

        if (c == java.lang.Object.class)
        {
            // Object field
            if (serialised)
            {
                // Serialised Object field
                return SerialisedReferenceMapping.class;
            }
            else if (embedded)
            {
                // Embedded Object field - do we ever want to support this ? I think not ;-)
                throw new NucleusUserException(LOCALISER.msg("041042", fieldName)).setFatal();
            }
            else
            {
                // Object field as reference to PC object
                return ObjectMapping.class;
            }
        }

        if (c.isArray())
        {
            // Array field
            if (api.isPersistable(c.getComponentType()))
            {
                // Array of PC objects
                return ArrayMapping.class;
            }
            else if (c.getComponentType().isInterface() &&
View Full Code Here

            {
                NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("041034",oid));
            }
        }

        ApiAdapter api = ec.getApiAdapter();
        if (api.isPersistable(oid)) //why check this?
        {
            return oid;
        }
        return oid == null ? null : ec.findObject(oid, false, true, null);
    }
View Full Code Here

        // Currently we only consider PC classes
        boolean toBeAdded = false;
        if (clr != null)
        {
            Class cls = clr.classForName(className);
            ApiAdapter api = getApiAdapter();
            if (cls != null && !cls.isInterface() && api.isPersistable(cls))
            {
                toBeAdded = true;
            }
        }
        else
View Full Code Here

    if (child == null) {
      return;
    }

    ExecutionContext ec = parentOP.getExecutionContext();
    ApiAdapter apiAdapter = ec.getApiAdapter();

    ObjectProvider childOP = ec.findObjectProvider(child);
    if (apiAdapter.isNew(child) &&
        (childOP == null ||
         childOP.getAssociatedValue(((DatastoreManager)ec.getStoreManager()).getDatastoreTransaction(ec)) == null)) {
      // This condition is difficult to get right.  An object that has been persisted
      // (and therefore had its primary key already established) may still be considered
      // NEW by the apiAdapter if there is a txn and the txn has not yet committed.
      // In order to determine if an object has been persisted we see if there is
      // a state manager for it.  If there isn't, there's no way it was persisted.
      // If there is, it's still possible that it hasn't been persisted so we check
      // to see if there is an associated Entity.
      // TODO Just call sm.isFlushedNew(). It's not that hard
      return;
    }
    // Since we only support owned relationships right now, we can assume
    // that this is parent/child and verify that the parent of the childSM
    // is the parent object in this cascade.
    // We know that the child primary key is a Key or an encoded String
    // because we don't support child objects with primary keys of type
    // Long or unencoded String and our metadata validation would have
    // caught it.
    Object childKeyOrString =
      apiAdapter.getTargetKeyForSingleFieldIdentity(apiAdapter.getIdForObject(child));
    if (childKeyOrString == null) {
      // must be a new object or transient
      return;
    }
    Key childKey = childKeyOrString instanceof Key
View Full Code Here

    } else {
      // Owned relation in earlier storage version so use parentKey to determine membership of list
      List<Key> keys = Utils.newArrayList();
      Set<Key> keySet = Utils.newHashSet();
      for (Object ele : elements) {
        ApiAdapter apiAdapter = ec.getApiAdapter();
        Object keyOrString =
          apiAdapter.getTargetKeyForSingleFieldIdentity(apiAdapter.getIdForObject(ele));
        Key key = keyOrString instanceof Key ? (Key) keyOrString : KeyFactory.stringToKey((String) keyOrString);
        if (key == null) {
          throw new NucleusUserException("Collection element does not have a primary key.");
        } else if (key.getParent() == null) {
          throw new NucleusUserException("Collection element primary key does not have a parent.");
View Full Code Here

    public Object getObject(ExecutionContext ec, final Object rs, int[] param)
    {
        Object value = super.getObject(ec, rs, param);
        if (value != null)
        {
            ApiAdapter api = ec.getApiAdapter();
            return api.getIdForObject(value);
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.api.ApiAdapter

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.