[jboss-cvs] JBossAS SVN: r59520 - in branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp: jdbc/bridge and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 11 07:01:27 EST 2007


Author: alex.loubyansky at jboss.com
Date: 2007-01-11 07:01:17 -0500 (Thu, 11 Jan 2007)
New Revision: 59520

Modified:
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/EJBQLToSQL92Compiler.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDynamicQLQuery.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLCompiler.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLQuery.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCJBossQLQuery.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCType.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplex.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeSimple.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/QLCompiler.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/SQLUtil.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DeclaredSQLQueryCommand.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/EJBQLQueryCommand.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/FindByPrimaryKeyCommand.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/bridge/JDBCCMRFieldBridge2.java
   branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/EntityTable.java
Log:
JBAS-3800 backport from trunk

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/EJBQLToSQL92Compiler.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/EJBQLToSQL92Compiler.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/EJBQLToSQL92Compiler.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import java.io.StringReader;
@@ -34,11 +34,13 @@
 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCFieldBridge;
 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractEntityBridge;
 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMRFieldBridge;
+import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCTypeMappingMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCFunctionMappingMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
+import org.jboss.ejb.plugins.cmp.bridge.CMPFieldBridge;
 import org.jboss.ejb.EntityPersistenceStore;
 import org.jboss.logging.Logger;
 
@@ -84,6 +86,7 @@
    private StringBuffer onFindCMRJoin;
 
    private boolean countCompositePk;
+   private boolean selectDistinct;
 
    public EJBQLToSQL92Compiler(Catalog catalog)
    {
@@ -243,6 +246,11 @@
       return leftJoinCMRList;
    }
 
+   public boolean isSelectDistinct()
+   {
+      return selectDistinct;
+   }
+
    public Object visit(SimpleNode node, Object data)
    {
       throw new RuntimeException("Internal error: Found unknown node type in " +
@@ -300,6 +308,8 @@
          }
       }
 
+      selectDistinct = ((ASTSelect) selectNode).distinct || returnType == Set.class || forceDistinct;
+
       // assemble sql
       StringBuffer sql = (StringBuffer) data;
       if(selectManager.getMetaData().hasRowLocking() && !(selectObject instanceof SelectFunction))
@@ -310,7 +320,7 @@
             throw new IllegalStateException("Row locking template is not defined for given mapping: " + typeMapping.getName());
          }
 
