empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r691420 - in /incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db: DBColumn.java DBDatabase.java DBDatabaseDriver.java DBTable.java DBView.java hsql/DBDatabaseDriverHSql.java oracle/DBDatabaseDriverOracle.java
Date Tue, 02 Sep 2008 23:05:58 GMT
Author: doebele
Date: Tue Sep  2 16:05:57 2008
New Revision: 691420

URL: http://svn.apache.org/viewvc?rev=691420&view=rev
Log:
EMPIREDB-6

Modified:
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBView.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java?rev=691420&r1=691419&r2=691420&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBColumn.java Tue Sep
 2 16:05:57 2008
@@ -50,6 +50,8 @@
     protected final DBRowSet   rowset;
     protected final String     name;
     protected String           comment;
+
+    private Boolean quoteName = null;
     
     /**
      * Constructs a DBColumn object and set the specified parameters to this object.
@@ -126,7 +128,10 @@
         }
         // Append the name
         DBDatabaseDriver driver = getDatabase().getDriver();
-        driver.appendElementName(buf, name);
+        if (quoteName==null)
+            quoteName = driver.detectQuoteName(name);
+        // Append the name
+        driver.appendElementName(buf, name, quoteName.booleanValue());
     }
 
     /**

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java?rev=691420&r1=691419&r2=691420&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabase.java Tue
Sep  2 16:05:57 2008
@@ -267,10 +267,12 @@
      * 
      * @return the qualified object name
      */
+    @Deprecated
     public String getQualifiedName(String name)
     {
         StringBuilder buf = new StringBuilder();
-        appendQualifiedName(buf, name);
+        boolean quoteName = (driver!=null) ? driver.detectQuoteName(name) : false;
+        appendQualifiedName(buf, name, quoteName);
         return buf.toString();
     }
     
@@ -282,7 +284,7 @@
      * @param buf the string buffer to which to append the qualified object name
      * @param name the object's name
      */
-    public void appendQualifiedName(StringBuilder buf, String name)
+    public void appendQualifiedName(StringBuilder buf, String name, boolean quoteName)
     {
         // Check driver
         if (driver==null)
@@ -298,7 +300,7 @@
             buf.append(".");
         }
         // Append the name
-        driver.appendElementName(buf, name);
+        driver.appendElementName(buf, name, quoteName);
         // Database Link
         if (linkName!=null)
         { // Add Schema

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java?rev=691420&r1=691419&r2=691420&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
Tue Sep  2 16:05:57 2008
@@ -110,7 +110,7 @@
                                                                     '/', '.', '-', ',', '+',
'*', ')', '(',
                                                                     '\'', '&', '%', '!',
' '
                                                                   };        
