You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2022/01/20 14:06:32 UTC
[empire-db] branch version3 updated: EMPIREDB-363 DBContext changes
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 cc0802a EMPIREDB-363 DBContext changes
cc0802a is described below
commit cc0802a6432fac2866a093aa9d528b42c3054dbc
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Thu Jan 20 15:06:30 2022 +0100
EMPIREDB-363
DBContext changes
---
.../main/java/org/apache/empire/db/DBDatabase.java | 2 +-
.../main/java/org/apache/empire/db/DBReader.java | 5 ++--
.../main/java/org/apache/empire/db/DBRecord.java | 29 ++++++++++++++++++++--
.../main/java/org/apache/empire/db/DBRowSet.java | 14 +++++++++++
.../java/org/apache/empire/db/DBSQLScript.java | 3 ++-
.../main/java/org/apache/empire/db/DBUtils.java | 18 +++++++++++---
6 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
index 3d55d1e..fa73928 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
@@ -821,7 +821,7 @@ public abstract class DBDatabase extends DBObject
*
* @return the command object.
*/
- public DBCommand createCommand()
+ public final DBCommand createCommand()
{
checkOpen();
return driver.createCommand(this);
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBReader.java b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
index be52aaa..19ee3c8 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBReader.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
@@ -242,8 +242,9 @@ public class DBReader extends DBRecordData implements DBContextAware
* Support for finding code errors where a DBRecordSet is opened but not closed
*/
private static ThreadLocal<Map<DBReader, Exception>> threadLocalOpenResultSets = new ThreadLocal<Map<DBReader, Exception>>();
-
- private final DBContext context;
+
+ // the context
+ protected final DBContext context;
// Object references
private DBDatabase db = null;
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 33dc99f..8674cdd 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
@@ -38,6 +38,7 @@ import org.apache.empire.db.exceptions.FieldValueNotFetchedException;
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.MiscellaneousErrorException;
import org.apache.empire.exceptions.NotSupportedException;
import org.apache.empire.exceptions.ObjectNotValidException;
import org.apache.empire.xml.XMLUtil;
@@ -200,6 +201,7 @@ public class DBRecord extends DBRecordData implements DBContextAware, Record, Cl
protected static final Logger log = LoggerFactory.getLogger(DBRecord.class);
+ // the context
protected final DBContext context;
protected final DBRowSet rowset;
@@ -995,12 +997,17 @@ public class DBRecord extends DBRecordData implements DBContextAware, Record, Cl
* @param key an array of the primary key values
*/
public void read(Object... key)
- {
+ {
+ // temporarily check for rowset as first parameter
+ // invalid due to conversion from old Api where Rowset was first param
+ if (key[0] instanceof DBRowSet)
+ throw new MiscellaneousErrorException("Version 3 Migration Error: DBRecord.read() invalid key!");
+
// temporarily check for connection
// invalid due to conversion from old Api where Connection was the last param
for (int i=0; i<key.length; i++)
if (key[i] instanceof Connection)
- throw new InvalidArgumentException("key", key);
+ throw new MiscellaneousErrorException("Version 3 Migration Error: DBRecord.read() invalid key!");
// read
rowset.readRecord(this, key);
// remove rollback
@@ -1310,6 +1317,24 @@ public class DBRecord extends DBRecordData implements DBContextAware, Record, Cl
{
return setRecordValues(bean, null);
}
+
+ /**
+ * Compares the record to another one
+ * @param otherObject
+ * @return true if it is the same record (but maybe a different instance)
+ */
+ public boolean isSame(DBRecord other)
+ { // check valid
+ if (!isValid() || !other.isValid())
+ return false;
+ // compare table
+ if (!rowset.isSame(other.getRowSet()))
+ return false;
+ // compare key
+ Object[] key1 = getKeyValues();
+ Object[] key2 = other.getKeyValues();
+ return ObjectUtils.compareEqual(key1, key2);
+ }
/**
* Override this to do extra handling when the rowset for this record changes
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 c7a7d66..e1930e3 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
@@ -215,6 +215,20 @@ public abstract class DBRowSet extends DBExpr
}
return false;
}
+
+ /**
+ * Compares the rowset to another one
+ * @param otherObject
+ * @return true if it is the same rowset (but maybe a different instance)
+ */
+ public boolean isSame(DBRowSet other)
+ {
+ // record
+ if (!getDatabase().equals(other.getDatabase()))
+ return false;
+ // compare names
+ return StringUtils.compareEqual(getName(), other.getName(), true);
+ }
// ------- Abstract Methods -------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java b/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java
index e2bbfd0..9607c36 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBSQLScript.java
@@ -112,7 +112,8 @@ public class DBSQLScript implements DBContextAware, Iterable<String>
protected ArrayList<SQLStmt> sqlStmtList = new ArrayList<SQLStmt>();
- private final DBContext context;
+ // the context
+ protected final DBContext context;
public DBSQLScript(DBContext context)
{
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBUtils.java b/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
index 83847ee..a946020 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBUtils.java
@@ -28,10 +28,10 @@ public class DBUtils implements DBContextAware
// Threshold for long running queries in milliseconds
protected long longRunndingStmtThreshold = 30000;
-
- private final DBContext context;
-
- private final DBDatabaseDriver driver;
+ // the context
+ protected final DBContext context;
+ // the driver
+ protected final DBDatabaseDriver driver;
/**
* Constructs an empty DBRecordSet object.
@@ -54,6 +54,16 @@ public class DBUtils implements DBContextAware
return ((T)context);
}
+ /**
+ * Creates a new Command object for the given database
+ *
+ * @return the command object.
+ */
+ public final DBCommand createCommand(DBDatabase db)
+ {
+ return driver.createCommand(db);
+ }
+
/*
// Sequences
public Object getNextSequenceValue(String seqName)