Author: kevin1219
Date: Wed Aug 27 07:45:57 2008
New Revision: 2619
Modified:
trunk/src/ca/sqlpower/architect/CoreProject.java
trunk/src/ca/sqlpower/architect/olap/MondrianXMLReader.java
trunk/src/ca/sqlpower/architect/olap/xml-to-parser.xsl
Log:
Fixed a bug with OLAPSessions not loading with the database set.
This was happening because we put olap loading before the rest of the
project when we added olap gui loading to the digester so the sql object
map that was passed into the Mondrian parser was empty and each
OLAPSession's database was set to null. Fixed it by passing in a new map
that keeps track of OLAPSessions and the id of the database they reference
and then return to set the OLAPSessions' database once the sql object map
was populated.
Modified: trunk/src/ca/sqlpower/architect/CoreProject.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/CoreProject.java (original)
+++ trunk/src/ca/sqlpower/architect/CoreProject.java Wed Aug 27 07:45:57
2008
@@ -49,6 +49,7 @@
import ca.sqlpower.architect.ddl.GenericDDLGenerator;
import ca.sqlpower.architect.olap.MondrianXMLReader;
import ca.sqlpower.architect.olap.OLAPObject;
+import ca.sqlpower.architect.olap.OLAPSession;
import ca.sqlpower.architect.profile.ColumnProfileResult;
import ca.sqlpower.architect.profile.ColumnValueCount;
import ca.sqlpower.architect.profile.TableProfileResult;
@@ -165,6 +166,10 @@
dbcsLoadIdMap = new HashMap<String, SPDataSource>();
sqlObjectLoadIdMap = new HashMap<String, SQLObject>();
olapObjectLoadIdMap = new HashMap<String, OLAPObject>();
+
+ // sqlObjectLoadIdMap is not ready yet when parsing the olap
objects
+ // so this keeps track of the id of the SQLDatabase that
OLAPSessions reference.
+ Map<OLAPSession, String> sessionDbMap = new
HashMap<OLAPSession, String>();
if (uin.markSupported()) {
uin.mark(Integer.MAX_VALUE);
@@ -175,7 +180,7 @@
// parse the Mondrian business model parts first because the
olap id
// map is needed in the digester for parsing the olap gui
try {
- MondrianXMLReader.parse(uin, session.getOLAPRootObject(),
sqlObjectLoadIdMap, olapObjectLoadIdMap);
+ MondrianXMLReader.parse(uin, session.getOLAPRootObject(),
sessionDbMap, olapObjectLoadIdMap);
} catch (SAXException e) {
logger.error("Error parsing project file's olap schemas!",
e);
throw new ArchitectException("SAX Exception in project
file olap schemas parse!", e);
@@ -288,6 +293,14 @@
}
}
+ }
+
+ // now that the sqlObjectLoadIdMap is populated, we can set the
+ // OLAPSessions' database.
+ for (Map.Entry<OLAPSession, String> entry :
sessionDbMap.entrySet()) {
+ OLAPSession oSession = entry.getKey();
+ SQLDatabase db = (SQLDatabase)
sqlObjectLoadIdMap.get(entry.getValue());
+ oSession.setDatabase(db);
}
setModified(false);
Modified: trunk/src/ca/sqlpower/architect/olap/MondrianXMLReader.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/olap/MondrianXMLReader.java (original)
+++ trunk/src/ca/sqlpower/architect/olap/MondrianXMLReader.java Wed Aug 27
07:45:57 2008
@@ -18,8 +18,6 @@
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
-import ca.sqlpower.architect.SQLDatabase;
-import ca.sqlpower.architect.SQLObject;
/**
* This is class is generated from xml-to-parser.xsl! Do not alter it
directly.
@@ -57,9 +55,9 @@
* @param rootObj
* The OLAPRootObject that will be populated with all the
* OLAPObjects from the file, must not be null.
- * @param dbIdMap
- * A map containing references to SQLDatabases from the
architect
- * project, must not be null.
+ * @param sessionDbMap
+ * A map that will be populated with entries of OLAPSession
to
+ * the id of the SQLDatabase that they reference, must not
be null.
* @param olapIdMap
* A map that will be populated with the OLAPObjects from
the
* file and their generated ids, must not be null.
@@ -71,8 +69,8 @@
* If the xml in the file is malformed.
*/
public static OLAPObject parse(File f, OLAPRootObject rootObj,
- Map<String, SQLObject> dbIdMap, Map<String, OLAPObject>
olapIdMap) throws IOException, SAXException {
- return parse(new FileInputStream(f), rootObj, dbIdMap, olapIdMap);
+ Map<OLAPSession, String> sessionDbMap, Map<String, OLAPObject>
olapIdMap) throws IOException, SAXException {
+ return parse(new FileInputStream(f), rootObj, sessionDbMap,
olapIdMap);
}
/**
@@ -83,9 +81,9 @@
* @param rootObj
* The OLAPRootObject that will be populated with all the
* OLAPObjects from the file, must not be null.
- * @param dbIdMap
- * A map containing references to SQLDatabases from the
architect
- * project, must not be null.
+ * @param sessionDbMap
+ * A map that will be populated with entries of OLAPSession
to
+ * the id of the SQLDatabase that they reference, must not
be null.
* @param olapIdMap
* A map that will be populated with the OLAPObjects from
the
* file and their generated ids, must not be null.
@@ -96,10 +94,10 @@
* @throws SAXException
* If the xml in the input stream is malformed.
*/
- public static OLAPObject parse(InputStream in, OLAPRootObject rootObj,
Map<String, SQLObject> dbIdMap,
+ public static OLAPObject parse(InputStream in, OLAPRootObject rootObj,
Map<OLAPSession, String> sessionDbMap,
Map<String, OLAPObject> olapIdMap) throws IOException,
SAXException {
XMLReader reader = XMLReaderFactory.createXMLReader();
- MondrianSAXHandler handler = new MondrianSAXHandler(rootObj,
dbIdMap, olapIdMap);
+ MondrianSAXHandler handler = new MondrianSAXHandler(rootObj,
sessionDbMap, olapIdMap);
reader.setContentHandler(handler);
InputSource is = new InputSource(in);
reader.parse(is);
@@ -118,17 +116,18 @@
private final boolean importMode;
- private Map<String, SQLObject> dbIdMap;
+ private Map<OLAPSession, String> sessionDbMap;
private Map<String, OLAPObject> olapIdMap;
public MondrianSAXHandler() {
this.importMode = true;
}
- public MondrianSAXHandler(OLAPRootObject rootObj, Map<String,
SQLObject> dbIdMap, Map<String, OLAPObject> olapIdMap) {
+ public MondrianSAXHandler(OLAPRootObject rootObj, Map<OLAPSession,
String> sessionDbMap, Map<String,
+ OLAPObject> olapIdMap) {
this.importMode = false;
this.root = rootObj;
- this.dbIdMap = dbIdMap;
+ this.sessionDbMap = sessionDbMap;
this.olapIdMap = olapIdMap;
}
@@ -1527,8 +1526,8 @@
OLAPSession osession = new
OLAPSession((MondrianModel.Schema) currentElement);
for (String aname :
currentOSessionAtts.keySet()) {
String aval =
currentOSessionAtts.get(aname);
- if (aname.equals("db-ref")) {
- osession.setDatabase((SQLDatabase)
dbIdMap.get(aval));
+ if (sessionDbMap != null &&
aname.equals("db-ref")) {
+ sessionDbMap.put(osession, aval);
} else if (olapIdMap != null &&
aname.equals("id")) {
olapIdMap.put(aval,
osession);
} else {
Modified: trunk/src/ca/sqlpower/architect/olap/xml-to-parser.xsl
==============================================================================
--- trunk/src/ca/sqlpower/architect/olap/xml-to-parser.xsl (original)
+++ trunk/src/ca/sqlpower/architect/olap/xml-to-parser.xsl Wed Aug 27
07:45:57 2008
@@ -34,8 +34,6 @@
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
-import ca.sqlpower.architect.SQLDatabase;
-import ca.sqlpower.architect.SQLObject;
/**
* This is class is generated from xml-to-parser.xsl! Do not alter it
directly.
@@ -73,9 +71,9 @@
* @param rootObj
* The OLAPRootObject that will be populated with all the
* OLAPObjects from the file, must not be null.
- * @param dbIdMap
- * A map containing references to SQLDatabases from the
architect
- * project, must not be null.
+ * @param sessionDbMap
+ * A map that will be populated with entries of OLAPSession
to
+ * the id of the SQLDatabase that they reference, must not
be null.
* @param olapIdMap
* A map that will be populated with the OLAPObjects from
the
* file and their generated ids, must not be null.
@@ -87,8 +85,8 @@
* If the xml in the file is malformed.
*/
public static OLAPObject parse(File f, OLAPRootObject rootObj,
- Map<String, SQLObject> dbIdMap, Map<String,
OLAPObject> olapIdMap) throws IOException, SAXException {
- return parse(new FileInputStream(f), rootObj, dbIdMap, olapIdMap);
+ Map<OLAPSession, String> sessionDbMap, Map<String,
OLAPObject> olapIdMap) throws IOException, SAXException {
+ return parse(new FileInputStream(f), rootObj, sessionDbMap,
olapIdMap);
}
/**
@@ -99,9 +97,9 @@
* @param rootObj
* The OLAPRootObject that will be populated with all the
* OLAPObjects from the file, must not be null.
- * @param dbIdMap
- * A map containing references to SQLDatabases from the
architect
- * project, must not be null.
+ * @param sessionDbMap
+ * A map that will be populated with entries of OLAPSession
to
+ * the id of the SQLDatabase that they reference, must not
be null.
* @param olapIdMap
* A map that will be populated with the OLAPObjects from
the
* file and their generated ids, must not be null.
@@ -112,10 +110,10 @@
* @throws SAXException
* If the xml in the input stream is malformed.
*/
- public static OLAPObject parse(InputStream in, OLAPRootObject rootObj,
Map<String, SQLObject> dbIdMap,
+ public static OLAPObject parse(InputStream in, OLAPRootObject rootObj,
Map<OLAPSession, String> sessionDbMap,
Map<String, OLAPObject> olapIdMap) throws IOException,
SAXException {
XMLReader reader = XMLReaderFactory.createXMLReader();
- MondrianSAXHandler handler = new MondrianSAXHandler(rootObj,
dbIdMap, olapIdMap);
+ MondrianSAXHandler handler = new MondrianSAXHandler(rootObj,
sessionDbMap, olapIdMap);
reader.setContentHandler(handler);
InputSource is = new InputSource(in);
reader.parse(is);
@@ -134,17 +132,18 @@
private final boolean importMode;
- private Map<String, SQLObject> dbIdMap;
+ private Map<OLAPSession, String> sessionDbMap;
private Map<String, OLAPObject> olapIdMap;
public MondrianSAXHandler() {
this.importMode = true;
}
- public MondrianSAXHandler(OLAPRootObject rootObj, Map<String,
SQLObject> dbIdMap, Map<String, OLAPObject> olapIdMap) {
+ public MondrianSAXHandler(OLAPRootObject rootObj,
Map<OLAPSession, String> sessionDbMap, Map<String,
+ OLAPObject> olapIdMap) {
this.importMode = false;
this.root = rootObj;
- this.dbIdMap = dbIdMap;
+ this.sessionDbMap = sessionDbMap;
this.olapIdMap = olapIdMap;
}
@@ -218,8 +217,8 @@
OLAPSession osession = new
OLAPSession((MondrianModel.Schema) currentElement);
for (String aname :
currentOSessionAtts.keySet()) {
String aval =
currentOSessionAtts.get(aname);
- if (aname.equals("db-ref")) {
- osession.setDatabase((SQLDatabase)
dbIdMap.get(aval));
+ if (sessionDbMap != null &&
aname.equals("db-ref")) {
+ sessionDbMap.put(osession, aval);
} else if (olapIdMap != null &&
aname.equals("id")) {
olapIdMap.put(aval,
osession);
} else {