Package org.jpox.exceptions

Examples of org.jpox.exceptions.JPOXUserException


            if (getApiAdapter() instanceof JDOAdapter) // TODO Refactor this
            {
                // JDO doesnt allow deletion of transient
                if (!getApiAdapter().isPersistent(pc) && !getApiAdapter().isTransactional(pc))
                {
                    throw new JPOXUserException(LOCALISER.msg("010020"));
                }
                else if (!getApiAdapter().isPersistent(pc) && getApiAdapter().isTransactional(pc))
                {
                    throw new JPOXUserException(LOCALISER.msg("010021"));
                }
            }

            // Delete it
            StateManager sm = findStateManager(pc);
            if (sm == null)
            {
                if (!getApiAdapter().allowDeleteOfNonPersistentObject())
                {
                    // Not permitted by the API
                    throw new JPOXUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(pc)));
                }

                // Put StateManager around object so it is P_NEW (unpersisted), then P_NEW_DELETED soon after
                sm = StateManagerFactory.newStateManagerForPNewToBeDeleted(this, pc);
            }
View Full Code Here


                failures.add(e);
            }
        }
        if (failures != null && !failures.isEmpty())
        {
            throw new JPOXUserException(LOCALISER.msg("010040"),
                (Exception[]) failures.toArray(new Exception[failures.size()]));
        }
    }
View Full Code Here

                failures.add(e);
            }
        }
        if (failures != null && !failures.isEmpty())
        {
            throw new JPOXUserException(LOCALISER.msg("010040"),
                (Exception[]) failures.toArray(new Exception[failures.size()]));
        }
    }
View Full Code Here

        {
            clr.setPrimary(obj.getClass().getClassLoader());
            assertClassPersistable(obj.getClass());
            if (!getApiAdapter().isPersistent(obj) && getApiAdapter().isTransactional(obj) && getApiAdapter().isDirty(obj))
            {
                throw new JPOXUserException(LOCALISER.msg("010024"));
            }

            StateManager sm = findStateManager(obj);
            sm.makeNontransactional();
        }
View Full Code Here

            // Detached, so migrate to attached
            StateManager l1CachedSM = (StateManager)cache.get(id);
            if (l1CachedSM != null && l1CachedSM.getObject() != pc)
            {
                // attached object with the same id already present in the L1 cache so cannot attach in-situ
                throw new JPOXUserException(LOCALISER.msg("010017",
                    StringUtils.toJVMIDString(pc)));
            }

            if (JPOXLogger.PERSISTENCE.isDebugEnabled())
            {
View Full Code Here

        }

        StateManager sm = findStateManager(obj);
        if (sm == null)
        {
            throw new JPOXUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(obj)));
        }
        sm.detach(state);
    }
View Full Code Here

                else
                {
                    // JDO2 [12.6.8] "If a detachCopy method is called outside an active transaction, the reachability algorithm
                    // will not be run; if any transient instances are reachable via persistent fields, a JDOUserException is thrown
                    // for each persistent instance containing such fields.
                    throw new JPOXUserException(LOCALISER.msg("010014"));
                }
            }

            if (getApiAdapter().isDetached(thePC))
            {
                // Passing in a detached (dirty or clean) instance, so get a persistent copy to detach
                thePC = findObject(getApiAdapter().getIdForObject(thePC), false, true, null);
            }

            Object detached = ((DetachState)state).getDetachedCopyObject(thePC);
            if (detached == null)
            {
                StateManager sm = findStateManager(thePC);
                if (sm == null)
                {
                    throw new JPOXUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(thePC)));
                }

                detached = sm.detachCopy(state);
                ((DetachState)state).setDetachedCopyObject(detached, sm.getExternalObjectId(sm.getObject()));
            }
View Full Code Here

            {
                return cls.newInstance();
            }
            catch (IllegalAccessException iae)
            {
                throw new JPOXUserException(iae.toString(), iae);
            }
            catch (InstantiationException ie)
            {
                throw new JPOXUserException(ie.toString(), ie);
            }
        }

        // Use ImplementationCreator
        assertHasImplementationCreator();
View Full Code Here

                        putObjectIntoCache(sm, true, true);
                    }
                    catch (ClassNotResolvedException e)
                    {
                        JPOXLogger.PERSISTENCE.warn(LOCALISER.msg("010027", id));
                        throw new JPOXUserException(LOCALISER.msg("010027", id), e);
                    }
                }
            }
        }
        return pc;
