This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch version3
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/version3 by this push:
new 35b082b EMPIREDB-362 cleanup
35b082b is described below
commit 35b082bac388a3b0d6839ce812dbae4ad14e362f
Author: Rainer Döbele <[email protected]>
AuthorDate: Fri Jan 21 20:53:00 2022 +0100
EMPIREDB-362
cleanup
---
.../java/org/apache/empire/db/DBRecordData.java | 23 ++++++++++++----------
.../main/java/org/apache/empire/db/DBRowSet.java | 20 +++++++++++++++----
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
index 80c3b73..4380ed5 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecordData.java
@@ -103,7 +103,7 @@ public abstract class DBRecordData extends DBObject
* @param returnType the type of the returned value
* @return the value
*/
- public final <T> T getValue(int index, Class<T> returnType)
+ public <T> T getValue(int index, Class<T> returnType)
{
return ObjectUtils.convert(returnType, getValue(index));
}
@@ -116,7 +116,10 @@ public abstract class DBRecordData extends DBObject
*/
public final <T> T getValue(Column column, Class<T> returnType)
{
- return ObjectUtils.convert(returnType, getValue(column));
+ int index = getFieldIndex(column);
+ if (index<0)
+ throw new ItemNotFoundException(column.getName());
+ return getValue(index, returnType);
}
/**
@@ -125,7 +128,7 @@ public abstract class DBRecordData extends DBObject
* @param column the column expressions
* @return the corresponding record values
*/
- public final Object[] getValues(ColumnExpr[] columns)
+ public final Object[] getValues(ColumnExpr... columns)
{
Object[] values = new Object[columns.length];
for (int i=0; i<columns.length; i++)
@@ -145,7 +148,7 @@ public abstract class DBRecordData extends DBObject
* @param index index of the column
* @return the record value
*/
- public final int getInt(int index)
+ public int getInt(int index)
{
return ObjectUtils.getInteger(getValue(index));
}
@@ -169,7 +172,7 @@ public abstract class DBRecordData extends DBObject
* @param index index of the column
* @return the value
*/
- public final long getLong(int index)
+ public long getLong(int index)
{
return ObjectUtils.getLong(getValue(index));
}
@@ -193,7 +196,7 @@ public abstract class DBRecordData extends DBObject
* @param index index of the column
* @return the value
*/
- public final double getDouble(int index)
+ public double getDouble(int index)
{
return ObjectUtils.getDouble(getValue(index));
}
@@ -217,7 +220,7 @@ public abstract class DBRecordData extends DBObject
* @param index index of the column
* @return the value
*/
- public final BigDecimal getDecimal(int index)
+ public BigDecimal getDecimal(int index)
{
return ObjectUtils.getDecimal(getValue(index));
}
@@ -241,7 +244,7 @@ public abstract class DBRecordData extends DBObject
* @param index index of the column
* @return the value
*/
- public final boolean getBoolean(int index)
+ public boolean getBoolean(int index)
{
return ObjectUtils.getBoolean(getValue(index));
}
@@ -265,9 +268,9 @@ public abstract class DBRecordData extends DBObject
* @param index index of the column
* @return the value
*/
- public final String getString(int index)
+ public String getString(int index)
{
- return StringUtils.toString(getValue(index));
+ return ObjectUtils.getString(getValue(index));
}
/**
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
index 3dde471..029ca9f 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRowSet.java
@@ -658,7 +658,7 @@ public abstract class DBRowSet extends DBExpr
* <P>
* @param rec the DBRecord object which holds the record data
* @param cmd the SQL-Command used to query the record
- * @param conn a valid JDBC connection.
+ * @param rowSetData optional rowset specific data to be held on the record
*/
protected void readRecord(DBRecord rec, DBCommand cmd, Object rowSetData)
{
@@ -673,6 +673,18 @@ public abstract class DBRowSet extends DBExpr
reader.close();
}
}
+
+ /**
+ * Reads a single record from the database using the given command
object.<BR>
+ * If a record is found the DBRecord object will hold all record data.
+ * <P>
+ * @param rec the DBRecord object which holds the record data
+ * @param cmd the SQL-Command used to query the record
+ */
+ protected final void readRecord(DBRecord rec, DBCommand cmd)
+ {
+ readRecord(rec, cmd, null);
+ }
/**
* Reads the record with the given primary key from the database.
@@ -694,7 +706,7 @@ public abstract class DBRowSet extends DBExpr
setKeyConstraints(cmd, key);
try {
// Read Record
- readRecord(rec, cmd, null);
+ readRecord(rec, cmd);
} catch (QueryNoResultException e) {
// Translate exception
throw new RecordNotFoundException(this, key);
@@ -719,7 +731,7 @@ public abstract class DBRowSet extends DBExpr
DBCommand cmd = getDatabase().createCommand();
cmd.select(getColumns());
cmd.where(whereConstraints);
- readRecord(rec, cmd, null);
+ readRecord(rec, cmd);
}
/**
@@ -762,7 +774,7 @@ public abstract class DBRowSet extends DBExpr
setKeyConstraints(cmd, key);
try {
// Read Record
- readRecord(rec, cmd, null);
+ readRecord(rec, cmd);
} catch (QueryNoResultException e) {
// Translate exception
throw new RecordNotFoundException(this, key);