-         boolean distinct = ((ASTSelect) selectNode).distinct || returnType == Set.class || forceDistinct;
+         boolean distinct = selectDistinct;
 
          Object args[] = new Object[]{
             distinct ? SQLUtil.DISTINCT + selectClause : selectClause.toString(),
@@ -323,7 +333,7 @@
       else
       {
          sql.append(SQLUtil.SELECT);
-         if(((ASTSelect) selectNode).distinct || returnType == Set.class || forceDistinct)
+         if(selectDistinct)
          {
             sql.append(SQLUtil.DISTINCT);
          }
@@ -455,9 +465,14 @@
             setTypeFactory(selectEntity.getManager().getJDBCTypeFactory());
 
             final String alias = aliasManager.getAlias(path.getPath());
-            SQLUtil.getColumnNamesClause(selectEntity.getTableFields(),
-               alias,
-               sql);
+            if(select.distinct)
+            {
+               SQLUtil.getSearchableColumnNamesClause(selectEntity.getTableFields(), alias, sql);
+            }
+            else
+            {
+               SQLUtil.getColumnNamesClause(selectEntity.getTableFields(), alias, sql);
+            }
 
             /*
             if(readAhead.isOnFind())
@@ -904,6 +919,64 @@
    public Object visit(ASTValueClassComparison node, Object data)
    {
       throw new IllegalStateException("Value class comparison is not yet supported.");
+/*
+      StringBuffer buf = (StringBuffer) data;
+
+      boolean not = (node.opp.equals(SQLUtil.NOT_EQUAL));
+      String comparison = node.opp;
+      buf.append('(');
+      if(not)
+      {
+         buf.append(SQLUtil.NOT).append('(');
+         comparison = "=";
+      }
+
+      // setup the from path
+      ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
+      System.out.println("fromPath: " + fromPath.getPath());
+      addInnerJoinPath(fromPath);
+      String fromAlias = aliasManager.getAlias(fromPath.getPath(fromPath.size() - 2));
+      CMPFieldBridge fromCMPField = (CMPFieldBridge) fromPath.getCMPField();
+
+      Node toNode = node.jjtGetChild(1);
+      if(toNode instanceof ASTParameter)
+      {
+         ASTParameter toParam = (ASTParameter) toNode;
+
+         // can only compare like kind entities
+         Class parameterType = getParameterType(toParam.number);
+         if(!(fromCMPField.getFieldType().equals(parameterType)))
+         {
+            throw new IllegalStateException("Only like types can be " +
+               "compared: from CMP field=" +
+               fromCMPField.getFieldType() +
+               " to parameter=" + parameterType);
+         }
+
+         inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromCMPField));
+         SQLUtil.getWhereClause(fromCMPField.getJDBCType(), fromAlias, comparison, buf);
+      }
+      else
+      {
+         ASTPath toPath = (ASTPath) toNode;
+         addInnerJoinPath(toPath);
+         String toAlias = aliasManager.getAlias(toPath.getPath(toPath.size() - 2));
+         JDBCCMPFieldBridge toCMPField = (JDBCCMPFieldBridge) toPath.getCMPField();
+
+         // can only compare like kind entities
+         if(!(fromCMPField.getFieldType().equals(toCMPField.getFieldType())))
+         {
+            throw new IllegalStateException("Only like types can be " +
+               "compared: from CMP field=" +
+               fromCMPField.getFieldType() +
+               " to CMP field=" + toCMPField.getFieldType());
+         }
+
+         SQLUtil.getSelfCompareWhereClause(fromCMPField, toCMPField, fromAlias, toAlias, comparison, buf);
+      }
+
+      return (not ? buf.append(')') : buf).append(')');
+*/
    }
 
    public Object visit(ASTEntityComparison node, Object data)
@@ -1547,5 +1620,6 @@
       joinPaths.clear();
       identifierToTable.clear();
       joinedAliases.clear();
+      selectDistinct = false;
    }
 }

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDynamicQLQuery.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDynamicQLQuery.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDynamicQLQuery.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import java.lang.reflect.Method;
@@ -35,6 +35,7 @@
 import org.jboss.ejb.plugins.cmp.ejbql.SelectFunction;
 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge;
 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge;
+import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCFieldBridge;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCDynamicQLQueryMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData;
@@ -141,6 +142,19 @@
       {
          mask = selectEntity.getLoadGroupMask(readahead.getEagerLoadGroup());
          leftJoinCMRList = compiler.getLeftJoinCMRList();
+
+         // exclude non-searchable columns if distinct is used
+         if(compiler.isSelectDistinct())
+         {
+            JDBCFieldBridge[] tableFields = selectEntity.getTableFields();
+            for(int i = 0; i < tableFields.length; ++i)
+            {
+               if(mask[i] && !tableFields[i].getJDBCType().isSearchable())
+               {
+                  mask[i] = false;
+               }
+            }
+         }
       }
       else
       {

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLCompiler.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLCompiler.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLCompiler.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import java.io.StringReader;
@@ -137,6 +137,7 @@
 
    private boolean countCompositePk;
    private String selectAlias;
+   private boolean selectDistinct;
 
    public JDBCEJBQLCompiler(Catalog catalog)
    {
@@ -250,6 +251,7 @@
       onFindCMRJoin = null;
       countCompositePk = false;
       selectAlias = null;
+      selectDistinct = false;
    }
 
    public String getSQL()
@@ -317,6 +319,11 @@
       return leftJoinCMRList;
    }
 
