Search in sources :

Example 86 with NucleusException

use of org.datanucleus.exceptions.NucleusException in project datanucleus-core by datanucleus.

the class InterfaceMetaData method populate.

/**
 * Method to provide the details of the class being represented by this
 * MetaData. This can be used to firstly provide defaults for attributes
 * that aren't specified in the MetaData, and secondly to report any errors
 * with attributes that have been specified that are inconsistent with the
 * class being represented.
 * <P>
 * One possible use of this method would be to take a basic ClassMetaData
 * for a class and call this, passing in the users class. This would then
 * add AbstractMemberMetaData for all fields in this class providing defaults for all of these.
 *
 * @param clr ClassLoaderResolver to use in loading any classes
 * @param primary the primary ClassLoader to use (or null)
 * @param mgr MetaData manager
 */
public synchronized void populate(ClassLoaderResolver clr, ClassLoader primary, MetaDataManager mgr) {
    if (isInitialised() || isPopulated()) {
        NucleusLogger.METADATA.error(Localiser.msg("044068", name));
        throw new NucleusException(Localiser.msg("044068", fullName)).setFatal();
    }
    if (populating) {
        return;
    }
    this.mmgr = mgr;
    try {
        if (NucleusLogger.METADATA.isDebugEnabled()) {
            NucleusLogger.METADATA.debug(Localiser.msg("044075", fullName));
        }
        populating = true;
        Class cls = loadClass(clr, primary);
        // Load any Annotations definition for this class
        if (!isMetaDataComplete()) {
            mmgr.addAnnotationsDataToClass(cls, this, clr);
        }
        // Load any ORM definition for this class
        mmgr.addORMDataToClass(cls, clr);
        // If a class is an inner class and is non-static it is invalid
        if (ClassUtils.isInnerClass(fullName) && !Modifier.isStatic(cls.getModifiers()) && persistenceModifier == ClassPersistenceModifier.PERSISTENCE_CAPABLE) {
            throw new InvalidClassMetaDataException("044063", fullName);
        }
        determineSuperClassName(clr, cls);
        inheritIdentity();
        determineIdentity();
        validateUserInputForIdentity();
        addMetaDataForMembersNotInMetaData(cls);
        // Set inheritance
        validateUserInputForInheritanceMetaData(false);
        determineInheritanceMetaData();
        applyDefaultDiscriminatorValueWhenNotSpecified();
        if (objectidClass == null) {
            // No user-defined objectid-class but potentially have SingleFieldIdentity so make sure PK fields are set
            // PK fields
            populatePropertyMetaData(clr, cls, true, primary);
            determineObjectIdClass();
            // Non-PK fields
            populatePropertyMetaData(clr, cls, false, primary);
        } else {
            populatePropertyMetaData(clr, cls, true, primary);
            populatePropertyMetaData(clr, cls, false, primary);
            determineObjectIdClass();
        }
        setPopulated();
    } catch (RuntimeException e) {
        NucleusLogger.METADATA.debug(e);
        throw e;
    } finally {
        populating = false;
    }
}
Also used : NucleusException(org.datanucleus.exceptions.NucleusException)

Example 87 with NucleusException

use of org.datanucleus.exceptions.NucleusException in project datanucleus-core by datanucleus.

the class IdentityManagerImpl method getDatastoreId.

/* (non-Javadoc)
     * @see org.datanucleus.identity.IdentityManager#getDatastoreId(java.lang.String)
     */
