Author: gk
Date: Wed Jul 30 09:01:36 2025
New Revision: 1927531

Log:
add getSetPluralsgetSetPlurals method in FieldHelper (not used yet)

Modified:
   
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java
   
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java
   
db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/primaryKeyMethods.vm
   db/torque/trunk/torque-templates/src/test/schema/ext-schema.xml
   db/torque/trunk/torque-templates/src/test/schema/extext-schema.xml
   db/torque/trunk/torque-templates/src/test/schema/schema.xml

Modified: 
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java
==============================================================================
--- 
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java
   Wed Jul 30 09:00:51 2025        (r1927530)
+++ 
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java
   Wed Jul 30 09:01:36 2025        (r1927531)
@@ -153,6 +153,7 @@ public class LoadExternalSchemaTransform
                         rootDatabaseName,
                         controllerState);
 
+                // todo infinite loop
                 this.transform(externalSchemaRootElement, controllerState);
 
                 externalSchemaElement.getChildren().add(
@@ -244,7 +245,24 @@ public class LoadExternalSchemaTransform
                 = (Database) toModelTransformer.transform(
                         externalSchemaRootElement,
                         controllerState);
+                
+//                log.warn( "get value of database.rootDatabaseName and set " 
+ database.rootDatabaseName );
                 externalDatabase.rootDatabaseName = database.rootDatabaseName;
+
+                // TODO continue if 
+//                if (database.externalSchemaList.contains( externalSchema)) {
+//                    log.warn( "checked root has externalShema included: " + 
externalSchema );
+//                }
+//                log.warn( "database.name " + database.name );
+//                log.warn( "externalDatabase.externalSchemaList " + 
externalDatabase.externalSchemaList.toString() );
+//                log.warn( "externalDatabase.name " + externalDatabase.name );
+//                boolean identicalInclude = 
externalDatabase.externalSchemaList.stream().anyMatch( 
+//                        extSchema -> extSchema != null && 
extSchema.database.name.equals( externalDatabase.name ));
+//                        //.parent.externalSchemaList.contains( 
externalDatabase )  );
+//                log.warn( "identicalInclude " + identicalInclude );
+//                if (identicalInclude) {
+//                    return database;
+//                }
                 // TODO fix static access
                 
DatabaseMapInitTransformer.setDatabaseMapInitClassNameAttributes(
                         externalSchemaRootElement,

Modified: 
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java
==============================================================================
--- 
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java
  Wed Jul 30 09:00:51 2025        (r1927530)
+++ 
db/torque/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/FieldHelper.java
  Wed Jul 30 09:01:36 2025        (r1927531)
@@ -1,5 +1,11 @@
 package org.apache.torque.templates.transformer.om;
 
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -20,6 +26,7 @@ package org.apache.torque.templates.tran
  */
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.torque.generator.control.ControllerState;
 import org.apache.torque.templates.TemplateOptionName;
 import org.apache.torque.templates.typemapping.JavaType;
@@ -238,4 +245,26 @@ final class FieldHelper
                 TemplateOptionName.OM_SET_AND_SAVE_SUFFIX);
         return fillerName;
     }
+    
+    /**
+     * Pluralize the field name, if matches simple pattern, else return 
original.
+     * 
+     * @param fieldName
+     * @return the fied name, not null.
+     */
+    public static String getSetPlurals(final String fieldName)
+    {
+        Map<String,String> pluralizations = Map.ofEntries(
+            Map.entry("(.+(s|x|sh|ch))$", "$1es"),
+            Map.entry("(.+)", "$1s" ) );
+        for (final Entry<String, String> pluralization : 
pluralizations.entrySet()) {
+            Matcher candidate = Pattern
+                    .compile(pluralization.getKey())
+                    .matcher(fieldName);
+            if (candidate.matches()) {
+              return candidate.replaceFirst(pluralization.getValue());
+            }
+        }
+        return fieldName;
+    }
 }

Modified: 
db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/primaryKeyMethods.vm
==============================================================================
--- 
db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/primaryKeyMethods.vm
     Wed Jul 30 09:00:51 2025        (r1927530)
+++ 
db/torque/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/primaryKeyMethods.vm
     Wed Jul 30 09:01:36 2025        (r1927531)