+   public boolean isSelectDistinct()
+   {
+      return selectDistinct;
+   }
+
    public Object visit(SimpleNode node, Object data)
    {
       throw new RuntimeException("Internal error: Found unknown node type in " +
@@ -584,6 +591,8 @@
          where.append(fromThetaJoin.toString());
       }
 
+      selectDistinct = isDistinct(selectNode);
+
       // select size
       if(lazyResultSetLoading)
       {
@@ -594,7 +603,7 @@
             if(pkFields.length == 1)
             {
                buf.append('(').append(SQLUtil.SELECT).append("count(");
-               if(isDistinct(selectNode))
+               if(selectDistinct)
                {
                   buf.append(SQLUtil.DISTINCT);
                }
@@ -614,7 +623,7 @@
                   .append('(')
                   .append(SQLUtil.SELECT);
 
-               if(isDistinct(selectNode))
+               if(selectDistinct)
                {
                   buf.append(SQLUtil.DISTINCT);
                }
@@ -633,7 +642,7 @@
          else if(isSelectField())
          {
             buf.append('(').append(SQLUtil.SELECT).append("count(");
-            if(isDistinct(selectNode))
+            if(selectDistinct)
             {
                buf.append(SQLUtil.DISTINCT);
             }
@@ -649,7 +658,7 @@
       }
 
       // distinct
-      if(isDistinct(selectNode))
+      if(selectDistinct)
       {
          select.insert(0, SQLUtil.DISTINCT);
       }

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLQuery.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLQuery.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCEJBQLQuery.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,29 +1,30 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import org.jboss.deployment.DeploymentException;
 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge;
 import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge;
+import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCFieldBridge;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData;
@@ -83,6 +84,20 @@
          {
             setEagerLoadGroup(readahead.getEagerLoadGroup());
             setOnFindCMRList(compiler.getLeftJoinCMRList());
+
+            // exclude non-searchable columns if distinct is used
+            if(compiler.isSelectDistinct())
+            {
+               boolean[] mask = getEagerLoadMask();
+               JDBCFieldBridge[] tableFields = selectEntity.getTableFields();
+               for(int i = 0; i < tableFields.length; ++i)
+               {
+                  if(mask[i] && !tableFields[i].getJDBCType().isSearchable())
+                  {
+                     mask[i] = false;
+                  }
+               }
+            }
          }
       }
       else if(compiler.isSelectField())

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCJBossQLQuery.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCJBossQLQuery.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCJBossQLQuery.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import org.jboss.deployment.DeploymentException;
@@ -87,6 +87,20 @@
          {
             setEagerLoadGroup(readahead.getEagerLoadGroup());
             setOnFindCMRList(compiler.getLeftJoinCMRList());
+
+            // exclude non-searchable columns if distinct is used
+            if(compiler.isSelectDistinct())
+            {
+               boolean[] mask = getEagerLoadMask();
+               JDBCCMPFieldBridge[] tableFields = (JDBCCMPFieldBridge[])selectEntity.getTableFields();
+               for(int i = 0; i < tableFields.length; ++i)
+               {
+                  if(mask[i] && !tableFields[i].getJDBCType().isSearchable())
+                  {
+                     mask[i] = false;
+                  }
+               }
+            }
          }
       }
       else if(compiler.isSelectField())

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCType.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCType.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCType.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 /**
@@ -53,4 +53,6 @@
    Object setColumnValue(int index, Object value, Object columnValue);
 
    boolean hasMapper();
+
+   boolean isSearchable();
 }

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplex.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplex.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeComplex.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import java.util.HashMap;
@@ -118,6 +118,11 @@
       return false;
    }
 
+   public boolean isSearchable()
+   {
+      return false;
+   }
+
    public JDBCResultSetReader[] getResultSetReaders()
    {
       return resultSetReaders;

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeSimple.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeSimple.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCTypeSimple.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,27 +1,29 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
+import java.sql.Types;
 
+
 /**
  * This class provides a simple mapping of a Java type type to a single column.
  *
@@ -118,6 +120,17 @@
       return mapper != null;
    }
 
+   public boolean isSearchable()
+   {
+      int jdbcType = jdbcTypes[0];
+      return jdbcType != Types.BINARY &&
+         jdbcType != Types.BLOB &&
+         jdbcType != Types.CLOB &&
+         jdbcType != Types.LONGVARBINARY &&
+         jdbcType != Types.LONGVARCHAR &&
+         jdbcType != Types.VARBINARY;
+   }
+
    public final JDBCResultSetReader[] getResultSetReaders()
    {
       return resultSetReader;

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/QLCompiler.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/QLCompiler.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/QLCompiler.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCReadAheadMetaData;
@@ -79,4 +79,6 @@
    List getInputParameters();
 
    List getLeftJoinCMRList();
+
+   boolean isSelectDistinct();
 }

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/SQLUtil.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/SQLUtil.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/SQLUtil.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc;
 
 import java.sql.Connection;
@@ -315,6 +315,29 @@
    /**
     * Returns columnName0 [, columnName1 [AND columnName2 [...]]]
     */
+   public static StringBuffer getSearchableColumnNamesClause(JDBCFieldBridge[] fields,
+                                                             String identifier,
+                                                             StringBuffer buf)
+   {
+      boolean comma = false;
+      for(int i = 0; i < fields.length; ++i)
+      {
+         JDBCType type = getJDBCType(fields[i]);
+         if(type != null && type.isSearchable())
+         {
+            if(comma)
+               buf.append(COMMA);
+            else
+               comma = true;
+            getColumnNamesClause(type, identifier, buf);
+         }
+      }
+      return buf;
+   }
+
+   /**
+    * Returns columnName0 [, columnName1 [AND columnName2 [...]]]
+    */
    public static StringBuffer getColumnNamesClause(JDBCEntityBridge.FieldIterator loadIter, StringBuffer sb)
    {
       if(loadIter.hasNext())

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -2198,6 +2198,11 @@
          throw new UnsupportedOperationException("hasMapper is not implemented.");
       }
 
+      public boolean isSearchable()
+      {
+         throw new UnsupportedOperationException("isSearchable is not implemented.");
+      }
+
       public JDBCResultSetReader[] getResultSetReaders()
       {
          // foreign key fields has their result set readers

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2;
 
 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2;
@@ -100,10 +100,10 @@
       initCollectionStrategy();
    }
 
-   protected void setEntityReader(JDBCEntityBridge2 entity)
+   protected void setEntityReader(JDBCEntityBridge2 entity, boolean searchableOnly)
    {
       this.entity = entity;
-      this.resultReader = new EntityReader(entity);
+      this.resultReader = new EntityReader(entity, searchableOnly);
       initCollectionStrategy();
    }
 
@@ -346,15 +346,17 @@
    static class EntityReader implements ResultReader
    {
       private final JDBCEntityBridge2 entity;
+      private final boolean searchableOnly;
 
-      public EntityReader(JDBCEntityBridge2 entity)
+      public EntityReader(JDBCEntityBridge2 entity, boolean searchableOnly)
       {
          this.entity = entity;
+         this.searchableOnly = searchableOnly;
       }
 
       public Object readRow(ResultSet rs, GenericEntityObjectFactory factory)
       {
-         final Object pk = entity.getTable().loadRow(rs);
+         final Object pk = entity.getTable().loadRow(rs, searchableOnly);
          return pk == null ? null : factory.getEntityEJBObject(pk);
       }
    };

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DeclaredSQLQueryCommand.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DeclaredSQLQueryCommand.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DeclaredSQLQueryCommand.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2;
 
 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2;
@@ -61,7 +61,6 @@
       throws DeploymentException
    {
       String entityName = metadata.getEJBName();
-
       if(entityName != null)
       {
          Catalog catalog = entity.getManager().getCatalog();
@@ -80,7 +79,7 @@
       String fieldName = metadata.getFieldName();
       if(fieldName == null)
       {
-         setEntityReader(entity);
+         setEntityReader(this.entity, metadata.isSelectDistinct());
       }
       else
       {

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2;
 
 import java.util.Collection;
@@ -113,7 +113,7 @@
       }
       else
       {
-         resultReader = new AbstractQueryCommand.EntityReader((JDBCEntityBridge2)compiler.getSelectEntity());
+         resultReader = new AbstractQueryCommand.EntityReader((JDBCEntityBridge2)compiler.getSelectEntity(), compiler.isSelectDistinct());
       }
 
       return AbstractQueryCommand.fetchCollection(
@@ -161,7 +161,7 @@
       }
       else
       {
-         resultReader = new AbstractQueryCommand.EntityReader((JDBCEntityBridge2)compiler.getSelectEntity());
+         resultReader = new AbstractQueryCommand.EntityReader((JDBCEntityBridge2)compiler.getSelectEntity(), compiler.isSelectDistinct());
       }
 
       return AbstractQueryCommand.fetchOne(entity, sql, toArray(compiler.getInputParameters()),

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/EJBQLQueryCommand.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/EJBQLQueryCommand.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/EJBQLQueryCommand.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2;
 
 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2;
@@ -79,7 +79,7 @@
       }
       else
       {
-         setEntityReader((JDBCEntityBridge2)compiler.getSelectEntity());
+         setEntityReader((JDBCEntityBridge2)compiler.getSelectEntity(), compiler.isSelectDistinct());
       }
    }
 }

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/FindByPrimaryKeyCommand.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/FindByPrimaryKeyCommand.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/FindByPrimaryKeyCommand.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2;
 
 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2;
@@ -91,7 +91,7 @@
       log.debug("sql: " + sql);
 
       setParameters(QueryParameter.createPrimaryKeyParameters(0, entity));
-      setEntityReader(entity);
+      setEntityReader(entity, false);
    }
 
    public Object fetchOne(Schema schema, GenericEntityObjectFactory factory, Object[] args) throws FinderException

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2;
 
 import org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCEntityBridge2;
