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;
}
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations