Package org.jpox.exceptions

Examples of org.jpox.exceptions.JPOXUserException


    public Object newObjectId(Class pcClass, Object key)
    {
        assertIsOpen();
        if (pcClass == null)
        {
            throw new JPOXUserException(LOCALISER.msg("010028"));
        }
        assertClassPersistable(pcClass);

        AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(pcClass, clr);
        if (cmd == null)
        {
            throw new NoPersistenceInformationException(pcClass.getName());
        }

        // If the class is not yet managed, manage it
        if (!getStoreManager().managesClass(cmd.getFullClassName()))
        {
            getStoreManager().addClass(cmd.getFullClassName(), clr);
        }

        Object id = null;
        if (cmd.usesSingleFieldIdentityClass())
        {
            // Single Field Identity
            Class idType = clr.classForName(cmd.getObjectidClass());
            id = getApiAdapter().getNewSingleFieldIdentity(idType, pcClass, key);
        }
        else if (key instanceof java.lang.String)
        {
            // String-based PK (datastore identity or application identity)
            if (cmd.getIdentityType() == IdentityType.APPLICATION)
            {
                if (Modifier.isAbstract(pcClass.getModifiers()) && cmd.getObjectidClass() != null)
                {
                    try
                    {
                        Constructor c = clr.classForName(cmd.getObjectidClass()).getDeclaredConstructor(new Class[] {java.lang.String.class});
                        id = c.newInstance(new Object[] {(String)key});
                    }
                    catch(Exception e)
                    {
                        String msg = LOCALISER.msg("010030", cmd.getObjectidClass(), cmd.getFullClassName());
                        JPOXLogger.PERSISTENCE.error(msg);
                        JPOXLogger.PERSISTENCE.error(e);

                        throw new JPOXUserException(msg);
                    }
                }
                else
                {
                    clr.classForName(pcClass.getName(), true);
                    id = getApiAdapter().getNewApplicationIdentityObjectId(pcClass, key);
                }
            }
            else
            {
                id = OIDFactory.getInstance(this, (String)key);
            }
        }
        else
        {
            // Key is not a string, and is not SingleFieldIdentity
            throw new JPOXUserException(LOCALISER.msg("010029", pcClass.getName(), key.getClass().getName()));
        }

        return id;
    }
View Full Code Here


     */
    protected void assertIsOpen()
    {
        if (isClosed())
        {
            throw new JPOXUserException(LOCALISER.msg("010002")).setFatal();
        }
    }
View Full Code Here

     */
    protected void assertHasImplementationCreator()
    {
        if (getOMFContext().getImplementationCreator() == null)
        {
            throw new JPOXUserException(LOCALISER.msg("010035"));
        }
    }
View Full Code Here

        {
            // Need to set the mapped-by of <key> to be the PK of the <value>
            if (value.classMetaData.getNoOfPrimaryKeyMembers() != 1)
            {
                // TODO Localise this
                throw new JPOXUserException("JPOX does not support use of <map-key> with no name field when the" +
                    " value class has a composite primary key");
            }
            int[] valuePkFieldNums = value.classMetaData.getPKMemberPositions();
            keymd.mappedBy = value.classMetaData.getMetaDataForManagedMemberAtAbsolutePosition(valuePkFieldNums[0]).name;
        }
