This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch STABLE-4.2
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.2 by this push:
     new 430c4d806 CAY-2915 CayenneModeler DB Import forces meaningful PK  - 
treat empty string as an `exclude all`, not `include all`
430c4d806 is described below

commit 430c4d8067d11af5b0b5af9fa7a750f0214924b1
Author: Nikita Timofeev <[email protected]>
AuthorDate: Fri Mar 13 18:34:43 2026 +0400

    CAY-2915 CayenneModeler DB Import forces meaningful PK
     - treat empty string as an `exclude all`, not `include all`
---
 .../reverse/dbimport/DbImportConfiguration.java    | 20 ++++--
 .../dbimport/DbImportConfigurationTest.java        | 71 ++++++++++++++++++++++
 .../modeler/editor/dbimport/DbImportView.java      |  3 +-
 3 files changed, 86 insertions(+), 8 deletions(-)

diff --git 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DbImportConfiguration.java
 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DbImportConfiguration.java
index 6f142a97e..372bea3d1 100644
--- 
a/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DbImportConfiguration.java
+++ 
b/cayenne-dbsync/src/main/java/org/apache/cayenne/dbsync/reverse/dbimport/DbImportConfiguration.java
@@ -19,6 +19,8 @@
 package org.apache.cayenne.dbsync.reverse.dbimport;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.regex.Pattern;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -166,18 +168,24 @@ public class DbImportConfiguration {
 
     public NameFilter createMeaningfulPKFilter() {
 
-        if (meaningfulPkTables == null) {
+        if (meaningfulPkTables == null || meaningfulPkTables.trim().isEmpty()) 
{
             return NamePatternMatcher.EXCLUDE_ALL;
         }
 
         // TODO: this filter can't handle table names with comma in them
         String[] patternStrings = meaningfulPkTables.split(",");
-        Pattern[] patterns = new Pattern[patternStrings.length];
-        for (int i = 0; i < patterns.length; i++) {
-            patterns[i] = Pattern.compile(patternStrings[i]);
+        List<Pattern> patterns = new ArrayList<>(patternStrings.length);
+        for (String patternString : patternStrings) {
+            if (!patternString.trim().isEmpty()) {
+                patterns.add(Pattern.compile(patternString));
+            }
+        }
+
+        if (patterns.isEmpty()) {
+            return NamePatternMatcher.EXCLUDE_ALL;
         }
 
-        return new NamePatternMatcher(patterns, new Pattern[0]);
+        return new NamePatternMatcher(patterns.toArray(new Pattern[0]), new 
Pattern[0]);
     }
 
     public ObjectNameGenerator createNameGenerator() {
@@ -201,7 +209,7 @@ public class DbImportConfiguration {
     }
 
     protected DbEntityNameStemmer createStemmer() {
-        return (stripFromTableNames == null || stripFromTableNames.length() == 
0)
+        return (stripFromTableNames == null || stripFromTableNames.isEmpty())
                 ? NoStemStemmer.getInstance()
                 : new PatternStemmer(stripFromTableNames, false);
     }
diff --git 
a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbimport/DbImportConfigurationTest.java
 
b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbimport/DbImportConfigurationTest.java
new file mode 100644
index 000000000..f9cc8b50a
--- /dev/null
+++ 
b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbimport/DbImportConfigurationTest.java
@@ -0,0 +1,71 @@
+/*****************************************************************
+ *   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
+ *
+ *    https://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.
+ ****************************************************************/
+
+package org.apache.cayenne.dbsync.reverse.dbimport;
+
+import org.apache.cayenne.dbsync.filter.NameFilter;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class DbImportConfigurationTest {
+
+    @Test
+    public void testCreateMeaningfulPKFilter_NullExcludesAll() {
+        DbImportConfiguration config = new DbImportConfiguration();
+        config.setMeaningfulPkTables(null);
+        NameFilter filter = config.createMeaningfulPKFilter();
+
+        assertFalse(filter.isIncluded("ARTIST"));
+        assertFalse(filter.isIncluded("PAINTING"));
+        assertFalse(filter.isIncluded("ANY_TABLE"));
+    }
+
+    @Test
+    public void testCreateMeaningfulPKFilter_EmptyStringExcludesAll() {
+        DbImportConfiguration config = new DbImportConfiguration();
+        config.setMeaningfulPkTables("");
+        NameFilter filter = config.createMeaningfulPKFilter();
+
+        assertFalse(filter.isIncluded("ARTIST"));
+        assertFalse(filter.isIncluded("ANY_TABLE"));
+    }
+
+    @Test
+    public void testCreateMeaningfulPKFilter_WhitespaceStringExcludesAll() {
+        DbImportConfiguration config = new DbImportConfiguration();
+        config.setMeaningfulPkTables("   ");
+        NameFilter filter = config.createMeaningfulPKFilter();
+
+        assertFalse(filter.isIncluded("ARTIST"));
+        assertFalse(filter.isIncluded("ANY_TABLE"));
+    }
+
+    @Test
+    public void testCreateMeaningfulPKFilter_CommaSeparatedPatterns() {
+        DbImportConfiguration config = new DbImportConfiguration();
+        config.setMeaningfulPkTables("^ART.*$,,^T1$"); // Note double comma
+        NameFilter filter = config.createMeaningfulPKFilter();
+
+        assertTrue(filter.isIncluded("ARTIST"));
+        assertTrue(filter.isIncluded("T1"));
+
+        assertFalse("Empty tokens should not match everything", 
filter.isIncluded("PAINTING"));
+    }
+}
diff --git 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
index c99be2658..e38c24a25 100644
--- 
a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
+++ 
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
@@ -250,8 +250,7 @@ public class DbImportView extends JPanel {
     }
 
     public String getMeaningfulPk() {
-        return 
"".equals(configPanel.getMeaningfulPk().getComponent().getText())
-                ? null : 
configPanel.getMeaningfulPk().getComponent().getText();
+        return configPanel.getMeaningfulPk().getComponent().getText();
     }
 
     public String getNamingStrategy() {

Reply via email to