Revision: 3713
Author: [email protected]
Date: Mon Jul 12 14:17:47 2010
Log: Added in a way to create a context with a specified data source collection, instead of a path to a file. This is used by the project importer on the server.
http://code.google.com/p/power-architect/source/detail?r=3713

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionContextImpl.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionContextImpl.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectSessionContextImpl.java Mon Jul 12 14:17:47 2010
@@ -70,9 +70,9 @@
* will be removed from this list when they fire their sessionClosing lifecycle
      * event.
      */
-    private final Collection<ArchitectSession> sessions;
-
-    private final SPServerInfoManager serverManager;
+    private Collection<ArchitectSession> sessions;
+
+    private SPServerInfoManager serverManager;

     /**
* Creates a new session context. You will normally only need one of these
@@ -85,7 +85,7 @@
      * @throws BackingStoreException
      */
public ArchitectSessionContextImpl() throws SQLObjectException, BackingStoreException {
-        this(null);
+        this((String) null);
     }

public ArchitectSessionContextImpl(boolean checkPlDotIni) throws SQLObjectException, BackingStoreException {
@@ -102,12 +102,6 @@
      * @throws BackingStoreException
      */
public ArchitectSessionContextImpl(String PlDotIniPath, boolean checkPath) throws SQLObjectException, BackingStoreException {
-        sessions = new HashSet<ArchitectSession>();
-
-        ArchitectUtils.startup();
-
-        ArchitectUtils.configureLog4j();
-
         if (PlDotIniPath == null) {
PlDotIniPath = prefs.get(ArchitectSession.PREFS_PL_INI_PATH, null);
         }
@@ -117,6 +111,26 @@
         if (checkPath) {
setPlDotIniPath(ArchitectUtils.checkForValidPlDotIni(PlDotIniPath, "Architect"));
         }
+        init();
+    }
+
+    /**
+ * Similar to the default constructor, but we can specify a data source collection + * ourselves. (This has been created in order to support immutable dsc's for the server).
+     * @throws BackingStoreException
+     */
+ public ArchitectSessionContextImpl(DataSourceCollection<JDBCDataSource> dataSources) throws SQLObjectException, BackingStoreException {
+        plDotIni = dataSources;
+        init();
+    }
+
+    private void init() throws BackingStoreException {
+        sessions = new HashSet<ArchitectSession>();
+
+        ArchitectUtils.startup();
+
+        ArchitectUtils.configureLog4j();
+

SPServerInfo defaultSettings = new SPServerInfo("", "", 8080, DEFAULT_PATH, "", ""); serverManager = new SPServerInfoManager(getPrefs().node("servers"), new Version(
@@ -178,7 +192,7 @@
      */
     public DataSourceCollection<JDBCDataSource> getPlDotIni() {
         String path = getPlDotIniPath();
-        if (path == null) return null;
+        if (path == null && plDotIni == null) return null;

         if (plDotIni == null) {
DataSourceCollection<SPDataSource> newPlDotIni = new PlDotIni();
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionContextImpl.java Mon Jul 12 14:17:47 2010
@@ -142,6 +142,11 @@
             throws SQLObjectException, BackingStoreException {
         this(new ArchitectSessionContextImpl(plIniPath, checkPath));
     }
+
+ public ArchitectSwingSessionContextImpl(DataSourceCollection<JDBCDataSource> dsCollection)
+            throws SQLObjectException, BackingStoreException {
+        this(new ArchitectSessionContextImpl(dsCollection));
+    }

private ArchitectSwingSessionContextImpl(ArchitectSessionContextImpl delegate)
             throws SQLObjectException, BackingStoreException {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Mon Jul 12 14:17:47 2010
@@ -683,7 +683,11 @@
         // Write pl.ini data back
         try {
             if (!isEnterpriseSession())
- getDataSources().write(new File(context.getPlDotIniPath()));
+                if (context.getPlDotIniPath() != null) {
+ getDataSources().write(new File(context.getPlDotIniPath()));
+                } else {
+                    getDataSources().write();
+                }
         } catch (IOException e) {
             logger.error("Couldn't save PL.INI file!", e); //$NON-NLS-1$
         }

Reply via email to