View Full Code Here

            // Check that the implied class is managed
            className = ((OID)id).getPcClass();
            AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(className, clr);
            if (cmd.getIdentityType() != IdentityType.DATASTORE)
            {
                throw new JPOXUserException(LOCALISER.msg("038001", id, cmd.getFullClassName()));
            }

        }
        else if (getApiAdapter().isSingleFieldIdentity(id))
        {
            className = getApiAdapter().getTargetClassNameForSingleFieldIdentity(id);
            AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(className, clr);
            if (cmd.getIdentityType() != IdentityType.APPLICATION || !cmd.getObjectidClass().equals(id.getClass().getName()))
            {
                throw new JPOXUserException(LOCALISER.msg("038001", id, cmd.getFullClassName()));
            }
        }
        else
        {
            throw new JPOXException("StoreManager.manageClassForIdentity called for id=" + id +
View Full Code Here

            {
                tableGeneratorMetaData = getMetaDataManager().getMetaDataForTableGenerator(om.getClassLoaderResolver(),
                    valueGeneratorName);
                if (tableGeneratorMetaData == null)
                {
                    throw new JPOXUserException(LOCALISER.msg("038005", fieldName, valueGeneratorName));
                }
            }
            else if (strategy == IdentityStrategy.SEQUENCE)
            {
                sequenceMetaData = getMetaDataManager().getMetaDataForSequence(om.getClassLoaderResolver(),
                    valueGeneratorName);
                if (sequenceMetaData == null)
                {
                    throw new JPOXUserException(LOCALISER.msg("038006", fieldName, valueGeneratorName));
                }
            }
        }
        else if (strategy == IdentityStrategy.SEQUENCE && sequence != null)
        {
            // TODO Allow for package name of this class prefix for the sequence name
            sequenceMetaData = getMetaDataManager().getMetaDataForSequence(om.getClassLoaderResolver(), sequence);
            if (sequenceMetaData == null)
            {
                // JPOX 1.1 behaviour is just to use the sequence name in the datastore so log it and fallback to that
                JPOXLogger.DATASTORE.warn("Field " + fieldName + " has been specified to use sequence " + sequence +
                    " but there is no <sequence> specified in the MetaData. " +
                    "Falling back to use a sequence in the datastore with this name directly.");
            }
        }

        String strategyName = strategy.toString();
        if (strategy.equals(IdentityStrategy.CUSTOM))
        {
            // Using a "custom" generator
            strategyName = strategy.getCustomName();
        }
        else if (strategy.equals(IdentityStrategy.NATIVE))
        {
            strategyName = getStrategyForNative(sequence);
        }

        // POID Generators are cached against a name. Some POID Generators are unique per datastore.
        // Others are per class/field. Others have a user-defined name.
        // The name that they are cached under relates to what they use.
        // Generate the name for PoidManager to use the strategy for this field/class.
        String poidGeneratorName = null;
        String generatorNameKeyInManager = null;
        ConfigurationElement elem =
            omfContext.getPluginManager().getConfigurationElementForExtension("org.jpox.store_valuegenerator",
                new String[]{"name", "unique"}, new String[] {strategyName, "true"});
        if (elem != null)
        {
            // Unique value generator so set the key in PoidManager to the value generator name itself
            poidGeneratorName = elem.getAttribute("name");
            generatorNameKeyInManager = poidGeneratorName;
        }
        else
        {
            // Not a unique (datastore-independent) generator so try just for this datastore
            elem = omfContext.getPluginManager().getConfigurationElementForExtension("org.jpox.store_valuegenerator",
                new String[]{"name", "datastore"}, new String[] {strategyName, storeManagerKey});
            if (elem != null)
            {
                // Set the generator name (for use by the PoidManager)
                poidGeneratorName = elem.getAttribute("name");
            }
        }
        if (generatorNameKeyInManager == null)
        {
            // Value generator is not unique so set based on class/field
            if (absoluteFieldNumber >= 0)
            {
                // Require generation for a field so use field name for the generator symbolic name
                generatorNameKeyInManager = mmd.getFullFieldName();
            }
            else
            {
                // Require generation for a datastore id field so use the class name for the generator symbolic name
                generatorNameKeyInManager = cmd.getFullClassName();
            }
        }

        // Try to find the generator from the PoidManager if we already have it managed
        PoidGenerator generator = poidManager.getPoidGenerator(generatorNameKeyInManager);
        if (generator == null)
        {
            if (poidGeneratorName == null)
            {
                // No available value-generator for the specified strategy for this datastore
                throw new JPOXUserException(LOCALISER.msg("038004", strategy));
            }

            // Set up the default properties available for all value generators
            Properties props = getPropertiesForGenerator(cmd, absoluteFieldNumber, om, sequenceMetaData,
                tableGeneratorMetaData);
View Full Code Here

            valid = ((Number)versionObject).longValue() == ((Number)versionDatastore).longValue();
        }
        else if (versionMetaData.getVersionStrategy() == VersionStrategy.STATE_IMAGE)
        {
            // TODO Support state-image strategy
            throw new JPOXUserException(LOCALISER.msg("032017",
                sm.getClassMetaData().getFullClassName(), versionMetaData.getVersionStrategy()));
        }
        else
        {
            throw new JPOXUserException(LOCALISER.msg("032017",
                sm.getClassMetaData().getFullClassName(), versionMetaData.getVersionStrategy()));
        }

        if (!valid)
        {
View Full Code Here

                is.close();
            }
            catch (FileNotFoundException e)
            {
                properties.remove("org.jpox.propertiesFile");
                throw new JPOXUserException(LOCALISER.msg("008014", value), e).setFatal();
            }
            catch (IOException e)
            {
                properties.remove("org.jpox.propertiesFile");
                throw new JPOXUserException(LOCALISER.msg("008014", value), e).setFatal();
            }
        }
        else
        {
            // Try to load it as a resource in the CLASSPATH
            try
            {
                InputStream is = PersistenceConfiguration.class.getClassLoader().getResourceAsStream(value);
                props.load(is);
                is.close();

                properties.put("org.jpox.propertiesFile", value);
            }
            catch (Exception e)
            {
                // Still not loadable so throw exception
                throw new JPOXUserException(LOCALISER.msg("008014", value), e).setFatal();
            }
        }

        setOptions(props);
    }
View Full Code Here

     */
    protected void assertConfigurable()
    {
        if (!configurable)
        {
            throw new JPOXUserException(LOCALISER.msg("008016"));
        }
    }
View Full Code Here

     */
    protected void assertKeyNotNull(Object key)
    {
        if (key == null)
        {
            throw new JPOXUserException("Cannot create SingleFieldIdentity with null parameter");
        }
    }
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.