use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManager method getObjectIdClass.
/**
* Accessor for the class of the object id given the class of object.
* @param cls The class name of the object
* @return The class name of the object id
*/
public Class getObjectIdClass(Class cls) {
assertIsOpen();
if (!ec.getNucleusContext().getApiAdapter().isPersistable(cls) || !hasPersistenceInformationForClass(cls)) {
return null;
}
ClassLoaderResolver clr = ec.getClassLoaderResolver();
AbstractClassMetaData cmd = ec.getMetaDataManager().getMetaDataForClass(cls, clr);
if (cmd.getIdentityType() == IdentityType.DATASTORE) {
return ec.getNucleusContext().getIdentityManager().getDatastoreIdClass();
} else if (cmd.getIdentityType() == IdentityType.APPLICATION) {
try {
return this.ec.getClassLoaderResolver().classForName(ec.getMetaDataManager().getMetaDataForClass(cls, clr).getObjectidClass(), null);
} catch (ClassNotResolvedException e) {
String msg = Localiser.msg("011009", cls.getName());
LOGGER.error(msg);
throw new JDOException(msg);
}
} else {
if (cmd.isRequiresExtent()) {
return ec.getNucleusContext().getIdentityManager().getDatastoreIdClass();
}
return SCOID.class;
}
}
use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManager method evictAll.
/**
* Method to evict a collection of objects from L1 cache.
* @param pcs The objects
* @throws JDOUserException thrown if some instances could not be evicted
*/
public void evictAll(Collection pcs) {
assertIsOpen();
ArrayList failures = new ArrayList();
Iterator i = pcs.iterator();
while (i.hasNext()) {
try {
jdoEvict(i.next());
} catch (JDOException e) {
failures.add(e);
}
}
if (!failures.isEmpty()) {
throw new JDOUserException(Localiser.msg("010036"), (Exception[]) failures.toArray(new Exception[failures.size()]));
}
}
use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManagerFactory method freezeConfiguration.
/**
* Freezes the current configuration.
* @throws JDOException if the configuration was invalid or inconsistent in some way
*/
protected void freezeConfiguration() {
if (isConfigurable()) {
// Check for invalid javax.jdo properties by calling JDOImplHelper method (new in JDO3.1+)
Method m = null;
try {
m = JDOImplHelper.class.getDeclaredMethod("assertOnlyKnownStandardProperties", new Class[] { Map.class });
m.invoke(null, nucleusContext.getConfiguration().getPersistenceProperties());
} catch (InvocationTargetException ite) {
if (ite.getCause() instanceof JDOException) {
throw (JDOException) ite.getCause();
}
} catch (JDOException jdoe) {
throw jdoe;
} catch (Exception e) {
// Method not present so continue
}
synchronized (this) {
try {
// Initialise the NucleusContext
nucleusContext.initialise();
// Set up the Level 2 Cache
datastoreCache = new JDODataStoreCache(nucleusContext.getLevel2Cache());
setIsNotConfigurable();
} catch (TransactionIsolationNotSupportedException inse) {
throw new JDOUnsupportedOptionException(inse.getMessage());
} catch (NucleusException ne) {
throw NucleusJDOHelper.getJDOExceptionForNucleusException(ne);
}
}
}
}
use of javax.jdo.JDOException in project hive by apache.
the class HMSHandler method createDefaultDB.
/**
* create default database if it doesn't exist.
*
* This is a potential contention when HiveServer2 using embedded metastore and Metastore
* Server try to concurrently invoke createDefaultDB. If one failed, JDOException was caught
* for one more time try, if failed again, simply ignored by warning, which meant another
* succeeds.
*
* @throws MetaException
*/
private void createDefaultDB() throws MetaException {
try {
RawStore ms = getMS();
createDefaultCatalog(ms, wh);
createDefaultDB_core(ms);
} catch (JDOException e) {
LOG.warn("Retrying creating default database after error: " + e.getMessage(), e);
try {
RawStore ms = getMS();
createDefaultCatalog(ms, wh);
createDefaultDB_core(ms);
} catch (InvalidObjectException | InvalidOperationException e1) {
throw new MetaException(e1.getMessage());
}
} catch (InvalidObjectException | InvalidOperationException e) {
throw new MetaException(e.getMessage());
}
}
use of javax.jdo.JDOException in project datanucleus-api-jdo by datanucleus.
the class JDOQLTypedQueryImpl method parameter.
/* (non-Javadoc)
* @see javax.jdo.JDOQLTypedQuery#parameter(java.lang.String, java.lang.Class)
*/
public <P> Expression<P> parameter(String name, Class<P> type) {
assertIsOpen();
discardCompiled();
ExpressionImpl paramExpr = null;
if (type == Boolean.class || type == boolean.class) {
paramExpr = new BooleanExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == Byte.class || type == byte.class) {
paramExpr = new ByteExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == Character.class || type == char.class) {
paramExpr = new CharacterExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == Double.class || type == double.class) {
paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == Float.class || type == float.class) {
paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == Integer.class || type == int.class) {
paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == Long.class || type == long.class) {
paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == Short.class || type == short.class) {
paramExpr = new NumericExpressionImpl(type, name, ExpressionType.PARAMETER);
} else if (type == String.class) {
paramExpr = new StringExpressionImpl((Class<String>) type, name, ExpressionType.PARAMETER);
} else if (Time.class.isAssignableFrom(type)) {
paramExpr = new TimeExpressionImpl((Class<Time>) type, name, ExpressionType.PARAMETER);
} else if (Date.class.isAssignableFrom(type)) {
paramExpr = new DateExpressionImpl((Class<Date>) type, name, ExpressionType.PARAMETER);
} else if (java.util.Date.class.isAssignableFrom(type)) {
paramExpr = new DateTimeExpressionImpl((Class<java.util.Date>) type, name, ExpressionType.PARAMETER);
} else if (ec.getApiAdapter().isPersistable(type)) {
// Persistable class
String typeName = type.getName();
int pos = typeName.lastIndexOf('.');
String qName = typeName.substring(0, pos + 1) + getQueryClassNameForClassName(typeName.substring(pos + 1));
try {
Class qClass = ec.getClassLoaderResolver().classForName(qName);
Constructor ctr = qClass.getConstructor(new Class[] { Class.class, String.class, ExpressionType.class });
Object candObj = ctr.newInstance(new Object[] { type, name, ExpressionType.PARAMETER });
paramExpr = (ExpressionImpl) candObj;
} catch (NoSuchMethodException nsme) {
throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
} catch (IllegalAccessException iae) {
throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
} catch (InvocationTargetException ite) {
throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
} catch (InstantiationException ie) {
throw new JDOException("Class " + typeName + " has a Query class but has no constructor for parameters");
}
} else {
paramExpr = new ObjectExpressionImpl(type, name, ExpressionType.PARAMETER);
}
if (parameterExprByName == null) {
parameterExprByName = new ConcurrentHashMap<>();
}
parameterExprByName.put(name, paramExpr);
return paramExpr;
}
Aggregations