View Full Code Here

    public synchronized Object findObject(Object id, boolean validate, boolean checkInheritance, String objectClassName)
    {
        assertIsOpen();
        if (id == null)
        {
            throw new JPOXUserException(LOCALISER.msg("010044"));
        }

        // try to find object in cache(s)
        Object pc = getObjectFromCache(id);
        boolean fromCache = true;

        ApiAdapter api = getApiAdapter();
        if (id instanceof SCOID && pc != null)
        {
            if (api.isPersistent(pc) && !api.isNew(pc) && !api.isDeleted(pc) && !api.isTransactional(pc))
            {
                // JDO2 [5.4.4] Cant return HOLLOW nondurable objects
                throw new JPOXUserException(LOCALISER.msg("010005"));
            }
        }

        if (pc != null && api.isTransactional(pc))
        {
            // JDO2 [12.6.5] If there's already an object with the same id and it's transactional, return it
            return pc;
        }

        StateManager sm = null;
        if (pc == null)
        {
            // Find it direct from the store if the store supports that
            pc = getStoreManager().getPersistenceHandler().findObject(this, id);

            if (pc == null)
            {
                // Object not found in cache(s) with this identity
                String className = null;
                String originalClassName = null;
                boolean checkedClassName = false;
                if (id instanceof SCOID)
                {
                    throw new JPOXUserException(LOCALISER.msg("010006"));
                }
                else if (id instanceof OID)
                {
                    // OID, so check that the implied class is managed
                    originalClassName = getStoreManager().manageClassForIdentity(id, getClassLoaderResolver());
                }
                else if (api.isSingleFieldIdentity(id))
                {
                    // SingleFieldIdentity, so check that the implied class is managed
                    originalClassName = getStoreManager().manageClassForIdentity(id, getClassLoaderResolver());
                }
                else if (objectClassName != null)
                {
                    // Object class name specified so use that directly
                    originalClassName = objectClassName;
                }
                else
                {
                    // We dont know the object class so try to deduce it from what is known by the StoreManager
                    originalClassName = getStoreManager().getClassNameForObjectID(id, clr, this);
                    checkedClassName = true;
                }

                if (checkInheritance)
                {
                    // Verify if correct class inheritance level is set
                    if (!checkedClassName)
                    {
                        className = getStoreManager().getClassNameForObjectID(id, clr, this);
                    }
                    else
                    {
                        // We just checked the name of the class in the section above so just use that
                        className = originalClassName;
                    }
   
                    if (className == null)
                    {
                        throw new JPOXObjectNotFoundException(LOCALISER.msg("010026"), id);
                    }
   
                    if (originalClassName != null && !originalClassName.equals(className))
                    {
                        // Inheritance checking has found a different inherited
                        // object with this identity so create new id
                        if (id instanceof OID)
                        {
                            // Create new OID using correct target class
                            id = OIDFactory.getInstance(this, className, ((OID)id).getKeyValue());
   
                            // try again to read object from cache with this id
                            pc = getObjectFromCache(id);
                        }
                        else if (api.isSingleFieldIdentity(id))
                        {
                            // Create new SingleFieldIdentity using correct targetClass
                            id = api.getNewSingleFieldIdentity(id.getClass(), getClassLoaderResolver().classForName(className),
                                    api.getTargetKeyForSingleFieldIdentity(id));
   
                            // try again to read object from cache with this id
                            pc = getObjectFromCache(id);
                        }
                    }
                }
                else
                {
                    className = originalClassName;
                }

                if (pc == null)
                {
                    // Still not found so create a Hollow instance with the supplied field values
                    try
                    {
                        Class pcClass = clr.classForName(className, (id instanceof OID) ? null : id.getClass().getClassLoader());
                        sm = StateManagerFactory.newStateManagerForHollow(this, pcClass, id);
                        pc = sm.getObject();
                        fromCache = false;
                    }
                    catch (ClassNotResolvedException e)
                    {
                        JPOXLogger.PERSISTENCE.warn(LOCALISER.msg("010027", id));
                        throw new JPOXUserException(LOCALISER.msg("010027", id), e);
                    }
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.jpox.exceptions.JPOXUserException

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.