You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2013/11/21 22:48:13 UTC
svn commit: r1544336 - in /db/torque/torque4/trunk:
torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm
torque-test/src/test/java/org/apache/torque/om/OMByNameMethodsTest.java
Author: tfischer
Date: Thu Nov 21 21:48:12 2013
New Revision: 1544336
URL: http://svn.apache.org/r1544336
Log:
TORQUE-304 use FullyQualifiedName and ColumName as alternatives
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/om/OMByNameMethodsTest.java
Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm?rev=1544336&r1=1544335&r2=1544336&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm Thu Nov 21 21:48:12 2013
@@ -188,7 +188,8 @@
#set ( $columnFieldType = ${columnElement.getAttribute("fieldType")} )
#set ( $getter = ${columnElement.getAttribute("getter")} )
#set ( $peerColumnName = ${columnElement.getAttribute("peerColumnName")} )
- if (name.equals(${peerName}.${peerColumnName}.getSqlExpression()))
+ if (${peerName}.${peerColumnName}.getSqlExpression().equals(name)
+ || ${peerName}.${peerColumnName}.getColumnName().equals(name))
{
#if ($columnFieldType == "int")
return new Integer(${getter}());
@@ -230,7 +231,8 @@
#set ( $columnFieldType = ${columnElement.getAttribute("fieldType")} )
#set ( $javaName = ${columnElement.getAttribute("javaName")} )
#set ( $peerColumnName = ${columnElement.getAttribute("peerColumnName")} )
- if (${peerName}.${peerColumnName}.getSqlExpression().equals(name))
+ if (${peerName}.${peerColumnName}.getSqlExpression().equals(name)
+ || ${peerName}.${peerColumnName}.getColumnName().equals(name))
{
return setByName("${javaName}", value);
}
Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/om/OMByNameMethodsTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/om/OMByNameMethodsTest.java?rev=1544336&r1=1544335&r2=1544336&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/om/OMByNameMethodsTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/om/OMByNameMethodsTest.java Thu Nov 21 21:48:12 2013
@@ -347,7 +347,7 @@ public class OMByNameMethodsTest extends
* Checks that getValue returns the value set with a setByPeerName call for all
* known object and primitive types.
*/
- public void testSetByPeerNameMethod() throws Exception
+ public void testSetByFullyQualifiedPeerName() throws Exception
{
// Testing GetByName method for Object Types
ColumnAccessByName objectTypes = new TypesObject();
@@ -394,12 +394,64 @@ public class OMByNameMethodsTest extends
assertValues((TypesPrimitive) primitiveTypes);
}
+ /*
+ * Validate that the setByPeerName methods work using a BaseObject class type.
+ * Checks that getValue returns the value set with a setByPeerName call for all
+ * known object and primitive types.
+ */
+ public void testSetUnqualifiedPeerName() throws Exception
+ {
+ // Testing GetByName method for Object Types
+ ColumnAccessByName objectTypes = new TypesObject();
+ try
+ {
+ for (int i = 0; i < OBJECT_PEER_NAMES.length; i++)
+ {
+ boolean status = objectTypes.setByPeerName(
+ OBJECT_PEER_NAMES[i].getColumnName(),
+ OBJECT_TEST_VALUES[i]);
+ assertTrue("setByPeerName returned false setting column "
+ + OBJECT_PEER_NAMES[i], status);
+ }
+ }
+ catch (TorqueException e)
+ {
+ fail("Exception caught trying to call TypesObject.setByName() "
+ + "method!\nWas OM generated with torque.addGetByNameMethod "
+ + "property = true?\nError message was: '" + e.getMessage()
+ + "'");
+ }
+ assertValues((TypesObject) objectTypes);
+
+ // Test Primitive Types
+ ColumnAccessByName primitiveTypes = new TypesPrimitive();
+ try
+ {
+ for (int i = 0; i < PRIMITIVE_PEER_NAMES.length; i++)
+ {
+ boolean status = primitiveTypes.setByPeerName(
+ PRIMITIVE_PEER_NAMES[i].getColumnName(),
+ OBJECT_TEST_VALUES[i]);
+ assertTrue("setByPeerName returned false setting column "
+ + PRIMITIVE_PEER_NAMES[i], status);
+ }
+ }
+ catch (TorqueException e)
+ {
+ fail("Exception caught trying to call TypesObject.setByName() "
+ + "method!\nWas OM generated with torque.addGetByNameMethod "
+ + "property = true?\nError message was: '" + e.getMessage()
+ + "'");
+ }
+ assertValues((TypesPrimitive) primitiveTypes);
+ }
+
/**
* Validate that the getByPeerName methods work as expected for all types.
*
* @throws Exception if the test fails
*/
- public void testGetByPeerNameMethod() throws Exception
+ public void testGetByFullyQualifiedPeerName() throws Exception
{
// Testing GetByName method for Object Types
ColumnAccessByName objectTypes = new TypesObject();
@@ -453,6 +505,65 @@ public class OMByNameMethodsTest extends
}
}
+ /**
+ * Validate that the getByPeerName methods work as expected for all types.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testGetByUnqualifiedPeerName() throws Exception
+ {
+ // Testing GetByName method for Object Types
+ ColumnAccessByName objectTypes = new TypesObject();
+ try
+ {
+ for (int i = 0; i < OBJECT_COLUMN_NAMES.length; i++)
+ {
+ objectTypes.setByName(OBJECT_COLUMN_NAMES[i],
+ OBJECT_TEST_VALUES[i]);
+ }
+ }
+ catch (TorqueException e)
+ {
+ fail("Exception caught trying to call TypesObject.setByName() "
+ + "method!\nWas OM generated with torque.addGetByNameMethod "
+ + "property = true?\nError message was: '" + e.getMessage()
+ + "'");
+ }
+ String eMsg = "Did not get expected value for object column: ";
+ for (int i = 0; i < OBJECT_PEER_NAMES.length; i++)
+ {
+ assertEquals(eMsg + OBJECT_PEER_NAMES[i],
+ OBJECT_TEST_VALUES[i],
+ objectTypes.getByPeerName(
+ OBJECT_PEER_NAMES[i].getColumnName()));
+ }
+
+ // Test Primative Types
+ ColumnAccessByName primitiveTypes = new TypesPrimitive();
+ try
+ {
+ for (int i = 0; i < PRIMITIVE_COLUMN_NAMES.length; i++)
+ {
+ primitiveTypes.setByName(PRIMITIVE_COLUMN_NAMES[i],
+ PRIMITIVE_TEST_VALUES[i]);
+ }
+ }
+ catch (TorqueException e)
+ {
+ fail("Exception caught trying to call TypesObject.setByName() "
+ + "method!\nWas OM generated with torque.addGetByNameMethod "
+ + "property = true?\nError message was: '" + e.getMessage()
+ + "'");
+ }
+ for (int i = 0; i < PRIMITIVE_PEER_NAMES.length; i++)
+ {
+ assertEquals(eMsg + PRIMITIVE_PEER_NAMES[i],
+ PRIMITIVE_TEST_VALUES[i],
+ primitiveTypes.getByPeerName(
+ PRIMITIVE_PEER_NAMES[i].getColumnName()));
+ }
+ }
+
/*
* Validate that the setByPostion methods work using a BaseObject class type.
* Checks that getByPosition returns the value set with a setByPosition call
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org