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:
Pinaki Poddar 2008-07-17 20:11:42 +00:00
parent 948c38e332
commit c7e78fc80d
5 changed files with 18 additions and 8 deletions

View File

@ -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);
}

View File

@ -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) {

View File

@ -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;
/**

View File

@ -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) {

View File

@ -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,