openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Lee" <allee8...@gmail.com>
Subject Re: svn commit: r707270 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/ openjpa-project/src/doc/ma
Date Thu, 23 Oct 2008 22:14:44 GMT
A couple of questions:

1) looks like logSQLWarning(warn) is only called from logSQLWarnings(stmt),
but warn will never be null, hence the warn == null check in logSQLWarning
is unnecessary. If there is only a "_log.trace(..." being call,  would it be
more readable if the "_log.trace(" is in-line in logSQLWarnings()?

+    protected void logSQLWarnings(PreparedStatement stmt) {
+        if (stmt != null && _log != null && _log.isTraceEnabled()) {
+            try {
+                SQLWarning warn = stmt.getWarnings();
+                while (warn != null) {
+                    logSQLWarning(warn);
+                    warn = warn.getNextWarning();
+                } while (warn != null);
+            } catch (SQLException e) {}
+        }
+    }
+
+    /*
+     * Log the SQLWarning message.  Some drivers report expected conditions
+     * such as "no rows returned" as a warning.  These types of messages
can
+     * clutter up the default log very quickly, so trace level will be used
to
+     * log SQL warnings.
+     */
+    private void logSQLWarning(SQLWarning warn) {
+        if (warn != null) {
+            _log.trace(_loc.get("sql-warning", warn.getMessage()));
+        }
+    }

2) This feature is for Sybase but the listitem's id defined as
""OracleDictionary.IgnoreNumericTruncation". Is this correct?

+            <itemizedlist>
+                <listitem id="OracleDictionary.IgnoreNumericTruncation">
+                    <para>
+                    <indexterm>
+                        <primary>
+                            Sybase
+                        </primary>
+                        <secondary>
+                            IgnoreNumericTruncation
+                        </secondary>
+                    </indexterm>
+<literal>IgnoreNumericTruncation</literal>: If true, Sybase will ignore
numeric
+truncation on SQL operations.  Otherwise, if numeric trunctation is
detected,
+the operation will fail.
+                    </para>
+                </listitem>
+            </itemizedlist>

Albert Lee

On Wed, Oct 22, 2008 at 11:43 PM, <jrbauer@apache.org> wrote:

> Author: jrbauer
> Date: Wed Oct 22 21:43:35 2008
> New Revision: 707270
>
> URL: http://svn.apache.org/viewvc?rev=707270&view=rev
> Log:
> OPENJPA-750: Added option to Sybase dictionary to ignore truncation
> warnings, added doc for new dictionary option, and code to log any
> SQLWarnings when update count isn't expected value.
>
> Modified:
>
>  openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/BatchingPreparedStatementManagerImpl.java
>
>  openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
>
>  openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
>
>  openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
>    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
>
> Modified:
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/BatchingPreparedStatementManagerImpl.java
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/BatchingPreparedStatementManagerImpl.java?rev=707270&r1=707269&r2=707270&view=diff
>
> ==============================================================================
> ---
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/BatchingPreparedStatementManagerImpl.java
> (original)
> +++
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/BatchingPreparedStatementManagerImpl.java
> Wed Oct 22 21:43:35 2008
> @@ -55,7 +55,6 @@
>     private List _batchedRows = new ArrayList();
>     private int _batchLimit;
>     private boolean _disableBatch = false;
> -    private transient Log _log = null;
>
>     /**
>      * Constructor. Supply connection.
> @@ -64,7 +63,6 @@
>         Connection conn, int batchLimit) {
>         super(store, conn);
>         _batchLimit = batchLimit;
> -        _log =
> store.getConfiguration().getLog(JDBCConfiguration.LOG_JDBC);
>         if (_log.isTraceEnabled())
>             _log.trace(_loc.get("batch_limit",
> String.valueOf(_batchLimit)));
>     }
> @@ -216,6 +214,7 @@
>             row.flush(ps, _dict, _store);
>         int count = executeUpdate(ps, row.getSQL(_dict), row);
>         if (count != 1) {
> +            logSQLWarnings(ps);
>             Object failed = row.getFailedObject();
>             if (failed != null)
>                 _exceptions.add(new OptimisticException(failed));
> @@ -280,6 +279,7 @@
>                 break;
>             case 0: // no row is inserted, treats it as failed
>                 // case
> +                logSQLWarnings(ps);
>                 if (failed != null)
>                     _exceptions.add(new OptimisticException(failed));
>                 else if (row.getAction() == Row.ACTION_INSERT)
>
> Modified:
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java?rev=707270&r1=707269&r2=707270&view=diff
>
> ==============================================================================
> ---
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
> (original)
> +++
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java
> Wed Oct 22 21:43:35 2008
> @@ -22,11 +22,13 @@
>  import java.sql.PreparedStatement;
>  import java.sql.ResultSet;
>  import java.sql.SQLException;
> +import java.sql.SQLWarning;
>  import java.util.ArrayList;
>  import java.util.Collection;
>  import java.util.LinkedList;
>  import java.util.List;
>
> +import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
>  import org.apache.openjpa.jdbc.meta.ClassMapping;
>  import org.apache.openjpa.jdbc.schema.Column;
>  import org.apache.openjpa.jdbc.sql.DBDictionary;
> @@ -34,6 +36,7 @@
>  import org.apache.openjpa.jdbc.sql.RowImpl;
>  import org.apache.openjpa.jdbc.sql.SQLExceptions;
>  import org.apache.openjpa.kernel.OpenJPAStateManager;
> +import org.apache.openjpa.lib.log.Log;
>  import org.apache.openjpa.lib.util.Localizer;
>  import org.apache.openjpa.util.ApplicationIds;
>  import org.apache.openjpa.util.OpenJPAException;
> @@ -53,6 +56,7 @@
>     protected final JDBCStore _store;
>     protected final Connection _conn;
>     protected final DBDictionary _dict;
> +    protected transient Log _log = null;
>
>     // track exceptions
>     protected final Collection _exceptions = new LinkedList();
> @@ -64,6 +68,8 @@
>         _store = store;
>         _dict = store.getDBDictionary();
>         _conn = conn;
> +        if (store.getConfiguration() != null)
> +            _log =
> store.getConfiguration().getLog(JDBCConfiguration.LOG_JDBC);
>     }
>
>     public Collection getExceptions() {
> @@ -105,6 +111,7 @@
>         try {
>             int count = executeUpdate(stmnt, sql, row);
>             if (count != 1) {
> +                logSQLWarnings(stmnt);
>                 Object failed = row.getFailedObject();
>                 if (failed != null)
>                     _exceptions.add(new OptimisticException(failed));
> @@ -233,4 +240,32 @@
>         else
>             return _conn.prepareStatement(sql);
>     }
> +
> +    /**
> +     * Provided the JDBC log category is logging warnings, this method
> will
> +     * log any SQL warnings that result from the execution of a SQL
> statement.
> +     */
> +    protected void logSQLWarnings(PreparedStatement stmt) {
> +        if (stmt != null && _log != null && _log.isTraceEnabled()) {
> +            try {
> +                SQLWarning warn = stmt.getWarnings();
> +                while (warn != null) {
> +                    logSQLWarning(warn);
> +                    warn = warn.getNextWarning();
> +                } while (warn != null);
> +            } catch (SQLException e) {}
> +        }
> +    }
> +
> +    /*
> +     * Log the SQLWarning message.  Some drivers report expected
> conditions
> +     * such as "no rows returned" as a warning.  These types of messages
> can
> +     * clutter up the default log very quickly, so trace level will be
> used to
> +     * log SQL warnings.
> +     */
> +    private void logSQLWarning(SQLWarning warn) {
> +        if (warn != null) {
> +            _log.trace(_loc.get("sql-warning", warn.getMessage()));
> +        }
> +    }
>  }
>
> Modified:
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java?rev=707270&r1=707269&r2=707270&view=diff
>
> ==============================================================================
> ---
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
> (original)
> +++
> openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java
> Wed Oct 22 21:43:35 2008
> @@ -75,6 +75,13 @@
>      */
>     public String identityColumnName = "UNQ_INDEX";
>
> +    /**
> +     * If true, Sybase will ignore numeric truncation on insert or
> +     * update operations.  Otherwise, the operation will fail. The default
> +     * value, false is in accordance with SQL92.
> +     */
> +    public boolean ignoreNumericTruncation = false;
> +
>     public SybaseDictionary() {
>         platform = "Sybase";
>         schemaCase = SCHEMA_CASE_PRESERVE;
> @@ -277,6 +284,18 @@
>             stmnt.execute();
>             stmnt.close();
>         }
> +
> +        // By default, Sybase will fail to insert or update if a numeric
> +        // truncation occurs as a result of, for example, loss of decimal
> +        // precision.  This setting specifies that the operation should
> not
> +        // fail if a numeric truncation occurs.
> +        if (ignoreNumericTruncation) {
> +            String str = "set arithabort numeric_truncation off";
> +            PreparedStatement stmnt = prepareStatement(conn, str);
> +            stmnt.execute();
> +            stmnt.close();
> +        }
> +
>         return new SybaseConnection(conn);
>     }
>
>
> Modified:
> openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties?rev=707270&r1=707269&r2=707270&view=diff
>
> ==============================================================================
> ---
> openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
> (original)
> +++
> openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/kernel/localizer.properties
> Wed Oct 22 21:43:35 2008
> @@ -117,3 +117,4 @@
>        statement {1}.
>  cache-hit: SQL Cache hit with key: {0} in {1}
>  cache-missed: SQL Cache missed with key: {0} in {1}
> +sql-warning: The statement resulted in SQL warning: {0}
>
> Modified:
> openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
> URL:
> http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml?rev=707270&r1=707269&r2=707270&view=diff
>
> ==============================================================================
> --- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
> (original)
> +++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml Wed
> Oct 22 21:43:35 2008
> @@ -3360,7 +3360,41 @@
>                 </listitem>
>             </itemizedlist>
>         </section>
> -    </section>
> +        <section id="ref_guide_dbsetup_dbsupport_sybase">
> +            <title>
> +                SybaseDictionary Properties
> +            </title>
> +            <indexterm zone="ref_guide_dbsetup_dbsupport_sybase">
> +                <primary>
> +                    Sybase
> +                </primary>
> +                <seealso>
> +                    DBDictionary
> +                </seealso>
> +            </indexterm>
> +            <para>
> +The <literal>sybase</literal> dictionary understands the following
> additional
> +properties:
> +            </para>
> +            <itemizedlist>
> +                <listitem id="OracleDictionary.IgnoreNumericTruncation">
> +                    <para>
> +                    <indexterm>
> +                        <primary>
> +                            Sybase
> +                        </primary>
> +                        <secondary>
> +                            IgnoreNumericTruncation
> +                        </secondary>
> +                    </indexterm>
> +<literal>IgnoreNumericTruncation</literal>: If true, Sybase will ignore
> numeric
> +truncation on SQL operations.  Otherwise, if numeric trunctation is
> detected,
> +the operation will fail.
> +                    </para>
> +                </listitem>
> +            </itemizedlist>
> +        </section>
> +    </section>
>     <section id="ref_guide_dbsetup_isolation">
>         <title>
>             Setting the Transaction Isolation
>
>
>


-- 
Albert Lee.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message