/** * Convert the user-given hint value to an aggregate listener. * The hint can be an aggregate listener instance or class name. */ public static AggregateListener hintToAggregateListener(Object hint, ClassLoader loader) { if (hint == null) return null; if (hint instanceof AggregateListener) return (AggregateListener) hint; Exception cause = null; if (hint instanceof String) { try { return (AggregateListener) AccessController.doPrivileged( J2DoPrivHelper.newInstanceAction(Class.forName((String) hint, true, loader))); } catch (Exception e) { if (e instanceof PrivilegedActionException) e = ((PrivilegedActionException) e).getException(); cause = e; } } throw new UserException(_loc.get("bad-agg-listener-hint", hint, hint.getClass())).setCause(cause); }
/** * Throw an exception indicating that the current action can't be * performed on a detached object. */ private OpenJPAException newDetachedException(Object obj, String operation) { throw new UserException(_loc.get("bad-detached-op", operation, Exceptions.toString(obj))).setFailedObject(obj); }
/** * Make the given member accessible if it isn't already. */ private static void makeAccessible(AccessibleObject ao, int mods) { try { if (!Modifier.isPublic(mods) && !ao.isAccessible()) AccessController.doPrivileged(J2DoPrivHelper .setAccessibleAction(ao, true)); } catch (SecurityException se) { throw new UserException(_loc.get("reflect-security", ao)). setFatal(true); } }
/** * Throw all gathered exceptions. */ private void throwExceptions(List exceps) { if (exceps == null) return; if (exceps.size() == 1) throw (RuntimeException) exceps.get(0); throw new UserException(_loc.get("nested-exceps")). setNestedThrowables((Throwable[]) exceps.toArray (new Throwable[exceps.size()])); }
private Object newListener(Class<?> cls) { try { return AccessController.doPrivileged( J2DoPrivHelper.newInstanceAction(cls)); } catch (Throwable t) { if (t instanceof PrivilegedActionException) t = ((PrivilegedActionException) t).getException(); throw new UserException(_loc.get("bean-constructor", cls.getName()), t); } }
/** * Set of semicolon-separated {@link URL}s of metadata files or jars * supplied by user via auto-configuration. */ public void setURLs(String urls) { if (StringUtils.isEmpty(urls)) this.urls = null; else { String[] strs = Strings.split(urls, ";", 0); this.urls = new HashSet<URL>((int) (strs.length * 1.33 + 1)); try { for (int i = 0; i < strs.length; i++) this.urls.add(new URL(strs[i])); } catch (MalformedURLException mue) { throw new UserException(mue); } } }
/** * Used by proxy types to check that an attempt to add a new value is legal. */ public static void assertAllowedType(Object value, Class allowed) { if (value != null && allowed != null && !allowed.isInstance(value)) { throw new UserException(_loc.get("bad-elem-type", new Object[]{ AccessController.doPrivileged( J2DoPrivHelper.getClassLoaderAction(allowed)), allowed, AccessController.doPrivileged( J2DoPrivHelper.getClassLoaderAction(value.getClass())), value.getClass() })); } }
void error(ClassMetaData meta, Localizer.Message message) { Log log = meta.getRepository().getConfiguration() .getLog(OpenJPAConfiguration.LOG_RUNTIME); log.error(message.toString()); throw new UserException(message.toString()); }
public void dirty(String field) { FieldMetaData fmd = _meta.getField(field); if (fmd == null) throw translate(new UserException(_loc.get("no-field", field, ImplHelper.getManagedInstance(_pc).getClass())) .setFailedObject(getManagedInstance())); dirty(fmd.getIndex(), null, true); }
@Override public void initialize() { OpenJPAConfiguration conf = (OpenJPAConfiguration)getProvider().getConfiguration(); PreparedQueryCache pqc = conf.getQuerySQLCacheInstance(); if (pqc == null) { throw new UserException(_loc.get("prep-query-cache-not-found")); } setPreparedQueryCache(pqc); setConfigId(conf.getId()); setContextRef(Integer.toString(System.identityHashCode(getContext()))); }
public static int mergeFieldCode(ClassMetaData meta, FieldMetaData fmd, int fCode) { int cCode = meta.getAccessType(); try { return mergeFieldCode(cCode, fCode); } catch (IllegalStateException e) { throw new UserException(_loc.get("access-illegal-merge", fmd.getFullName(false), toFieldString(fCode), toClassString(cCode))); } }
@Override public void initialize() { OpenJPAConfiguration conf = (OpenJPAConfiguration)getProvider().getConfiguration(); DataCacheManager dcm = conf.getDataCacheManagerInstance(); QueryCache qc = dcm.getSystemQueryCache(); if (qc == null) { throw new UserException(_loc.get("query-cache-not-found")); } setQueryCache(qc); setConfigId(conf.getId()); setContextRef(Integer.toString(System.identityHashCode(getContext()))); }
static OpenJPAException newConnectException(JDBCConfiguration conf, boolean factory2, Exception cause) { return new UserException(_eloc.get("poolds-null", factory2 ? new Object[]{conf.getConnection2DriverName(), conf.getConnection2URL()} : new Object[]{conf.getConnectionDriverName(), conf.getConnectionURL()}), cause).setFatal(true); }
/** * Return a broker configured with the proper settings. * By default, this method constructs a new * BrokerImpl of the class set for this factory. */ protected BrokerImpl newBrokerImpl(String user, String pass) { BrokerImpl broker = _conf.newBrokerInstance(user, pass); if (broker == null) throw new UserException(_loc.get("no-broker-class", _conf.getBrokerImpl())); return broker; }
/** * Set the value of the property named by the hint key. */ public static void hintToSetter(Object target, String hintKey, Object value) { if (target == null || hintKey == null) return; Method setter = Reflection.findSetter(target.getClass(), hintKey, true); if (value instanceof String) { if ("null".equals(value)) value = null; else { try { value = StringUtil.parse((String) value, setter.getParameterTypes()[0]); } catch (Exception e) { throw new UserException(_loc.get("bad-setter-hint-arg", hintKey, value, setter.getParameterTypes()[0])). setCause(e); } } } Reflection.set(target, setter, value); }
/** * Constructor; supply id, type metadata, and owning persistence manager. */ protected StateManagerImpl(Object id, ClassMetaData meta, BrokerImpl broker) { _id = id; _meta = meta; _broker = broker; _single = new SingleFieldManager(this, broker); if (broker.getMultithreaded()) _instanceLock = new ReentrantLock(); if (_meta.getIdentityType() == ClassMetaData.ID_UNKNOWN && !_meta.isEmbeddable()) throw new UserException(_loc.get("meta-unknownid", _meta)); }
public void setNontransactionalRead(boolean val) { assertOpen(); if ((_flags & FLAG_PRESTORING) != 0) throw new UserException(_loc.get("illegal-op-in-prestore")); // make sure the runtime supports it if (val && !_conf.supportedOptions().contains (OpenJPAConfiguration.OPTION_NONTRANS_READ)) throw new UnsupportedException(_loc.get ("nontrans-read-not-supported")); _nontransRead = val; }
} catch (UserException ue) { invalidatePreparedQuery(); Log log = _em.getConfiguration().getLog(OpenJPAConfiguration.LOG_RUNTIME); if (log.isWarnEnabled()) log.warn(ue.getMessage()); return false;
/** * Constructor; supply id, type metadata, and owning persistence manager. */ protected StateManagerImpl(Object id, ClassMetaData meta, BrokerImpl broker) { _id = id; _meta = meta; _broker = broker; _single = new SingleFieldManager(this, broker); if (_meta.getIdentityType() == ClassMetaData.ID_UNKNOWN) throw new UserException(_loc.get("meta-unknownid", _meta)); }
@ExceptionHandler(UserException.class) public ModelAndView handleUserException(UserException e) { ModelAndView modelAndView = new ModelAndView("viewName"); modelAndView.addObject("errorMessage", e.getMessage()); return modelAndView; }