@@ -108,7 +108,8 @@
   #elseif($columnFieldType == "double")
         ${setter}(Double.parseDouble(key));
   #elseif ($number == "true" && ($primitive != "true"))
-        ${setter}(new ${columnFieldType}(key));
+        // expected match: Short,Double,Float,Long,Byte,Integer
+        ${setter}(${columnFieldType}.valueOf(key));
   #elseif($columnFieldType == "String")
         ${setter}(key);
   #elseif($columnFieldType == "java.util.Date")

Modified: db/torque/trunk/torque-templates/src/test/schema/ext-schema.xml
==============================================================================
--- db/torque/trunk/torque-templates/src/test/schema/ext-schema.xml     Wed Jul 
30 09:00:51 2025        (r1927530)
+++ db/torque/trunk/torque-templates/src/test/schema/ext-schema.xml     Wed Jul 
30 09:01:36 2025        (r1927531)
@@ -20,8 +20,8 @@
 <database
     xmlns="http://db.apache.org/torque/5.0/templates/database";
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-    xsi:schemaLocation="http://db.apache.org/torque/5.0/templates/database 
-        
http://db.apache.org/torque/torque-5.0/documentation/orm-reference/database-5-0.xsd";
+    xsi:schemaLocation="https://db.apache.org/torque/5.0/templates/database 
+        
https://db.apache.org/torque/torque-5.0/documentation/orm-reference/database-5-0.xsd";
     name="ext"
     defaultIdMethod="native">
 

Modified: db/torque/trunk/torque-templates/src/test/schema/extext-schema.xml
==============================================================================
--- db/torque/trunk/torque-templates/src/test/schema/extext-schema.xml  Wed Jul 
30 09:00:51 2025        (r1927530)
+++ db/torque/trunk/torque-templates/src/test/schema/extext-schema.xml  Wed Jul 
30 09:01:36 2025        (r1927531)
@@ -20,14 +20,21 @@
 <database
     xmlns="http://db.apache.org/torque/5.0/templates/database";
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-    xsi:schemaLocation="http://db.apache.org/torque/5.0/templates/database
-        
http://db.apache.org/torque/torque-5.0/documentation/orm-reference/database-5-0.xsd";
+    xsi:schemaLocation="https://db.apache.org/torque/5.0/templates/database
+        
https://db.apache.org/torque/torque-5.0/documentation/orm-reference/database-5-0.xsd";
     name="extext"
     defaultIdMethod="idbroker">
     
-    <!-- TODO Torque-369 
-    external-schema filename="ext-schema.xml"
-    /-->
+    <!-- TODO Torque-369
+    
+    Assuming that if an external schema is referenced it is always (?) 
+    for the same database and the 'database element name attribute in an 
external schema is just an identifier,
+    but not a new database.
+    Assuming this, rootDatabaseName is just the identifer, but not the 
database and
+    this might make sense just to define parts of the same database in 
different xml files.
+     
+        external-schema filename="ext-schema.xml"/>
+     -->
 
   <table name="extext">
     <column

Modified: db/torque/trunk/torque-templates/src/test/schema/schema.xml
==============================================================================
--- db/torque/trunk/torque-templates/src/test/schema/schema.xml Wed Jul 30 
09:00:51 2025        (r1927530)
+++ db/torque/trunk/torque-templates/src/test/schema/schema.xml Wed Jul 30 
09:01:36 2025        (r1927531)
@@ -20,8 +20,8 @@
 <database
     xmlns="http://db.apache.org/torque/5.0/templates/database";
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-    xsi:schemaLocation="http://db.apache.org/torque/5.0/templates/database
-        
http://db.apache.org/torque/torque-5.0/documentation/orm-reference/database-5-0.xsd";
+    xsi:schemaLocation="https://db.apache.org/torque/5.0/templates/database
+        
https://db.apache.org/torque/torque-5.0/documentation/orm-reference/database-5-0.xsd";
     name="bookstore"
     defaultIdMethod="native" >
   <external-schema filename="ext-schema.xml" />


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org
For additional commands, e-mail: torque-dev-h...@db.apache.org

Reply via email to