Quantcast

svn commit: r1754171 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/util/ torque-templates/src/main/resources/org/apache/torque/templates/om/conf/ torque-templates/src/main/resources/org/apache/torque/templates/om/templat...

classic Classic list List threaded Threaded
3 messages Options
tv
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

svn commit: r1754171 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/util/ torque-templates/src/main/resources/org/apache/torque/templates/om/conf/ torque-templates/src/main/resources/org/apache/torque/templates/om/templat...

tv
Author: tv
Date: Tue Jul 26 19:16:55 2016
New Revision: 1754171

URL: http://svn.apache.org/viewvc?rev=1754171&view=rev
Log:
TORQUE-346: First attempt

Added:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java   (with props)
Modified:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java?rev=1754171&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java Tue Jul 26 19:16:55 2016
@@ -0,0 +1,194 @@
+package org.apache.torque.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.util.List;
+
+import org.apache.torque.TooManyRowsException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
+import org.apache.torque.map.TableMap;
+import org.apache.torque.om.ObjectKey;
+import org.apache.torque.om.Persistent;
+import org.apache.torque.om.mapper.RecordMapper;
+
+/**
+ * This is an abstract layer for all generated peer classes that
+ * implements several convenience methods that otherwise would have
+ * to be generated.
+ *
+ * @param <T> The data object class for this Peer.
+ *
+ * @author <a href="mailto:[hidden email]">Thomas Vandahl</a>
+ * @version $Id: BasePeerImpl.java 1701342 2015-09-05 02:18:04Z tfischer $
+ */
+public abstract class AbstractPeerImpl<T extends Persistent> extends BasePeerImpl<T>
+{
+    /** Serial version */
+    private static final long serialVersionUID = 1236684692145864194L;
+
+    /**
+     * Default constructor
+     */
+    public AbstractPeerImpl()
+    {
+        super();
+    }
+
+    /**
+     * Constructor providing the objects to be injected as parameters.
+     *
+     * @param recordMapper a record mapper to map JDBC result sets to objects
+     * @param tableMap the default table map
+     * @param databaseName the name of the database
+     */
+    public AbstractPeerImpl(final RecordMapper<T> recordMapper, final TableMap tableMap, final String databaseName)
+    {
+        super(recordMapper, tableMap, databaseName);
+    }
+
+    /**
+     * Build a Criteria object from the data object for this peer.
+     *
+     * @param obj the object to build the criteria from, not null.
+     */
+    public abstract Criteria buildCriteria(T obj);
+
+    /**
+     * Build a Criteria object from the data object for this peer,
+     * skipping all binary columns.
+     *
+     * @param obj the object to build the criteria from, not null.
+     */
+    public abstract Criteria buildSelectCriteria(T obj);
+
+    /**
+     * Returns the contents of the object as ColumnValues object.
+     * Primary key columns which are generated on insertion are not
+     * added to the returned object if they still have their initial
+     * value. Also, columns which have the useDatabaseDefaultValue
+     * flag set to true are also not added to the returned object
+     * if they still have their initial value.
+     *
+     * @throws TorqueException if the table map cannot be retrieved
+     *         (should not happen).
+     */
+    public abstract ColumnValues buildColumnValues(T obj) throws TorqueException;
+
+    /**
+     * Selects objects from the database which have
+     * the same content as the passed object.
+     *
+     * @return The list of selected objects, not null.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public List<T> doSelect(T obj) throws TorqueException
+    {
+        return doSelect(buildSelectCriteria(obj));
+    }
+
+    /**
+     * Selects at most one object from the database
+     * which has the same content as the passed object.
+     *
+     * @return the selected Object, or null if no object was selected.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public T doSelectSingleRecord(T obj) throws TorqueException
+    {
+        List<T> omList = doSelect(obj);
+        T om = null;
+        if (omList.size() > 1)
+        {
+            throw new TooManyRowsException("Object " + obj
+                + " matched more than one record");
+        }
+        if (!omList.isEmpty())
+        {
+            om = omList.get(0);
+        }
+        return om;
+    }
+
+    /**
+     * Method to do inserts.  This method is to be used during a transaction,
+     * otherwise use the doInsert(Criteria) method.
+     *
+     * @param columnValues the values to insert.
+     * @param con the connection to use, not null.
+     *
+     * @return the primary key of the inserted row or null if the table has
+     * no primary key
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    @Override
+    public ObjectKey doInsert(ColumnValues columnValues, Connection con)
+        throws TorqueException
+    {
+        correctBooleans(columnValues);
+        return super.doInsert(columnValues, con);
+    }
+
+    /**
+     * Method to do inserts
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void doInsert(T obj) throws TorqueException
+    {
+        ObjectKey primaryKey = doInsert(buildColumnValues(obj));
+        if (primaryKey != null)
+        {
+            obj.setPrimaryKey(primaryKey);
+        }
+        obj.setNew(false);
+        obj.setModified(false);
+    }
+
+    /**
+     * Method to do inserts.  This method is to be used during a transaction,
+     * otherwise use the doInsert(T) method.  It will take
+     * care of the connection details internally.
+     *
+     * @param obj the data object to insert into the database.
+     * @param con the connection to use
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void doInsert(T obj, Connection con)
+        throws TorqueException
+    {
+        ObjectKey primaryKey = doInsert(buildColumnValues(obj), con);
+        if (primaryKey != null)
+        {
+            obj.setPrimaryKey(primaryKey);
+        }
+        obj.setNew(false);
+        obj.setModified(false);
+    }
+}

Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties Tue Jul 26 19:16:55 2016
@@ -223,7 +223,7 @@ torque.om.dbObjectDefaultBaseClass =
 # The base class for all Peer classes
 torque.om.basePeerBaseClass =
 # The base class for all Peer implementation classes
-torque.om.basePeerImplBaseClass = org.apache.torque.util.BasePeerImpl
+torque.om.basePeerImplBaseClass = org.apache.torque.util.AbstractPeerImpl
 
 # Prefixes and suffixes for the java names of the generated classes
 #

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm Tue Jul 26 19:16:55 2016
@@ -27,103 +27,4 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
-    /**
-     * Method to do inserts.
-     *
-     * @param columnValues the values to insert.
-     *
-#if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-     * @return always null (because the table does not have a primary key).
-#else
-     * @return the primary key of the inserted row.
-#end
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public ObjectKey doInsert(ColumnValues columnValues) throws TorqueException
-    {
-        Connection connection = null;
-        try
-        {
-            connection = Transaction.begin(
-                    ${peerClassName}.DATABASE_NAME);
-            ObjectKey result = doInsert(columnValues, connection);
-            Transaction.commit(connection);
-            connection = null;
-            return result;
-        }
-        finally
-        {
-            if (connection != null)
-            {
-                Transaction.safeRollback(connection);
-            }
-        }
-    }
-
-    /**
-     * Method to do inserts.  This method is to be used during a transaction,
-     * otherwise use the doInsert(Criteria) method.
-     *
-     * @param columnValues the values to insert.
-     * @param con the connection to use, not null.
-     *
-#if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-     * @return always null (because the table does not have a primary key).
-#else
-     * @return the primary key of the inserted row.
-#end
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public ObjectKey doInsert(ColumnValues columnValues, Connection con)
-        throws TorqueException
-    {
-        correctBooleans(columnValues);
-        return super.doInsert(columnValues, con);
-    }
-
-    /**
-     * Method to do inserts
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public void doInsert($dbObjectClassName obj) throws TorqueException
-    {
-  #if ($idMethod.equals("none") || $torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-        doInsert(buildColumnValues(obj));
-  #else
-        obj.setPrimaryKey(doInsert(buildColumnValues(obj)));
-  #end
-        obj.setNew(false);
-        obj.setModified(false);
-    }
-
-    /**
-     * Method to do inserts.  This method is to be used during a transaction,
-     * otherwise use the doInsert($dbObjectClassName) method.  It will take
-     * care of the connection details internally.
-     *
-     * @param obj the data object to insert into the database.
-     * @param con the connection to use
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public void doInsert($dbObjectClassName obj, Connection con)
-        throws TorqueException
-    {
-  #if ($idMethod.equals("none") || $torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-        doInsert(buildColumnValues(obj), con);
-  #else
-        ObjectKey primaryKey = doInsert(buildColumnValues(obj), con);
-        if (primaryKey != null)
-        {
-            obj.setPrimaryKey(primaryKey);
-        }
-  #end
-        obj.setNew(false);
-        obj.setModified(false);
-    }
+## empty
\ No newline at end of file

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm Tue Jul 26 19:16:55 2016
@@ -27,46 +27,4 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
-    /**
-     * Selects ${dbObjectClassName} objects from the database which have
-     * the same content as the passed object.
-     *
-     * @return The list of selected objects, not null.
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public List<${dbObjectClassName}> doSelect($dbObjectClassName obj)
-            throws TorqueException
-    {
-        return doSelect(buildSelectCriteria(obj));
-    }
-#if ($torqueGen.booleanOption("torque.om.addSelectSingleRecordMethods"))
-
-    /**
-     * Selects at most one ${dbObjectClassName} object from the database
-     * which has the same content as the passed object.
-     *
-     * @return the selected Object, or null if no object was selected.
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public ${dbObjectClassName} doSelectSingleRecord(
-                $dbObjectClassName obj)
-            throws TorqueException
-    {
-        List<${dbObjectClassName}> ${field}List = doSelect(obj);
-        ${dbObjectClassName} ${field} = null;
-        if (${field}List.size() > 1)
-        {
-            throw new TooManyRowsException("Object " + obj
-                + " matched more than one record");
-        }
-        if (!${field}List.isEmpty())
-        {
-            ${field} = ${field}List.get(0);
-        }
-        return ${field};
-    }
-#end
+## empty
\ No newline at end of file

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm Tue Jul 26 19:16:55 2016
@@ -28,38 +28,6 @@
 ## as velocity variables.  
 ##
     /**
-     * Method to do updates.
-     *
-     * @param columnValues the values to update plus the primary key
-     *        identifying the row to update.
-     *
-     * @return the number of affected rows.
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public int doUpdate(ColumnValues columnValues) throws TorqueException
-    {
-        Connection connection = null;
-        try
-        {
-            connection = Transaction.begin(
-                    ${peerClassName}.DATABASE_NAME);
-            int result = doUpdate(columnValues, connection);
-            Transaction.commit(connection);
-            connection = null;
-            return result;
-        }
-        finally
-        {
-            if (connection != null)
-            {
-                Transaction.safeRollback(connection);
-            }
-        }
-    }
-
-    /**
      * Method to do updates.  This method is to be used during a transaction,
      * otherwise use the doUpdate(Criteria) method.
      *

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm Tue Jul 26 19:16:55 2016
@@ -53,8 +53,8 @@ import java.util.Set;
 import java.util.HashSet;
 
 import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+##import org.apache.commons.logging.Log;
+##import org.apache.commons.logging.LogFactory;
 import org.apache.torque.NoRowsException;
 import org.apache.torque.OptimisticLockingFailedException;
 import org.apache.torque.TooManyRowsException;

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm Tue Jul 26 19:16:55 2016
@@ -27,5 +27,5 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
-    /** The class log. */
-    private static Log log = LogFactory.getLog(${basePeerImplClassName}.class);
\ No newline at end of file
+##    /** The class log. */
+##    private static Log log = LogFactory.getLog(${basePeerImplClassName}.class);
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: svn commit: r1754171 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/util/ torque-templates/src/main/resources/org/apache/torque/templates/om/conf/ torque-templates/src/main/resources/org/apache/torque/templates/om/templat...

Thomas Fox
Thomas, is it ok if I remove the empty templates
doSelect.vm
doInsert.vm
log.vm

and the commented lines in imports.vm?

Also it seems to me that the generation option
torque.om.addSelectSingleRecordMethods
does not make sensae anymore as it's only used in the static wrapper- the implementation methods are there anyway, it seems.
So I'd remove that option if nobody objects

   Cheers,

      Thomas

----- Urspr√ľngliche Mail -----
Von: "tv" <[hidden email]>
An: [hidden email]
Gesendet: Dienstag, 26. Juli 2016 21:16:55
Betreff: svn commit: r1754171 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/util/ torque-templates/src/main/resources/org/apache/torque/templates/om/conf/ torque-templates/src/main/resources/org/apache/torque/templates/om/templat...

Author: tv
Date: Tue Jul 26 19:16:55 2016
New Revision: 1754171

URL: http://svn.apache.org/viewvc?rev=1754171&view=rev
Log:
TORQUE-346: First attempt

Added:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java   (with props)
Modified:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java?rev=1754171&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java Tue Jul 26 19:16:55 2016
@@ -0,0 +1,194 @@
+package org.apache.torque.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.util.List;
+
+import org.apache.torque.TooManyRowsException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
+import org.apache.torque.map.TableMap;
+import org.apache.torque.om.ObjectKey;
+import org.apache.torque.om.Persistent;
+import org.apache.torque.om.mapper.RecordMapper;
+
+/**
+ * This is an abstract layer for all generated peer classes that
+ * implements several convenience methods that otherwise would have
+ * to be generated.
+ *
+ * @param <T> The data object class for this Peer.
+ *
+ * @author <a href="mailto:[hidden email]">Thomas Vandahl</a>
+ * @version $Id: BasePeerImpl.java 1701342 2015-09-05 02:18:04Z tfischer $
+ */
+public abstract class AbstractPeerImpl<T extends Persistent> extends BasePeerImpl<T>
+{
+    /** Serial version */
+    private static final long serialVersionUID = 1236684692145864194L;
+
+    /**
+     * Default constructor
+     */
+    public AbstractPeerImpl()
+    {
+        super();
+    }
+
+    /**
+     * Constructor providing the objects to be injected as parameters.
+     *
+     * @param recordMapper a record mapper to map JDBC result sets to objects
+     * @param tableMap the default table map
+     * @param databaseName the name of the database
+     */
+    public AbstractPeerImpl(final RecordMapper<T> recordMapper, final TableMap tableMap, final String databaseName)
+    {
+        super(recordMapper, tableMap, databaseName);
+    }
+
+    /**
+     * Build a Criteria object from the data object for this peer.
+     *
+     * @param obj the object to build the criteria from, not null.
+     */
+    public abstract Criteria buildCriteria(T obj);
+
+    /**
+     * Build a Criteria object from the data object for this peer,
+     * skipping all binary columns.
+     *
+     * @param obj the object to build the criteria from, not null.
+     */
+    public abstract Criteria buildSelectCriteria(T obj);
+
+    /**
+     * Returns the contents of the object as ColumnValues object.
+     * Primary key columns which are generated on insertion are not
+     * added to the returned object if they still have their initial
+     * value. Also, columns which have the useDatabaseDefaultValue
+     * flag set to true are also not added to the returned object
+     * if they still have their initial value.
+     *
+     * @throws TorqueException if the table map cannot be retrieved
+     *         (should not happen).
+     */
+    public abstract ColumnValues buildColumnValues(T obj) throws TorqueException;
+
+    /**
+     * Selects objects from the database which have
+     * the same content as the passed object.
+     *
+     * @return The list of selected objects, not null.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public List<T> doSelect(T obj) throws TorqueException
+    {
+        return doSelect(buildSelectCriteria(obj));
+    }
+
+    /**
+     * Selects at most one object from the database
+     * which has the same content as the passed object.
+     *
+     * @return the selected Object, or null if no object was selected.
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public T doSelectSingleRecord(T obj) throws TorqueException
+    {
+        List<T> omList = doSelect(obj);
+        T om = null;
+        if (omList.size() > 1)
+        {
+            throw new TooManyRowsException("Object " + obj
+                + " matched more than one record");
+        }
+        if (!omList.isEmpty())
+        {
+            om = omList.get(0);
+        }
+        return om;
+    }
+
+    /**
+     * Method to do inserts.  This method is to be used during a transaction,
+     * otherwise use the doInsert(Criteria) method.
+     *
+     * @param columnValues the values to insert.
+     * @param con the connection to use, not null.
+     *
+     * @return the primary key of the inserted row or null if the table has
+     * no primary key
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    @Override
+    public ObjectKey doInsert(ColumnValues columnValues, Connection con)
+        throws TorqueException
+    {
+        correctBooleans(columnValues);
+        return super.doInsert(columnValues, con);
+    }
+
+    /**
+     * Method to do inserts
+     *
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void doInsert(T obj) throws TorqueException
+    {
+        ObjectKey primaryKey = doInsert(buildColumnValues(obj));
+        if (primaryKey != null)
+        {
+            obj.setPrimaryKey(primaryKey);
+        }
+        obj.setNew(false);
+        obj.setModified(false);
+    }
+
+    /**
+     * Method to do inserts.  This method is to be used during a transaction,
+     * otherwise use the doInsert(T) method.  It will take
+     * care of the connection details internally.
+     *
+     * @param obj the data object to insert into the database.
+     * @param con the connection to use
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void doInsert(T obj, Connection con)
+        throws TorqueException
+    {
+        ObjectKey primaryKey = doInsert(buildColumnValues(obj), con);
+        if (primaryKey != null)
+        {
+            obj.setPrimaryKey(primaryKey);
+        }
+        obj.setNew(false);
+        obj.setModified(false);
+    }
+}

Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties Tue Jul 26 19:16:55 2016
@@ -223,7 +223,7 @@ torque.om.dbObjectDefaultBaseClass =
 # The base class for all Peer classes
 torque.om.basePeerBaseClass =
 # The base class for all Peer implementation classes
-torque.om.basePeerImplBaseClass = org.apache.torque.util.BasePeerImpl
+torque.om.basePeerImplBaseClass = org.apache.torque.util.AbstractPeerImpl
 
 # Prefixes and suffixes for the java names of the generated classes
 #

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doInsert.vm Tue Jul 26 19:16:55 2016
@@ -27,103 +27,4 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
-    /**
-     * Method to do inserts.
-     *
-     * @param columnValues the values to insert.
-     *
-#if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-     * @return always null (because the table does not have a primary key).
-#else
-     * @return the primary key of the inserted row.
-#end
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public ObjectKey doInsert(ColumnValues columnValues) throws TorqueException
-    {
-        Connection connection = null;
-        try
-        {
-            connection = Transaction.begin(
-                    ${peerClassName}.DATABASE_NAME);
-            ObjectKey result = doInsert(columnValues, connection);
-            Transaction.commit(connection);
-            connection = null;
-            return result;
-        }
-        finally
-        {
-            if (connection != null)
-            {
-                Transaction.safeRollback(connection);
-            }
-        }
-    }
-
-    /**
-     * Method to do inserts.  This method is to be used during a transaction,
-     * otherwise use the doInsert(Criteria) method.
-     *
-     * @param columnValues the values to insert.
-     * @param con the connection to use, not null.
-     *
-#if ($torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-     * @return always null (because the table does not have a primary key).
-#else
-     * @return the primary key of the inserted row.
-#end
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public ObjectKey doInsert(ColumnValues columnValues, Connection con)
-        throws TorqueException
-    {
-        correctBooleans(columnValues);
-        return super.doInsert(columnValues, con);
-    }
-
-    /**
-     * Method to do inserts
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public void doInsert($dbObjectClassName obj) throws TorqueException
-    {
-  #if ($idMethod.equals("none") || $torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-        doInsert(buildColumnValues(obj));
-  #else
-        obj.setPrimaryKey(doInsert(buildColumnValues(obj)));
-  #end
-        obj.setNew(false);
-        obj.setModified(false);
-    }
-
-    /**
-     * Method to do inserts.  This method is to be used during a transaction,
-     * otherwise use the doInsert($dbObjectClassName) method.  It will take
-     * care of the connection details internally.
-     *
-     * @param obj the data object to insert into the database.
-     * @param con the connection to use
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public void doInsert($dbObjectClassName obj, Connection con)
-        throws TorqueException
-    {
-  #if ($idMethod.equals("none") || $torqueGen.getChild("primary-keys").getChildren("column").isEmpty())
-        doInsert(buildColumnValues(obj), con);
-  #else
-        ObjectKey primaryKey = doInsert(buildColumnValues(obj), con);
-        if (primaryKey != null)
-        {
-            obj.setPrimaryKey(primaryKey);
-        }
-  #end
-        obj.setNew(false);
-        obj.setModified(false);
-    }
+## empty
\ No newline at end of file

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doSelect.vm Tue Jul 26 19:16:55 2016
@@ -27,46 +27,4 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
-    /**
-     * Selects ${dbObjectClassName} objects from the database which have
-     * the same content as the passed object.
-     *
-     * @return The list of selected objects, not null.
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public List<${dbObjectClassName}> doSelect($dbObjectClassName obj)
-            throws TorqueException
-    {
-        return doSelect(buildSelectCriteria(obj));
-    }
-#if ($torqueGen.booleanOption("torque.om.addSelectSingleRecordMethods"))
-
-    /**
-     * Selects at most one ${dbObjectClassName} object from the database
-     * which has the same content as the passed object.
-     *
-     * @return the selected Object, or null if no object was selected.
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public ${dbObjectClassName} doSelectSingleRecord(
-                $dbObjectClassName obj)
-            throws TorqueException
-    {
-        List<${dbObjectClassName}> ${field}List = doSelect(obj);
-        ${dbObjectClassName} ${field} = null;
-        if (${field}List.size() > 1)
-        {
-            throw new TooManyRowsException("Object " + obj
-                + " matched more than one record");
-        }
-        if (!${field}List.isEmpty())
-        {
-            ${field} = ${field}List.get(0);
-        }
-        return ${field};
-    }
-#end
+## empty
\ No newline at end of file

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doUpdate.vm Tue Jul 26 19:16:55 2016
@@ -28,38 +28,6 @@
 ## as velocity variables.  
 ##
     /**
-     * Method to do updates.
-     *
-     * @param columnValues the values to update plus the primary key
-     *        identifying the row to update.
-     *
-     * @return the number of affected rows.
-     *
-     * @throws TorqueException Any exceptions caught during processing will be
-     *         rethrown wrapped into a TorqueException.
-     */
-    public int doUpdate(ColumnValues columnValues) throws TorqueException
-    {
-        Connection connection = null;
-        try
-        {
-            connection = Transaction.begin(
-                    ${peerClassName}.DATABASE_NAME);
-            int result = doUpdate(columnValues, connection);
-            Transaction.commit(connection);
-            connection = null;
-            return result;
-        }
-        finally
-        {
-            if (connection != null)
-            {
-                Transaction.safeRollback(connection);
-            }
-        }
-    }
-
-    /**
      * Method to do updates.  This method is to be used during a transaction,
      * otherwise use the doUpdate(Criteria) method.
      *

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/imports.vm Tue Jul 26 19:16:55 2016
@@ -53,8 +53,8 @@ import java.util.Set;
 import java.util.HashSet;
 
 import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+##import org.apache.commons.logging.Log;
+##import org.apache.commons.logging.LogFactory;
 import org.apache.torque.NoRowsException;
 import org.apache.torque.OptimisticLockingFailedException;
 import org.apache.torque.TooManyRowsException;

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm?rev=1754171&r1=1754170&r2=1754171&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/log.vm Tue Jul 26 19:16:55 2016
@@ -27,5 +27,5 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
-    /** The class log. */
-    private static Log log = LogFactory.getLog(${basePeerImplClassName}.class);
\ No newline at end of file
+##    /** The class log. */
+##    private static Log log = LogFactory.getLog(${basePeerImplClassName}.class);
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

tv
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: svn commit: r1754171 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/util/ torque-templates/src/main/resources/org/apache/torque/templates/om/conf/ torque-templates/src/main/resources/org/apache/torque/templates/om/templat...

tv
On 05.09.16 03:53, Thomas Fox wrote:
> Thomas, is it ok if I remove the empty templates
> doSelect.vm
> doInsert.vm
> log.vm
>
> and the commented lines in imports.vm?

Absolutely. I have to admit that I do not fully understand how the
generator is configured so I decided for the smallest impact possible.

> Also it seems to me that the generation option
> torque.om.addSelectSingleRecordMethods
> does not make sensae anymore as it's only used in the static wrapper- the implementation methods are there anyway, it seems.
> So I'd remove that option if nobody objects

Yes, go ahead.

As you are at it: There is a getPeer() method in the OM classes which
returns the static Peer wrapper. Wouldn't it be more logical to return
the peerImpl here?

Bye, Thomas.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...