@Override
public DatastoreId getDatastoreId(String idString) {
    if (datastoreIdClass == ClassConstants.IDENTITY_DATASTORE_IMPL) {
        // Hardcoded for performance
        return new DatastoreIdImpl(idString);
    }
    // Others are pluggable
    try {
        Class[] ctrArgTypes = new Class[] { String.class };
        String ctrName = getConstructorNameForCache(datastoreIdClass, ctrArgTypes);
        Constructor ctr = constructorCache.get(ctrName);
        if (ctr == null) {
            ctr = datastoreIdClass.getConstructor(ctrArgTypes);
            constructorCache.put(ctrName, ctr);
        }
        return (DatastoreId) ctr.newInstance(new Object[] { idString });
    } catch (Exception e) {
        // TODO Localise this
        throw new NucleusException("Error encountered while creating datastore instance for string \"" + idString + "\"", e);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) NucleusException(org.datanucleus.exceptions.NucleusException) NucleusException(org.datanucleus.exceptions.NucleusException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException)

Example 88 with NucleusException

use of org.datanucleus.exceptions.NucleusException in project datanucleus-core by datanucleus.

the class IdentityManagerImpl method getDatastoreId.

/* (non-Javadoc)
     * @see org.datanucleus.identity.IdentityManager#getDatastoreId(long)
     */
@Override
public DatastoreId getDatastoreId(long value) {
    if (datastoreIdClass == DatastoreUniqueLongId.class) {
        // Hardcoded for performance
        return new DatastoreUniqueLongId(value);
    }
    // Others are pluggable
    try {
        Class[] ctrArgTypes = new Class[] { Long.class };
        String ctrName = getConstructorNameForCache(datastoreIdClass, ctrArgTypes);
        Constructor ctr = constructorCache.get(ctrName);
        if (ctr == null) {
            ctr = datastoreIdClass.getConstructor(ctrArgTypes);
            constructorCache.put(ctrName, ctr);
        }
        return (DatastoreId) ctr.newInstance(new Object[] { Long.valueOf(value) });
    } catch (Exception e) {
        // TODO Localise this
        throw new NucleusException("Error encountered while creating datastore instance for unique value \"" + value + "\"", e);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) NucleusException(org.datanucleus.exceptions.NucleusException) NucleusException(org.datanucleus.exceptions.NucleusException) ClassNotResolvedException(org.datanucleus.exceptions.ClassNotResolvedException) NucleusUserException(org.datanucleus.exceptions.NucleusUserException)

Example 89 with NucleusException

use of org.datanucleus.exceptions.NucleusException in project datanucleus-core by datanucleus.

the class SerializableByteArrayConverter method toDatastoreType.

/* (non-Javadoc)
     * @see org.datanucleus.store.types.converters.TypeConverter#toDatastoreType(java.lang.Object)
     */
public byte[] toDatastoreType(Serializable memberValue) {
    byte[] bytes = null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = null;
    try {
        try {
            oos = new ObjectOutputStream(baos);
            oos.writeObject(memberValue);
            bytes = baos.toByteArray();
        } finally {
            try {
                baos.close();
            } finally {
                if (oos != null) {
                    oos.close();
                }
            }
        }
    } catch (IOException ioe) {
        throw new NucleusException("Error serialising object of type " + memberValue.getClass().getName() + " to byte[]", ioe);
    }
    return bytes;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) NucleusException(org.datanucleus.exceptions.NucleusException)

Example 90 with NucleusException

use of org.datanucleus.exceptions.NucleusException in project datanucleus-core by datanucleus.

the class SerializableByteBufferConverter method toDatastoreType.

/* (non-Javadoc)
     * @see org.datanucleus.store.types.converters.TypeConverter#toDatastoreType(java.lang.Object)
     */
public ByteBuffer toDatastoreType(Serializable memberValue) {
    if (memberValue == null) {
        return null;
    }
    byte[] bytes = null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = null;
    try {
        try {
            oos = new ObjectOutputStream(baos);
            oos.writeObject(memberValue);
            bytes = baos.toByteArray();
        } finally {
            try {
                baos.close();
            } finally {
                if (oos != null) {
                    oos.close();
                }
            }
        }
    } catch (IOException ioe) {
        throw new NucleusException("Error serialising object of type " + memberValue.getClass().getName() + " to ByteBuffer", ioe);
    }
    return ByteBuffer.wrap(bytes);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) NucleusException(org.datanucleus.exceptions.NucleusException)

Aggregations

NucleusException (org.datanucleus.exceptions.NucleusException)326 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)71 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)67 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)62 ParameterExpression (org.datanucleus.query.expression.ParameterExpression)53 PrimaryExpression (org.datanucleus.query.expression.PrimaryExpression)52 ArrayList (java.util.ArrayList)48 Literal (org.datanucleus.query.expression.Literal)47 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)44 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)43 InvokeExpression (org.datanucleus.query.expression.InvokeExpression)40 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)37 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)36 StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)35 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)35 Expression (org.datanucleus.query.expression.Expression)32 HashMap (java.util.HashMap)31 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)31 VariableExpression (org.datanucleus.query.expression.VariableExpression)26 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)26