db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1237843 - in /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter: AbstractDBAdapter.java DB.java DBDerby.java DBHsqldb.java DBMM.java DBMSSQL.java DBNone.java DBOracle.java DBPostgres.java
Date Mon, 30 Jan 2012 17:51:39 GMT
Author: tfischer
Date: Mon Jan 30 17:51:39 2012
New Revision: 1237843

URL: http://svn.apache.org/viewvc?rev=1237843&view=rev
Log:
- removed unused methods from the adapter
- added @Override annotations
- TORQUE-16 fix lockTables methods in  MSSQL and Oracle

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBHsqldb.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMSSQL.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBNone.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBPostgres.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/AbstractDBAdapter.java
Mon Jan 30 17:51:39 2012
@@ -21,8 +21,6 @@ package org.apache.torque.adapter;
 
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.util.Date;
 import java.util.Hashtable;
 import java.util.Map;
 
@@ -215,7 +213,7 @@ public abstract class AbstractDBAdapter 
      *
      * @throws TorqueException if any error occurs when building the query
      */
-    public void generateLimits(Query query, int offset, int limit)
+    public void generateLimits(Query query, long offset, int limit)
         throws TorqueException
     {
         if (supportsNativeLimit())
@@ -238,51 +236,6 @@ public abstract class AbstractDBAdapter 
     }
 
     /**
-     * This method is used to check whether the database supports
-     * limiting the size of the resultset.
-     *
-     * @return The limit style for the database.
-     * @deprecated This should not be exposed to the outside
-     */
-    public int getLimitStyle()
-    {
-        return LIMIT_STYLE_NONE;
-    }
-
-    /**
-     * This method is used to format any date string.
-     * Database can use different default date formats.
-     *
-     * @param date the Date to format
-     * @return The proper date formatted String.
-     */
-    public String getDateString(Date date)
-    {
-        Timestamp ts = null;
-        if (date instanceof Timestamp)
-        {
-            ts = (Timestamp) date;
-        }
-        else
-        {
-            ts = new Timestamp(date.getTime());
-        }
-
-        return ("{ts '" + ts + "'}");
-    }
-
-    /**
-     * This method is used to format a boolean string.
-     *
-     * @param b the Boolean to format
-     * @return The proper date formatted String.
-     */
-    public String getBooleanString(Boolean b)
-    {
-        return (Boolean.TRUE.equals(b) ? "1" : "0");
-    }
-
-    /**
      * Whether ILIKE should be used for case insensitive like clauses.
      *
      * As most databases do not use ILIKE, this implementation returns false.

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DB.java
Mon Jan 30 17:51:39 2012
@@ -22,7 +22,6 @@ package org.apache.torque.adapter;
 import java.io.Serializable;
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.Date;
 
 import org.apache.torque.TorqueException;
 import org.apache.torque.sql.Query;
@@ -68,36 +67,6 @@ import org.apache.torque.util.functions.
  */
 public interface DB extends Serializable, IDMethod
 {
-    /** Database does not support limiting result sets.
-     *  @deprecated This should not be exposed to the outside
-     */
-    int LIMIT_STYLE_NONE = 0;
-
-    /** <code>SELECT ... LIMIT <limit>, [&lt;offset&gt;]</code>
-     *  @deprecated This should not be exposed to the outside
-     */
-    int LIMIT_STYLE_POSTGRES = 1;
-
-    /** <code>SELECT ... LIMIT [<offset>, ] &lt;offset&gt;</code>
-     *  @deprecated This should not be exposed to the outside
-     */
-    int LIMIT_STYLE_MYSQL = 2;
-
-    /** <code>SET ROWCOUNT &lt;offset&gt; SELECT ... SET ROWCOUNT 0</code>
-     *  @deprecated This should not be exposed to the outside
-     */
-    int LIMIT_STYLE_SYBASE = 3;
-
-    /** <code><pre>SELECT ... WHERE ... AND ROWNUM < <limit></pre></code>
-     *  @deprecated This should not be exposed to the outside
-     */
-    int LIMIT_STYLE_ORACLE = 4;
-
-    /** <code><pre>SELECT ... WHERE ... AND ROW_NUMBER() OVER() < <limit></pre></code>
-     *  @deprecated This should not be exposed to the outside
-     */
-    int LIMIT_STYLE_DB2 = 5;
-
     /**
      * Key for the configuration which contains database adapters.
      */
@@ -220,7 +189,7 @@ public interface DB extends Serializable
      *
      * @throws TorqueException if any error occurs when building the query
      */
-    void generateLimits(Query query, int offset, int limit)
+    void generateLimits(Query query, long offset, int limit)
         throws TorqueException;
 
     /**
@@ -235,32 +204,6 @@ public interface DB extends Serializable
     boolean escapeText();
 
     /**
-     * This method is used to check whether the database supports
-     * limiting the size of the resultset.
-     *
-     * @return The limit style for the database.
-     * @deprecated This should not be exposed to the outside
-     */
-    int getLimitStyle();
-
-    /**
-     * This method is used to format any date string.
-     * Database can use different default date formats.
-     *
-     * @param date the Date to format
-     * @return The proper date formatted String.
-     */
-    String getDateString(Date date);
-
-    /**
-     * This method is used to format a boolean string.
-     *
-     * @param b the Boolean to format
-     * @return The proper date formatted String.
-     */
-    String getBooleanString(Boolean b);
-
-    /**
      * Whether ILIKE should be used for case insensitive like clauses.
      *
      * @return true if ilike should be used for case insensitive likes,

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBDerby.java
Mon Jan 30 17:51:39 2012
@@ -50,6 +50,7 @@ public class DBDerby extends AbstractDBA
      * @param str The string to transform to upper case.
      * @return The upper case string.
      */
+    @Override
     public String toUpperCase(String str)
     {
         return new StringBuffer("UPPER(")
@@ -64,6 +65,7 @@ public class DBDerby extends AbstractDBA
      * @param str The string whose case to ignore.
      * @return The string in a case that can be ignored.
      */
+    @Override
     public String ignoreCase(String str)
     {
         return toUpperCase(str);
@@ -72,6 +74,7 @@ public class DBDerby extends AbstractDBA
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodType()
      */
+    @Override
     public String getIDMethodType()
     {
         return AUTO_INCREMENT;
@@ -84,6 +87,7 @@ public class DBDerby extends AbstractDBA
      *
      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
      */
+    @Override
     public String getIDMethodSQL(Object obj)
     {
         return "VALUES IDENTITY_VAL_LOCAL()";
@@ -96,6 +100,7 @@ public class DBDerby extends AbstractDBA
      * @param table The name of the table to lock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void lockTable(Connection con, String table)
             throws SQLException
     {
@@ -113,6 +118,7 @@ public class DBDerby extends AbstractDBA
      * @param table The name of the table to unlock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void unlockTable(Connection con, String table)
             throws SQLException
     {
@@ -129,7 +135,7 @@ public class DBDerby extends AbstractDBA
      * @return true if the database needs to escape backslashes
      *         in SqlExpressions.
      */
-
+    @Override
      public boolean escapeText()
      {
          return false;
@@ -144,6 +150,7 @@ public class DBDerby extends AbstractDBA
      *
      * @return whether the escape clause should be appended or not.
      */
+    @Override
     public boolean useEscapeClauseForLike()
     {
         return true;

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBHsqldb.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBHsqldb.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBHsqldb.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBHsqldb.java
Mon Jan 30 17:51:39 2012
@@ -50,6 +50,7 @@ public class DBHsqldb extends AbstractDB
      * @param in The string to transform to upper case.
      * @return The upper case string.
      */
+    @Override
     public String toUpperCase(String in)
     {
         String s = new StringBuffer("UPPER(").append(in).append(")").toString();
@@ -62,6 +63,7 @@ public class DBHsqldb extends AbstractDB
      * @param in The string whose case to ignore.
      * @return The string in a case that can be ignored.
      */
+    @Override
     public String ignoreCase(String in)
     {
         return toUpperCase(in);
@@ -70,6 +72,7 @@ public class DBHsqldb extends AbstractDB
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodType()
      */
+    @Override
     public String getIDMethodType()
     {
         return AUTO_INCREMENT;
@@ -78,6 +81,7 @@ public class DBHsqldb extends AbstractDB
     /**
      * @see org.apache.torque.adapter.DB#ignoreCaseInOrderBy(String)
      */
+    @Override
     public String ignoreCaseInOrderBy(String in)
     {
         return "CAST(" + in + " AS VARCHAR_IGNORECASE(10000))";
@@ -86,6 +90,7 @@ public class DBHsqldb extends AbstractDB
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
      */
+    @Override
     public String getIDMethodSQL(Object obj)
     {
         StringBuffer command = new StringBuffer("select IDENTITY() from ");
@@ -101,6 +106,7 @@ public class DBHsqldb extends AbstractDB
      * @param table The name of the table to lock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void lockTable(Connection con, String table) throws SQLException
     {
     }
@@ -112,6 +118,7 @@ public class DBHsqldb extends AbstractDB
      * @param table The name of the table to unlock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void unlockTable(Connection con, String table) throws SQLException
     {
     }
@@ -123,6 +130,7 @@ public class DBHsqldb extends AbstractDB
      *
      * @return false.
      */
+    @Override
     public boolean escapeText()
     {
         return false;
@@ -137,6 +145,7 @@ public class DBHsqldb extends AbstractDB
      *
      * @return whether the escape clause should be appended or not.
      */
+    @Override
     public boolean useEscapeClauseForLike()
     {
         return true;

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMM.java
Mon Jan 30 17:51:39 2012
@@ -22,8 +22,6 @@ package org.apache.torque.adapter;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Date;
-import java.text.SimpleDateFormat;
 
 import org.apache.torque.sql.Query;
 
@@ -49,9 +47,6 @@ public class DBMM extends AbstractDBAdap
      */
     private static final long serialVersionUID = 7547291410802807010L;
 
-    /** A specialized date format for MySQL. */
-    private static final String DATE_FORMAT = "yyyyMMddHHmmss";
-
     /**
      * Empty protected constructor.
      */
@@ -65,6 +60,7 @@ public class DBMM extends AbstractDBAdap
      * @param in The string to transform to upper case.
      * @return The upper case string.
      */
+    @Override
     public String toUpperCase(String in)
     {
         return in;
@@ -76,6 +72,7 @@ public class DBMM extends AbstractDBAdap
      * @param in The string whose case to ignore.
      * @return The string in a case that can be ignored.
      */
+    @Override
     public String ignoreCase(String in)
     {
         return in;
@@ -84,6 +81,7 @@ public class DBMM extends AbstractDBAdap
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodType()
      */
+    @Override
     public String getIDMethodType()
     {
         return AUTO_INCREMENT;
@@ -96,6 +94,7 @@ public class DBMM extends AbstractDBAdap
      *
      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
      */
+    @Override
     public String getIDMethodSQL(Object obj)
     {
         return "SELECT LAST_INSERT_ID()";
@@ -109,6 +108,7 @@ public class DBMM extends AbstractDBAdap
      * @exception SQLException No Statement could be created or
      * executed.
      */
+    @Override
     public void lockTable(Connection con, String table) throws SQLException
     {
         Statement statement = con.createStatement();
@@ -125,6 +125,7 @@ public class DBMM extends AbstractDBAdap
      * @exception SQLException No Statement could be created or
      * executed.
      */
+    @Override
     public void unlockTable(Connection con, String table) throws SQLException
     {
         Statement statement = con.createStatement();
@@ -140,7 +141,8 @@ public class DBMM extends AbstractDBAdap
      * @param offset the offset Value
      * @param limit the limit Value
      */
-    public void generateLimits(Query query, int offset, int limit)
+    @Override
+    public void generateLimits(Query query, long offset, int limit)
     {
         if (offset > 0)
         {
@@ -153,7 +155,7 @@ public class DBMM extends AbstractDBAdap
                 // Limit must always be set in mysql if offset is set
                 query.setLimit("18446744073709551615");
             }
-            query.setOffset(Integer.toString(offset));
+            query.setOffset(Long.toString(offset));
         }
         else
         {
@@ -168,21 +170,10 @@ public class DBMM extends AbstractDBAdap
     }
 
     /**
-     * This method is used to chek whether the database supports
-     * limiting the size of the resultset.
-     *
-     * @return LIMIT_STYLE_MYSQL.
-     * @deprecated This should not be exposed to the outside
-     */
-    public int getLimitStyle()
-    {
-        return DB.LIMIT_STYLE_MYSQL;
-    }
-
-    /**
      * Return true for MySQL
      * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit()
      */
+    @Override
     public boolean supportsNativeLimit()
     {
         return true;
@@ -192,22 +183,9 @@ public class DBMM extends AbstractDBAdap
      * Return true for MySQL
      * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeOffset()
      */
+    @Override
     public boolean supportsNativeOffset()
     {
         return true;
     }
-
-    /**
-     * This method overrides the JDBC escapes used to format dates
-     * using a <code>DateFormat</code>.  As of version 2.0.11, the MM
-     * JDBC driver does not implement JDBC 3.0 escapes.
-     *
-     * @param date the date to format
-     * @return The properly formatted date String.
-     */
-    public String getDateString(Date date)
-    {
-        char delim = getStringDelimiter();
-        return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim);
-    }
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMSSQL.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMSSQL.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMSSQL.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBMSSQL.java
Mon Jan 30 17:51:39 2012
@@ -22,9 +22,9 @@ package org.apache.torque.adapter;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.torque.TorqueException;
 import org.apache.torque.sql.Query;
 
@@ -42,8 +42,8 @@ public class DBMSSQL extends AbstractDBA
      */
     private static final long serialVersionUID = -2924485528975497044L;
 
-    /** date format */
-    private static final String DATE_FORMAT = "yyyyMMdd HH:mm:ss";
+    /** The class logger. */
+    private static final Log log = LogFactory.getLog(DBMSSQL.class);
 
     /**
      * Empty constructor.
@@ -58,6 +58,7 @@ public class DBMSSQL extends AbstractDBA
      * @param in The string to transform to upper case.
      * @return The upper case string.
      */
+    @Override
     public String toUpperCase(String in)
     {
         return new StringBuffer("UPPER(").append(in).append(")").toString();
@@ -69,6 +70,7 @@ public class DBMSSQL extends AbstractDBA
      * @param in The string whose case to ignore.
      * @return The string in a case that can be ignored.
      */
+    @Override
     public String ignoreCase(String in)
     {
         return new StringBuffer("UPPER(").append(in).append(")").toString();
@@ -77,6 +79,7 @@ public class DBMSSQL extends AbstractDBA
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodType()
      */
+    @Override
     public String getIDMethodType()
     {
         return AUTO_INCREMENT;
@@ -89,6 +92,7 @@ public class DBMSSQL extends AbstractDBA
      *
      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
      */
+    @Override
     public String getIDMethodSQL(Object unused)
     {
         return "select @@identity";
@@ -99,18 +103,31 @@ public class DBMSSQL extends AbstractDBA
      *
      * @param con The JDBC connection to use.
      * @param table The name of the table to lock.
-     * @throws SQLException No Statement could be created or executed.
+     * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void lockTable(Connection con, String table) throws SQLException
     {
-        Statement statement = con.createStatement();
-
-        StringBuffer stmt = new StringBuffer();
-        stmt.append("SELECT next_id FROM ")
-        .append(table)
-        .append(" FOR UPDATE");
-
-        statement.executeQuery(stmt.toString());
+        Statement statement = null;
+        try
+        {
+            statement = con.createStatement();
+            statement.execute("SELECT * FROM " +  table + " WITH (TABLOCKX)");
+        }
+        finally
+        {
+            if (statement != null)
+            {
+                try
+                {
+                    statement.close();
+                }
+                catch (Exception e)
+                {
+                    log.warn("Colud not close lock statement", e);
+                }
+            }
+        }
     }
 
     /**
@@ -120,6 +137,7 @@ public class DBMSSQL extends AbstractDBA
      * @param table The name of the table to unlock.
      * @throws SQLException No Statement could be created or executed.
      */
+    @Override
     public void unlockTable(Connection con, String table) throws SQLException
     {
         // Tables in Sybase are unlocked when a commit is issued.  The
@@ -128,21 +146,10 @@ public class DBMSSQL extends AbstractDBA
     }
 
     /**
-     * This method is used to chek whether the database supports
-     * limiting the size of the resultset.
-     *
-     * @return LIMIT_STYLE_SYBASE.
-     * @deprecated This should not be exposed to the outside
-     */
-    public int getLimitStyle()
-    {
-        return DB.LIMIT_STYLE_SYBASE;
-    }
-
-    /**
      * Return true for Sybase
      * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit()
      */
+    @Override
     public boolean supportsNativeLimit()
     {
         return true;
@@ -157,7 +164,8 @@ public class DBMSSQL extends AbstractDBA
      *
      * @throws TorqueException if any error occurs when building the query
      */
-    public void generateLimits(Query query, int offset, int limit)
+    @Override
+    public void generateLimits(Query query, long offset, int limit)
         throws TorqueException
     {
         if (limit < 0 && offset >= 0) // Offset only test
@@ -176,20 +184,6 @@ public class DBMSSQL extends AbstractDBA
     }
 
     /**
-     * This method overrides the JDBC escapes used to format dates
-     * using a <code>DateFormat</code>.  As of version 11, the Sybase
-     * JDBC driver does not implement JDBC 3.0 escapes.
-     *
-     * @param date the date to format
-     * @return The properly formatted date String.
-     */
-    public String getDateString(Date date)
-    {
-        char delim = getStringDelimiter();
-        return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim);
-    }
-
-    /**
      * Determines whether backslashes (\) should be escaped in explicit SQL
      * strings. If true is returned, a BACKSLASH will be changed to "\\".
      * If false is returned, a BACKSLASH will be left as "\".
@@ -200,6 +194,7 @@ public class DBMSSQL extends AbstractDBA
      * @return false
      * @see org.apache.torque.adapter.DB#escapeText()
      */
+    @Override
     public boolean escapeText()
     {
         return false;
@@ -214,6 +209,7 @@ public class DBMSSQL extends AbstractDBA
      *
      * @return whether the escape clause should be appended or not.
      */
+    @Override
     public boolean useEscapeClauseForLike()
     {
         return true;

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBNone.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBNone.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBNone.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBNone.java
Mon Jan 30 17:51:39 2012
@@ -45,19 +45,12 @@ public class DBNone extends AbstractDBAd
     }
 
     /**
-     * @return null
-     */
-    public Connection getConnection()
-    {
-        return null;
-    }
-
-    /**
      * This method is used to ignore case.
      *
      * @param in The string to transform to upper case.
      * @return The upper case string.
      */
+    @Override
     public String toUpperCase(String in)
     {
         return in;
@@ -69,6 +62,7 @@ public class DBNone extends AbstractDBAd
      * @param in The string whose case to ignore.
      * @return The string in a case that can be ignored.
      */
+    @Override
     public String ignoreCase(String in)
     {
         return in;
@@ -77,6 +71,7 @@ public class DBNone extends AbstractDBAd
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodType()
      */
+    @Override
     public String getIDMethodType()
     {
         return NO_ID_METHOD;
@@ -85,6 +80,7 @@ public class DBNone extends AbstractDBAd
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
      */
+    @Override
     public String getIDMethodSQL(Object obj)
     {
         return null;
@@ -97,6 +93,7 @@ public class DBNone extends AbstractDBAd
      * @param table The name of the table to lock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void lockTable(Connection con, String table) throws SQLException
     {
     }
@@ -108,6 +105,7 @@ public class DBNone extends AbstractDBAd
      * @param table The name of the table to unlock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void unlockTable(Connection con, String table) throws SQLException
     {
     }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBOracle.java
Mon Jan 30 17:51:39 2012
@@ -22,12 +22,12 @@ package org.apache.torque.adapter;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.ListIterator;
 import java.util.Set;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.torque.sql.Query;
 import org.apache.torque.util.UniqueList;
 
@@ -47,8 +47,8 @@ public class DBOracle extends AbstractDB
      */
     private static final long serialVersionUID = 8966976210230241194L;
 
-    /** date format used in getDateString() */
-    private static final String DATE_FORMAT = "dd-MM-yyyy HH:mm:ss";
+    /** The class logger. */
+    private static final Log log = LogFactory.getLog(DBOracle.class);
 
     /**
      * Empty constructor.
@@ -63,6 +63,7 @@ public class DBOracle extends AbstractDB
      * @param in The string to transform to upper case.
      * @return The upper case string.
      */
+    @Override
     public String toUpperCase(String in)
     {
         return new StringBuffer("UPPER(").append(in).append(")").toString();
@@ -74,26 +75,16 @@ public class DBOracle extends AbstractDB
      * @param in The string whose case to ignore.
      * @return The string in a case that can be ignored.
      */
+    @Override
     public String ignoreCase(String in)
     {
         return new StringBuffer("UPPER(").append(in).append(")").toString();
     }
 
     /**
-     * This method is used to format any date string.
-     *
-     * @param date the Date to format
-     * @return The date formatted String for Oracle.
-     */
-    public String getDateString(Date date)
-    {
-        return "TO_DATE('" + new SimpleDateFormat(DATE_FORMAT).format(date)
-                + "', 'DD-MM-YYYY HH24:MI:SS')";
-    }
-
-    /**
      * @see org.apache.torque.adapter.DB#getIDMethodType()
      */
+    @Override
     public String getIDMethodType()
     {
         return SEQUENCE;
@@ -112,6 +103,7 @@ public class DBOracle extends AbstractDB
      * @return SQL to retreive the next database key.
      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object)
      */
+    @Override
     public String getIDMethodSQL(Object sequenceName)
     {
         return ("select " + sequenceName + ".nextval from dual");
@@ -124,16 +116,29 @@ public class DBOracle extends AbstractDB
      * @param table The name of the table to lock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void lockTable(Connection con, String table) throws SQLException
     {
-        Statement statement = con.createStatement();
-
-        StringBuffer stmt = new StringBuffer();
-        stmt.append("SELECT next_id FROM ")
-                .append(table)
-                .append(" FOR UPDATE");
-
-        statement.executeQuery(stmt.toString());
+        Statement statement = null;
+        try
+        {
+            statement = con.createStatement();
+            statement.execute("SELECT * FROM " +  table + " FOR UPDATE");
+        }
+        finally
+        {
+            if (statement != null)
+            {
+                try
+                {
+                    statement.close();
+                }
+                catch (Exception e)
+                {
+                    log.warn("Colud not close lock statement", e);
+                }
+            }
+        }
     }
 
     /**
@@ -143,6 +148,7 @@ public class DBOracle extends AbstractDB
      * @param table The name of the table to unlock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void unlockTable(Connection con, String table) throws SQLException
     {
         // Tables in Oracle are unlocked when a commit is issued.  The
@@ -151,21 +157,10 @@ public class DBOracle extends AbstractDB
     }
 
     /**
-     * This method is used to check whether the database supports
-     * limiting the size of the resultset.
-     *
-     * @return LIMIT_STYLE_ORACLE.
-     * @deprecated This should not be exposed to the outside
-     */
-    public int getLimitStyle()
-    {
-        return DB.LIMIT_STYLE_ORACLE;
-    }
-
-    /**
      * Return true for Oracle
      * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit()
      */
+    @Override
     public boolean supportsNativeLimit()
     {
         return true;
@@ -175,6 +170,7 @@ public class DBOracle extends AbstractDB
      * Return true for Oracle
      * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeOffset()
      */
+    @Override
     public boolean supportsNativeOffset()
     {
         return true;
@@ -197,7 +193,8 @@ public class DBOracle extends AbstractDB
      * @param offset the offset Value
      * @param limit the limit Value
      */
-    public void generateLimits(Query query, int offset, int limit)
+    @Override
+    public void generateLimits(Query query, long offset, int limit)
     {
         StringBuffer preLimit = new StringBuffer()
         .append("SELECT B.* FROM ( ")
@@ -328,6 +325,7 @@ public class DBOracle extends AbstractDB
      *
      * @return false.
      */
+    @Override
     public boolean escapeText()
     {
         return false;
@@ -342,6 +340,7 @@ public class DBOracle extends AbstractDB
      *
      * @return whether the escape clause should be appended or not.
      */
+    @Override
     public boolean useEscapeClauseForLike()
     {
         return true;

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBPostgres.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBPostgres.java?rev=1237843&r1=1237842&r2=1237843&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBPostgres.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/adapter/DBPostgres.java
Mon Jan 30 17:51:39 2012
@@ -21,9 +21,6 @@ package org.apache.torque.adapter;
 
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 
 import org.apache.torque.sql.Query;
 
@@ -43,9 +40,6 @@ public class DBPostgres extends Abstract
      */
     private static final long serialVersionUID = 7643304924262475272L;
 
-    /** A specialized date format for PostgreSQL. */
-    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
-
     /**
      * Empty constructor.
      */
@@ -59,6 +53,7 @@ public class DBPostgres extends Abstract
      * @param in The string to transform to upper case.
      * @return The upper case string.
      */
+    @Override
     public String toUpperCase(String in)
     {
         String s = new StringBuffer("UPPER(").append(in).append(")").toString();
@@ -71,6 +66,7 @@ public class DBPostgres extends Abstract
      * @param in The string whose case to ignore.
      * @return The string in a case that can be ignored.
      */
+    @Override
     public String ignoreCase(String in)
     {
         String s = new StringBuffer("UPPER(").append(in).append(")").toString();
@@ -80,6 +76,7 @@ public class DBPostgres extends Abstract
     /**
      * @see org.apache.torque.adapter.DB#getIDMethodType()
      */
+    @Override
     public String getIDMethodType()
     {
         return SEQUENCE;
@@ -91,6 +88,7 @@ public class DBPostgres extends Abstract
      * @return SQL to retreive the next database key.
      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object)
      */
+    @Override
     public String getIDMethodSQL(Object name)
     {
         return ("select nextval('" + name + "')");
@@ -103,6 +101,7 @@ public class DBPostgres extends Abstract
      * @param table The name of the table to lock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void lockTable(Connection con, String table) throws SQLException
     {
     }
@@ -114,26 +113,16 @@ public class DBPostgres extends Abstract
      * @param table The name of the table to unlock.
      * @exception SQLException No Statement could be created or executed.
      */
+    @Override
     public void unlockTable(Connection con, String table) throws SQLException
     {
     }
 
     /**
-     * This method is used to chek whether the database supports
-     * limiting the size of the resultset.
-     *
-     * @return LIMIT_STYLE_POSTGRES.
-     * @deprecated This should not be exposed to the outside
-     */
-    public int getLimitStyle()
-    {
-        return DB.LIMIT_STYLE_POSTGRES;
-    }
-
-    /**
      * Return true for PostgreSQL
      * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit()
      */
+    @Override
     public boolean supportsNativeLimit()
     {
         return true;
@@ -143,6 +132,7 @@ public class DBPostgres extends Abstract
      * Return true for PostgreSQL
      * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeOffset()
      */
+    @Override
     public boolean supportsNativeOffset()
     {
         return true;
@@ -157,11 +147,12 @@ public class DBPostgres extends Abstract
      * @param offset the offset Value
      * @param limit the limit Value
      */
-    public void generateLimits(Query query, int offset, int limit)
+    @Override
+    public void generateLimits(Query query, long offset, int limit)
     {
         if (offset > 0)
         {
-            query.setOffset(Integer.toString(offset));
+            query.setOffset(Long.toString(offset));
         }
         if (limit >= 0)
         {
@@ -173,37 +164,6 @@ public class DBPostgres extends Abstract
     }
 
     /**
-     * Override the default behavior to associate b with null?
-     *
-     * @see DB#getBooleanString(Boolean)
-     */
-    public String getBooleanString(Boolean b)
-    {
-        return (b == null) ? "FALSE" : (Boolean.TRUE.equals(b) ? "TRUE" : "FALSE");
-    }
-
-    /**
-     * This method overrides the JDBC escapes used to format dates
-     * using a <code>DateFormat</code>.
-     *
-     * This generates the timedate format defined in
-     * http://www.postgresql.org/docs/7.3/static/datatype-datetime.html
-     * which defined PostgreSQL dates as YYYY-MM-DD hh:mm:ss
-     * @param date the date to format
-     * @return The properly formatted date String.
-     */
-    public String getDateString(Date date)
-    {
-        DateFormat df = new SimpleDateFormat(DATE_FORMAT);
-        StringBuffer dateBuf = new StringBuffer();
-        char delim = getStringDelimiter();
-        dateBuf.append(delim);
-        dateBuf.append(df.format(date));
-        dateBuf.append(delim);
-        return dateBuf.toString();
-    }
-
-    /**
      * Whether ILIKE should be used for case insensitive like clauses.
      *
      * As postgres uses ILIKE, this mimplementation returns true.
@@ -211,6 +171,7 @@ public class DBPostgres extends Abstract
      * @return true if ilike should be used for case insensitive likes,
      *         false if ignoreCase should be applied to the compared strings.
      */
+    @Override
     public boolean useIlike()
     {
         return true;



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message