@@ -78,7 +78,7 @@
       }
       else
       {
-         setEntityReader((JDBCEntityBridge2)compiler.getSelectEntity());
+         setEntityReader((JDBCEntityBridge2)compiler.getSelectEntity(), compiler.isSelectDistinct());
       }
    }
 }

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/bridge/JDBCCMRFieldBridge2.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/bridge/JDBCCMRFieldBridge2.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/bridge/JDBCCMRFieldBridge2.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2.bridge;
 
 import org.jboss.ejb.plugins.cmp.bridge.EntityBridge;
@@ -1272,7 +1272,7 @@
 
             while(rs.next())
             {
-               value = relatedTable.loadRow(rs);
+               value = relatedTable.loadRow(rs, false);
                state.addLoadedPk(value);
             }
          }
@@ -1372,7 +1372,7 @@
 
             while(rs.next())
             {
-               value = relatedTable.loadRow(rs);
+               value = relatedTable.loadRow(rs, false);
                state.addLoadedPk(value);
             }
          }

Modified: branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/EntityTable.java
===================================================================
--- branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/EntityTable.java	2007-01-11 11:01:39 UTC (rev 59519)
+++ branches/Branch_4_0/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/schema/EntityTable.java	2007-01-11 12:01:17 UTC (rev 59520)
@@ -1,24 +1,24 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.ejb.plugins.cmp.jdbc2.schema;
 
 import org.jboss.deployment.DeploymentException;
