Examples of ApiAdapter


Examples of org.jpox.api.ApiAdapter

            {
                return new NullLiteral(qs);
            }

            JavaTypeMapping m = null;
            ApiAdapter api = qs.getStoreManager().getApiAdapter();
            if (api.isPersistable(cls))
            {
                // PC class, so maybe has its own table
                try
                {
                    // PC class, so maybe has its own table
View Full Code Here

Examples of org.jpox.api.ApiAdapter

     * @param fieldNumber field number of this object in the owning object
     */
    public void setObject(ObjectManager om, Object preparedStatement, int[] exprIndex, Object value,
            StateManager ownerSM, int fieldNumber)
    {
        ApiAdapter api = om.getApiAdapter();
        if (api.isPersistable(value))
        {
            // Assign a StateManager to the serialised object if none present
            StateManager embSM = om.findStateManager(value);
            if (embSM == null || ObjectManagerHelper.getObjectManager(value) == null)
            {
                embSM = StateManagerFactory.newStateManagerForEmbedded(om, value, false);
                embSM.addEmbeddedOwner(ownerSM, fieldNumber);
            }
        }

        StateManager sm = null;
        if (api.isPersistable(value))
        {
            // Find SM for serialised PC object
            sm = om.findStateManager(value);
        }

View Full Code Here

Examples of org.jpox.api.ApiAdapter

     * @return The (deserialised) PersistenceCapable object
     */
    public Object getObject(ObjectManager om, Object resultSet, int[] exprIndex, StateManager ownerSM, int fieldNumber)
    {
        Object obj = getDataStoreMapping(0).getObject(resultSet, exprIndex[0]);
        ApiAdapter api = om.getApiAdapter();
        if (api.isPersistable(obj))
        {
            // Assign a StateManager to the serialised object if none present
            StateManager embSM = om.findStateManager(obj);
            if (embSM == null || ObjectManagerHelper.getObjectManager(obj) == null)
            {
View Full Code Here

Examples of org.jpox.api.ApiAdapter

        {
            getDataStoreMapping(0).setObject(ps, param[0], null);
        }
        else
        {
            ApiAdapter api = om.getApiAdapter();
            OID oid;
            if (api.isPersistable(value))
            {
                oid = (OID) api.getIdForObject(value);
                if (oid == null)
                {
                    if (om.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
                        om.persistObjectInternal(value, null, null, -1, StateManager.PC);
                        om.flushInternal(false);
                    }
                }
                oid = (OID) api.getIdForObject(value);
            }
            else
            {
                oid = (OID) value;
            }
View Full Code Here

Examples of org.jpox.api.ApiAdapter

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

Examples of org.jpox.api.ApiAdapter

     * @param clr ClassLoaderResolver to use in loading any classes
     * @param primary the primary ClassLoader to use (or null)
     */
    public void populate(ClassLoaderResolver clr, ClassLoader primary)
    {
        ApiAdapter api = getMetaDataManager().getApiAdapter();

        // Check the field type and see if it is an array type
        Class field_type = getMemberMetaData().getType();
        if (!field_type.isArray())
        {
            throw new InvalidMetaDataException(LOCALISER,
                    "044141",
                    getFieldName(),getMemberMetaData().getClassName(false));
        }

        // "embedded-element"
        if (element.embedded == null)
        {
            // Assign default for "embedded-element" based on 18.13.1 of JDO 2 spec
            // Note : this fails when using in the enhancer since not yet PC
            Class component_type = field_type.getComponentType();
            if (getMetaDataManager().getOMFContext().getTypeManager().isDefaultEmbeddedType(component_type))
            {
                element.embedded = Boolean.TRUE;
            }
            else if (api.isPersistable(component_type) || Object.class.isAssignableFrom(component_type) ||
                component_type.isInterface())
            {
                element.embedded = Boolean.FALSE;
            }
            else
            {
                element.embedded = Boolean.TRUE;
            }
        }
        if (element.embedded == Boolean.FALSE)
        {
            // If the user has set a non-PC/non-Interface as not embedded, correct it since not supported.
            // Note : this fails when using in the enhancer since not yet PC
            Class component_type = field_type.getComponentType();
            if (!api.isPersistable(component_type) && !component_type.isInterface() &&
                component_type != java.lang.Object.class)
            {
                element.embedded = Boolean.TRUE;
            }
        }

        if (!getMemberMetaData().getAbstractClassMetaData().getMetaDataManager().isEnhancing() && !getMemberMetaData().isSerialized())
        {
            // Catch situations that JPOX doesnt support
            if (getMemberMetaData().getJoinMetaData() == null &&
                !api.isPersistable(getMemberMetaData().getType().getComponentType()) &&
                getMetaDataManager().supportsORM())
            {
                // JPOX only supports persisting particular array types as byte-streams (non-Java-serialised)
                String arrayComponentType = getMemberMetaData().getType().getComponentType().getName();
                if (!arrayComponentType.equals(ClassNameConstants.BOOLEAN) &&
                    !arrayComponentType.equals(ClassNameConstants.BYTE) &&
                    !arrayComponentType.equals(ClassNameConstants.CHAR) &&
                    !arrayComponentType.equals(ClassNameConstants.DOUBLE) &&
                    !arrayComponentType.equals(ClassNameConstants.FLOAT) &&
                    !arrayComponentType.equals(ClassNameConstants.INT) &&
                    !arrayComponentType.equals(ClassNameConstants.LONG) &&
                    !arrayComponentType.equals(ClassNameConstants.SHORT) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_BOOLEAN) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_BYTE) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_CHARACTER) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_DOUBLE) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_FLOAT) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_INTEGER) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_LONG) &&
                    !arrayComponentType.equals(ClassNameConstants.JAVA_LANG_SHORT) &&
                    !arrayComponentType.equals("BigDecimal") &&
                    !arrayComponentType.equals("BigInteger"))
                {
                    // Impossible to persist an array of a non-PC element without a join table or without serialising the array
                    throw new InvalidMetaDataException(LOCALISER, "044142",
                        getFieldName(), getMemberMetaData().getType().getComponentType().getName());
                }
            }
        }

        // Keep a reference to the MetaData for the element
        MetaDataManager mmgr = getMemberMetaData().getAbstractClassMetaData().getMetaDataManager();
        if (element.type != null)
        {
            Class elementCls = clr.classForName(element.type, primary);
           
            if (api.isPersistable(elementCls))
            {
                mayContainPersistenceCapableElements = true;
            }
           
           
View Full Code Here

Examples of org.jpox.api.ApiAdapter

    public void storeObjectField(int fieldNumber, Object value)
    {
        // Note : when doing updates always do replaceField first and makeDirty after since the replaceField
        // can cause flush() to be called meaning that an update with null would be made before the new value
        // makes it into the field
        ApiAdapter api = smAttached.getObjectManager().getApiAdapter();
        if (value == null)
        {
            Object oldValue = null;
            AbstractClassMetaData cmd = smAttached.getClassMetaData();
            AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
            if (fmd.isDependent())
            {
                try
                {
                    // Get any old value of this field so we can do cascade-delete if being nulled
                    smAttached.loadFieldFromDatastore(fieldNumber);
                }
                catch (Exception e)
                {
                    // Error loading the field so didnt exist before attaching anyway
                }
                oldValue = smAttached.provideField(fieldNumber);
            }

            if (dirtyFields[fieldNumber] || !persistent)
            {
                smAttached.replaceField(fieldNumber, null, true);
                smAttached.makeDirty(fieldNumber);
            }

            if (fmd.isDependent() && !fmd.isEmbedded() &&
                oldValue != null && value == null && api.isPersistable(oldValue))
            {
                // Check for a field storing a PC where it is being nulled and the other object is dependent
                smAttached.flush(); // Flush the nulling of the field
                JPOXLogger.PERSISTENCE.debug(LOCALISER.msg("026026", oldValue, fmd.getFullFieldName()));
                smAttached.getObjectManager().deleteObjectInternal(oldValue);
            }
        }
        else if (secondClassMutableFields[fieldNumber])
        {
            AbstractMemberMetaData fmd =
                smAttached.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
            if (fmd.isSerialized())
            {
                // SCO Field is serialised so just update the column with this new value - dont do comparisons yet
                smAttached.replaceField(fieldNumber, value, true);
                smAttached.makeDirty(fieldNumber);
            }
            else
            {
                // Make sure that the value is a SCO wrapper
                Object oldValue = smAttached.provideField(fieldNumber);
                SCO sco;
                if (oldValue == null || (oldValue != null && !(oldValue instanceof SCO)))
                {
                    // The field wasn't initialised at creation, so create an empty SCO wrapper and copy the new values in
                    if (JPOXLogger.JDO.isDebugEnabled())
                    {
                        JPOXLogger.JDO.debug(LOCALISER.msg("026029", StringUtils.toJVMIDString(smAttached.getObject()),
                            smAttached.getInternalObjectId(), fmd.getName()));
                    }
                    sco = SCOUtils.newSCOInstance(smAttached, fmd, fmd.getType(), null, null, false, false, false);
                    if (sco instanceof SCOContainer)
                    {
                        // Load any containers to avoid update issues
                        ((SCOContainer)sco).load();
                    }
                    smAttached.replaceField(fieldNumber, sco, true);
                }
                else
                {
                    // The field is already a SCO wrapper, so just copy the new values to it
                    sco = (SCO) oldValue;
                }

                if (cascadeAttach)
                {
                    // Only trigger the cascade when required
                    if (copy)
                    {
                        // Attach copy of the SCO
                        sco.attachCopy(value);
                    }
                    else
                    {
                        // Attach SCO in-situ
                        if (sco instanceof Collection)
                        {
                            // Attach all PC elements of the collection
                            boolean elementsWithoutIdentity = SCOUtils.collectionHasElementsWithoutIdentity(fmd);
                            SCOUtils.attachForCollection(smAttached, ((Collection)sco).toArray(), elementsWithoutIdentity);
                            sco.unsetOwner();
                        }
                        else if (sco instanceof Map)
                        {
                            // Attach all PC keys/values of the map
                            boolean keysWithoutIdentity = SCOUtils.mapHasKeysWithoutIdentity(fmd);
                            boolean valuesWithoutIdentity = SCOUtils.mapHasValuesWithoutIdentity(fmd);
                            SCOUtils.attachForMap(smAttached, ((Map)sco).entrySet(), keysWithoutIdentity, valuesWithoutIdentity);
                            sco.unsetOwner();
                        }
                        else
                        {
                            // Initialise the SCO with the new value
                            sco.initialise(value, false, false);
                        }
                    }
                }

                if (dirtyFields[fieldNumber] || !persistent)
                {
                    smAttached.makeDirty(fieldNumber);
                }
            }
        }
        else if (api.isPersistable(value))
        {
            // Field containing PC object
            if (cascadeAttach)
            {
                // Determine if field is "second-class" (no identity) - if has "embedded" info or serialised
View Full Code Here

Examples of org.jpox.api.ApiAdapter

    protected Object internalFetchObjectField(int fieldNumber)
    {
        SingleValueFieldManager sfv = new SingleValueFieldManager();
        sm.provideFields(new int[]{fieldNumber}, sfv);
        Object value = sfv.fetchObjectField(fieldNumber);
        ApiAdapter api = sm.getObjectManager().getApiAdapter();

        if (value != null)
        {
            if (api.isPersistable(value))
            {
                // Process PC fields
                processPersistable(value);
            }
            else if (value instanceof Collection)
            {
                // Process all elements of the Collection that are PC
                if (!(value instanceof SCO))
                {
                    // Replace with SCO
                    value = sm.wrapSCOField(fieldNumber, value, false, false, true);
                }
                SCO sco = (SCO)value;

                Collection coll = (Collection)value;
                Iterator iter = coll.iterator();
                while (iter.hasNext())
                {
                    Object element = iter.next();
                    if (api.isPersistable(element))
                    {
                        processPersistable(element);
                    }
                }
                sco.unsetOwner();
            }
            else if (value instanceof Map)
            {
                // Process all keys, values of the Map that are PC
                if (!(value instanceof SCO))
                {
                    // Replace with SCO
                    value = sm.wrapSCOField(fieldNumber, value, false, false, true);
                }
                SCO sco = (SCO)value;

                Map map = (Map)value;

                // Process any keys that are PersistenceCapable
                Set keys = map.keySet();
                Iterator iter = keys.iterator();
                while (iter.hasNext())
                {
                    Object mapKey = iter.next();
                    if (api.isPersistable(mapKey))
                    {
                        processPersistable(mapKey);
                    }
                }

                // Process any values that are PersistenceCapable
                Collection values = map.values();
                iter = values.iterator();
                while (iter.hasNext())
                {
                    Object mapValue = iter.next();
                    if (api.isPersistable(mapValue))
                    {
                        processPersistable(mapValue);
                    }
                }

                sco.unsetOwner();
            }
            else if (value instanceof Object[])
            {
                Object[] array = (Object[]) value;
                for (int i=0;i<array.length;i++)
                {
                    Object element = array[i];
                    if (api.isPersistable(element))
                    {
                        processPersistable(element);
                    }
                }
            }
View Full Code Here

Examples of org.jpox.api.ApiAdapter

        // 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

Examples of org.jpox.api.ApiAdapter

     * @return Object value
     */
    public Object fetchObjectField(int fieldNumber)
    {
        Object value = sm.provideField(fieldNumber);
        ApiAdapter api = sm.getObjectManager().getApiAdapter();
        if (value == null)
        {
            return null;
        }
        else if (api.isPersistable(value))
        {
            // Process PC fields
            sm.makeDirty(fieldNumber);
            return null;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.