cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r894388 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/ modeler/action/ modeler/dialog/db/ modeler/pref/ pref/
Date Tue, 29 Dec 2009 13:50:12 GMT
Author: oltka
Date: Tue Dec 29 13:50:11 2009
New Revision: 894388

URL: http://svn.apache.org/viewvc?rev=894388&view=rev
Log:
CAY-1327

* DataNodeDefaults to API

Added:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java
      - copied, changed from r894385, cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
Removed:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/_DataNodeDefaults.java
Modified:
    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/pref/DataNodeDefaults.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/CayenneProjectPreferences.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java

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=894388&r1=894387&r2=894388&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 29 13:50:11 2009
@@ -135,8 +135,9 @@
  * </p>
  */
 public class ProjectController extends CayenneController {
+
     private static final Log logObj = LogFactory.getLog(ProjectController.class);
-    
+
     /*
      * A snapshot of the current state of the project controller. This was added so that
      * we could support history of recent objects.
@@ -264,7 +265,7 @@
 
     protected ApplicationProject project;
     protected Domain projectPreferences;
-    
+
     protected Preferences projectControllerPreferences;
 
     protected ControllerState currentState;
@@ -299,10 +300,11 @@
         // watchdog extra time, adding this check
         {
             if (this.project != null) {
-                ((ModelerProjectConfiguration) 
-                        project.getConfiguration()).getGraphRegistry().unregister(this);
+                ((ModelerProjectConfiguration) project.getConfiguration())
+                        .getGraphRegistry()
+                        .unregister(this);
             }
-            
+
             this.project = currentProject;
             this.projectPreferences = null;
             this.projectControllerPreferences = null;
@@ -321,9 +323,9 @@
                 }
 
                 watchdog.reconfigure();
-                
-                addDomainListener(((ModelerProjectConfiguration) 
-                        project.getConfiguration()).getGraphRegistry());
+
+                addDomainListener(((ModelerProjectConfiguration) project
+                        .getConfiguration()).getGraphRegistry());
             }
         }
     }
@@ -356,7 +358,7 @@
 
         return projectPreferences;
     }
-    
+
     public Preferences getPreferenceForProject() {
         if (getProject() == null) {
             throw new CayenneRuntimeException("No Project selected");
@@ -368,14 +370,16 @@
                     .getAbsolutePath();
 
             projectControllerPreferences = Preferences.userNodeForPackage(Project.class);
-            
-            if(key.length()>0){
-                projectControllerPreferences = projectControllerPreferences.node(projectControllerPreferences.absolutePath()+key.replace(".xml",
""));
-            } 
+
+            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
@@ -392,6 +396,15 @@
                 .getSubdomain(dataDomain.getName());
     }
 
+    public Preferences getPreferenceForDataDomain() {
+        DataDomain dataDomain = getCurrentDataDomain();
+        if (dataDomain == null) {
+            throw new CayenneRuntimeException("No DataDomain selected");
+        }
+
+        return getPreferenceForProject().node("DataDomains").node(dataDomain.getName());
+    }
+
     /**
      * Returns preferences object for the current DataMap. If no preferences exist for the
      * current DataMap, a new Preferences object is created. If no DataMap is currently
@@ -424,10 +437,14 @@
             throw new CayenneRuntimeException("No DataNode selected");
         }
 
-        return (DataNodeDefaults) getPreferenceDomainForDataDomain().getDetail(
-                node.getName(),
-                DataNodeDefaults.class,
-                true);
+        return (DataNodeDefaults) application
+                .getCayenneProjectPreferences()
+                .getProjectDetailObject(
+                        DataNodeDefaults.class,
+                        getPreferenceForDataDomain()
+                                .node("DataNode")
+                                .node(node.getName()));
+
     }
 
     public void projectOpened() {
@@ -492,9 +509,7 @@
      * Finds a domain containing specified DataNode.
      */
     public DataDomain findDomain(DataNode node) {
-        Collection<DataDomain> domains = (getProject())
-                .getConfiguration()
-                .getDomains();
+        Collection<DataDomain> domains = (getProject()).getConfiguration().getDomains();
 
         for (DataDomain domain : domains) {
             if (domain.getNode(node.getName()) == node) {
@@ -509,9 +524,7 @@
      * Finds a domain containing specified DataMap.
      */
     public DataDomain findDomain(DataMap map) {
-        Collection<DataDomain> domains = (getProject())
-                .getConfiguration()
-                .getDomains();
+        Collection<DataDomain> domains = (getProject()).getConfiguration().getDomains();
 
         if (map == null) {
             map = getCurrentDataMap();
@@ -679,7 +692,7 @@
     public void addDomainListener(DomainListener listener) {
         listenerList.add(DomainListener.class, listener);
     }
-    
+
     public void removeDomainListener(DomainListener listener) {
         listenerList.remove(DomainListener.class, listener);
     }
@@ -699,7 +712,7 @@
     public void addDataMapListener(DataMapListener listener) {
         listenerList.add(DataMapListener.class, listener);
     }
-    
+
     public void removeDataMapListener(DataMapListener listener) {
         listenerList.remove(DataMapListener.class, listener);
     }
@@ -707,7 +720,7 @@
     public void addDbEntityListener(DbEntityListener listener) {
         listenerList.add(DbEntityListener.class, listener);
     }
-    
+
     public void removeDbEntityListener(DbEntityListener listener) {
         listenerList.remove(DbEntityListener.class, listener);
     }
@@ -715,7 +728,7 @@
     public void addObjEntityListener(ObjEntityListener listener) {
         listenerList.add(ObjEntityListener.class, listener);
     }
-    
+
     public void removeObjEntityListener(ObjEntityListener listener) {
         listenerList.remove(ObjEntityListener.class, listener);
     }
@@ -740,7 +753,7 @@
     public void addDbAttributeListener(DbAttributeListener listener) {
         listenerList.add(DbAttributeListener.class, listener);
     }
-    
+
     public void removeDbAttributeListener(DbAttributeListener listener) {
         listenerList.remove(DbAttributeListener.class, listener);
     }
@@ -752,7 +765,7 @@
     public void addObjAttributeListener(ObjAttributeListener listener) {
         listenerList.add(ObjAttributeListener.class, listener);
     }
-    
+
     public void removeObjAttributeListener(ObjAttributeListener listener) {
         listenerList.remove(ObjAttributeListener.class, listener);
     }
@@ -764,7 +777,7 @@
     public void addDbRelationshipListener(DbRelationshipListener listener) {
         listenerList.add(DbRelationshipListener.class, listener);
     }
-    
+
     public void removeDbRelationshipListener(DbRelationshipListener listener) {
         listenerList.add(DbRelationshipListener.class, listener);
     }
@@ -776,7 +789,7 @@
     public void addObjRelationshipListener(ObjRelationshipListener listener) {
         listenerList.add(ObjRelationshipListener.class, listener);
     }
-    
+
     public void removeObjRelationshipListener(ObjRelationshipListener listener) {
         listenerList.remove(ObjRelationshipListener.class, listener);
     }
@@ -1329,7 +1342,6 @@
         }
     }
 
-    
     public void fireEmbeddableDisplayEvent(EmbeddableDisplayEvent e) {
         boolean changed = e.getEmbeddable() != currentState.embeddable;
 
@@ -1355,7 +1367,7 @@
             temp.currentEmbeddableChanged(e);
         }
     }
-    
+
     public void fireQueryDisplayEvent(QueryDisplayEvent e) {
         boolean changed = e.getQuery() != currentState.query;
 
@@ -1530,7 +1542,7 @@
 
     public void fireObjAttributeDisplayEvent(AttributeDisplayEvent e) {
         boolean changed = !Arrays.equals(e.getAttributes(), currentState.objAttrs);
-        
+
         if (changed) {
             if (e.getEntity() != currentState.objEntity) {
                 clearState();
@@ -1919,8 +1931,6 @@
         return null;
     }
 
-    
-
     public void addEmbeddableAttributeListener(EmbeddableAttributeListener listener) {
         listenerList.add(EmbeddableAttributeListener.class, listener);
     }
@@ -1973,13 +1983,13 @@
             }
         }
     }
-    
+
     public ArrayList<Embeddable> getEmbeddableNamesInCurRentDataDomain() {
         DataDomain dd = getCurrentDataDomain();
         Collection<DataMap> maps = dd.getDataMaps();
         Iterator<DataMap> it = maps.iterator();
         ArrayList<Embeddable> embs = new ArrayList<Embeddable>();
-        while(it.hasNext()){
+        while (it.hasNext()) {
             embs.addAll(it.next().getEmbeddables());
         }
         return embs;

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=894388&r1=894387&r2=894388&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 29 13:50:11 2009
@@ -63,7 +63,7 @@
             return (node != null && DriverDataSourceFactory.class.getName().equals(
                     node.getDataSourceFactory())) ? "DataNode Connection Info" : null;
         }
-        
+
         return nodeInfo.getNodeName();
     }
 
@@ -79,9 +79,11 @@
         }
 
         // if node has local DS set, use it
-        DataNodeDefaults nodeDefaults = (DataNodeDefaults) getProjectController()
-                .getPreferenceDomainForDataDomain()
-                .getDetail(node.getName(), DataNodeDefaults.class, false);
+        DataNodeDefaults nodeDefaults = (DataNodeDefaults) getApplication()
+                .getCayenneProjectPreferences()
+                .getProjectDetailObject(DataNodeDefaults.class,
+                        getProjectController().getPreferenceForDataDomain().node(
+                                "DataNode").node(node.getName()));
 
         String key = (nodeDefaults != null) ? nodeDefaults.getLocalDataSource() : null;
         if (key != null) {

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=894388&r1=894387&r2=894388&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 29 13:50:11 2009
@@ -206,7 +206,7 @@
                 info.setDbAdapter("org.apache.cayenne."
                         + info.getDbAdapter().substring(_12package.length()));
 
-                info.getObjectContext().commitChanges();
+               // info.getObjectContext().commitChanges();
             }
         }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java?rev=894388&r1=894387&r2=894388&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
Tue Dec 29 13:50:11 2009
@@ -18,6 +18,25 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.pref;
 
-public class DataNodeDefaults extends _DataNodeDefaults {
+import java.util.prefs.Preferences;
 
+import org.apache.cayenne.pref.CayennePreferenceForProject;
+
+public class DataNodeDefaults extends CayennePreferenceForProject {
+
+    public DataNodeDefaults(Preferences pref) {
+        super(pref);
+    }
+
+    public static final String LOCAL_DATA_SOURCE_PROPERTY = "localDataSource";
+
+    public void setLocalDataSource(String localDataSource) {
+        if (getCurrentPreference() != null) {
+            getCurrentPreference().put(LOCAL_DATA_SOURCE_PROPERTY, localDataSource);
+        }
+    }
+
+    public String getLocalDataSource() {
+        return getCurrentPreference().get(LOCAL_DATA_SOURCE_PROPERTY, null);
+    }
 }

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=894388&r1=894387&r2=894388&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 29 13:50:11 2009
@@ -20,9 +20,7 @@
 
 import java.util.prefs.Preferences;
 
-import org.apache.cayenne.CayenneDataObject;
-
-public class CayennePreference extends CayenneDataObject implements Preference {
+public class CayennePreference implements Preference {
 
     private Preferences rootPreference;
     private Preferences cayennePreference;

Copied: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java
(from r894385, cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java?p2=cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java&p1=cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java&r1=894385&r2=894388&rev=894388&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/pref/DataNodeDefaults.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java
Tue Dec 29 13:50:11 2009
@@ -16,8 +16,13 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-package org.apache.cayenne.modeler.pref;
+package org.apache.cayenne.pref;
 
-public class DataNodeDefaults extends _DataNodeDefaults {
+import java.util.prefs.Preferences;
 
+
+public abstract class CayennePreferenceForProject extends CayennePreference {
+    public CayennePreferenceForProject(Preferences pref) {
+        setCurrentPreference(pref);
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java?rev=894388&r1=894387&r2=894388&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayenneProjectPreferences.java
Tue Dec 29 13:50:11 2009
@@ -18,33 +18,75 @@
  ****************************************************************/
 package org.apache.cayenne.pref;
 
+import java.lang.reflect.Constructor;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 
-
 public class CayenneProjectPreferences {
-    
-    private Map<Class, Object> cayenneProjectPreferences;
-    
-    
+
+    // for preferences not dependences from project
+    private Map<Class, Object> cayennePreferences;
+
+    // for preferences dependences from project
+    private HashMap<Preferences, Object> projectCayennePreferences;
+
     public CayenneProjectPreferences() {
-        cayenneProjectPreferences = new HashMap<Class, Object>();
-        cayenneProjectPreferences.put(DBConnectionInfo.class, new ChildrenMapPreference(new
DBConnectionInfo()));
+        cayennePreferences = new HashMap<Class, Object>();
+        cayennePreferences.put(DBConnectionInfo.class, new ChildrenMapPreference(
+                new DBConnectionInfo()));
+        projectCayennePreferences = new HashMap<Preferences, Object>();
         initPreference();
     }
 
     private void initPreference() {
-        Iterator it = cayenneProjectPreferences.entrySet().iterator();
+        Iterator it = cayennePreferences.entrySet().iterator();
         while (it.hasNext()) {
-            Map.Entry pairs = (Map.Entry)it.next();
-            ((ChildrenMapPreference)cayenneProjectPreferences.get(pairs.getKey())).initChildrenPreferences();
+            Map.Entry pairs = (Map.Entry) it.next();
+            ((ChildrenMapPreference) cayennePreferences.get(pairs.getKey()))
+                    .initChildrenPreferences();
         }
     }
-    
+
     public ChildrenMapPreference getDetailObject(Class className) {
-        return (ChildrenMapPreference) cayenneProjectPreferences.get(className);
+        return (ChildrenMapPreference) cayennePreferences.get(className);
+    }
+
+    public CayennePreference getProjectDetailObject(
+            Class className,
+            Preferences preference) {
+        if (projectCayennePreferences.get(preference) == null) {
+            try {
+                Class cls = className;
+                Class partypes[] = new Class[1];
+                partypes[0] = Preferences.class;
+                Constructor ct = cls.getConstructor(partypes);
+                Object arglist[] = new Object[1];
+                arglist[0] = preference;
+                Object retobj = ct.newInstance(arglist);
+                projectCayennePreferences.put(preference, retobj);
+            }
+            catch (Throwable e) {
+                new CayenneRuntimeException("Error initing preference");
+            }
+        }
+
+        return (CayennePreference) projectCayennePreferences.get(preference);
+    }
+
+    // delete property
+    public void removeProjectDetailObject(Preferences preference) {
+        try {
+            preference.removeNode();
+            projectCayennePreferences.remove(preference);
+        }
+        catch (BackingStoreException e) {
+            new CayenneRuntimeException("error delete preferences " + e);
+        }
     }
 }

Modified: 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=894388&r1=894387&r2=894388&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/ChildrenMapPreference.java
Tue Dec 29 13:50:11 2009
@@ -34,12 +34,19 @@
 
     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 ChildrenMapPreference(CayennePreference decoratedPreference, Preferences preferences)
{
+        super(decoratedPreference);
+        decoratedPreference.setCurrentPreference(preferences);
+        this.childrens = new HashMap<String, Object>();
+    }
 
     public Preferences getCayennePreference() {
         return decoratedPreference.getCayennePreference();
@@ -135,11 +142,6 @@
             }
         }
         
-        // наверное стоит как-то помечать
чтобы не все пересохранять
-        // как?
-        // !!!!!!!!!!!!!!!!!
-        
-        
         Iterator it = childrens.entrySet().iterator();
         while (it.hasNext()) {
             Map.Entry pairs = (Map.Entry)it.next();



Mime
View raw message