cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r893147 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/ modeler/action/ modeler/dialog/db/ modeler/dialog/pref/ modeler/editor/datanode/ modeler/pref/ pref/
Date Tue, 22 Dec 2009 11:49:47 GMT
Author: oltka
Date: Tue Dec 22 11:49:21 2009
New Revision: 893147

URL: http://svn.apache.org/viewvc?rev=893147&view=rev
Log:
CAY_1327

* DBConfigInfo switched to Java preferences API

Added:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
      - copied, changed from r892753, cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
Removed:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/_DBConnectionInfo.java
Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DBWizardAction.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/pref/CayenneModelerPreferenceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceCreator.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceDuplicator.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/ComponentGeometry.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreference.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceDecorator.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/HSQLEmbeddedPreferenceEditor.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/UpgradeCayennePreference.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
Tue Dec 22 11:49:21 2009
@@ -38,6 +38,7 @@
 import org.apache.cayenne.modeler.util.CayenneDialog;
 import org.apache.cayenne.modeler.util.CayenneUserDir;
 import org.apache.cayenne.pref.CayennePreference;
+import org.apache.cayenne.pref.CayenneProjectPreferences;
 import org.apache.cayenne.pref.Domain;
 import org.apache.cayenne.pref.DomainPreference;
 import org.apache.cayenne.pref.HSQLEmbeddedPreferenceEditor;
@@ -85,11 +86,14 @@
     protected File initialProject;
     protected String name;
     protected String preferencesDB;
+    
     protected BindingFactory bindingFactory;
     protected AdapterMapping adapterMapping;
 
     protected CayenneUndoManager undoManager;
 
+    protected CayenneProjectPreferences cayenneProjectPreferences;
+    
     // This is for OS X support
     private boolean isQuittingApplication = false;
 
@@ -224,6 +228,10 @@
         return preferenceService;
     }
 
+    public CayenneProjectPreferences getCayenneProjectPreferences() {
+        return cayenneProjectPreferences;
+    }
+    
     /**
      * Returns top preferences Domain for the application.
      */
@@ -286,6 +294,7 @@
                 preferencesDB,
                 PREFERENCES_MAP_PACKAGE,
                 getName());
+        this.cayenneProjectPreferences = new CayenneProjectPreferences();
         service.stopOnShutdown();
         this.preferenceService = service;
         this.preferenceService.startService();

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
Tue Dec 22 11:49:21 2009
@@ -29,6 +29,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
+import java.util.prefs.Preferences;
 
 import javax.swing.event.EventListenerList;
 
@@ -263,6 +264,8 @@
 
     protected ApplicationProject project;
     protected Domain projectPreferences;
+    
+    protected Preferences projectControllerPreferences;
 
     protected ControllerState currentState;
     protected CircularArray controllerStateHistory;
@@ -302,6 +305,7 @@
             
             this.project = currentProject;
             this.projectPreferences = null;
+            this.projectControllerPreferences = null;
 
             if (project == null) // null project -> no files to watch
             {
@@ -352,6 +356,26 @@
 
         return projectPreferences;
     }