-    private static final String[] generalSQLKeywords = new String[] { "count", "user", "on",
"off",
+    private static final String[] generalSQLKeywords = new String[] { "user", "group", 
                                                            "table", "column", "view", "index",
"constraint", 
                                                            "select", "udpate", "insert",
"alter", "delete" };        
     protected final Set<String> reservedSQLKeywords;
@@ -233,12 +233,12 @@
     public abstract boolean isSupported(DBDriverFeature type);
 
     /**
-     * Checks wether a table or column name needs to be quoted or not<BR/>
+     * Detects wether a table or column name needs to be quoted or not<BR/>
      * By default all reserved SQL keywords as well as names 
      * containing a "-", "/", "+" or " " require quoting.<BR/>
      * Overrides this function to add database specific keywords like "user" or "count" 

      */
-    protected boolean quoteElementName(String name)
+    protected boolean detectQuoteName(String name)
     {
         // Check for reserved names
         if (reservedSQLKeywords.contains(name.toLowerCase()))
@@ -264,10 +264,9 @@
      * @param sql the StringBuilder containing the SQL phrase.
      * @param name the name of the object (table, view or column)
      */
-    public void appendElementName(StringBuilder sql, String name)
+    public void appendElementName(StringBuilder sql, String name, boolean useQuotes)
     {
         // Check whether to use quotes or not
-        boolean useQuotes = quoteElementName(name);
         if (useQuotes)
             sql.append(getSQLPhrase(DBDatabaseDriver.SQL_QUOTES_OPEN));
         // Append Name
@@ -276,6 +275,16 @@
         if (useQuotes)
             sql.append(getSQLPhrase(DBDatabaseDriver.SQL_QUOTES_CLOSE));
     }
+
+    /**
+     * Appends a table, view or column name to an SQL phrase. 
+     * @param sql the StringBuilder containing the SQL phrase.
+     * @param name the name of the object (table, view or column)
+     */
+    public final void appendElementName(StringBuilder sql, String name)
+    {
+        appendElementName(sql, name, detectQuoteName(name));
+    }
     
     /**
      * Returns an sql phrase template for this database system.<br>

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java?rev=691420&r1=691419&r2=691420&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBTable.java Tue Sep
 2 16:05:57 2008
@@ -42,6 +42,7 @@
     private String         alias;
     private List<DBIndex>  indexes       = new ArrayList<DBIndex>();
     private boolean        cascadeDelete = false;
+    private Boolean        quoteName     = null;
 
     /**
      * Construct a new DBTable object set the specified parameters
@@ -280,8 +281,12 @@
     {
         // Append Name
         if ((context & CTX_NAME|CTX_FULLNAME)!=0)
-        {    // Add Schema
-             db.appendQualifiedName(buf, name);
+        {   // Append the name
+            DBDatabaseDriver driver = getDatabase().getDriver();
+            if (quoteName==null)
+                quoteName = driver.detectQuoteName(name);
+            // append Qualified Name 
+            db.appendQualifiedName(buf, name, quoteName);
         }
         // Append Alias
         if ((context & CTX_ALIAS)!=0 && alias!=null)

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBView.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBView.java?rev=691420&r1=691419&r2=691420&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBView.java (original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBView.java Tue Sep
 2 16:05:57 2008
@@ -165,6 +165,7 @@
     private String     name;
     private String     alias;
     private boolean    updateable;  // true if the view is updateable
+    private Boolean    quoteName  = null;
 
     /**
      * Creates a view object for a given view in the database.
@@ -348,19 +349,20 @@
     @Override
     public void addSQL(StringBuilder buf, long context)
     {
-        if ((context & CTX_FULLNAME) != 0 && db != null)
-        { // Add Schema
-            db.appendQualifiedName(buf, name);
-        } 
-        else
-        { // Simple Name only
-            buf.append(name);
+        // Append Name
+        if ((context & CTX_NAME|CTX_FULLNAME)!=0)
+        {   // Append the name
+            DBDatabaseDriver driver = getDatabase().getDriver();
+            if (quoteName==null)
+                quoteName = driver.detectQuoteName(name);
+            // append Qualified Name 
+            db.appendQualifiedName(buf, name, quoteName);
         }
-        // Add Alias
-        if ((context & CTX_ALIAS) != 0 && alias != null)
-        { // append alias
-            buf.append(getRenameTablePhrase());
-            buf.append(alias);
+        // Append Alias
+        if ((context & CTX_ALIAS)!=0 && alias!=null)
+        {    // append alias
+             buf.append(getRenameTablePhrase());
+             buf.append(alias);
         }
     }
 

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java?rev=691420&r1=691419&r2=691420&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
Tue Sep  2 16:05:57 2008
@@ -225,7 +225,7 @@
         StringBuilder sql = new StringBuilder(80);
         sql.append("SELECT ");
         sql.append("NEXT VALUE FOR ");
-        db.appendQualifiedName(sql, seqName);
+        db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
         sql.append(" FROM INFORMATION_SCHEMA.SYSTEM_SEQUENCES WHERE SEQUENCE_NAME='"+ seqName
+ "'");
         	
         Object val = db.querySingleValue(sql.toString(), conn);
@@ -379,7 +379,7 @@
         sql.append(c.toString());
         sql.append(" --\r\n");
         sql.append("CREATE SEQUENCE ");
-        db.appendQualifiedName(sql, seqName);
+        db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
         sql.append(" START WITH 1");
         // executeDLL
         return script.addStmt(sql);

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java?rev=691420&r1=691419&r2=691420&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/oracle/DBDatabaseDriverOracle.java
Tue Sep  2 16:05:57 2008
@@ -284,7 +284,7 @@
     { // Use Oracle Sequences
         StringBuilder sql = new StringBuilder(80);
         sql.append("SELECT ");
-        db.appendQualifiedName(sql, seqName);
+        db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
         sql.append(".NEXTVAL FROM DUAL");
         Object val = db.querySingleValue(sql.toString(), conn);
         if (val == null)
@@ -461,7 +461,7 @@
         sql.append(c.getFullName());
         sql.append(" --\r\n");
         sql.append("CREATE SEQUENCE ");
-        db.appendQualifiedName(sql, seqName);
+        db.appendQualifiedName(sql, seqName, detectQuoteName(seqName));
         sql.append(" INCREMENT BY 1 START WITH 1 MINVALUE 0 NOCYCLE NOCACHE NOORDER");
         // executeDLL
         return script.addStmt(sql);



Mime
View raw message