public int compareVersion(Object v1, Object v2) { if (v1 == v2) return StoreManager.VERSION_SAME; if (v1 == null || v2 == null) return StoreManager.VERSION_DIFFERENT; int cmp = compare(v1, v2); if (cmp < 0) return StoreManager.VERSION_EARLIER; if (cmp > 0) return StoreManager.VERSION_LATER; return StoreManager.VERSION_SAME; }
public int compareVersion(Object v1, Object v2) { if (v1 == v2) return StoreManager.VERSION_SAME; if (v1 == null || v2 == null) return StoreManager.VERSION_DIFFERENT; int cmp = compare(v1, v2); if (cmp < 0) return StoreManager.VERSION_EARLIER; if (cmp > 0) return StoreManager.VERSION_LATER; return StoreManager.VERSION_SAME; }
public int compareVersion(Object v1, Object v2) { if (v1 == v2) return StoreManager.VERSION_SAME; if (v1 == null || v2 == null) return StoreManager.VERSION_DIFFERENT; int cmp = compare(v1, v2); if (cmp < 0) return StoreManager.VERSION_EARLIER; if (cmp > 0) return StoreManager.VERSION_LATER; return StoreManager.VERSION_SAME; } }
public int compareVersion(Object v1, Object v2) { if (v1 == v2) return StoreManager.VERSION_SAME; if (v1 == null || v2 == null) return StoreManager.VERSION_DIFFERENT; int cmp = compare(v1, v2); if (cmp < 0) return StoreManager.VERSION_EARLIER; if (cmp > 0) return StoreManager.VERSION_LATER; return StoreManager.VERSION_SAME; }
public int compareVersion(Object v1, Object v2) { if (v1 == v2) return StoreManager.VERSION_SAME; if (v1 == null || v2 == null) return StoreManager.VERSION_DIFFERENT; int cmp = compare(v1, v2); if (cmp < 0) return StoreManager.VERSION_EARLIER; if (cmp > 0) return StoreManager.VERSION_LATER; return StoreManager.VERSION_SAME; }
/** * Compare each element of the given arrays that must be of equal size. * The given array values represent version values and the result designate * whether first version is earlier, same or later than the second one. * * @return If any element of a1 is later than corresponding element of * a2 then returns 1 i.e. the first version is later than the second * version. If each element of a1 is equal to corresponding element of a2 * then return 0 i.e. the first version is same as the second version. * else return a negative number i.e. the first version is earlier than * the second version. */ protected int compare(Object[] a1, Object[] a2) { if (a1.length != a2.length) throw new InternalException(); int total = 0; for (int i = 0; i < a1.length; i++) { int c = compare(a1[i], a2[i]); if (c > 0) return 1; total += c; } return total; }
/** * Compare each element of the given arrays that must be of equal size. * The given array values represent version values and the result designate * whether first version is earlier, same or later than the second one. * * @return If any element of a1 is later than corresponding element of * a2 then returns 1 i.e. the first version is later than the second * version. If each element of a1 is equal to corresponding element of a2 * then return 0 i.e. the first version is same as the second version. * else return a negative number i.e. the first version is earlier than * the second version. */ protected int compare(Object[] a1, Object[] a2) { if (a1.length != a2.length) throw new InternalException(); int total = 0; for (int i = 0; i < a1.length; i++) { int c = compare(a1[i], a2[i]); if (c > 0) return 1; total += c; } return total; }
/** * Compare each element of the given arrays that must be of equal size. * The given array values represent version values and the result designate * whether first version is earlier, same or later than the second one. * * @return If any element of a1 is later than corresponding element of * a2 then returns 1 i.e. the first version is later than the second * version. If each element of a1 is equal to corresponding element of a2 * then return 0 i.e. the first version is same as the second version. * else return a negative number i.e. the first version is earlier than * the second version. */ protected int compare(Object[] a1, Object[] a2) { if (a1.length != a2.length) throw new InternalException(); int total = 0; for (int i = 0; i < a1.length; i++) { int c = compare(a1[i], a2[i]); if (c > 0) return 1; total += c; } return total; }
/** * Compare the two versions. Defaults to assuming the version objects * implement {@link Comparable}. * * @see Comparator#compare */ protected int compare(Object v1, Object v2) { if (v1 == v2) return 0; if (v1 == null) return -1; if (v2 == null) return 1; if (v1.getClass().isArray()) { if (!v2.getClass().isArray()) throw new InternalException(); return compare((Object[])v1, (Object[])v2); } if (v1.getClass() != v2.getClass()) { if (v1 instanceof Number && !(v1 instanceof BigDecimal)) v1 = new BigDecimal(((Number) v1).doubleValue()); if (v2 instanceof Number && !(v2 instanceof BigDecimal)) v2 = new BigDecimal(((Number) v2).doubleValue()); } return ((Comparable) v1).compareTo(v2); }
/** * Compare the two versions. Defaults to assuming the version objects * implement {@link Comparable}. * * @see Comparator#compare */ protected int compare(Object v1, Object v2) { if (v1 == v2) return 0; if (v1 == null) return -1; if (v2 == null) return 1; if (v1.getClass().isArray()) { if (!v2.getClass().isArray()) throw new InternalException(); return compare((Object[])v1, (Object[])v2); } if (v1.getClass() != v2.getClass()) { if (v1 instanceof Number && !(v1 instanceof BigDecimal)) v1 = new BigDecimal(((Number) v1).doubleValue()); if (v2 instanceof Number && !(v2 instanceof BigDecimal)) v2 = new BigDecimal(((Number) v2).doubleValue()); } return ((Comparable) v1).compareTo(v2); }
/** * Compare the two versions. Defaults to assuming the version objects * implement {@link Comparable}. * * @see Comparator#compare */ protected int compare(Object v1, Object v2) { if (v1 == v2) return 0; if (v1 == null) return -1; if (v2 == null) return 1; if (v1.getClass().isArray()) { if (!v2.getClass().isArray()) throw new InternalException(); return compare((Object[])v1, (Object[])v2); } if (v1.getClass() != v2.getClass()) { if (v1 instanceof Number && !(v1 instanceof BigDecimal)) v1 = new BigDecimal(((Number) v1).doubleValue()); if (v2 instanceof Number && !(v2 instanceof BigDecimal)) v2 = new BigDecimal(((Number) v2).doubleValue()); } return ((Comparable) v1).compareTo(v2); }
/** * Compare each element of the given arrays that must be of equal size. * The given array values represent version values and the result designate * whether first version is earlier, same or later than the second one. * * @return If any element of a1 is later than corresponding element of * a2 then returns 1 i.e. the first version is later than the second * version. If each element of a1 is equal to corresponding element of a2 * then return 0 i.e. the first version is same as the second version. * else return a negative number i.e. the first version is earlier than * the second version. */ protected int compare(Object[] a1, Object[] a2) { if (a1.length != a2.length) throw new InternalException(); int total = 0; for (int i = 0; i < a1.length; i++) { int c = compare(a1[i], a2[i]); if (c > 0) return 1; total += c; } return total; }
/** * Compare the two versions. Defaults to assuming the version objects * implement {@link Comparable}. * * @see Comparator#compare */ protected int compare(Object v1, Object v2) { if (v1 == v2) return 0; if (v1 == null) return -1; if (v2 == null) return 1; if (v1.getClass().isArray()) { if (!v2.getClass().isArray()) throw new InternalException(); return compare((Object[])v1, (Object[])v2); } if (v1.getClass() != v2.getClass()) { if (v1 instanceof Number && !(v1 instanceof BigDecimal)) v1 = new BigDecimal(((Number) v1).doubleValue()); if (v2 instanceof Number && !(v2 instanceof BigDecimal)) v2 = new BigDecimal(((Number) v2).doubleValue()); } return ((Comparable) v1).compareTo(v2); }
mem = ((Object[]) memVersion)[i]; if (mem == null || (db != null && compare(mem, db) < 0)) refresh = true;
public boolean checkVersion(OpenJPAStateManager sm, JDBCStore store, boolean updateVersion) throws SQLException { Column[] cols = vers.getColumns(); Select sel = store.getSQLFactory().newSelect(); sel.select(cols); sel.wherePrimaryKey(sm.getObjectId(), vers.getClassMapping(), store); // No need to lock version field (i.e. optimistic), except when version update is required (e.g. refresh) JDBCFetchConfiguration fetch = store.getFetchConfiguration(); if (!updateVersion && fetch.getReadLockLevel() >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { fetch = (JDBCFetchConfiguration) fetch.clone(); fetch.setReadLockLevel(MixedLockLevels.LOCK_NONE); } Result res = sel.execute(store, fetch); try { if (!res.next()) return false; Object memVersion = sm.getVersion(); Object dbVersion = populateFromResult(res, null); boolean refresh = compare(memVersion, dbVersion) < 0; if (updateVersion) sm.setVersion(dbVersion); return !refresh; } finally { res.close(); } }
public boolean checkVersion(OpenJPAStateManager sm, JDBCStore store, boolean updateVersion) throws SQLException { Column[] cols = vers.getColumns(); Select sel = store.getSQLFactory().newSelect(); sel.select(cols); sel.wherePrimaryKey(sm.getObjectId(), vers.getClassMapping(), store); // No need to lock version field (i.e. optimistic), except when version update is required (e.g. refresh) JDBCFetchConfiguration fetch = store.getFetchConfiguration(); if (!updateVersion && fetch.getReadLockLevel() >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { fetch = (JDBCFetchConfiguration) fetch.clone(); fetch.setReadLockLevel(MixedLockLevels.LOCK_NONE); } Result res = sel.execute(store, fetch); try { if (!res.next()) return false; Object memVersion = sm.getVersion(); Object dbVersion = populateFromResult(res, null); boolean refresh = compare(memVersion, dbVersion) < 0; if (updateVersion) sm.setVersion(dbVersion); return !refresh; } finally { res.close(); } }
public boolean checkVersion(OpenJPAStateManager sm, JDBCStore store, boolean updateVersion) throws SQLException { Column[] cols = vers.getColumns(); Select sel = store.getSQLFactory().newSelect(); sel.select(cols); sel.wherePrimaryKey(sm.getObjectId(), vers.getClassMapping(), store); // No need to lock version field (i.e. optimistic), except when version update is required (e.g. refresh) JDBCFetchConfiguration fetch = store.getFetchConfiguration(); if (!updateVersion && fetch.getReadLockLevel() >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { fetch = (JDBCFetchConfiguration) fetch.clone(); fetch.setReadLockLevel(MixedLockLevels.LOCK_NONE); } Result res = sel.execute(store, fetch); try { if (!res.next()) return false; Object memVersion = sm.getVersion(); Object dbVersion = populateFromResult(res, null); boolean refresh = compare(memVersion, dbVersion) < 0; if (updateVersion) sm.setVersion(dbVersion); return !refresh; } finally { res.close(); } }
public boolean checkVersion(OpenJPAStateManager sm, JDBCStore store, boolean updateVersion) throws SQLException { Column[] cols = vers.getColumns(); Select sel = store.getSQLFactory().newSelect(); sel.select(cols); sel.wherePrimaryKey(sm.getObjectId(), vers.getClassMapping(), store); // No need to lock version field (i.e. optimistic), except when version update is required (e.g. refresh) JDBCFetchConfiguration fetch = store.getFetchConfiguration(); if (!updateVersion && fetch.getReadLockLevel() >= MixedLockLevels.LOCK_PESSIMISTIC_READ) { fetch = (JDBCFetchConfiguration) fetch.clone(); fetch.setReadLockLevel(MixedLockLevels.LOCK_NONE); } Result res = sel.execute(store, fetch); try { if (!res.next()) return false; Object memVersion = sm.getVersion(); Object dbVersion = populateFromResult(res, null); boolean refresh = compare(memVersion, dbVersion) < 0; if (updateVersion) sm.setVersion(dbVersion); return !refresh; } finally { res.close(); } }