+    
+    public Preferences getPreferenceForProject() {
+        if (getProject() == null) {
+            throw new CayenneRuntimeException("No Project selected");
+        }
+        if (projectControllerPreferences == null) {
+            String key = getProject().isLocationUndefined() ? new String(IDUtil
+                    .pseudoUniqueByteSequence16()) : project
+                    .getMainFile()
+                    .getAbsolutePath();
+
+            projectControllerPreferences = Preferences.userNodeForPackage(Project.class);
+            
+            if(key.length()>0){
+                projectControllerPreferences = projectControllerPreferences.node(projectControllerPreferences.absolutePath()+key.replace(".xml",
""));
+            } 
+        }
+       
+        return projectControllerPreferences;
+     }
 
     /**
      * Returns top preferences Domain for the current project, throwing an exception if no

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DBWizardAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DBWizardAction.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DBWizardAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DBWizardAction.java
Tue Dec 22 11:49:21 2009
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.modeler.action;
 
 import org.apache.cayenne.access.DataNode;
@@ -57,15 +56,15 @@
     }
 
     protected String preferredDataSourceLabel(DBConnectionInfo nodeInfo) {
-        if (nodeInfo == null || nodeInfo.getDomainPreference() == null) {
+        if (nodeInfo == null) {
 
             // only driver nodes have meaningful connection info set
             DataNode node = getPreferredNode();
             return (node != null && DriverDataSourceFactory.class.getName().equals(
                     node.getDataSourceFactory())) ? "DataNode Connection Info" : null;
         }
-
-        return nodeInfo.getKey();
+        
+        return nodeInfo.getNodeName();
     }
 
     /**
@@ -87,8 +86,10 @@
         String key = (nodeDefaults != null) ? nodeDefaults.getLocalDataSource() : null;
         if (key != null) {
             DBConnectionInfo info = (DBConnectionInfo) getApplication()
-                    .getPreferenceDomain()
-                    .getDetail(key, DBConnectionInfo.class, false);
+                    .getCayenneProjectPreferences()
+                    .getDetailObject(DBConnectionInfo.class)
+                    .getObject(key);
+
             if (info != null) {
                 return info;
             }

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=893147&r1=893146&r2=893147&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
Tue Dec 22 11:49:21 2009
@@ -67,15 +67,15 @@
         this.altDataSource = altDataSource;
         this.altDataSourceKey = altDataSourceKey;
         this.connectionInfo = new DBConnectionInfo();
-
+        
         initBindings();
     }
-    
+
     /**
-     * Creates swing dialog for this wizard 
+     * Creates swing dialog for this wizard
      */
     protected DataSourceWizardView createView() {
-        return new DataSourceWizardView(this); 
+        return new DataSourceWizardView(this);
     }
 
     protected void initBindings() {
@@ -191,8 +191,10 @@
     }
 
     protected void refreshDataSources() {
-        this.dataSources = getApplication().getPreferenceDomain().getDetailsMap(
-                DBConnectionInfo.class);
+        this.dataSources = getApplication()
+                .getCayenneProjectPreferences()
+                .getDetailObject(DBConnectionInfo.class)
+                .getChildrenPreferences();
 
         // 1.2 migration fix - update data source adapter names
         Iterator it = dataSources.values().iterator();
@@ -203,6 +205,7 @@
             if (info.getDbAdapter() != null && info.getDbAdapter().startsWith(_12package))
{
                 info.setDbAdapter("org.apache.cayenne."
                         + info.getDbAdapter().substring(_12package.length()));
+
                 info.getObjectContext().commitChanges();
             }
         }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/CayenneModelerPreferenceEditor.java
Tue Dec 22 11:49:21 2009
@@ -36,7 +36,7 @@
     protected Application application;
 
     public CayenneModelerPreferenceEditor(Application application) {
-        super((HSQLEmbeddedPreferenceService) application.getPreferenceService());
+        super((HSQLEmbeddedPreferenceService) application.getPreferenceService(), application.getCayenneProjectPreferences());
         this.application = application;
     }
 
@@ -50,7 +50,7 @@
 
     public void save() {
         super.save();
-
+        
         if (isRefreshingClassLoader()) {
             application.initClassLoader();
             refreshingClassLoader = false;

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceCreator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceCreator.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceCreator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceCreator.java
Tue Dec 22 11:49:21 2009
@@ -138,10 +138,10 @@
             return null;
         }
 
-        DBConnectionInfo dataSource = (DBConnectionInfo) editor.createDetail(
-                domain,
-                getName(),
-                DBConnectionInfo.class);
+        DBConnectionInfo dataSource = (DBConnectionInfo) getApplication()
+                .getCayenneProjectPreferences()
+                .getDetailObject(DBConnectionInfo.class)
+                .create(getName());
 
         Object adapter = view.getAdapters().getSelectedItem();
         if (NO_ADAPTER.equals(adapter)) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceDuplicator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceDuplicator.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceDuplicator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourceDuplicator.java
Tue Dec 22 11:49:21 2009
@@ -129,10 +129,10 @@
         }
 
         DBConnectionInfo prototype = (DBConnectionInfo) dataSources.get(prototypeKey);
