/** * Throw exception for failures. */ private void throwExceptions(List exceps, List failed, boolean opt) { if (exceps == null) return; if (exceps.size() == 1) throw (RuntimeException) exceps.get(0); Throwable[] t = (Throwable[]) exceps.toArray (new Throwable[exceps.size()]); if (opt && failed != null) throw new OptimisticException(failed, t); if (opt) throw new OptimisticException(t); throw new UserException(_loc.get("nested-exceps")). setNestedThrowables(t); }
/** * Throw exception for failures. */ private void throwExceptions(List exceps, List failed, boolean opt) { if (exceps == null) return; if (exceps.size() == 1) throw (RuntimeException) exceps.get(0); Throwable[] t = (Throwable[]) exceps.toArray (new Throwable[exceps.size()]); if (opt && failed != null) throw new OptimisticException(failed, t); if (opt) throw new OptimisticException(t); throw new UserException(_loc.get("nested-exceps")). setNestedThrowables(t); }
/** * Throw exception for failures. */ private void throwExceptions(List exceps, List failed, boolean opt) { if (exceps == null) return; if (exceps.size() == 1) throw (RuntimeException) exceps.get(0); Throwable[] t = (Throwable[]) exceps.toArray (new Throwable[exceps.size()]); if (opt && failed != null) throw new OptimisticException(failed, t); if (opt) throw new OptimisticException(t); throw new UserException(_loc.get("nested-exceps")). setNestedThrowables(t); }
/** * Throw exception for failures. */ private void throwExceptions(List exceps, List failed, boolean opt) { if (exceps == null) return; if (exceps.size() == 1) throw (RuntimeException) exceps.get(0); Throwable[] t = (Throwable[]) exceps.toArray (new Throwable[exceps.size()]); if (opt && failed != null) throw new OptimisticException(failed, t); if (opt) throw new OptimisticException(t); throw new UserException(_loc.get("nested-exceps")). setNestedThrowables(t); }
/** * Throw exception for failures. */ private void throwExceptions(List exceps, List failed, boolean opt) { if (exceps == null) return; if (exceps.size() == 1) throw (RuntimeException) exceps.get(0); Throwable[] t = (Throwable[]) exceps.toArray (new Throwable[exceps.size()]); if (opt && failed != null) throw new OptimisticException(failed, t); if (opt) throw new OptimisticException(t); throw new UserException(_loc.get("nested-exceps")). setNestedThrowables(t); }
/** * Throw the proper exception based on the given set of flush errors, or * do nothing if no errors occurred. */ private OpenJPAException newFlushException(Collection exceps) { if (exceps == null || exceps.isEmpty()) return null; Throwable[] t = (Throwable[]) exceps.toArray (new Throwable[exceps.size()]); List failed = new ArrayList(t.length); // create fatal exception with nested exceptions for all the failed // objects; if all OL exceptions, throw a top-level OL exception boolean opt = true; for (int i = 0; opt && i < t.length; i++) { opt = t[i] instanceof OptimisticException; if (opt) { Object f = ((OptimisticException) t[i]).getFailedObject(); if (f != null) failed.add(f); } } if (opt && !failed.isEmpty()) return new OptimisticException(failed, t); if (opt) return new OptimisticException(t); return new StoreException(_loc.get("rolled-back")). setNestedThrowables(t).setFatal(true); }
private void flushSingleRow(RowImpl row, PreparedStatement ps) throws SQLException { row.flush(ps, _dict, _store); int count = ps.executeUpdate(); if (count != 1) { Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get("update-failed-no-failed-obj", String.valueOf(count), row.getSQL(_dict)).getMessage()); } }
return new OptimisticException(_loc.get("broker-suppressing-exceptions",t.length)); }else{ return new OptimisticException(failed, t); return new OptimisticException(t);
private void flushSingleRow(RowImpl row, PreparedStatement ps) throws SQLException { if (ps != null) row.flush(ps, _dict, _store); int count = executeUpdate(ps, row.getSQL(_dict), row); if (count != 1) { logSQLWarnings(ps); Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get("update-failed-no-failed-obj", String.valueOf(count), row.getSQL(_dict)).getMessage()); } }
private void flushSingleRow(RowImpl row, PreparedStatement ps) throws SQLException { if (ps != null) row.flush(ps, _dict, _store); int count = executeUpdate(ps, row.getSQL(_dict), row); if (count != 1) { logSQLWarnings(ps); Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get("update-failed-no-failed-obj", String.valueOf(count), row.getSQL(_dict)).getMessage()); } }
private void flushSingleRow(RowImpl row, PreparedStatement ps) throws SQLException { if (ps != null) row.flush(ps, _dict, _store); int count = executeUpdate(ps, row.getSQL(_dict), row); if (count != 1) { logSQLWarnings(ps); Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get("update-failed-no-failed-obj", String.valueOf(count), row.getSQL(_dict)).getMessage()); } }
private void flushSingleRow(RowImpl row, PreparedStatement ps) throws SQLException { if (ps != null) row.flush(ps, _dict, _store); int count = executeUpdate(ps, row.getSQL(_dict), row); if (count != 1) { logSQLWarnings(ps); Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get("update-failed-no-failed-obj", String.valueOf(count), row.getSQL(_dict)).getMessage()); } }
/** * Narrows the given SQLException to a specific type of * {@link StoreException#getSubtype() StoreException} by analyzing the * SQLState code supplied by SQLException. Each database-specific * {@link DBDictionary dictionary} can supply a set of error codes that will * map to a specific specific type of StoreException via * {@link DBDictionary#getSQLStates(int) getSQLStates()} method. * The default behavior is to return generic {@link StoreException * StoreException}. */ public static OpenJPAException narrow(String msg, SQLException se, DBDictionary dict) { String e = se.getSQLState(); if (dict.getSQLStates(StoreException.LOCK).contains(e)) return new LockException(msg); else if (dict.getSQLStates(StoreException.OBJECT_EXISTS).contains(e)) return new ObjectExistsException(msg); else if (dict.getSQLStates(StoreException.OBJECT_NOT_FOUND).contains(e)) return new ObjectNotFoundException(msg); else if (dict.getSQLStates(StoreException.OPTIMISTIC).contains(e)) return new OptimisticException(msg); else if (dict.getSQLStates(StoreException.REFERENTIAL_INTEGRITY) .contains(e)) return new ReferentialIntegrityException(msg); else return new StoreException(msg); } }
failed = row.getFailedObject(); if (failed != null || row.getAction() == Row.ACTION_UPDATE) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get(
Object failed = row.getFailedObject(); if (failed != null) _exceptions.add(new OptimisticException(failed)); else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get(
/** * Make sure the version information is correct in the detached object. */ private void compareVersion(StateManagerImpl sm, PersistenceCapable pc) { Object version = pc.pcGetVersion(); if (version == null) return; // don't need to load unloaded fields since its implicitly // a single field value StoreManager store = sm.getBroker().getStoreManager(); switch (store.compareVersion(sm, version, sm.getVersion())) { case StoreManager.VERSION_LATER: // we have a later version: set it into the object. // lock validation will occur at commit time sm.setVersion(version); break; case StoreManager.VERSION_EARLIER: case StoreManager.VERSION_DIFFERENT: sm.setVersion(version); throw new OptimisticException(sm.getManagedInstance()); case StoreManager.VERSION_SAME: // no action required break; } }
protected void optimisticLockInternal(OpenJPAStateManager sm, int level, int timeout, Object sdata, boolean postLockVersionCheck) { super.optimisticLockInternal(sm, level, timeout, sdata, postLockVersionCheck); if (postLockVersionCheck) { if (level >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { ClassMapping mapping = (ClassMapping) sm.getMetaData(); try { if (!mapping.getVersion().checkVersion(sm, this.getStore(), false)) { throw (new OptimisticException(_loc.get( "optimistic-violation-lock").getMessage())) .setFailedObject(sm.getObjectId()); } } catch (SQLException se) { throw SQLExceptions.getStore(se, sm.getObjectId(), getStore().getDBDictionary()); } } } }
protected void optimisticLockInternal(OpenJPAStateManager sm, int level, int timeout, Object sdata, boolean postLockVersionCheck) { super.optimisticLockInternal(sm, level, timeout, sdata, postLockVersionCheck); if (postLockVersionCheck) { if (level >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { ClassMapping mapping = (ClassMapping) sm.getMetaData(); try { if (!mapping.getVersion().checkVersion(sm, this.getStore(), false)) { throw (new OptimisticException(_loc.get( "optimistic-violation-lock").getMessage())) .setFailedObject(sm.getObjectId()); } } catch (SQLException se) { throw SQLExceptions.getStore(se, sm.getObjectId(), getStore().getDBDictionary()); } } } }
protected void optimisticLockInternal(OpenJPAStateManager sm, int level, int timeout, Object sdata, boolean postLockVersionCheck) { super.optimisticLockInternal(sm, level, timeout, sdata, postLockVersionCheck); if (postLockVersionCheck) { if (level >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { ClassMapping mapping = (ClassMapping) sm.getMetaData(); try { if (!mapping.getVersion().checkVersion(sm, this.getStore(), false)) { throw (new OptimisticException(_loc.get( "optimistic-violation-lock").getMessage())) .setFailedObject(sm.getObjectId()); } } catch (SQLException se) { throw SQLExceptions.getStore(se, sm.getObjectId(), getStore().getDBDictionary()); } } } }
protected void optimisticLockInternal(OpenJPAStateManager sm, int level, int timeout, Object sdata, boolean postLockVersionCheck) { super.optimisticLockInternal(sm, level, timeout, sdata, postLockVersionCheck); if (postLockVersionCheck) { if (level >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { ClassMapping mapping = (ClassMapping) sm.getMetaData(); try { if (!mapping.getVersion().checkVersion(sm, this.getStore(), false)) { throw (new OptimisticException(_loc.get( "optimistic-violation-lock").getMessage())) .setFailedObject(sm.getObjectId()); } } catch (SQLException se) { throw SQLExceptions.getStore(se, sm.getObjectId(), getStore().getDBDictionary()); } } } }