use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-core by datanucleus.
the class KeyMetaData method populate.
/**
* Populate the MetaData.
* @param clr Class loader to use
* @param primary the primary ClassLoader to use (or null)
*/
public void populate(ClassLoaderResolver clr, ClassLoader primary) {
AbstractMemberMetaData mmd = (AbstractMemberMetaData) parent;
if (mmd.getMap() == null) {
// TODO Use InvalidMemberMetaDataException
throw new NucleusUserException("The field " + mmd.getFullFieldName() + " is defined with <key>, however no <map> definition was found.").setFatal();
}
// Populate the key metadata
if (hasExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME)) {
if (mmd.getMap().key.embedded == null) {
// Default to embedded since the converter process requires it
mmd.getMap().key.embedded = Boolean.TRUE;
}
}
mmd.getMap().key.populate(mmd.getAbstractClassMetaData().getPackageName(), clr, primary);
// Make sure key type is set and is valid
String keyType = mmd.getMap().getKeyType();
Class keyTypeClass = null;
try {
keyTypeClass = clr.classForName(keyType, primary);
} catch (ClassNotResolvedException cnre) {
throw new InvalidMemberMetaDataException("044147", mmd.getClassName(), mmd.getName(), keyType);
}
if (embeddedMetaData != null && (keyTypeClass.isInterface() || keyTypeClass.getName().equals("java.lang.Object"))) {
throw new InvalidMemberMetaDataException("044152", mmd.getClassName(), mmd.getName(), keyTypeClass.getName());
}
// that MapMetaData can call when it is populated
if (embeddedMetaData == null && mmd.hasMap() && mmd.getMap().isEmbeddedKey() && mmd.getJoinMetaData() != null && mmd.getMap().keyIsPersistent()) {
// User has specified that the key is embedded in a join table but not how we embed it
// so add a dummy definition
embeddedMetaData = new EmbeddedMetaData();
embeddedMetaData.parent = this;
}
super.populate(clr, primary);
}
use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-core by datanucleus.
the class DataNucleusEnhancer method addClasses.
/**
* Method to add the specified classes to the list of classes to enhance.
* @param classNames Names of the classes
* @return The enhancer
*/
public DataNucleusEnhancer addClasses(String... classNames) {
if (classNames == null) {
return this;
}
Collection names = new HashSet();
for (int i = 0; i < classNames.length; i++) {
if (classNames[i].endsWith(".class")) {
// Absolute/relative class file (should really be via addFiles())
String name = classNames[i];
String msg = null;
if (!StringUtils.getFileForFilename(classNames[i]).exists()) {
msg = Localiser.msg("005003", classNames[i]);
addMessage(msg, true);
name = null;
} else {
// Extra the name of the class from the name of the file
name = ClassEnhancerImpl.getClassNameForFileName(classNames[i]);
}
if (name != null) {
names.add(name);
}
} else {
// Assumed to be actual class name ("mydomain.MyClass")
try {
// Check for class existence
clr.classForName(classNames[i], false);
} catch (ClassNotResolvedException cnre) {
addMessage("Class " + classNames[i] + " not found in CLASSPATH! : " + cnre.getMessage(), true);
}
names.add(classNames[i]);
}
}
if (!names.isEmpty()) {
componentsToEnhance.add(new EnhanceComponent(EnhanceComponent.CLASS, names.toArray(new String[names.size()])));
}
return this;
}
use of org.datanucleus.exceptions.ClassNotResolvedException in project tests by datanucleus.
the class JPAPersistenceTestCase method getEMF.
/**
* Method to obtain the EMF to use allowing specification of custom user EMF properties.
* Creates a new EMF on each call.
* NOTE : THIS SETS THE "emf" AND "storeMgr" FIELDS.
* @param unitName Name of the persistence unit to use (if any)
* @param userProps The custom EMF props to use when creating the EMF
* @return The EMF (also stored in the local "emf" variable)
*/
protected synchronized EntityManagerFactory getEMF(String unitName, Properties userProps) {
emf = getEMF(1, unitName, userProps);
storeMgr = emf.unwrap(PersistenceNucleusContext.class).getStoreManager();
ClassLoaderResolver clr = storeMgr.getNucleusContext().getClassLoaderResolver(null);
try {
clr.classForName("org.datanucleus.store.rdbms.RDBMSStoreManager");
if (storeMgr instanceof org.datanucleus.store.rdbms.RDBMSStoreManager) {
// RDBMS datastores have a vendor id
vendorID = ((org.datanucleus.store.rdbms.RDBMSStoreManager) storeMgr).getDatastoreAdapter().getVendorID();
}
} catch (ClassNotResolvedException cnre) {
}
return emf;
}
use of org.datanucleus.exceptions.ClassNotResolvedException in project datanucleus-rdbms by datanucleus.
the class QueryToSQLMapper method processCreatorExpression.
/* (non-Javadoc)
* @see org.datanucleus.query.evaluator.AbstractExpressionEvaluator#processCreatorExpression(org.datanucleus.query.expression.CreatorExpression)
*/
@Override
protected Object processCreatorExpression(CreatorExpression expr) {
String className = expr.getId();
Class cls = null;
try {
cls = clr.classForName(className);
} catch (ClassNotResolvedException cnre) {
if (importsDefinition != null) {
cls = importsDefinition.resolveClassDeclaration(className, clr, null);
}
}
List<SQLExpression> ctrArgExprs = null;
List<String> ctrArgAliases = null;
boolean hasAliases = false;
List args = expr.getArguments();
if (args != null) {
Class[] ctrArgTypes = new Class[args.size()];
boolean[] ctrArgTypeCheck = new boolean[args.size()];
ctrArgExprs = new ArrayList<>(args.size());
ctrArgAliases = new ArrayList<>(args.size());
Iterator iter = args.iterator();
int i = 0;
while (iter.hasNext()) {
Expression argExpr = (Expression) iter.next();
String argAlias = argExpr.getAlias();
if (argAlias != null) {
hasAliases = true;
}
SQLExpression sqlExpr = (SQLExpression) evaluate(argExpr);
// TODO Cater for "SQL_function" mapping on to ANY type of constructor argument at that position since we don't know the precise type
if (argExpr instanceof InvokeExpression && ((InvokeExpression) argExpr).getOperation().equalsIgnoreCase("SQL_function")) {
ctrArgTypeCheck[i] = false;
} else {
ctrArgTypeCheck[i] = true;
}
ctrArgExprs.add(sqlExpr);
ctrArgAliases.add(argAlias != null ? argAlias : "####");
if (sqlExpr instanceof NewObjectExpression) {
ctrArgTypes[i] = ((NewObjectExpression) sqlExpr).getNewClass();
} else if (sqlExpr.getJavaTypeMapping() instanceof DatastoreIdMapping || sqlExpr.getJavaTypeMapping() instanceof PersistableMapping) {
ctrArgTypes[i] = clr.classForName(sqlExpr.getJavaTypeMapping().getType());
} else {
ctrArgTypes[i] = sqlExpr.getJavaTypeMapping().getJavaType();
}
i++;
}
// Check that this class has the required constructor
Constructor ctr = ClassUtils.getConstructorWithArguments(cls, ctrArgTypes, ctrArgTypeCheck);
if (ctr == null) {
throw new NucleusUserException(Localiser.msg("021033", className, StringUtils.objectArrayToString(ctrArgTypes)));
}
}
// TODO Retain the selected constructor (above)
NewObjectExpression newExpr = new NewObjectExpression(stmt, cls, ctrArgExprs);
if (hasAliases) {
newExpr.setArgAliases(ctrArgAliases);
}
stack.push(newExpr);
return newExpr;
}
Aggregations