Author: gk Date: Tue Apr 23 14:22:16 2024 New Revision: 1917285 URL: http://svn.apache.org/viewvc?rev=1917285&view=rev Log: - remove jacoco profile as with dependency update to 0.8.12 restriction is obsolete.
Added: db/torque/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/MappingStrategy.java Modified: db/torque/trunk/README.md db/torque/trunk/pom.xml db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm db/torque/trunk/torque-test/README.md db/torque/trunk/torque-test/pom.xml Modified: db/torque/trunk/README.md URL: http://svn.apache.org/viewvc/db/torque/trunk/README.md?rev=1917285&r1=1917284&r2=1917285&view=diff ============================================================================== --- db/torque/trunk/README.md (original) +++ db/torque/trunk/README.md Tue Apr 23 14:22:16 2024 @@ -25,9 +25,9 @@ ## Requirements - Version 5 and 5.1 requires Java 8. -- Version 5.2 requires Java 11. +- Version 6 requires Java 11. -- Build and Tests run with Java 8 and 14 (v5.1) and Java 20 (v.5.2). +- Build and Tests run with Java 8 and 14 (v5.1) and Java 20 (v.6.0). - IDE integration @@ -99,11 +99,17 @@ although they are build for inspection i To build all with checksums run in root - mvn clean install -Papache-release,derbyEmbedded-jenkins,beans,managers,owasp - + mvn clean install -Papache-release,derbyEmbedded-jenkins,beans,managers + +Profile apache-release activates torque-test profile. We need at least one "database" profile (see below) to replace in database replacements +in generate sources, e.g. setting torque.driver, in the example it is derbyEmbedded-jenkins. +Profiles beans and managers are needed to get the beans for the Bean*Tests (test-exclude is not working in compile plugin). + +To check seucrity issues run profile owasp -- one "database" profile (setting torque.driver) is required to be active -- managers and beans profile currently are required to be activated + mvn package -Papache-release,derbyEmbedded-jenkins,owasp + +The flag dependency.check.skip is set in the owasp profile to false, which is by default true. #### Provided database profiles @@ -136,7 +142,7 @@ Public Key is added to KEYS. You will be asked for your gpg passphrase during the build process, if not provided otherwise. - mvn clean package -Papache-release,derbyEmbedded-jenkins,beans,managers,owasp + mvn clean package -Papache-release,derbyEmbedded-jenkins,beans,managers,owasp -Ddependency.check.skip=false mvn deploy -DskipTests=true Modified: db/torque/trunk/pom.xml URL: http://svn.apache.org/viewvc/db/torque/trunk/pom.xml?rev=1917285&r1=1917284&r2=1917285&view=diff ============================================================================== --- db/torque/trunk/pom.xml (original) +++ db/torque/trunk/pom.xml Tue Apr 23 14:22:16 2024 @@ -686,7 +686,7 @@ <!-- runs with java 17, but not 20 --> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <version>0.8.8</version> + <version>0.8.12</version> <configuration> <skip>${jacoco.skip}</skip> <excludes> @@ -936,16 +936,6 @@ <dependency.check.skip>false</dependency.check.skip> </properties> </profile> - <profile> - <id>javaAbove12</id> - <activation> - <jdk>[12,)</jdk> - </activation> - <properties> - <!--java.version>12</java.version--> - <jacoco.skip>true</jacoco.skip> - </properties> - </profile> </profiles> </project> Added: db/torque/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/MappingStrategy.java URL: http://svn.apache.org/viewvc/db/torque/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/MappingStrategy.java?rev=1917285&view=auto ============================================================================== --- db/torque/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/MappingStrategy.java (added) +++ db/torque/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/MappingStrategy.java Tue Apr 23 14:22:16 2024 @@ -0,0 +1,105 @@ +package org.apache.torque.om.mapper; + +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import org.apache.commons.lang3.function.FailableBiConsumer; + +/* + * 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.commons.lang3.tuple.Pair; +import org.apache.torque.TorqueException; + +/** + * Mapping strategy used in processRow method of generated mappers. + * + * @param <T> + */ +public class MappingStrategy<T> { + + /** + * The {@link Pair#getLeft()} is to allow lazy sorting, {@link Pair#getRight()} contains the object to be mapped + */ + private final List<Pair<Integer, FailableBiConsumer<ResultSet, T, TorqueException>>> tasks; + + private boolean allSet; + + public MappingStrategy() + { + this.tasks = new ArrayList<>(); + this.allSet = false; + } + + public void addColumn(int offset, FailableBiConsumer<ResultSet, T, TorqueException> setter) + { + this.tasks.add(Pair.of(offset, setter)); + } + + /** + * Last finishing steps before execute. + * + * @param num_fields the total column size of the object + * @param sort <code>true</code> explicitely sort with {@link Pair#getLeft()} of the {@link #tasks}. + */ + public void finish(int num_fields, boolean sort) + { + // The list should already be in the correct order because Criteria loops through the columns + // in the same order in which they are added to the SQL statement but just in case something weird + // is being done this gets us closer to the desired contract of ResultSet of looping over monotonically + // increasing indices of columns only. + if (sort) { + this.tasks.sort(Comparator.comparing(Pair::getLeft)); + } + this.allSet = this.tasks.size() == num_fields; + } + + public boolean isEmpty() + { + return this.tasks.isEmpty(); + } + + public boolean isAllSet() { + return this.allSet; + } + + public void reset() + { + // to use this and to use only a single strategy we might need to Collections.sync(ArrayList). + this.tasks.clear(); + } + + /** + * Iterates through the {@link #tasks} list and executes each task. + * + * @param result Resultset + * @param instance target object + * + * @throws TorqueException + */ + public void execute(ResultSet result, T instance) throws TorqueException + { + for (Pair<Integer, FailableBiConsumer<ResultSet, T, TorqueException>> strategy : this.tasks) + { + strategy.getRight().accept(result, instance); + } + } +} \ No newline at end of file Modified: db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties URL: http://svn.apache.org/viewvc/db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties?rev=1917285&r1=1917284&r2=1917285&view=diff ============================================================================== --- db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties (original) +++ db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties Tue Apr 23 14:22:16 2024 @@ -1,4 +1,3 @@ -# 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 @@ -77,6 +76,11 @@ torque.om.bean.beanExtendsClass = # using JCS. torque.om.useManagers = false +# use new org.apache.torque.om.mapper.MappingStrategy<T> in processRow method of generated mappers +torque.om.useMappingStrategy = true +# If useMappingStrategy is true, perform an additiona sort in finish method. +torque.om.mappingStrategySort = true + # Whether to generate methods which select at most a single record torque.om.addSelectSingleRecordMethods = true Modified: db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm URL: http://svn.apache.org/viewvc/db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm?rev=1917285&r1=1917284&r2=1917285&view=diff ============================================================================== --- db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm (original) +++ db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm Tue Apr 23 14:22:16 2024 @@ -41,6 +41,7 @@ import org.apache.torque.Column; import org.apache.torque.TorqueException; import org.apache.torque.criteria.Criteria; import org.apache.torque.om.mapper.RecordMapper; +import org.apache.torque.om.mapper.MappingStrategy; #foreach ($columnElement in $torqueGen.getSourceElement().getChildren("column")) #set ($colEnumPackage = $columnElement.getAttribute("enumPackage")) @@ -99,12 +100,24 @@ public class ${baseRecordMapperClassName private static Log log = LogFactory.getLog(${baseRecordMapperClassName}.class); - ## Cached SQL expressions to speed up looking for columns selected by a given Criteria + ## TORQUE-364: Cached SQL expressions to speed up looking for columns selected by a given Criteria #foreach ($columnElement in $torqueGen.getChildren("column")) #set ( $peerColumnName = $columnElement.getAttribute("peerColumnName") ) private static final String ${peerColumnName}_EXPRESSION = ${basePeerClassName}.${peerColumnName}.getSqlExpression(); #end + private boolean useMappingStrategy = #if("${useMappingStrategy}" == "true")true#{else}false#end; + + ## TORQUE-364: Should this be cached per RecordMapper (Thread safety/Multi query safety?) + private MappingStrategy<${dbObjectClassName}> strategy; + + ## TORQUE-364: init a new Strategy implementation + public void initStrategy() + { + this.strategy = new MappingStrategy<${dbObjectClassName}>(); + } + + /** * Constructs the object from the current row in the resultSet. * @@ -156,6 +169,9 @@ $torqueGen.mergepoint("createDbObjectIns } else { + if (useMappingStrategy) { + initStrategy(); + } // try to get columns to be mapped // from criteria's select columns int totalOffset = offset + 1; @@ -166,6 +182,7 @@ $torqueGen.mergepoint("createDbObjectIns Set<String> columnsMapped = new HashSet<String>(); for (Column column : columnsWithoutOffset) { + final int nextOffset = totalOffset; ## leaking assignment #set ( $else = "" ) #foreach ($columnElement in $torqueGen.getChildren("column")) #set ( $setter = $columnElement.getAttribute("setter") ) @@ -174,8 +191,14 @@ $torqueGen.mergepoint("createDbObjectIns ${else}if (!columnsMapped.contains(${peerColumnName}_EXPRESSION ) && ${peerColumnName}_EXPRESSION.equals( column.getSqlExpression())) { - ${field}.${setter}( - ${getter}(resultSet, totalOffset)); + if (useMappingStrategy) + { + strategy.addColumn(nextOffset, + (res, inst) -> inst.${setter}( ${getter}(res, nextOffset))); + } else + { + ${field}.${setter}( ${getter}(resultSet, totalOffset)); + } columnsMapped.add( ${peerColumnName}_EXPRESSION ); } #set ( $else = "else ") @@ -188,6 +211,11 @@ $torqueGen.mergepoint("createDbObjectIns + "returning null"); return null; } + if (useMappingStrategy) + { + this.strategy.finish($torqueGen.getChildren("column").size(), #if("${mappingStrategySort}"=="true")true#{else}false#end); + this.strategy.execute(resultSet, $field); + } } ${field}.setNew(false); ${field}.setModified(false); Modified: db/torque/trunk/torque-test/README.md URL: http://svn.apache.org/viewvc/db/torque/trunk/torque-test/README.md?rev=1917285&r1=1917284&r2=1917285&view=diff ============================================================================== --- db/torque/trunk/torque-test/README.md (original) +++ db/torque/trunk/torque-test/README.md Tue Apr 23 14:22:16 2024 @@ -4,18 +4,23 @@ - A profile exists for each database in folder src/test/profile/<db>. -- Tested with Java 8 and Java 14. +- Tested with Java 11 and Java 20. - A Maven test is started like this: -```sh -mvn clean test -P<data-type>,managers,beans -``` + mvn clean test -P<data-type>,managers,beans * e.g. for database Hsqldb use `mvn clean test -Phsqldb,managers,beans`. Running tests against a non-memory or non-docker-containerized database requires a host-based database to be installed and running. +### Debug a single test + +Use surefire flag maven.surefire.debug (Port 5005) + + mvn test -PderbyEmbedded,beans,managers -Dtest=<TEST-CLASS> -Dmaven.surefire.debug=true + + ### Database Profiles Find more details about database and db user settings in the profile. Modified: db/torque/trunk/torque-test/pom.xml URL: http://svn.apache.org/viewvc/db/torque/trunk/torque-test/pom.xml?rev=1917285&r1=1917284&r2=1917285&view=diff ============================================================================== --- db/torque/trunk/torque-test/pom.xml (original) +++ db/torque/trunk/torque-test/pom.xml Tue Apr 23 14:22:16 2024 @@ -61,6 +61,7 @@ <torque.test.testcontainer.version>1.19.7</torque.test.testcontainer.version> <!-- --> <torque.test.idmethod>native</torque.test.idmethod> + </properties> <scm> --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org For additional commands, e-mail: torque-dev-h...@db.apache.org