Added get() for when you expect your query to match only a single record and
want the ResultSet to be properly closed once you have that record. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1756 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -13,6 +13,8 @@ package com.samskivert.jdbc.jora;
|
||||
import java.util.*;
|
||||
import java.sql.*;
|
||||
|
||||
import com.samskivert.Log;
|
||||
|
||||
/** Cursor is used for successive access to records fetched by SELECT
|
||||
* statement. As far as records can be retrived from several derived tables
|
||||
* (polymorphic form of select), this class can issue several requests
|
||||
@@ -90,6 +92,29 @@ public class Cursor {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element matched by this cursor or null if no elements
|
||||
* were matched. Checks to ensure that no subsequent elements were matched
|
||||
* by the query, logs a warning if there were spurious additional matches.
|
||||
*/
|
||||
public Object get()
|
||||
throws SQLException
|
||||
{
|
||||
Object result = next();
|
||||
if (result != null) {
|
||||
int spurious = 0;
|
||||
while (next() != null) {
|
||||
spurious++;
|
||||
}
|
||||
if (spurious > 0) {
|
||||
Log.warning("Cursor.get() quietly tossed " + spurious +
|
||||
" spurious additional records. " +
|
||||
"[query=" + query + "].");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Update current record pointed by cursor. This method can be called
|
||||
* only after next() method, which returns non-null object. This objects
|
||||
* is used to update current record fields.<P>
|
||||
|
||||
Reference in New Issue
Block a user