You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tv...@apache.org on 2010/11/23 22:56:25 UTC

svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Author: tv
Date: Tue Nov 23 21:56:25 2010
New Revision: 1038355

URL: http://svn.apache.org/viewvc?rev=1038355&view=rev
Log:
Attempt to fix case-sensitivity and Oracle metadata problems

Modified:
    db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Modified: db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java
URL: http://svn.apache.org/viewvc/db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java?rev=1038355&r1=1038354&r2=1038355&view=diff
==============================================================================
--- db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java (original)
+++ db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java Tue Nov 23 21:56:25 2010
@@ -32,6 +32,8 @@ import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 
 /**
  * The Schema object represents the <a href="Column.html">Columns</a> in a database table. It contains a collection of <a
@@ -54,7 +56,7 @@ public final class Schema
 
     /** TODO: DOCUMENT ME! */
     private Column [] columns;
-    private Hashtable columnNumberByName;
+    private Map columnNumberByName;
 
     /** TODO: DOCUMENT ME! */
     private static final Hashtable schemaCache = new Hashtable();
@@ -186,15 +188,11 @@ public final class Schema
                 {
                     String sql = "SELECT " + columnsAttribute + " FROM " + tableName + " WHERE 1 = -1";
 
-                    /*
-                     *  prepare dummy query as recommended by John Goodson in
-                     *  http://www.theserverside.com/news/1365579/Using-Database-MetaData-methods-appropriately
-                     */
                     stmt = conn.prepareStatement(sql);
 
-                    // query is never executed on the server - only prepared
                     if (stmt != null)
                     {
+                        stmt.executeQuery();
                         tableSchema = this;
                         tableSchema.setTableName(tableName);
                         tableSchema.setAttributes(columnsAttribute);
@@ -461,7 +459,7 @@ public final class Schema
     {
         this.numberOfColumns = meta.getColumnCount();
         columns = new Column[numberOfColumns() + 1];
-        columnNumberByName = new Hashtable((int) ((1.25 * numberOfColumns) + 1));
+        columnNumberByName = new TreeMap(String.CASE_INSENSITIVE_ORDER);
 
         String connURL = (conn != null) ? conn.getMetaData().getURL() : null;
 
@@ -604,7 +602,7 @@ public final class Schema
     {
         List cols = new ArrayList();
         String tableName = null;
-        columnNumberByName = new Hashtable();
+        columnNumberByName = new TreeMap(String.CASE_INSENSITIVE_ORDER);
 
         while (dbMeta.next())
         {



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


Re: svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Posted by Thomas Fox <Th...@seitenbau.net>.
Hi Thomas,

> Could you please re-run your test project against Oracle with this
> version and tell me the findings?

will do. Might take a week or so.

   Thomas


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


RE: svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Posted by Greg Monroe <Gr...@dukece.com>.
The SummaryHelper class has been refactored to use a new ListOrderedMapCI 
class that converts all String keys to lowercase.  Also, some changes where
made to the SummaryHelperTest class to better allow for DB's that might add
an UPPER column (Oracle) to the record.  The fix that was in place broke with
MS SQL.  The new code now checks if there's an extra column and adjusts 
accordingly.

Note that if anyone is using this in their code (with a runtime jar built 
from CVS), they may have to make sure that their code uses the new class to
ensure column names are case insensitive.  Alternatively, you can still use
the OrderMap interface if you make sure your keys are lowercased.

I have tested this against MySQL and MS SQL. Testing with Oracle and 
Postgres would be nice if someone has access/time.

TIA

> -----Original Message-----
> From: Greg Monroe
> Sent: Thursday, December 02, 2010 5:34 PM
> To: 'Apache Torque Developers List'
> Subject: RE: svn commit: r1038355 -
> /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java
> 
> OK, catching up after a week and a bit off...
> 
> FYI - SummaryHelper did not make it into the last Torque release, so it's
> only in the repository.  The Village release probably should not be held
> up by this.
> 
> As pointed out, the underlying problem is that column names in the
> metadata
> may have different cases depending on the DB server. This means that
> results
> can be stored under a different name that was defined.
> 
> FWIW - I used ListOrderedMap for the results since it was close to what
> you
> get in a normal JDBC ResultSet.  E.g, access info by index or name.
> 
> Unfortunately, there doesn't seem to be a case insensitive version of
> this
> in commons.
> 
> I think the quick fix would be to create a subclass of ListOrderedMap
> that
> added a case insensitive methods like get( String key ),
> put( String key, Object value ), indexOf(String key), remove( String
> key),
> and containsKey ( String key ). Then use this instead of ListOrderedMap
> in
> the SummaryHelper code.
> 
> Greg
> 
> > -----Original Message-----
> > From: Thomas Vandahl [mailto:tv@apache.org]
> > Sent: Thursday, December 02, 2010 4:27 PM
> > To: Apache Torque Developers List
> > Subject: Re: svn commit: r1038355 -
> > /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java
> >
> > On 28.11.10 21:42, Thomas Fox wrote:
> > >> Could you please re-run your test project against Oracle with this
> > >> version and tell me the findings?
> > >
> > > Looks good. The test project runs ok against oracle using the current
> > > village 3.3.1 trunk.
> > > I did not run the test project for other databases.
> >
> > Ok. I tested against MySQL and PostgreSQL and the test project worked
> > fine. Both consistently fail on SummaryHelperTest, however.
> >
> > By looking at the code of SummaryHelper I guess this is based on the
> > fact that the results are put into a case-sensitive OrderedMap using
> the
> > column names returned from the database as a key. In the case of
> > Postgresql for example, the database returns the column names in lower
> > case, so that the test cannot find them. See example output of
> > dumpResults():
> >
> > ---8<---
> > "group_by1", "count_recs", "avg_int1", "min_int1", "max_int1",
> > "sum_int1", "avg_float1", "min_float1", "max_float1", "sum_float1",
> > "upper"
> > "A1", 4, 2.5000000000000000, 1, 4, 10, 5.0, 2.0, 8.0, 20.0, "A1"
> > "B1", 4, 3.5000000000000000, 2, 5, 14, 7.0, 4.0, 10.0, 28.0, "B1"
> > "C1", 4, 4.5000000000000000, 3, 6, 18, 9.0, 6.0, 12.0, 36.0, "C1"
> > "D1", 4, 5.5000000000000000, 4, 7, 22, 11.0, 8.0, 14.0, 44.0, "D1"
> > ---8<---
> >
> > So I believe either the test or the implementation is wrong.
> >
> > Other than this, shall we try another RC for Village 3.3.1?
> >
> > Bye, Thomas
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-dev-help@db.apache.org
> 
> DukeCE Privacy Statement:
> Please be advised that this e-mail and any files transmitted with
> it are confidential communication or may otherwise be privileged or
> confidential and are intended solely for the individual or entity
> to whom they are addressed. If you are not the intended recipient
> you may not rely on the contents of this email or any attachments,
> and we ask that you please not read, copy or retransmit this
> communication, but reply to the sender and destroy the email, its
> contents, and all copies thereof immediately. Any unauthorized
> dissemination, distribution or copying of this communication is
> strictly prohibited.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org


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


RE: svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Posted by Greg Monroe <Gr...@dukece.com>.
OK, catching up after a week and a bit off... 

FYI - SummaryHelper did not make it into the last Torque release, so it's 
only in the repository.  The Village release probably should not be held 
up by this.

As pointed out, the underlying problem is that column names in the metadata
may have different cases depending on the DB server. This means that results
can be stored under a different name that was defined.

FWIW - I used ListOrderedMap for the results since it was close to what you
get in a normal JDBC ResultSet.  E.g, access info by index or name.  

Unfortunately, there doesn't seem to be a case insensitive version of this 
in commons.

I think the quick fix would be to create a subclass of ListOrderedMap that
added a case insensitive methods like get( String key ), 
put( String key, Object value ), indexOf(String key), remove( String key), 
and containsKey ( String key ). Then use this instead of ListOrderedMap in 
the SummaryHelper code.

Greg

> -----Original Message-----
> From: Thomas Vandahl [mailto:tv@apache.org]
> Sent: Thursday, December 02, 2010 4:27 PM
> To: Apache Torque Developers List
> Subject: Re: svn commit: r1038355 -
> /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java
> 
> On 28.11.10 21:42, Thomas Fox wrote:
> >> Could you please re-run your test project against Oracle with this
> >> version and tell me the findings?
> >
> > Looks good. The test project runs ok against oracle using the current
> > village 3.3.1 trunk.
> > I did not run the test project for other databases.
> 
> Ok. I tested against MySQL and PostgreSQL and the test project worked
> fine. Both consistently fail on SummaryHelperTest, however.
> 
> By looking at the code of SummaryHelper I guess this is based on the
> fact that the results are put into a case-sensitive OrderedMap using the
> column names returned from the database as a key. In the case of
> Postgresql for example, the database returns the column names in lower
> case, so that the test cannot find them. See example output of
> dumpResults():
> 
> ---8<---
> "group_by1", "count_recs", "avg_int1", "min_int1", "max_int1",
> "sum_int1", "avg_float1", "min_float1", "max_float1", "sum_float1",
> "upper"
> "A1", 4, 2.5000000000000000, 1, 4, 10, 5.0, 2.0, 8.0, 20.0, "A1"
> "B1", 4, 3.5000000000000000, 2, 5, 14, 7.0, 4.0, 10.0, 28.0, "B1"
> "C1", 4, 4.5000000000000000, 3, 6, 18, 9.0, 6.0, 12.0, 36.0, "C1"
> "D1", 4, 5.5000000000000000, 4, 7, 22, 11.0, 8.0, 14.0, 44.0, "D1"
> ---8<---
> 
> So I believe either the test or the implementation is wrong.
> 
> Other than this, shall we try another RC for Village 3.3.1?
> 
> Bye, Thomas
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org

DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

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


Re: svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Posted by Thomas Fox <Th...@seitenbau.net>.
> So I believe either the test or the implementation is wrong.

The test is wrong. I believe Greg has already fixed it.

> Other than this, shall we try another RC for Village 3.3.1?

Go ahead.

   Thomas


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


Re: svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Posted by Thomas Vandahl <tv...@apache.org>.
On 28.11.10 21:42, Thomas Fox wrote:
>> Could you please re-run your test project against Oracle with this
>> version and tell me the findings?
> 
> Looks good. The test project runs ok against oracle using the current
> village 3.3.1 trunk.
> I did not run the test project for other databases.

Ok. I tested against MySQL and PostgreSQL and the test project worked
fine. Both consistently fail on SummaryHelperTest, however.

By looking at the code of SummaryHelper I guess this is based on the
fact that the results are put into a case-sensitive OrderedMap using the
column names returned from the database as a key. In the case of
Postgresql for example, the database returns the column names in lower
case, so that the test cannot find them. See example output of
dumpResults():

---8<---
"group_by1", "count_recs", "avg_int1", "min_int1", "max_int1",
"sum_int1", "avg_float1", "min_float1", "max_float1", "sum_float1", "upper"
"A1", 4, 2.5000000000000000, 1, 4, 10, 5.0, 2.0, 8.0, 20.0, "A1"
"B1", 4, 3.5000000000000000, 2, 5, 14, 7.0, 4.0, 10.0, 28.0, "B1"
"C1", 4, 4.5000000000000000, 3, 6, 18, 9.0, 6.0, 12.0, 36.0, "C1"
"D1", 4, 5.5000000000000000, 4, 7, 22, 11.0, 8.0, 14.0, 44.0, "D1"
---8<---

So I believe either the test or the implementation is wrong.

Other than this, shall we try another RC for Village 3.3.1?

Bye, Thomas

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


Re: svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Posted by Thomas Fox <Th...@seitenbau.net>.
> Hi Thomas,
>
> On 23.11.10 22:56, tv@apache.org wrote:
> > Author: tv
> > Date: Tue Nov 23 21:56:25 2010
> > New Revision: 1038355
> >
> > URL: http://svn.apache.org/viewvc?rev=1038355&view=rev
> > Log:
> > Attempt to fix case-sensitivity and Oracle metadata problems
> >
> > Modified:
> >
db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java
>
> Could you please re-run your test project against Oracle with this
> version and tell me the findings?

Looks good. The test project runs ok against oracle using the current
village 3.3.1 trunk.
I did not run the test project for other databases.

    Thomas


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


Re: svn commit: r1038355 - /db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Posted by Thomas Vandahl <tv...@apache.org>.
Hi Thomas,

On 23.11.10 22:56, tv@apache.org wrote:
> Author: tv
> Date: Tue Nov 23 21:56:25 2010
> New Revision: 1038355
> 
> URL: http://svn.apache.org/viewvc?rev=1038355&view=rev
> Log:
> Attempt to fix case-sensitivity and Oracle metadata problems
> 
> Modified:
>     db/torque/village/trunk/src/java/com/workingdogs/village/Schema.java

Could you please re-run your test project against Oracle with this
version and tell me the findings?

Bye, Thomas.

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