Fetch joined nodes in dedicated method, fixing a number of bugs related
to reading to the resultset after ResultSet.next() has been called.
This commit is contained in:
parent
8fcdf88bcf
commit
a9f1797258
1 changed files with 33 additions and 85 deletions
|
@ -1134,27 +1134,7 @@ public final class NodeManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int resultSetOffset = columns.length;
|
fetchJoinedNodes(rs, joins, columns.length);
|
||||||
// create joined objects
|
|
||||||
for (int i = 0; i < joins.length; i++) {
|
|
||||||
DbMapping jdbm = joins[i].otherType;
|
|
||||||
node = createNode(jdbm, rs, jdbm.getColumns(), resultSetOffset);
|
|
||||||
if (node != null) {
|
|
||||||
primKey = node.getKey();
|
|
||||||
// register new nodes with the cache. If an up-to-date copy
|
|
||||||
// existed in the cache, use that.
|
|
||||||
synchronized (cache) {
|
|
||||||
Node oldnode = (Node) cache.put(primKey, node);
|
|
||||||
|
|
||||||
if ((oldnode != null) &&
|
|
||||||
(oldnode.getState() != INode.INVALID)) {
|
|
||||||
// found an ok version in the cache, use it.
|
|
||||||
cache.put(primKey, oldnode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultSetOffset += jdbm.getColumns().length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -1308,27 +1288,7 @@ public final class NodeManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int resultSetOffset = columns.length;
|
fetchJoinedNodes(rs, joins, columns.length);
|
||||||
// create joined objects
|
|
||||||
for (int i = 0; i < joins.length; i++) {
|
|
||||||
DbMapping jdbm = joins[i].otherType;
|
|
||||||
node = createNode(jdbm, rs, jdbm.getColumns(), resultSetOffset);
|
|
||||||
if (node != null) {
|
|
||||||
primKey = node.getKey();
|
|
||||||
// register new nodes with the cache. If an up-to-date copy
|
|
||||||
// existed in the cache, use that.
|
|
||||||
synchronized (cache) {
|
|
||||||
Node oldnode = (Node) cache.put(primKey, node);
|
|
||||||
|
|
||||||
if ((oldnode != null) &&
|
|
||||||
(oldnode.getState() != INode.INVALID)) {
|
|
||||||
// found an ok version in the cache, use it.
|
|
||||||
cache.put(primKey, oldnode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultSetOffset += jdbm.getColumns().length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If these are grouped nodes, build the intermediary group nodes
|
// If these are grouped nodes, build the intermediary group nodes
|
||||||
|
@ -1540,27 +1500,7 @@ public final class NodeManager {
|
||||||
|
|
||||||
node = createNode(dbm, rs, columns, 0);
|
node = createNode(dbm, rs, columns, 0);
|
||||||
|
|
||||||
int resultSetOffset = columns.length;
|
fetchJoinedNodes(rs, joins, columns.length);
|
||||||
// create joined objects
|
|
||||||
for (int i = 0; i < joins.length; i++) {
|
|
||||||
DbMapping jdbm = joins[i].otherType;
|
|
||||||
node = createNode(jdbm, rs, jdbm.getColumns(), resultSetOffset);
|
|
||||||
if (node != null) {
|
|
||||||
Key primKey = node.getKey();
|
|
||||||
// register new nodes with the cache. If an up-to-date copy
|
|
||||||
// existed in the cache, use that.
|
|
||||||
synchronized (cache) {
|
|
||||||
Node oldnode = (Node) cache.put(primKey, node);
|
|
||||||
|
|
||||||
if ((oldnode != null) &&
|
|
||||||
(oldnode.getState() != INode.INVALID)) {
|
|
||||||
// found an ok version in the cache, use it.
|
|
||||||
cache.put(primKey, oldnode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultSetOffset += jdbm.getColumns().length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
throw new RuntimeException("More than one value returned by query.");
|
throw new RuntimeException("More than one value returned by query.");
|
||||||
|
@ -1651,6 +1591,8 @@ public final class NodeManager {
|
||||||
|
|
||||||
node = createNode(rel.otherType, rs, columns, 0);
|
node = createNode(rel.otherType, rs, columns, 0);
|
||||||
|
|
||||||
|
fetchJoinedNodes(rs, joins, columns.length);
|
||||||
|
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
throw new RuntimeException("More than one value returned by query.");
|
throw new RuntimeException("More than one value returned by query.");
|
||||||
}
|
}
|
||||||
|
@ -1665,28 +1607,6 @@ public final class NodeManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int resultSetOffset = columns.length;
|
|
||||||
// create joined objects
|
|
||||||
for (int i = 0; i < joins.length; i++) {
|
|
||||||
DbMapping jdbm = joins[i].otherType;
|
|
||||||
node = createNode(jdbm, rs, jdbm.getColumns(), resultSetOffset);
|
|
||||||
if (node != null) {
|
|
||||||
Key primKey = node.getKey();
|
|
||||||
// register new nodes with the cache. If an up-to-date copy
|
|
||||||
// existed in the cache, use that.
|
|
||||||
synchronized (cache) {
|
|
||||||
Node oldnode = (Node) cache.put(primKey, node);
|
|
||||||
|
|
||||||
if ((oldnode != null) &&
|
|
||||||
(oldnode.getState() != INode.INVALID)) {
|
|
||||||
// found an ok version in the cache, use it.
|
|
||||||
cache.put(primKey, oldnode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultSetOffset += jdbm.getColumns().length;
|
|
||||||
}
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (stmt != null) {
|
if (stmt != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -1886,6 +1806,34 @@ public final class NodeManager {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch nodes that are fetched additionally to another node via join.
|
||||||
|
*/
|
||||||
|
private void fetchJoinedNodes(ResultSet rs, Relation[] joins, int offset)
|
||||||
|
throws ClassNotFoundException, SQLException, IOException {
|
||||||
|
int resultSetOffset = offset;
|
||||||
|
// create joined objects
|
||||||
|
for (int i = 0; i < joins.length; i++) {
|
||||||
|
DbMapping jdbm = joins[i].otherType;
|
||||||
|
Node node = createNode(jdbm, rs, jdbm.getColumns(), resultSetOffset);
|
||||||
|
if (node != null) {
|
||||||
|
Key primKey = node.getKey();
|
||||||
|
// register new nodes with the cache. If an up-to-date copy
|
||||||
|
// existed in the cache, use that.
|
||||||
|
synchronized (cache) {
|
||||||
|
Node oldnode = (Node) cache.put(primKey, node);
|
||||||
|
|
||||||
|
if ((oldnode != null) &&
|
||||||
|
(oldnode.getState() != INode.INVALID)) {
|
||||||
|
// found an ok version in the cache, use it.
|
||||||
|
cache.put(primKey, oldnode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultSetOffset += jdbm.getColumns().length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a DbMapping for a given prototype name. This is just a proxy
|
* Get a DbMapping for a given prototype name. This is just a proxy
|
||||||
|
|
Loading…
Add table
Reference in a new issue