@@ -80,6 +80,8 @@
    private static final byte DELETED = 8;
    private static final byte DIRTY_RELATIONS = 16;
 
+   private static final Object NOT_LOADED = new Object();
+
    private JDBCEntityBridge2 entity;
    private String tableName;
    private int fieldsTotal;
@@ -447,19 +449,13 @@
       return dataSource;
    }
 
-   public void loadRow(ResultSet rs, Object pk)
+   public Object loadRow(ResultSet rs, boolean searchableOnly)
    {
       View view = getView();
-      view.loadRow(rs, pk);
-   }
-
-   public Object loadRow(ResultSet rs)
-   {
-      View view = getView();
       Object pk = view.loadPk(rs);
       if(pk != null)
       {
-         view.loadRow(rs, pk);
+         view.loadRow(rs, pk, searchableOnly);
       }
       else if(log.isTraceEnabled())
       {
@@ -522,7 +518,7 @@
             throw new NoSuchEntityException("Row not found: " + id);
          }
 
-         return view.loadRow(rs, id);
+         return view.loadRow(rs, id, false);
       }
       catch(SQLException e)
       {
@@ -982,7 +978,7 @@
          }
       }
 
-      public Row loadRow(ResultSet rs, Object pk)
+      public Row loadRow(ResultSet rs, Object pk, boolean searchableOnly)
       {
          Row row = getRowByPk(pk, false);
          if(row != null)
@@ -1000,12 +996,21 @@
 
          row = createCleanRow(pk);
          JDBCCMPFieldBridge2[] tableFields = (JDBCCMPFieldBridge2[]) entity.getTableFields();
-         //int rsInd = 1;
+         // this rsOffset is kind of a hack
+         // but since tableIndex and rowIndex of a field are the same
+         // this should work ok
+         int rsOffset = 1;
          for(int i = 0; i < tableFields.length; ++i)
          {
             JDBCCMPFieldBridge2 field = tableFields[i];
-            //Object columnValue = field.loadArgumentResults(rs, rsInd++);
-            Object columnValue = field.loadArgumentResults(rs, field.getRowIndex() + 1);
+            if(searchableOnly && !field.getJDBCType().isSearchable())
+            {
+               row.fields[field.getRowIndex()] = NOT_LOADED;
+               --rsOffset;
+               continue;
+            }
+
+            Object columnValue = field.loadArgumentResults(rs, field.getRowIndex() + rsOffset);
             row.fields[field.getRowIndex()] = columnValue;
 
             if(field.getVersionIndex() != -1)
@@ -1448,7 +1453,14 @@
          {
             throw new NoSuchObjectLocalException("The instance was removed: " + pk);
          }
-         return fields[i];
+
+         Object value = fields[i];
+         if(value == NOT_LOADED)
+         {
+            value = loadField(i);
+         }
+
+         return value;
       }
 
       public void setFieldValue(int i, Object value)
@@ -1724,6 +1736,75 @@
             JDBCUtil.safeClose(con);
          }
       }
