/** * Select the data for the given instance and return the result. Return * null if there is no data in the current fetch groups to select. */ private Result getInitializeStateResult(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch, int subs) throws SQLException { Select sel = _sql.newSelect(); if (!select(sel, mapping, subs, sm, null, fetch, JDBCFetchConfiguration.EAGER_JOIN, true, false)) return null; sel.wherePrimaryKey(sm.getObjectId(), mapping, this); sel.setExpectedResultCount(1, false); return sel.execute(this, fetch); }
public Result[] getResults(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode, Joins[] joins, boolean lrs) throws SQLException { Select sel = store.getSQLFactory().newSelect(); sel.setLRS(lrs); sel.select(_kcols); sel.select(_vcols); sel.whereForeignKey(field.getJoinForeignKey(), sm.getObjectId(), field.getDefiningMapping(), store); Result res = sel.execute(store, fetch); return new Result[]{ res, res }; }
public Result[] getResults(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode, Joins[] joins, boolean lrs) throws SQLException { Select sel = store.getSQLFactory().newSelect(); sel.setLRS(lrs); sel.select(_kcols); sel.select(_vcols); sel.whereForeignKey(field.getJoinForeignKey(), sm.getObjectId(), field.getDefiningMapping(), store); Result res = sel.execute(store, fetch); return new Result[]{ res, res }; }
public Result[] getResults(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode, Joins[] joins, boolean lrs) throws SQLException { Select sel = store.getSQLFactory().newSelect(); sel.setLRS(lrs); sel.select(_kcols); sel.select(_vcols); sel.whereForeignKey(field.getJoinForeignKey(), sm.getObjectId(), field.getDefiningMapping(), store); Result res = sel.execute(store, fetch); return new Result[]{ res, res }; }
public Result[] getResults(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode, Joins[] joins, boolean lrs) throws SQLException { Select sel = store.getSQLFactory().newSelect(); sel.setLRS(lrs); sel.select(_kcols); sel.select(_vcols); sel.whereForeignKey(field.getJoinForeignKey(), sm.getObjectId(), field.getDefiningMapping(), store); Result res = sel.execute(store, fetch); return new Result[]{ res, res }; }
public Result[] getResults(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode, Joins[] joins, boolean lrs) throws SQLException { Select sel = store.getSQLFactory().newSelect(); sel.setLRS(lrs); sel.select(_kcols); sel.select(_vcols); sel.whereForeignKey(field.getJoinForeignKey(), sm.getObjectId(), field.getDefiningMapping(), store); Result res = sel.execute(store, fetch); return new Result[]{ res, res }; }
public void load(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch) throws SQLException { Column col = field.getColumns()[0]; Select sel = store.getSQLFactory().newSelect(); sel.select(col); field.wherePrimaryKey(sel, sm, store); Result res = sel.execute(store, fetch); Object val = null; try { if (res.next()) val = load(col, res, null); } finally { res.close(); } sm.store(field.getIndex(), val); }
public void load(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch) throws SQLException { Column col = field.getColumns()[0]; Select sel = store.getSQLFactory().newSelect(); sel.select(col); field.wherePrimaryKey(sel, sm, store); Result res = sel.execute(store, fetch); Object val = null; try { if (res.next()) val = load(col, res, null); } finally { res.close(); } sm.store(field.getIndex(), val); }
public void load(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch) throws SQLException { Column col = field.getColumns()[0]; Select sel = store.getSQLFactory().newSelect(); sel.select(col); field.wherePrimaryKey(sel, sm, store); Result res = sel.execute(store, fetch); Object val = null; try { if (res.next()) val = load(col, res, null); } finally { res.close(); } sm.store(field.getIndex(), val); }
public void load(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch) throws SQLException { Column col = field.getColumns()[0]; Select sel = store.getSQLFactory().newSelect(); sel.select(col); field.wherePrimaryKey(sel, sm, store); Result res = sel.execute(store, fetch); Object val = null; try { if (res.next()) val = load(col, res, null); } finally { res.close(); } sm.store(field.getIndex(), val); }
public void load(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch) throws SQLException { Column col = field.getColumns()[0]; Select sel = store.getSQLFactory().newSelect(); sel.select(col); field.wherePrimaryKey(sel, sm, store); Result res = sel.execute(store, fetch); Object val = null; try { if (res.next()) val = load(col, res, null); } finally { res.close(); } sm.store(field.getIndex(), val); }
/** * Select the data for the given instance and return the result. Return * null if there is no data in the current fetch groups to select. */ private Result getInitializeStateResult(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch, int subs) throws SQLException { FinderQueryImpl fq = getFinder(mapping, fetch); if (fq != null) return fq.execute(sm, this, fetch); Select sel = _sql.newSelect(); if (!select(sel, mapping, subs, sm, null, fetch, JDBCFetchConfiguration.EAGER_JOIN, true, false)) return null; sel.wherePrimaryKey(sm.getObjectId(), mapping, this); sel.setExpectedResultCount(1, false); if (_log.isTraceEnabled()) { _log.trace("getInitializeStateResult: oid="+sm.getObjectId()+" "+mapping.getDescribedType()); } Result result = sel.execute(this, fetch); cacheFinder(mapping, sel, fetch); return result; }
/** * Select the data for the given instance and return the result. Return * null if there is no data in the current fetch groups to select. */ private Result getInitializeStateResult(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch, int subs) throws SQLException { FinderQueryImpl fq = getFinder(mapping, fetch); if (fq != null) return fq.execute(sm, this, fetch); Select sel = _sql.newSelect(); if (!select(sel, mapping, subs, sm, null, fetch, JDBCFetchConfiguration.EAGER_JOIN, true, false)) return null; sel.wherePrimaryKey(sm.getObjectId(), mapping, this); sel.setExpectedResultCount(1, false); if (_log.isTraceEnabled()) { _log.trace("getInitializeStateResult: oid="+sm.getObjectId()+" "+mapping.getDescribedType()); } Result result = sel.execute(this, fetch); cacheFinder(mapping, sel, fetch); return result; }
/** * Select the data for the given instance and return the result. Return * null if there is no data in the current fetch groups to select. */ private Result getInitializeStateResult(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch, int subs) throws SQLException { FinderQueryImpl fq = getFinder(mapping, fetch); if (fq != null) return fq.execute(sm, this, fetch); Select sel = _sql.newSelect(); if (!select(sel, mapping, subs, sm, null, fetch, JDBCFetchConfiguration.EAGER_JOIN, true, false)) return null; sel.wherePrimaryKey(sm.getObjectId(), mapping, this); sel.setExpectedResultCount(1, false); if (_log.isTraceEnabled()) { _log.trace("getInitializeStateResult: oid="+sm.getObjectId()+" "+mapping.getDescribedType()); } Result result = sel.execute(this, fetch); cacheFinder(mapping, sel, fetch); return result; }
/** * Select the data for the given instance and return the result. Return * null if there is no data in the current fetch groups to select. */ private Result getInitializeStateResult(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch, int subs) throws SQLException { FinderQueryImpl fq = getFinder(mapping, fetch); if (fq != null) return fq.execute(sm, this, fetch); Select sel = _sql.newSelect(); if (!select(sel, mapping, subs, sm, null, fetch, JDBCFetchConfiguration.EAGER_JOIN, true, false)) return null; sel.wherePrimaryKey(sm.getObjectId(), mapping, this); sel.setExpectedResultCount(1, false); if (_log.isTraceEnabled()) { _log.trace("getInitializeStateResult: oid="+sm.getObjectId()+" "+mapping.getDescribedType()); } Result result = sel.execute(this, fetch); cacheFinder(mapping, sel, fetch); return result; }
/** * Select primary key data to make sure the given instance exists, locking * if needed. */ private boolean selectPrimaryKey(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch) throws SQLException { // select pks from base class record to ensure it exists and lock // it if needed ClassMapping base = mapping; while (base.getJoinablePCSuperclassMapping() != null) base = base.getJoinablePCSuperclassMapping(); Select sel = _sql.newSelect(); sel.select(base.getPrimaryKeyColumns()); sel.wherePrimaryKey(sm.getObjectId(), base, this); if (_log.isTraceEnabled()) { _log.trace("selectPrimaryKey: oid="+sm.getObjectId()+" "+mapping.getDescribedType()); } Result exists = sel.execute(this, fetch); try { if (isEmptyResult(exists)) return false; // record locked? if (_active && _lm != null && exists.isLocking()) _lm.loadedForUpdate(sm); return true; } finally { exists.close(); } }
/** * Select primary key data to make sure the given instance exists, locking * if needed. */ private boolean selectPrimaryKey(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch) throws SQLException { // select pks from base class record to ensure it exists and lock // it if needed ClassMapping base = mapping; while (base.getJoinablePCSuperclassMapping() != null) base = base.getJoinablePCSuperclassMapping(); Select sel = _sql.newSelect(); sel.select(base.getPrimaryKeyColumns()); sel.wherePrimaryKey(sm.getObjectId(), base, this); if (_log.isTraceEnabled()) { _log.trace("selectPrimaryKey: oid="+sm.getObjectId()+" "+mapping.getDescribedType()); } Result exists = sel.execute(this, fetch); try { if (isEmptyResult(exists)) return false; // record locked? if (_active && _lm != null && exists.isLocking()) _lm.loadedForUpdate(sm); return true; } finally { exists.close(); } }
/** * Select primary key data to make sure the given instance exists, locking * if needed. */ private boolean selectPrimaryKey(OpenJPAStateManager sm, ClassMapping mapping, JDBCFetchConfiguration fetch) throws SQLException { // select pks from base class record to ensure it exists and lock // it if needed ClassMapping base = mapping; while (base.getJoinablePCSuperclassMapping() != null) base = base.getJoinablePCSuperclassMapping(); Select sel = _sql.newSelect(); sel.select(base.getPrimaryKeyColumns()); sel.wherePrimaryKey(sm.getObjectId(), base, this); if (_log.isTraceEnabled()) { _log.trace("selectPrimaryKey: oid="+sm.getObjectId()+" "+mapping.getDescribedType()); } Result exists = sel.execute(this, fetch); try { if (isEmptyResult(exists)) return false; // record locked? if (_active && _lm != null && exists.isLocking()) _lm.loadedForUpdate(sm); return true; } finally { exists.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(); } }