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:
hns 2003-05-28 18:01:23 +00:00
parent 8fcdf88bcf
commit a9f1797258

View file

@ -1134,27 +1134,7 @@ 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) {
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;
}
fetchJoinedNodes(rs, joins, columns.length);
}
} finally {
@ -1308,27 +1288,7 @@ 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) {
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;
}
fetchJoinedNodes(rs, joins, columns.length);
}
// If these are grouped nodes, build the intermediary group nodes
@ -1540,27 +1500,7 @@ public final class NodeManager {
node = createNode(dbm, rs, columns, 0);
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;
}
fetchJoinedNodes(rs, joins, columns.length);
if (rs.next()) {
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);
fetchJoinedNodes(rs, joins, columns.length);
if (rs.next()) {
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 {
if (stmt != null) {
try {
@ -1886,6 +1806,34 @@ public final class NodeManager {
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