This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new 76df2c1 EMPIREDB-282 new read method on DBRecord and keywords for
Oracle
76df2c1 is described below
commit 76df2c180be5ad56d6dc7e8e508a34282e713789
Author: Rainer Döbele <[email protected]>
AuthorDate: Fri Oct 25 16:51:57 2019 +0200
EMPIREDB-282
new read method on DBRecord and keywords for Oracle
---
.../main/java/org/apache/empire/db/DBRecord.java | 34 ++++++++++++++++++++--
.../empire/db/oracle/DBDatabaseDriverOracle.java | 3 ++
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
index 8a1f1cc..0f337be 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBRecord.java
@@ -21,7 +21,9 @@ package org.apache.empire.db;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtilsBean;
@@ -32,6 +34,7 @@ import org.apache.empire.data.Column;
import org.apache.empire.data.ColumnExpr;
import org.apache.empire.data.Record;
import org.apache.empire.db.exceptions.FieldIsReadOnlyException;
+import org.apache.empire.db.expr.compare.DBCompareExpr;
import org.apache.empire.exceptions.BeanPropertyGetException;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.ObjectNotValidException;
@@ -833,7 +836,7 @@ public class DBRecord extends DBRecordData implements
Record, Cloneable
}
/**
- * Loads a record from the database identified by it's primary key.
+ * Reads a record from the database identified by it's primary key.
* After successful reading the record will be valid and all values will
be accessible.
* @see org.apache.empire.db.DBTable#readRecord(DBRecord, Object[],
Connection)
*
@@ -850,7 +853,7 @@ public class DBRecord extends DBRecordData implements
Record, Cloneable
}
/**
- * Loads a record from the database identified by it's primary key.
+ * Reads a record from the database identified by it's primary key.
* After successful reading the record will be valid and all values will
be accessible.
* @see org.apache.empire.db.DBTable#readRecord(DBRecord, Object[],
Connection)
*
@@ -869,6 +872,33 @@ public class DBRecord extends DBRecordData implements
Record, Cloneable
}
/**
+ * Reads a record from the database identified by one or more constraints.
+ *
+ * In oder to concatenate constraints use the and() operator from the
first constraint
+ * e.g. FIRSTNAME.is("Joe").and(LASTNAME.is("Doe"))
+ *
+ * @param table the rowset from which to read the record
+ * @param whereConstraints the constraint(s) (which must all be on the
table)
+ * @param conn a valid connection to the database.
+ */
+ public void read(DBRowSet table, DBCompareExpr whereConstraints,
Connection conn)
+ {
+ if (whereConstraints==null)
+ throw new InvalidArgumentException("whereConstraints", null);
+ // check constraints
+ Set<DBColumn> columns = new HashSet<DBColumn>();
+ whereConstraints.addReferencedColumns(columns);
+ for (DBColumn c : columns)
+ if (!table.equals(c.getRowSet()))
+ throw new InvalidArgumentException("whereConstraints",
c.getFullName());
+ // read now
+ DBCommand cmd = table.getDatabase().createCommand();
+ cmd.select(table.getColumns());
+ cmd.where(whereConstraints);
+ table.readRecord(this, cmd, conn);
+ }
+
+ /**
* Updates the record and saves all changes in the database.
*
* @see org.apache.empire.db.DBTable#updateRecord(DBRecord, Connection)
diff --git
a/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
b/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
index c25e7b9..5e32c1d 100644
---
a/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
+++
b/empire-db/src/main/java/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
@@ -78,6 +78,9 @@ public class DBDatabaseDriverOracle extends DBDatabaseDriver
{
// Info
log.info("DBDatabaseDriverOracle created. Boolean Type is " +
booleanType);
+ // Additional reserved names
+ this.reservedSQLKeywords.add("date");
+ this.reservedSQLKeywords.add("number");
}
public boolean isOracle8Compatibilty()