Author: tfischer
Date: Wed Sep 3 21:00:19 2014
New Revision: 1622356
URL: http://svn.apache.org/r1622356
Log:
TORQUE-309 Add interface to generated peer classes
Thanks to Georg Kallidis for providing the basis for this feature
Added:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/PeerInterfaceSkipDecider.java
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerInterface.xml
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/interface/peerInterface.vm
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
Modified:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java?rev=1622356&r1=1622355&r2=1622356&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
Wed Sep 3 21:00:19 2014
@@ -62,6 +62,8 @@ public enum TorqueSchemaAttributeName im
INHERITANCE("inheritance"),
/** attribute interface. */
INTERFACE("interface"),
+ /** attribute peerInterface. */
+ PEER_INTERFACE("peerInterface"),
/** attribute protected. */
PROTECTED("protected"),
/** attribute default. */
Added:
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/PeerInterfaceSkipDecider.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/PeerInterfaceSkipDecider.java?rev=1622356&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/PeerInterfaceSkipDecider.java
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/PeerInterfaceSkipDecider.java
Wed Sep 3 21:00:19 2014
@@ -0,0 +1,50 @@
+package org.apache.torque.templates.skipdecider;
+
+/*
+ * 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 org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.skipDecider.SkipDecider;
+import org.apache.torque.templates.TorqueSchemaAttributeName;
+
+/**
+ * A skip decider which returns true if the attribute "peerInterface"
+ * is set on the current source element and if the name does not contain
+ * a dot.
+ *
+ * @version $Id$
+ */
+public class PeerInterfaceSkipDecider implements SkipDecider
+{
+ public boolean proceed(ControllerState controllerState)
+ {
+ SourceElement sourceElement
+ = (SourceElement) controllerState.getModel();
+ String interfaceName
+ = (String) sourceElement.getAttribute(
+ TorqueSchemaAttributeName.PEER_INTERFACE.getName());
+ if (interfaceName == null)
+ {
+ return false;
+ }
+ boolean containsDot = interfaceName.indexOf('.') != -1;
+ return !containsDot;
+ }
+}
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml?rev=1622356&r1=1622355&r2=1622356&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml
Wed Sep 3 21:00:19 2014
@@ -227,6 +227,35 @@
<postprocessor
class="org.apache.torque.generator.processor.string.RemoveUnusedImportsProcessor"
/>
</output>
+ <output name="torque.om.peerInterface" existingTargetStrategy="skip"
outputDirKey="modifiable">
+ <filenameOutlet
+ xsi:type="javaOutlet"
+ class="org.apache.torque.generator.outlet.java.JavaFilenameOutlet">
+ <mergepoint name="package">
+ <action
+ xsi:type="sourceElementAttributeAction"
+ element="."
+ attribute="peerPackage"
+ acceptNotSet="false"/>
+ </mergepoint>
+ <mergepoint name="classname">
+ <action
+ xsi:type="sourceElementAttributeAction"
+ element="."
+ attribute="peerInterface"
+ acceptNotSet="true"/>
+ </mergepoint>
+ </filenameOutlet>
+ <source xsi:type="fileSource" elements="all-tables/table"
+
skipDecider="org.apache.torque.templates.skipdecider.PeerInterfaceSkipDecider">
+ <transformer
class="org.apache.torque.templates.transformer.om.OMTransformer"/>
+ <include>*schema.xml</include>
+ <exclude>id-table-schema.xml</exclude>
+ </source>
+ <outlet name="torque.om.peerInterface"/>
+ <postprocessor
class="org.apache.torque.generator.processor.string.RemoveUnusedImportsProcessor"
/>
+ </output>
+
<output name="torque.om.peer" existingTargetStrategy="skip"
outputDirKey="modifiable">
<filenameOutlet
xsi:type="javaOutlet"
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerInterface.xml
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerInterface.xml?rev=1622356&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerInterface.xml
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peerInterface.xml
Wed Sep 3 21:00:19 2014
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<outlets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration
http://db.apache.org/torque/4.0/generator/configuration.xsd"
+ xmlns="http://db.apache.org/torque/4.0/generator/configuration">
+ <outlet name="torque.om.peerInterface"
+ xsi:type="velocityOutlet"
+ path="interface/peerInterface.vm">
+ </outlet>
+</outlets>
\ No newline at end of file
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/interface/peerInterface.vm
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/interface/peerInterface.vm?rev=1622356&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/interface/peerInterface.vm
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/interface/peerInterface.vm
Wed Sep 3 21:00:19 2014
@@ -0,0 +1,47 @@
+## 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.
+##
+######
+##
+## version $Id$
+##
+## This template creates source code for a Interface for a Peer object.
+## The generated code is intended to be modified by the user.
+## The template expects as input a "table" element from the torque schema
+## which was processed by the OMTransformer.
+##
+
+package ${peerPackage};
+
+/**
+#if ($description)
+ * $description
+ *
+#end
+ * This is an interface that should be filled with the public api of the
+ * $peerImplClassName objects.
+ * The skeleton for this class was autogenerated by Torque #if
($torqueGen.booleanOption("torque.om.addTimeStamp"))on:
+ *
+ * [${torqueGen.now()}]
+ * #end
+ * You should add additional methods to this class to meet the
+ * application requirements. This class will only be generated as
+ * long as it does not already exist in the output directory.
+ */
+public interface ${peerInterface}
+{
+}
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd?rev=1622356&r1=1622355&r2=1622356&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd
Wed Sep 3 21:00:19 2014
@@ -316,6 +316,20 @@ other applications or APIs.
</xs:documentation>
</xs:annotation>
</xs:attribute>
+ <xs:attribute name="peerInterface" type="javaQualifiedNameType"
+ use="optional" >
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+The interface attribute specifies an interface that should be referenced in
+the implements section of the generated peer class. If this is a fully
+qualified class name (i. e. the string contains dots), the interface will
+simply be implemented by the peer object. If the interface is a simple
+class name (without dots), an empty interface file will be generated in the
+peer package. This feature allows to use Torque generated peer classes
+in the context of other applications or APIs.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
<xs:attribute name="baseClass" type="javaQualifiedNameType" use="optional">
<xs:annotation>
<xs:documentation xml:lang="en">
Modified:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1622356&r1=1622355&r2=1622356&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
(original)
+++
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
Wed Sep 3 21:00:19 2014
@@ -62,10 +62,13 @@ import org.apache.torque.test.peer.Bigin
import org.apache.torque.test.peer.BookPeer;
import org.apache.torque.test.peer.CompPkContainsFkPeer;
import org.apache.torque.test.peer.IfcTablePeer;
+import org.apache.torque.test.peer.IfcTablePeerImpl;
import org.apache.torque.test.peer.InheritanceClassnameTestPeer;
import org.apache.torque.test.peer.InheritanceTestPeer;
import org.apache.torque.test.peer.IntegerTypePeer;
import org.apache.torque.test.peer.LocalIfcTablePeer;
+import org.apache.torque.test.peer.LocalIfcTablePeerImpl;
+import org.apache.torque.test.peer.LocalTestPeerInterface;
import org.apache.torque.test.peer.MultiPkPeer;
import org.apache.torque.test.peer.NopkPeer;
import org.apache.torque.test.peer.VarcharTypePeer;
@@ -1056,7 +1059,8 @@ public class DataTest extends BaseDataba
IfcTable ifc = new IfcTable();
- assertTrue("IfcTable should be an instance of TestInterface", ifc
instanceof TestInterface);
+ assertTrue("IfcTable should be an instance of TestInterface",
+ ifc instanceof TestInterface);
ifc.setID(1);
ifc.setName("John Doe");
@@ -1071,6 +1075,11 @@ public class DataTest extends BaseDataba
ifcTable instanceof TestInterface);
}
+ IfcTablePeerImpl peerImpl = IfcTablePeer.getIfcTablePeerImpl();
+ assertTrue("IfcTablePeerImpl should be an instance of "
+ + "TestPeerInterface",
+ peerImpl instanceof TestPeerInterface);
+
LocalIfcTable localIfc = new LocalIfcTable();
assertTrue("LocalIfcTable should be an instance of LocalTestInterface",
@@ -1084,6 +1093,11 @@ public class DataTest extends BaseDataba
+ " instances of LocalTestInterface",
readLocalIfcTable instanceof LocalTestInterface);
}
+
+ LocalIfcTablePeerImpl localPeerImpl =
LocalIfcTablePeer.getLocalIfcTablePeerImpl();
+ assertTrue("LocalIfcTablePeerImpl should be an instance of "
+ + "LocalTestPeerInterface",
+ localPeerImpl instanceof LocalTestPeerInterface);
}
public void testInheritanceWithKeys() throws Exception
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]