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 Object load(OpenJPAStateManager sm, JDBCStore store, Result res, Joins joins) throws SQLException { // typically if one version column is in the result, they all are, so // optimize by checking for the first one before doing any real work Column[] cols = vers.getColumns(); if (!res.contains(cols[0], joins)) { return null; } Object version = populateFromResult(res, joins); // OPENJPA-662 Allow a null StateManager because this method may just be // invoked to get the result of projection query if (sm != null) { sm.setVersion(version); } return version; }
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); if (cols == null || cols.length == 0 || !sm.isDirty() && !sm.isVersionUpdateRequired()) return; Object curVersion = sm.getVersion(); Object nextVersion = nextVersion(curVersion); // set where and update conditions on row for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_UPDATE, sm, true); row.setFailedObject(sm.getManagedInstance()); if (curVersion != null && sm.isVersionCheckRequired()) { row.whereObject(cols[i], getColumnValue(curVersion, i)); if (isSecondaryColumn(cols[i], sm)) { ForeignKey[] fks = cols[i].getTable().getForeignKeys(); for (ForeignKey fk : fks) { row.whereForeignKey(fk, sm); } } } if (vers.getColumnIO().isUpdatable(i, nextVersion == null)) row.setObject(cols[i], getColumnValue(nextVersion, i)); } if (nextVersion != null) sm.setNextVersion(nextVersion); }
public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); ColumnIO io = vers.getColumnIO(); Object initial = nextVersion(null); for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_INSERT, sm, true); if (io.isInsertable(i, initial == null)) row.setObject(cols[i], getColumnValue(initial, i)); } // set initial version into state manager Object nextVersion; nextVersion = initial; sm.setNextVersion(nextVersion); }
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 void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); Object curVersion = sm.getVersion(); Object cur; for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_DELETE, sm, true); row.setFailedObject(sm.getManagedInstance()); cur = getColumnValue(curVersion, i); // set where and update conditions on row if (cur != null) { row.whereObject(cols[i], cur); if (isSecondaryColumn(cols[i], sm)) { ForeignKey[] fks = cols[i].getTable().getForeignKeys(); for (ForeignKey fk : fks) { row.whereForeignKey(fk, sm); } } } } }
templates[i].setSize(infoColumn.getSize()); templates[i].setDecimalDigits(infoColumn.getDecimalDigits()); templates[i].setJavaType(getJavaType(i)); templates[i].setIdentifier(infoColumn.getIdentifier()); } else { Column tmplate = new Column(); tmplate.setJavaType(getJavaType()); DBDictionary dict = vers.getMappingRepository().getDBDictionary(); DBIdentifier versName = DBIdentifier.newColumn("versn", dict != null ? dict.delimitAll() : false);
/** * Return the code from {@link JavaTypes} for the version value this given * column index uses. Only used if the version strategy employs more than * one column. */ protected int getJavaType(int i) { throw new AbstractMethodError(_loc.get( "multi-column-version-unsupported",getAlias()).toString()); }
public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); ColumnIO io = vers.getColumnIO(); Object initial = nextVersion(null); Row row = rm.getRow(vers.getClassMapping().getTable(), Row.ACTION_INSERT, sm, true); for (int i = 0; i < cols.length; i++) if (io.isInsertable(i, initial == null)) row.setObject(cols[i], initial); // set initial version into state manager Object nextVersion; nextVersion = initial; sm.setNextVersion(nextVersion); }
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); if (cols == null || cols.length == 0 || !sm.isDirty() && !sm.isVersionUpdateRequired()) return; Object curVersion = sm.getVersion(); Object nextVersion = nextVersion(curVersion); // set where and update conditions on row for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_UPDATE, sm, true); row.setFailedObject(sm.getManagedInstance()); if (curVersion != null && sm.isVersionCheckRequired()) { row.whereObject(cols[i], getColumnValue(curVersion, i)); if (isSecondaryColumn(cols[i], sm)) { ForeignKey[] fks = cols[i].getTable().getForeignKeys(); for (ForeignKey fk : fks) { row.whereForeignKey(fk, sm); } } } if (vers.getColumnIO().isUpdatable(i, nextVersion == null)) row.setObject(cols[i], getColumnValue(nextVersion, i)); } if (nextVersion != null) sm.setNextVersion(nextVersion); }
public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); ColumnIO io = vers.getColumnIO(); Object initial = nextVersion(null); for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_INSERT, sm, true); if (io.isInsertable(i, initial == null)) row.setObject(cols[i], getColumnValue(initial, i)); } // set initial version into state manager Object nextVersion; nextVersion = initial; sm.setNextVersion(nextVersion); }
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 void delete(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); Object curVersion = sm.getVersion(); Object cur; for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_DELETE, sm, true); row.setFailedObject(sm.getManagedInstance()); cur = getColumnValue(curVersion, i); // set where and update conditions on row if (cur != null) { row.whereObject(cols[i], cur); if (isSecondaryColumn(cols[i], sm)) { ForeignKey[] fks = cols[i].getTable().getForeignKeys(); for (ForeignKey fk : fks) { row.whereForeignKey(fk, sm); } } } } }
templates[i].setSize(infoColumn.getSize()); templates[i].setDecimalDigits(infoColumn.getDecimalDigits()); templates[i].setJavaType(getJavaType(i)); templates[i].setIdentifier(infoColumn.getIdentifier()); } else { Column tmplate = new Column(); tmplate.setJavaType(getJavaType()); DBDictionary dict = vers.getMappingRepository().getDBDictionary(); DBIdentifier versName = DBIdentifier.newColumn("versn", dict != null ? dict.delimitAll() : false);
/** * Return the code from {@link JavaTypes} for the version value this given * column index uses. Only used if the version strategy employs more than * one column. */ protected int getJavaType(int i) { throw new AbstractMethodError(_loc.get( "multi-column-version-unsupported",getAlias()).toString()); }
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); if (cols == null || cols.length == 0 || !sm.isDirty() && !sm.isVersionUpdateRequired()) return; Object curVersion = sm.getVersion(); Object nextVersion = nextVersion(curVersion); Row row = rm.getRow(vers.getClassMapping().getTable(), Row.ACTION_UPDATE, sm, true); row.setFailedObject(sm.getManagedInstance()); // set where and update conditions on row for (int i = 0; i < cols.length; i++) { if (curVersion != null && sm.isVersionCheckRequired()) row.whereObject(cols[i], curVersion); if (vers.getColumnIO().isUpdatable(i, nextVersion == null)) row.setObject(cols[i], nextVersion); } if (nextVersion != null) sm.setNextVersion(nextVersion); }
public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); if (cols == null || cols.length == 0 || !sm.isDirty() && !sm.isVersionUpdateRequired()) return; Object curVersion = sm.getVersion(); Object nextVersion = nextVersion(curVersion); // set where and update conditions on row for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_UPDATE, sm, true); row.setFailedObject(sm.getManagedInstance()); if (curVersion != null && sm.isVersionCheckRequired()) { row.whereObject(cols[i], getColumnValue(curVersion, i)); if (isSecondaryColumn(cols[i], sm)) { ForeignKey[] fks = cols[i].getTable().getForeignKeys(); for (ForeignKey fk : fks) { row.whereForeignKey(fk, sm); } } } if (vers.getColumnIO().isUpdatable(i, nextVersion == null)) row.setObject(cols[i], getColumnValue(nextVersion, i)); } if (nextVersion != null) sm.setNextVersion(nextVersion); }
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 void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm) throws SQLException { Column[] cols = vers.getColumns(); ColumnIO io = vers.getColumnIO(); Object initial = nextVersion(null); for (int i = 0; i < cols.length; i++) { Row row = rm.getRow(cols[i].getTable(), Row.ACTION_INSERT, sm, true); if (io.isInsertable(i, initial == null)) row.setObject(cols[i], getColumnValue(initial, i)); } // set initial version into state manager Object nextVersion; nextVersion = initial; sm.setNextVersion(nextVersion); }
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(); } }