-        DBConnectionInfo dataSource = (DBConnectionInfo) editor.createDetail(
-                domain,
-                getName(),
-                DBConnectionInfo.class);
+        DBConnectionInfo dataSource = (DBConnectionInfo) getApplication()
+                .getCayenneProjectPreferences()
+                .getDetailObject(DBConnectionInfo.class)
+                .create(getName());
 
         prototype.copyTo(dataSource);
         return dataSource;

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
Tue Dec 22 11:49:21 2009
@@ -33,6 +33,7 @@
 import org.apache.cayenne.conn.DriverDataSource;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.pref.ChildrenMapPreference;
 import org.apache.cayenne.pref.Domain;
 import org.apache.cayenne.pref.PreferenceEditor;
 import org.apache.cayenne.swing.BindingBuilder;
@@ -48,6 +49,7 @@
     protected PreferenceEditor editor;
     protected String dataSourceKey;
     protected Map dataSources;
+    protected ChildrenMapPreference dataSourcePreferences;
 
     public DataSourcePreferences(PreferenceDialog parentController) {
         super(parentController);
@@ -56,7 +58,10 @@
         this.editor = parentController.getEditor();
 
         // init view data
-        this.dataSources = getDataSourceDomain().getDetailsMap(DBConnectionInfo.class);
+        this.dataSourcePreferences = getApplication()
+                .getCayenneProjectPreferences()
+                .getDetailObject(DBConnectionInfo.class);
+        this.dataSources = dataSourcePreferences.getChildrenPreferences();
 
         Object[] keys = dataSources.keySet().toArray();
         Arrays.sort(keys);
@@ -113,7 +118,7 @@
     }
 
     public DBConnectionInfo getConnectionInfo() {
-        return (DBConnectionInfo) dataSources.get(dataSourceKey);
+        return (DBConnectionInfo) dataSourcePreferences.getObject(dataSourceKey);
     }
 
     /**
@@ -125,7 +130,8 @@
         DBConnectionInfo dataSource = creatorWizard.startupAction();
 
         if (dataSource != null) {
-            dataSources.put(creatorWizard.getName(), dataSource);
+            dataSourcePreferences.create(creatorWizard.getName(), dataSource);
+            dataSources = dataSourcePreferences.getChildrenPreferences();
 
             Object[] keys = dataSources.keySet().toArray();
             Arrays.sort(keys);
@@ -146,7 +152,8 @@
             DBConnectionInfo dataSource = wizard.startupAction();
 
             if (dataSource != null) {
-                dataSources.put(wizard.getName(), dataSource);
+                dataSourcePreferences.create(wizard.getName(), dataSource);
+                dataSources = dataSourcePreferences.getChildrenPreferences();
 
                 Object[] keys = dataSources.keySet().toArray();
                 Arrays.sort(keys);
@@ -164,8 +171,9 @@
         String key = getDataSourceKey();
         if (key != null) {
             editor.deleteDetail(getDataSourceDomain(), key);
-            dataSources.remove(key);
+            dataSourcePreferences.remove(key);
 
+            dataSources = dataSourcePreferences.getChildrenPreferences();
             Object[] keys = dataSources.keySet().toArray();
             Arrays.sort(keys);
             view.getDataSources().setModel(new DefaultComboBoxModel(keys));
@@ -246,13 +254,14 @@
             StringTokenizer st = new StringTokenizer(message);
             StringBuilder sbMessage = new StringBuilder();
             int len = 0;
-            
+
             String tempString;
             while (st.hasMoreTokens()) {
                 tempString = st.nextElement().toString();
-                if(len < 110){
+                if (len < 110) {
                     len = len + tempString.length() + 1;
-                } else {
+                }
+                else {
                     sbMessage.append("\n");
                     len = 0;
                 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/JDBCDataSourceEditor.java
Tue Dec 22 11:49:21 2009
@@ -89,9 +89,10 @@
             return;
         }
 
-        DBConnectionInfo dataSource = (DBConnectionInfo) parent
-                .getApplicationPreferenceDomain()
-                .getDetail(key, DBConnectionInfo.class, false);
+        DBConnectionInfo dataSource = (DBConnectionInfo) getApplication()
+            .getCayenneProjectPreferences()
+            .getDetailObject(DBConnectionInfo.class)
+            .getObject(key);
 
         if (dataSource != null) {
             if (dataSource.copyTo(projectDS.getDataSourceInfo())) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
Tue Dec 22 11:49:21 2009
@@ -22,7 +22,6 @@
 import java.awt.Component;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -253,20 +252,20 @@
 
     protected void refreshLocalDataSources() {
         localDataSources.clear();
-
-        Collection sources = getApplication().getPreferenceDomain().getDetails(
-                DBConnectionInfo.class);
+        
+        Map sources = getApplication().getCayenneProjectPreferences().getDetailObject(
+                DBConnectionInfo.class).getChildrenPreferences();
 
         int len = sources.size();
         Object[] keys = new Object[len + 1];
 
         // a slight chance that a real datasource is called NO_LOCAL_DATA_SOURCE...
         keys[0] = NO_LOCAL_DATA_SOURCE;
-        Iterator it = sources.iterator();
-        for (int i = 1; i <= len; i++) {
-            DBConnectionInfo info = (DBConnectionInfo) it.next();
-            keys[i] = info.getKey();
-            localDataSources.put(keys[i], info);
+        
+        Iterator it = sources.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry pairs = (Map.Entry)it.next();
+            localDataSources.put(pairs.getKey(), pairs.getValue());
         }
 
         view.getLocalDataSources().setModel(new DefaultComboBoxModel(keys));

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/ComponentGeometry.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/ComponentGeometry.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/ComponentGeometry.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/ComponentGeometry.java
Tue Dec 22 11:49:21 2009
@@ -44,10 +44,10 @@
     };
     
     public Preferences getPreference() {
-        if (currentPreference == null) {
+        if (getCurrentPreference() == null) {
             setCurrentNodeForPreference(this.getClass(), GEOMETRY_PREF_KEY);
         }
-        return currentPreference;
+        return getCurrentPreference();
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DBConnectionInfo.java
Tue Dec 22 11:49:21 2009
@@ -21,6 +21,7 @@
 
 import java.sql.Driver;
 import java.sql.SQLException;
+import java.util.prefs.Preferences;
 
 import javax.sql.DataSource;
 
@@ -29,9 +30,149 @@
 import org.apache.cayenne.dba.AutoAdapter;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.modeler.ClassLoadingService;
+import org.apache.cayenne.pref.CayennePreference;
 import org.apache.cayenne.util.Util;
 
-public class DBConnectionInfo extends _DBConnectionInfo {
+public class DBConnectionInfo extends CayennePreference {
+
+    public static final String DB_ADAPTER_PROPERTY = "dbAdapter";
+    public static final String JDBC_DRIVER_PROPERTY = "jdbcDriver";
+    public static final String PASSWORD_PROPERTY = "password";
+    public static final String URL_PROPERTY = "url";
+    public static final String USER_NAME_PROPERTY = "userName";
+    private static final String DB_CONNECTION_INFO = "dbConnectionInfo";
+    
+    public static final String ID_PK_COLUMN = "id";
+
+    private String nodeName;
+
+    private String dbAdapter;
+    private String jdbcDriver;
+    private String password;
+    private String url;
+    private String userName;
+
+    private Preferences dbConnectionInfoPreferences;
+
+    public DBConnectionInfo() {
+        dbConnectionInfoPreferences = getCayennePreference().node(DB_CONNECTION_INFO);
+        setCurrentPreference(dbConnectionInfoPreferences);
+    };
+
+    public DBConnectionInfo(String nameNode, boolean initFromPreferences) {
+        this();
+        setNodeName(nameNode);
+        if (initFromPreferences) {
+            initObjectPreference();
+        }
+    };
+
+    @Override
+    public Preferences getCurrentPreference() {
+        if (getNodeName() == null) {
+            return super.getCurrentPreference();
+        }
+        return dbConnectionInfoPreferences.node(getNodeName());
+    }
+
+    @Override
+    public void setObject(CayennePreference object) {
+        if (object instanceof DBConnectionInfo) {
+            setUrl(((DBConnectionInfo) object).getUrl());
+            setUserName(((DBConnectionInfo) object).getUserName());
+            setPassword(((DBConnectionInfo) object).getPassword());
+            setJdbcDriver(((DBConnectionInfo) object).getJdbcDriver());
+            setDbAdapter(((DBConnectionInfo) object).getDbAdapter());
+        }
+    }
+
+    @Override
+    public void saveObjectPreference() {
+        if (getCurrentPreference() != null) {
+            if (getDbAdapter() != null) {
+                getCurrentPreference().put(DB_ADAPTER_PROPERTY, getDbAdapter());
+            }
+            if (getUrl() != null) {
+                getCurrentPreference().put(URL_PROPERTY, getUrl());
+            }
+            if (getUserName() != null) {
+                getCurrentPreference().put(USER_NAME_PROPERTY, getUserName());
+            }
+            if (getPassword() != null) {
+                getCurrentPreference().put(PASSWORD_PROPERTY, getPassword());
+            }
+            if (getJdbcDriver() != null) {
+                getCurrentPreference().put(JDBC_DRIVER_PROPERTY, getJdbcDriver());
+            }
+        }
+    }
+
+    public void initObjectPreference() {
+        if (getCurrentPreference() != null) {
+            setDbAdapter(getCurrentPreference().get(DB_ADAPTER_PROPERTY, null));
+            setUrl(getCurrentPreference().get(URL_PROPERTY, null));
+            setUserName(getCurrentPreference().get(USER_NAME_PROPERTY, null));
+            setPassword(getCurrentPreference().get(PASSWORD_PROPERTY, null));
+            setJdbcDriver(getCurrentPreference().get(JDBC_DRIVER_PROPERTY, null));
+            setNodeName(getCurrentPreference().name());
+        }
+    }
+
+    public String getNodeName() {
+        return nodeName;
+    }
+
+    public void setNodeName(String nodeName) {
+        this.nodeName = nodeName;
+    }
+
+    public String getDbAdapter() {
+        return dbAdapter;
+    }
+
+    public void setDbAdapter(String dbAdapter) {
+        this.dbAdapter = dbAdapter;
+    }
+
+    public String getJdbcDriver() {
+        return jdbcDriver;
+    }
+
+    public void setJdbcDriver(String jdbcDriver) {
+        this.jdbcDriver = jdbcDriver;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public Preferences getDbConnectionInfoPreferences() {
+        return dbConnectionInfoPreferences;
+    }
+
+    public void setDbConnectionInfoPreferences(Preferences dbConnectionInfoPreferences) {
+        this.dbConnectionInfoPreferences = dbConnectionInfoPreferences;
+    }
 
     /**
      * Creates a DbAdapter based on configured values.
@@ -176,4 +317,4 @@
 
         return updated;
     }
-}
+}
\ No newline at end of file

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreference.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreference.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreference.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreference.java
Tue Dec 22 11:49:21 2009
@@ -20,12 +20,24 @@
 
 import java.util.prefs.Preferences;
 
-public class CayennePreference implements Preference {
+import org.apache.cayenne.CayenneDataObject;
+
+public class CayennePreference extends CayenneDataObject implements Preference {
 
     private Preferences rootPreference;
     private Preferences cayennePreference;
 
-    protected Preferences currentPreference;
+    private Preferences currentPreference;
+
+    
+    public Preferences getCurrentPreference() {
+        return currentPreference;
+    }
+
+    
+    public void setCurrentPreference(Preferences currentPreference) {
+        this.currentPreference = currentPreference;
+    }
 
     public Preferences getRootPreference() {
         if (rootPreference == null) {
@@ -51,4 +63,10 @@
     public void setCurrentNodeForPreference(Class className, String path) {
         currentPreference = getNode(className, path);
     }
+    
+    public void setObject(CayennePreference object){
+    }
+    
+    public void saveObjectPreference() {
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceDecorator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceDecorator.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceDecorator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceDecorator.java
Tue Dec 22 11:49:21 2009
@@ -26,4 +26,5 @@
         this.decoratedPreference = decoratedPreference;
     }
 
+    
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceEditor.java
Tue Dec 22 11:49:21 2009
@@ -20,6 +20,7 @@
 package org.apache.cayenne.pref;
 
 import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 
 /**
  * An editor for modifying CayennePreferenceService.
@@ -31,14 +32,16 @@
     protected DataContext editingContext;
     protected boolean restartRequired;
     protected int saveInterval;
+    protected CayenneProjectPreferences cayenneProjectPreferences;
 
-    public CayennePreferenceEditor(CayennePreferenceService service) {
+    public CayennePreferenceEditor(CayennePreferenceService service, CayenneProjectPreferences
cayenneProjectPreferences) {
         this.service = service;
         this.editingContext = service
                 .getDataContext()
                 .getParentDataDomain()
                 .createDataContext();
         this.saveInterval = service.getSaveInterval();
+        this.cayenneProjectPreferences = cayenneProjectPreferences;
     }
 
     protected boolean isRestartRequired() {
@@ -113,6 +116,7 @@
     }
 
     public void save() {
+        cayenneProjectPreferences.getDetailObject(DBConnectionInfo.class).save();
         service.setSaveInterval(saveInterval);
         editingContext.commitChanges();
 
@@ -122,6 +126,7 @@
     }
 
     public void revert() {
+        cayenneProjectPreferences.getDetailObject(DBConnectionInfo.class).cancel();
         editingContext.rollbackChanges();
         restartRequired = false;
     }

Copied: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
(from r892753, cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java?p2=cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java&p1=cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java&r1=892753&r2=893147&rev=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
Tue Dec 22 11:49:21 2009
@@ -18,21 +18,33 @@
  ****************************************************************/
 package org.apache.cayenne.pref;
 
