mirror of https://github.com/apache/openjpa.git
OPENJPA-662: Allow version field values be loaded in projection query
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@677704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
948c38e332
commit
c7e78fc80d
|
@ -880,6 +880,11 @@ public class FieldMapping
|
|||
public Object loadProjection(JDBCStore store, JDBCFetchConfiguration fetch,
|
||||
Result res, Joins joins)
|
||||
throws SQLException {
|
||||
// OPENJPA-662: Version fields have NoneFieldStrategy -- hence they
|
||||
// need special treatment
|
||||
if (isVersion()) {
|
||||
return getDefiningMapping().getVersion().load(null, store, res);
|
||||
}
|
||||
return assertStrategy().loadProjection(store, fetch, res, joins);
|
||||
}
|
||||
|
||||
|
|
|
@ -338,9 +338,9 @@ public class Version
|
|||
return assertStrategy().select(sel, mapping);
|
||||
}
|
||||
|
||||
public void load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
public Object load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
throws SQLException {
|
||||
assertStrategy().load(sm, store, res);
|
||||
return assertStrategy().load(sm, store, res);
|
||||
}
|
||||
|
||||
public void afterLoad(OpenJPAStateManager sm, JDBCStore store) {
|
||||
|
|
|
@ -53,7 +53,7 @@ public interface VersionStrategy
|
|||
/**
|
||||
* Load data.
|
||||
*/
|
||||
public void load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
public Object load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
throws SQLException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,8 +53,9 @@ public abstract class AbstractVersionStrategy
|
|||
return false;
|
||||
}
|
||||
|
||||
public void load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
public Object load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void afterLoad(OpenJPAStateManager sm, JDBCStore store) {
|
||||
|
|
|
@ -178,13 +178,13 @@ public abstract class ColumnVersionStrategy
|
|||
return true;
|
||||
}
|
||||
|
||||
public void load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
public Object load(OpenJPAStateManager sm, JDBCStore store, Result res)
|
||||
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]))
|
||||
return;
|
||||
return null;
|
||||
|
||||
Object version = null;
|
||||
if (cols.length > 0)
|
||||
|
@ -192,14 +192,18 @@ public abstract class ColumnVersionStrategy
|
|||
Object cur;
|
||||
for (int i = 0; i < cols.length; i++) {
|
||||
if (i > 0 && !res.contains(cols[i]))
|
||||
return;
|
||||
return null;
|
||||
cur = res.getObject(cols[i], -1, null);
|
||||
if (cols.length == 1)
|
||||
version = cur;
|
||||
else
|
||||
((Object[]) version)[i] = cur;
|
||||
}
|
||||
// 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 boolean checkVersion(OpenJPAStateManager sm, JDBCStore store,
|
||||
|
|
Loading…
Reference in New Issue