cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r700707 - in /cayenne/main/trunk/framework/cayenne-modeler: ./ src/main/java/org/apache/cayenne/modeler/action/ src/main/java/org/apache/cayenne/modeler/dialog/db/ src/main/java/org/apache/cayenne/modeler/dialog/pref/ src/main/java/org/apac...
Date Wed, 01 Oct 2008 07:43:24 GMT
Author: andrey
Date: Wed Oct  1 00:43:23 2008
New Revision: 700707

URL: http://svn.apache.org/viewvc?rev=700707&view=rev
Log: (empty)

Added:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizardView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SmartNamingStrategy.java
    cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/SmartNamingStrategyTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-modeler/pom.xml
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDBAction.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizardView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DBConnectionInfoEditorView.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/pom.xml?rev=700707&r1=700706&r2=700707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/pom.xml (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/pom.xml Wed Oct  1 00:43:23 2008
@@ -1,170 +1,176 @@
-<?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.   
---><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
-	<modelVersion>4.0.0</modelVersion>
-
-	<parent>
-		<groupId>org.apache.cayenne</groupId>
-		<artifactId>cayenne-parent</artifactId>
-		<version>3.0-SNAPSHOT</version>
-	</parent>
-
-	<artifactId>cayenne-modeler</artifactId>
-	<name>Cayenne Modeler</name>
-	<packaging>jar</packaging>
-
-	<dependencies>
-		<dependency>
-			<groupId>junit</groupId>
-			<artifactId>junit</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>commons-collections</groupId>
-			<artifactId>commons-collections</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>commons-logging</groupId>
-			<artifactId>commons-logging</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>commons-dbcp</groupId>
-			<artifactId>commons-dbcp</artifactId>
-			<scope>compile</scope>
-		</dependency>
-
-		<dependency>
-			<groupId>commons-pool</groupId>
-			<artifactId>commons-pool</artifactId>
-			<scope>compile</scope>
-		</dependency>
-
-		<dependency>
-			<groupId>velocity</groupId>
-			<artifactId>velocity</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>org.objectstyle.ashwood</groupId>
-			<artifactId>ashwood</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>jgoodies</groupId>
-			<artifactId>looks</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>jgoodies</groupId>
-			<artifactId>forms</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>org.scopemvc</groupId>
-			<artifactId>scopemvc</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>org.apache.cayenne.unpublished</groupId>
-			<artifactId>cayenne-legal-unpublished</artifactId>
-			<version>${version}</version>
-			<scope>provided</scope>
-		</dependency>
-		
-		<dependency>
-			<groupId>org.apache.cayenne.unpublished</groupId>
-			<artifactId>cayenne-jdk1.5-unpublished</artifactId>
-			<version>${version}</version>
-			<scope>provided</scope>
-		</dependency>
-
-		<dependency>
-			<groupId>ognl</groupId>
-			<artifactId>ognl</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>hsqldb</groupId>
-			<artifactId>hsqldb</artifactId>
-		</dependency>
-
-		<dependency>
-			<groupId>mockrunner</groupId>
-			<artifactId>mockrunner</artifactId>
-		</dependency>
-		
-	  	<dependency>
-      		<groupId>net.sf.jedit-syntax</groupId>
-      		<artifactId>jedit-syntax</artifactId>
-      		<version>2.2.2</version>
-    	</dependency>
-  </dependencies>
-
-	<build>
-		<plugins>
-			<plugin>
-				<artifactId>maven-remote-resources-plugin</artifactId>
-				<executions>
-					<execution>
-						<goals>
-							<goal>process</goal>
-						</goals>
-						<phase>process-resources</phase>
-						<configuration>
-							<outputDirectory>
-								${project.build.directory}/classes
-							</outputDirectory>
-							<resourceBundles>
-								<resourceBundle>
-									org.apache.cayenne.unpublished:cayenne-legal-unpublished:${version}
-								</resourceBundle>
-							</resourceBundles>
-						</configuration>
-					</execution>
-				</executions>
-			</plugin>
-
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<configuration>
-					<source>1.5</source>
-					<target>1.5</target>
-				</configuration>
-			</plugin>
-			<plugin>
-                                <groupId>org.apache.maven.plugins</groupId>
-                                <artifactId>maven-source-plugin</artifactId>
-                                <executions>
-                                        <execution>
-                                                <id>bundle-source-jar</id>
-                                                <phase>package</phase>
-                                                <goals>
-                                                        <goal>jar</goal>
-                                                </goals>
-                                        </execution>
-                                </executions>
-                        </plugin>
-		</plugins>
-
-	</build>
+<?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.   
+--><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.cayenne</groupId>
+		<artifactId>cayenne-parent</artifactId>
+		<version>3.0-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>cayenne-modeler</artifactId>
+	<name>Cayenne Modeler</name>
+	<packaging>jar</packaging>
+
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-collections</groupId>
+			<artifactId>commons-collections</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-dbcp</groupId>
+			<artifactId>commons-dbcp</artifactId>
+			<scope>compile</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-pool</groupId>
+			<artifactId>commons-pool</artifactId>
+			<scope>compile</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>velocity</groupId>
+			<artifactId>velocity</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.objectstyle.ashwood</groupId>
+			<artifactId>ashwood</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>jgoodies</groupId>
+			<artifactId>looks</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>jgoodies</groupId>
+			<artifactId>forms</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.scopemvc</groupId>
+			<artifactId>scopemvc</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.cayenne.unpublished</groupId>
+			<artifactId>cayenne-legal-unpublished</artifactId>
+			<version>${version}</version>
+			<scope>provided</scope>
+		</dependency>
+		
+		<dependency>
+			<groupId>org.apache.cayenne.unpublished</groupId>
+			<artifactId>cayenne-jdk1.5-unpublished</artifactId>
+			<version>${version}</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>ognl</groupId>
+			<artifactId>ognl</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>hsqldb</groupId>
+			<artifactId>hsqldb</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>mockrunner</groupId>
+			<artifactId>mockrunner</artifactId>
+		</dependency>
+		
+	  	<dependency>
+      		<groupId>net.sf.jedit-syntax</groupId>
+      		<artifactId>jedit-syntax</artifactId>
+      		<version>2.2.2</version>
+    	</dependency>
+    	
+    	<dependency>
+  			<groupId>net.java.dev.inflector</groupId>
+			  <artifactId>inflector</artifactId>
+			  <version>0.7.0</version>
+		</dependency>
+  </dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-remote-resources-plugin</artifactId>
+				<executions>
+					<execution>
+						<goals>
+							<goal>process</goal>
+						</goals>
+						<phase>process-resources</phase>
+						<configuration>
+							<outputDirectory>
+								${project.build.directory}/classes
+							</outputDirectory>
+							<resourceBundles>
+								<resourceBundle>
+									org.apache.cayenne.unpublished:cayenne-legal-unpublished:${version}
+								</resourceBundle>
+							</resourceBundles>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+			<plugin>
+                                <groupId>org.apache.maven.plugins</groupId>
+                                <artifactId>maven-source-plugin</artifactId>
+                                <executions>
+                                        <execution>
+                                                <id>bundle-source-jar</id>
+                                                <phase>package</phase>
+                                                <goals>
+                                                        <goal>jar</goal>
+                                                </goals>
+                                        </execution>
+                                </executions>
+                        </plugin>
+		</plugins>
+
+	</build>
 </project>
\ No newline at end of file

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDBAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDBAction.java?rev=700707&r1=700706&r2=700707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDBAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ImportDBAction.java
Wed Oct  1 00:43:23 2008
@@ -23,6 +23,7 @@
 import java.sql.Connection;
 
 import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.reveng.NamingStrategy;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.dialog.db.ConnectionWizard;
@@ -68,6 +69,8 @@
         Connection connection = connectWizard.getConnection();
         DbAdapter adapter = connectWizard.getAdapter();
         DBConnectionInfo dataSourceInfo = connectWizard.getConnectionInfo();
+        
+        NamingStrategy strategy = connectWizard.getNamingStrategy();
 
         // from here pass control to DbLoaderHelper, running it from a thread separate
         // from EventDispatch
@@ -76,7 +79,8 @@
                 getProjectController(),
                 connection,
                 adapter,
-                dataSourceInfo.getUserName());
+                dataSourceInfo.getUserName(),
+                strategy);
         Thread th = new Thread(new Runnable() {
 
             public void run() {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java?rev=700707&r1=700706&r2=700707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
Wed Oct  1 00:43:23 2008
@@ -20,9 +20,15 @@
 package org.apache.cayenne.modeler.dialog.db;
 
 import java.sql.Connection;
+import java.util.Vector;
 
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+
+import org.apache.cayenne.access.reveng.NamingStrategy;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.modeler.ClassLoadingService;
+import org.apache.cayenne.modeler.ModelerPreferences;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 import org.apache.cayenne.modeler.util.CayenneController;
 
@@ -36,14 +42,41 @@
 // TODO: after refactoring DbLoader to accept a DataSource instead of connection this
 // dialog should be merged with superclass - DataSourceWizard.
 public class ConnectionWizard extends DataSourceWizard {
+    /**
+     * Preference to store latest strategies
+     */
+    private static final String STRATEGIES_PREFERENCE = "recent.preferences";
+    
+    /**
+     * Naming strategies to appear in combobox by default
+     */
+    private static final Vector<String> PREDEFINED_STRATEGIES = new Vector<String>();
+    static {
+        PREDEFINED_STRATEGIES.add("org.apache.cayenne.access.reveng.BasicNamingStrategy");
+        PREDEFINED_STRATEGIES.add("org.apache.cayenne.modeler.util.SmartNamingStrategy");
+    };
 
     protected Connection connection;
     protected DbAdapter adapter;
+    
+    protected NamingStrategy strategy;
 
     public ConnectionWizard(CayenneController parent, String title,
             String altDataSourceKey, DBConnectionInfo altDataSource) {
         super(parent, title, altDataSourceKey, altDataSource);
     }
+    
+    protected DataSourceWizardView createView() {
+        ConnectionWizardView view = new ConnectionWizardView(this);
+        
+        ModelerPreferences pref = ModelerPreferences.getPreferences();
+        Vector<?> arr = pref.getVector(STRATEGIES_PREFERENCE, PREDEFINED_STRATEGIES);
+        
+        JComboBox strategyCombo = view.getStrategyComboBox();
+        strategyCombo.setModel(new DefaultComboBoxModel(arr));
+        
+        return view;
+    }
 
     /**
      * Overrides superclass to keep an open connection around for the caller's use.
@@ -69,6 +102,30 @@
             reportError("Connection Error", th);
             return;
         }
+        
+        try {
+            String strategyClass = (String) 
+                ((ConnectionWizardView) view).getStrategyComboBox().getSelectedItem();
+            
+            this.strategy = (NamingStrategy) classLoader.loadClass(strategyClass).newInstance();
+            
+            /**
+             * Be user-friendly and update preferences with specified strategy
+             */
+            ModelerPreferences pref = ModelerPreferences.getPreferences();
+            Vector arr = pref.getVector(STRATEGIES_PREFERENCE, PREDEFINED_STRATEGIES);
+            
+            //move to top
+            arr.remove(strategyClass);
+            arr.add(0, strategyClass);
+            
+            pref.setProperty(STRATEGIES_PREFERENCE, arr);
+        }
+        catch (Throwable th) {
+            reportError("Naming Strategy Initialization Error", 
+                    new Exception("Naming Strategy Initialization Error: " + th.getMessage()));
+            return;
+        }
 
         // set success flag, and unblock the caller...
         canceled = false;
@@ -88,4 +145,11 @@
     public DbAdapter getAdapter() {
         return adapter;
     }
+    
+    /**
+     * Returns configured naming strategy
+     */
+    public NamingStrategy getNamingStrategy() {
+        return strategy;
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizardView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizardView.java?rev=700707&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizardView.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizardView.java
Wed Oct  1 00:43:23 2008
@@ -0,0 +1,55 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.modeler.dialog.db;
+
+import javax.swing.JComboBox;
+
+import org.apache.cayenne.modeler.dialog.pref.DBConnectionInfoEditorView;
+import org.apache.cayenne.modeler.util.CayenneController;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+
+/**
+ * Dialog special for reverse engineering. Has one special combobox for
+ * choosing naming strategy 
+ * @author Andrey Razumovsky
+ */
+public class ConnectionWizardView extends DataSourceWizardView {
+    /**
+     * Combobox for naming strategy
+     */
+    protected JComboBox strategyCombo;
+    
+    public ConnectionWizardView(CayenneController controller) {
+        super(controller);
+        
+        strategyCombo = new JComboBox();
+        strategyCombo.setEditable(true);
+        
+        DefaultFormBuilder builder = ((DBConnectionInfoEditorView) connectionInfo.getView()).getBuilder();
+        builder.append("Naming Strategy:", strategyCombo);
+    }
+    
+    /**
+     * @return combobox for naming strategy
+     */
+    public JComboBox getStrategyComboBox() {
+        return strategyCombo;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java?rev=700707&r1=700706&r2=700707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
Wed Oct  1 00:43:23 2008
@@ -63,7 +63,7 @@
             String altDataSourceKey, DBConnectionInfo altDataSource) {
         super(parent);
 
-        this.view = new DataSourceWizardView(this);
+        this.view = createView();
         this.view.setTitle(title);
         this.altDataSource = altDataSource;
         this.altDataSourceKey = altDataSourceKey;
@@ -71,6 +71,13 @@
 
         initBindings();
     }
+    
+    /**
+     * Creates swing dialog for this wizard 
+     */
+    protected DataSourceWizardView createView() {
+        return new DataSourceWizardView(this); 
+    }
 
     protected void initBindings() {
         BindingBuilder builder = new BindingBuilder(

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizardView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizardView.java?rev=700707&r1=700706&r2=700707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizardView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizardView.java
Wed Oct  1 00:43:23 2008
@@ -56,7 +56,7 @@
 
         CellConstraints cc = new CellConstraints();
         PanelBuilder builder = new PanelBuilder(new FormLayout(
-                "20dlu:grow, pref, 3dlu, fill:max(50dlu;pref), 3dlu, fill:20dlu",
+                "20dlu:grow, pref, 3dlu, fill:max(150dlu;pref), 3dlu, fill:20dlu",
                 "p"));
         builder.setDefaultDialogBorder();
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java?rev=700707&r1=700706&r2=700707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
Wed Oct  1 00:43:23 2008
@@ -19,10 +19,23 @@
 
 package org.apache.cayenne.modeler.dialog.db;
 
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DbLoader;
 import org.apache.cayenne.access.DbLoaderDelegate;
+import org.apache.cayenne.access.reveng.BasicNamingStrategy;
+import org.apache.cayenne.access.reveng.NamingStrategy;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
@@ -40,14 +53,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.swing.*;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
 /**
  * Stateful helper class that encapsulates access to DbLoader.
  * 
@@ -94,12 +99,17 @@
 
         return mergeDialog;
     }
-
+    
     public DbLoaderHelper(ProjectController mediator, Connection connection,
             DbAdapter adapter, String dbUserName) {
+        this(mediator, connection, adapter, dbUserName, new BasicNamingStrategy());
+    }
+
+    public DbLoaderHelper(ProjectController mediator, Connection connection,
+            DbAdapter adapter, String dbUserName, NamingStrategy strategy) {
         this.dbUserName = dbUserName;
         this.mediator = mediator;
-        this.loader = new DbLoader(connection, adapter, new LoaderDelegate());
+        this.loader = new DbLoader(connection, adapter, new LoaderDelegate(), strategy);
     }
 
     public void setOverwritingEntities(boolean overwritePreference) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DBConnectionInfoEditorView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DBConnectionInfoEditorView.java?rev=700707&r1=700706&r2=700707&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DBConnectionInfoEditorView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DBConnectionInfoEditorView.java
Wed Oct  1 00:43:23 2008
@@ -47,6 +47,8 @@
     protected JPasswordField password;
 
     protected Collection labels;
+    
+    protected DefaultFormBuilder builder;
 
     public DBConnectionInfoEditorView() {
         adapters = new JComboBox();
@@ -60,7 +62,7 @@
 
         // assemble
         FormLayout layout = new FormLayout("right:pref, 3dlu, fill:160dlu:grow", "");
-        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
+        builder = new DefaultFormBuilder(layout);
         builder.setDefaultDialogBorder();
 
         labels.add(builder.append("JDBC Driver:", driver));
@@ -92,6 +94,13 @@
     public JTextField getUserName() {
         return userName;
     }
+    
+    /**
+     * @return Builder of the view (to allow dynamic extending of the component)
+     */
+    public DefaultFormBuilder getBuilder() {
+        return builder;
+    }
 
     public void setEnabled(boolean enabled) {
         if (isEnabled() != enabled) {

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SmartNamingStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SmartNamingStrategy.java?rev=700707&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SmartNamingStrategy.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/SmartNamingStrategy.java
Wed Oct  1 00:43:23 2008
@@ -0,0 +1,89 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.modeler.util;
+
+import java.util.Locale;
+
+import org.apache.cayenne.access.reveng.BasicNamingStrategy;
+import org.apache.cayenne.access.reveng.ExportedKey;
+import org.apache.cayenne.util.NameConverter;
+import org.jvnet.inflector.Noun;
+
+/**
+ * SmartNamingStrategy is a new strategy for generating names of
+ * entities, attributes etc.
+ * 
+ * Advantages of this strategy are:
+ * -Using of FK names at generating relationship names
+ * -Dropping 'to' prefix for obj relationships and therefore for generated class methods'
names
+ * -Using pluralized form instead-of "ARRAY" suffix for to-many relationships (i.e. 'adresses'

+ *   instead-of 'addressArray')
+ * 
+ * @since 3.0
+ * @author Andrey Razumovsky
+ */
+public class SmartNamingStrategy extends BasicNamingStrategy {
+    @Override
+    public String createDbRelationshipName(
+            ExportedKey key,
+            boolean toMany) {
+        
+        String name;
+        
+        if (!toMany) {
+            String fkColName = key.getFKColumnName();
+        
+            //trim "ID" in the end
+            if (fkColName.toUpperCase().endsWith("_ID") && fkColName.length() >
3) {
+                fkColName = fkColName.substring(0, fkColName.length() - 3);
+            }
+            else if (fkColName.toUpperCase().endsWith("ID") && fkColName.length()
> 2) {
+                fkColName = fkColName.substring(0, fkColName.length() - 2);
+            }
+            else {
+                /**
+                 * We don't want relationship to conflict with attribute, so we'd better
return
+                 * superior value with 'to'
+                 */
+                return super.createDbRelationshipName(key, toMany);
+            }
+        
+            name = fkColName;
+        }
+        else {
+            try {
+                /**
+                 * by default we use english language rules here.
+                 * uppercase is required for NameConverter to work properly 
+                 */
+                name = Noun.pluralOf(key.getFKTableName().toLowerCase(), Locale.ENGLISH).toUpperCase();
+            }
+            catch (Exception inflectorError) {
+                /**
+                 * seems that Inflector cannot be trusted. For instance, it throws an exception
+                 * when invoked for word "ADDRESS" (although lower case works fine). To feel
safe, we
+                 * use superclass' behavior if something's gone wrong 
+                 */
+                return super.createDbRelationshipName(key, toMany);
+            }
+        }
+
+        return NameConverter.underscoredToJava(name, false);
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/SmartNamingStrategyTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/SmartNamingStrategyTest.java?rev=700707&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/SmartNamingStrategyTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/SmartNamingStrategyTest.java
Wed Oct  1 00:43:23 2008
@@ -0,0 +1,56 @@
+/*****************************************************************
+ *   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.
+ ****************************************************************/
+package org.apache.cayenne.modeler.util;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.access.reveng.ExportedKey;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbRelationship;
+
+public class SmartNamingStrategyTest extends TestCase {
+    public void testStrategy() throws Exception {
+        SmartNamingStrategy strategy = new SmartNamingStrategy();
+        
+        ExportedKey key = new ExportedKey("ARTIST", "ARTIST_ID", null,
+                "PAINTING", "ARTIST_ID", null);
+        assertEquals(strategy.createDbRelationshipName(key, false), "artist"); 
+        assertEquals(strategy.createDbRelationshipName(key, true), "paintings");
+        
+        key = new ExportedKey("PERSON", "PERSON_ID", null,
+                "PERSON", "MOTHER_ID", null);
+        assertEquals(strategy.createDbRelationshipName(key, false), "mother"); 
+        assertEquals(strategy.createDbRelationshipName(key, true), "people");
+        
+        key = new ExportedKey("PERSON", "PERSON_ID", null,
+                "ADDRESS", "SHIPPING_ADDRESS", null);
+        assertEquals(strategy.createDbRelationshipName(key, false), "shippingAddress"); 
+        assertEquals(strategy.createDbRelationshipName(key, true), "addresses");
+        
+        assertEquals(strategy.createObjEntityName(new DbEntity("ARTIST")), "Artist");
+        assertEquals(strategy.createObjEntityName(new DbEntity("ARTIST_WORK")), "ArtistWork");
+        
+        assertEquals(strategy.createObjAttributeName(new DbAttribute("NAME")), "name");
+        assertEquals(strategy.createObjAttributeName(new DbAttribute("ARTIST_NAME")), "artistName");
+        
+        assertEquals(strategy.createObjRelationshipName(new DbRelationship("mother")), "mother");
+        assertEquals(strategy.createObjRelationshipName(new DbRelationship("persons")), "persons");
+    }
+}



Mime
View raw message