-import java.util.prefs.Preferences;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
+import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 
-public interface Preference {
 
-    /** Key for preferences. */
-    public static final String CAYENNE_PREFERENCE = "org/apache/cayenne";
+public class CayenneProjectPreferences {
     
-    /**  node name for editor */ 
-    public static final String EDITOR = "editor";
+    private Map<Class, Object> cayenneProjectPreferences;
     
-    /** node name for list of the last 12 opened project files. */
-    public static final String LAST_PROJ_FILES = "lastSeveralProjectFiles";
     
-    public Preferences getRootPreference();
+    public CayenneProjectPreferences() {
+        cayenneProjectPreferences = new HashMap<Class, Object>();
+        cayenneProjectPreferences.put(DBConnectionInfo.class, new ChildrenMapPreference(new
DBConnectionInfo()));
+        initPreference();
+    }
+
+    private void initPreference() {
+        Iterator it = cayenneProjectPreferences.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry pairs = (Map.Entry)it.next();
+            ((ChildrenMapPreference)cayenneProjectPreferences.get(pairs.getKey())).initChildrenPreferences();
+        }
+    }
     
-    public Preferences getCayennePreference();
+    public ChildrenMapPreference getDetailObject(Class className) {
+        return (ChildrenMapPreference) cayenneProjectPreferences.get(className);
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java?rev=893147&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
Tue Dec 22 11:49:21 2009
@@ -0,0 +1,158 @@
+/*****************************************************************
+ *   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.pref;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
+
+import org.apache.cayenne.CayenneRuntimeException;
+
+
+public class ChildrenMapPreference extends CayennePreferenceDecorator {
+
+    private Map<String, Object> childrens;
+    private List<String> removeObject;
+
+    public ChildrenMapPreference(CayennePreference decoratedPreference) {
+        super(decoratedPreference);
+        this.childrens = new HashMap<String, Object>();
+        this.removeObject = new ArrayList<String>();
+    }
+
+    public Preferences getCayennePreference() {
+        return decoratedPreference.getCayennePreference();
+    }
+
+    public Preferences getRootPreference() {
+        return decoratedPreference.getRootPreference();
+    }
+
+    public void initChildrenPreferences() {
+        Map<String, Object> children = new HashMap<String, Object>();
+        try {
+            String[] names = getCurrentPreference().childrenNames();
+            for (int i = 0; i < names.length; i++) {
+
+                try {
+                    Class cls = decoratedPreference.getClass();
+                    Class partypes[] = new Class[2];
+                    partypes[0] = String.class;
+                    partypes[1] = boolean.class;
+                    Constructor ct = cls.getConstructor(partypes);
+                    Object arglist[] = new Object[2];
+                    arglist[0] = names[i];
+                    arglist[1] = true;
+                    Object retobj = ct.newInstance(arglist);
+                    children.put(names[i], retobj);
+                }
+                catch (Throwable e) {
+                    new CayenneRuntimeException("Error initing preference");
+                }
+
+            }
+
+            this.childrens.putAll(children);
+        }
+        catch (BackingStoreException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public Map getChildrenPreferences() {
+        return childrens;
+    }
+
+    public Preferences getCurrentPreference() {
+        return decoratedPreference.getCurrentPreference();
+    }
+
+    public CayennePreference getObject(String key) {
+        return (CayennePreference) childrens.get(key);
+    }
+
+    public void remove(String key) {
+        removeObject.add(key);
+        childrens.remove(key);
+    }
+
+    public CayennePreference create(String nodeName) {
+        try {
+            Class cls = decoratedPreference.getClass();
+            Class partypes[] = new Class[2];
+            partypes[0] = String.class;
+            partypes[1] = boolean.class;
+            Constructor ct = cls.getConstructor(partypes);
+            Object arglist[] = new Object[2];
+            arglist[0] = nodeName;
+            arglist[1] = false;
+            Object retobj = ct.newInstance(arglist);
+            childrens.put(nodeName, retobj);
+        }
+        catch (Throwable e) {
+            new CayenneRuntimeException("Error creating preference");
+        }
+        return (CayennePreference) childrens.get(nodeName);
+    }
+
+    public void create(String nodeName, Object obj) {
+        childrens.put(nodeName, obj);
+    }
+
+    public void save() {
+        if (removeObject.size() > 0) {
+            for (int i = 0; i < removeObject.size(); i++) {
+                try {
+                    decoratedPreference
+                            .getCurrentPreference()
+                            .node(removeObject.get(i))
+                            .removeNode();
+                }
+                catch (BackingStoreException e) {
+                    new CayenneRuntimeException("Error saving preference");
+                }
+            }
+        }
+        
+        // наверное стоит как-то помечать
чтобы не все пересохранять
+        // как?
+        // !!!!!!!!!!!!!!!!!
+        
+        
+        Iterator it = childrens.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry pairs = (Map.Entry)it.next();
+            
+            decoratedPreference.getCurrentPreference().node((String) pairs.getKey());
+            ((CayennePreference) pairs.getValue())
+                    .saveObjectPreference();
+            
+        }
+    }
+
+    public void cancel() {
+        this.childrens.clear();
+        initChildrenPreferences();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/HSQLEmbeddedPreferenceEditor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/HSQLEmbeddedPreferenceEditor.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/HSQLEmbeddedPreferenceEditor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/HSQLEmbeddedPreferenceEditor.java
Tue Dec 22 11:49:21 2009
@@ -27,8 +27,8 @@
 
     protected Delegate delegate;
 
-    public HSQLEmbeddedPreferenceEditor(HSQLEmbeddedPreferenceService service) {
-        super(service);
+    public HSQLEmbeddedPreferenceEditor(HSQLEmbeddedPreferenceService service, CayenneProjectPreferences
cayenneProjectPreferences) {
+        super(service, cayenneProjectPreferences);
     }
 
     public Delegate getDelegate() {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
Tue Dec 22 11:49:21 2009
@@ -35,4 +35,6 @@
     public Preferences getRootPreference();
     
     public Preferences getCayennePreference();
+    
+    public Preferences getCurrentPreference();
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/UpgradeCayennePreference.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/UpgradeCayennePreference.java?rev=893147&r1=893146&r2=893147&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/UpgradeCayennePreference.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/UpgradeCayennePreference.java
Tue Dec 22 11:49:21 2009
@@ -115,4 +115,9 @@
         return decoratedPreference.getCayennePreference();
     }
 
+    public Preferences getCurrentPreference() {
+        upgrade();
+        return decoratedPreference.getCayennePreference();
+    }
+
 }



Mime
View raw message