+
+      private Object loadField(int i)
+      {
+         JDBCCMPFieldBridge2 field = (JDBCCMPFieldBridge2)entity.getFields().get(i);
+
+         StringBuffer query = new StringBuffer();
+         query.append("select ")
+            .append(field.getColumnName())
+            .append(" from ")
+            .append(tableName)
+            .append(" where ");
+
+         JDBCCMPFieldBridge2[] pkFields = (JDBCCMPFieldBridge2[])entity.getPrimaryKeyFields();
+         for(int pkI = 0; pkI < pkFields.length; ++pkI)
+         {
+            if(pkI > 0)
+            {
+               query.append(" and ");
+            }
+            query.append(pkFields[pkI].getColumnName()).append("=?");
+         }
+
+         if(log.isDebugEnabled())
+         {
+            log.debug("executing: " + query.toString());
+         }
+
+         Object value = null;
+         Connection con = null;
+         PreparedStatement ps = null;
+         ResultSet rs = null;
+
+         try
+         {
+            con = dataSource.getConnection();
+            ps = con.prepareStatement(query.toString());
+
+            for(int pkI = 0; pkI < pkFields.length; ++pkI)
+            {
+               JDBCCMPFieldBridge2 pkField = pkFields[pkI];
+               Object fieldValue = fields[pkField.getRowIndex()];
+               pkField.setArgumentParameters(ps, pkI + 1, fieldValue);
+            }
+
+            rs = ps.executeQuery();
+
+            if(!rs.next())
+            {
+               throw new NoSuchEntityException("Row not found: " + pk);
+            }
+
+            value = field.loadArgumentResults(rs, 1);
+         }
+         catch(SQLException e)
+         {
+            throw new EJBException("Failed to load field " +
+               entity.getEntityName() + "." + field.getFieldName() +
+               ": " + e.getMessage(), e);
+         }
+         finally
+         {
+            JDBCUtil.safeClose(rs);
+            JDBCUtil.safeClose(ps);
+            JDBCUtil.safeClose(con);
+         }
+
+         fields[field.getRowIndex()] = value;
+         return value;
+      }
    }
 
    public static interface CommitStrategy




More information about the jboss-cvs-commits mailing list