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 19:16:37 UTC
[empire-db] branch version3 updated: EMPIREDB-362
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 3698652 EMPIREDB-362
3698652 is described below
commit 3698652f4e1e4f021feddd590a0d7178cfabd0e7
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Thu Jan 20 20:16:34 2022 +0100
EMPIREDB-362
---
.../main/java/org/apache/empire/db/DBDatabase.java | 83 ++++++++++++----------
.../main/java/org/apache/empire/db/DBRowSet.java | 4 +-
2 files changed, 46 insertions(+), 41 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 fa73928..6aab38b 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
@@ -39,6 +39,7 @@ import org.apache.empire.db.expr.compare.DBCompareExpr;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.ItemExistsException;
import org.apache.empire.exceptions.MiscellaneousErrorException;
+import org.apache.empire.exceptions.NotSupportedException;
import org.apache.empire.exceptions.PropertyReadOnlyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -122,14 +123,17 @@ public abstract class DBDatabase extends DBObject
return null;
}
- /** the database schema * */
- protected String schema = null; // database schema name
- protected String linkName = null; // database link name
- protected List<DBTable> tables = new ArrayList<DBTable>();
- protected List<DBRelation> relations = new ArrayList<DBRelation>();
- protected List<DBView> views = new ArrayList<DBView>();
+ // properties
+ protected String schema; // database schema name
+ protected String linkName; // database link name
+ protected String instanceId; // internal instance id
+
+ // Collections
+ protected final List<DBTable> tables = new ArrayList<DBTable>();
+ protected final List<DBRelation> relations = new ArrayList<DBRelation>();
+ protected final List<DBView> views = new ArrayList<DBView>();
+
protected DBDatabaseDriver driver = null;
- protected String instanceId;
/**
* Property that indicates whether to always use usePreparedStatements (Default is false!)
@@ -175,16 +179,14 @@ public abstract class DBDatabase extends DBObject
* Do not reuse this object afterwards!
* Hint: Database must be closed!
*/
- public synchronized void destroy()
+ public synchronized void discard()
{
if (isOpen())
- throw new MiscellaneousErrorException("Database is open. Destroy not possible.");
+ throw new MiscellaneousErrorException("Database is open. Discard not possible.");
// unregister
databaseMap.remove(this.instanceId);
this.instanceId = null;
// clear all
- this.schema = null;
- this.linkName = null;
tables.clear();
relations.clear();
views.clear();
@@ -312,14 +314,22 @@ public abstract class DBDatabase extends DBObject
*/
public void open(DBContext context)
{
- // Close Database if already open
- if (isOpen())
- close(context);
- // Attach to driver
DBDatabaseDriver driver = context.getDriver();
- driver.attachDatabase(this, context.getConnection());
- // set new driver
- this.driver = driver;
+ if (driver==this.driver)
+ {
+ log.warn("Database already attached to this driver");
+ }
+ else if (this.driver!=null)
+ {
+ log.error("Database already attached to another driver {}", this.driver.getClass().getName());
+ throw new NotSupportedException(this, "open");
+ }
+ else
+ { // Attach to driver
+ driver.attachDatabase(this, context.getConnection());
+ // set latest driver
+ this.driver = driver;
+ }
}
/**
@@ -331,10 +341,22 @@ public abstract class DBDatabase extends DBObject
*/
public void close(DBContext context)
{
- if (driver != null)
- driver.detachDatabase(this, context.getConnection());
- // No diver
- this.driver = null;
+ DBDatabaseDriver driver = context.getDriver();
+ if (this.driver == null)
+ {
+ log.warn("Database not attached to a driver");
+ }
+ else if (driver!=this.driver)
+ {
+ log.error("Database attached to another driver {}", this.driver.getClass().getName());
+ throw new NotSupportedException(this, "close");
+ }
+ else
+ { // Detach
+ this.driver.detachDatabase(this, context.getConnection());
+ // No diver
+ this.driver = null;
+ }
}
/**
@@ -446,23 +468,6 @@ public abstract class DBDatabase extends DBObject
// Set Link
this.linkName = linkName;
}
-
- /**
- * Returns the full qualified object name including schema prefix
- * and database link postfix (if any).
- *
- * @param name the object's name
- *
- * @return the qualified object name
- */
- @Deprecated
- public String getQualifiedName(String name)
- {
- StringBuilder buf = new StringBuilder();
- boolean quoteName = (driver!=null) ? driver.detectQuoteName(name) : false;
- appendQualifiedName(buf, name, quoteName);
- return buf.toString();
- }
/**
* Adds a full qualified object name including schema prefix
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 770c6c9..013c104 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
@@ -471,9 +471,9 @@ public abstract class DBRowSet extends DBExpr
*/
protected String getRenameTablePhrase()
{
- if (db==null || db.driver==null)
+ if (db==null || db.getDriver()==null)
return " ";
- return db.driver.getSQLPhrase(DBDatabaseDriver.SQL_RENAME_TABLE);
+ return db.getDriver().getSQLPhrase(DBDatabaseDriver.SQL_RENAME_TABLE);
}
/**