diff --git a/build.properties b/build.properties index 50e874c..72af147 100644 --- a/build.properties +++ b/build.properties @@ -9,12 +9,10 @@ # Modify this file to override build settings. It is read by ant's build.xml. # See also 'test.properties', which contains settings for the regression # suite. -# -# Uncomment to use yDoc doclet for enhanced javadoc (requires commercial -# license). -#ydoc.home=/usr/local/ydoc-2.2_03-jdk1.5 project.revision=0.9.8-SNAPSHOT +project.revision.major=0 +project.revision.minor=9070232 ivy.artifact.id=olap4j ivy.artifact.group=org.olap4j impl.title=olap4j @@ -26,4 +24,10 @@ javadoc.packagenames=org.olap4j.* build.dir=build +ivy.repository.publish=http://repo.pentaho.org/artifactory + +# Uncomment to use yDoc doclet for enhanced javadoc (requires commercial +# license). +#ydoc.home=/usr/local/ydoc-3.0-jdk1.5 + # End build.properties diff --git a/build.xml b/build.xml index e83b214..0f3a4e6 100644 --- a/build.xml +++ b/build.xml @@ -132,6 +132,21 @@ test.properties.example" /> + /* + * Project version information. Generated - do not modify. + */ +package org.olap4j.driver.xmla; +/** + * Version information for the XMLA driver. (Generated.) + */ +class XmlaOlap4jDriverVersion { + static final String NAME = "olap4j driver for XML/A"; + static final String VERSION = "${project.revision}"; + static final int MAJOR_VERSION = ${project.revision.major}; + static final int MINOR_VERSION = ${project.revision.minor}; +} + +// End XmlaOlap4jDriverVersion.java diff --git a/src/org/olap4j/driver/xmla/Factory.java b/src/org/olap4j/driver/xmla/Factory.java index 2cc3e71..783f456 100644 --- a/src/org/olap4j/driver/xmla/Factory.java +++ b/src/org/olap4j/driver/xmla/Factory.java @@ -27,26 +27,72 @@ * @since Jun 14, 2007 */ interface Factory { + /** + * Creates a connection. + * + * @param driver Driver + * @param proxy Proxy (for submitting requests, via HTTP or otherwise) + * @param url URL of server + * @param info Properties defining the connection + * @return Connection + * @throws SQLException on error + */ Connection newConnection( + XmlaOlap4jDriver driver, XmlaOlap4jProxy proxy, String url, Properties info) throws SQLException; + /** + * Creates an empty result set. + * + * @param olap4jConnection Connection + * @return Result set + */ EmptyResultSet newEmptyResultSet( XmlaOlap4jConnection olap4jConnection); + /** + * Creates a result set with a fixed set of rows. + * + * @param olap4jConnection Connection + * @param headerList Column headers + * @param rowList Row values + * @return Result set + */ ResultSet newFixedResultSet( XmlaOlap4jConnection olap4jConnection, List headerList, List> rowList); + /** + * Creates a cell set. + * + * @param olap4jStatement Statement + * @return Cell set + * @throws OlapException on error + */ XmlaOlap4jCellSet newCellSet( XmlaOlap4jStatement olap4jStatement) throws OlapException; + /** + * Creates a prepared statement. + * + * @param mdx MDX query text + * @param olap4jConnection Connection + * @return Prepared statement + * @throws OlapException on error + */ XmlaOlap4jPreparedStatement newPreparedStatement( String mdx, XmlaOlap4jConnection olap4jConnection) throws OlapException; + /** + * Creates a metadata object. + * + * @param olap4jConnection Connection + * @return Metadata object + */ XmlaOlap4jDatabaseMetaData newDatabaseMetaData( XmlaOlap4jConnection olap4jConnection); } diff --git a/src/org/olap4j/driver/xmla/FactoryJdbc3Impl.java b/src/org/olap4j/driver/xmla/FactoryJdbc3Impl.java index 5c76027..a4a3164 100644 --- a/src/org/olap4j/driver/xmla/FactoryJdbc3Impl.java +++ b/src/org/olap4j/driver/xmla/FactoryJdbc3Impl.java @@ -22,14 +22,21 @@ * @since Jun 14, 2007 */ class FactoryJdbc3Impl implements Factory { + /** + * Creates a FactoryJdbc3Impl. + */ + public FactoryJdbc3Impl() { + } + public Connection newConnection( + XmlaOlap4jDriver driver, XmlaOlap4jProxy proxy, String url, Properties info) throws SQLException { return new FactoryJdbc3Impl.XmlaOlap4jConnectionJdbc3( - proxy, url, info); + driver, proxy, url, info); } public EmptyResultSet newEmptyResultSet( @@ -106,12 +113,13 @@ public EmptyResultSetJdbc3( private class XmlaOlap4jConnectionJdbc3 extends XmlaOlap4jConnection { public XmlaOlap4jConnectionJdbc3( + XmlaOlap4jDriver driver, XmlaOlap4jProxy proxy, String url, Properties info) throws SQLException { - super(FactoryJdbc3Impl.this, proxy, url, info); + super(FactoryJdbc3Impl.this, driver, proxy, url, info); } } diff --git a/src/org/olap4j/driver/xmla/FactoryJdbc4Impl.java b/src/org/olap4j/driver/xmla/FactoryJdbc4Impl.java index 163a734..de094c7 100644 --- a/src/org/olap4j/driver/xmla/FactoryJdbc4Impl.java +++ b/src/org/olap4j/driver/xmla/FactoryJdbc4Impl.java @@ -2,7 +2,7 @@ // This software is subject to the terms of the Eclipse Public License v1.0 // Agreement, available at the following URL: // http://www.eclipse.org/legal/epl-v10.html. -// Copyright (C) 2007-2008 Julian Hyde +// Copyright (C) 2007-2009 Julian Hyde // All Rights Reserved. // You must accept the terms of that agreement to use this software. */ @@ -24,14 +24,21 @@ * @since Jun 14, 2007 */ class FactoryJdbc4Impl implements Factory { + /** + * Creates a FactoryJdbc4Impl. + */ + public FactoryJdbc4Impl() { + } + public Connection newConnection( + XmlaOlap4jDriver driver, XmlaOlap4jProxy proxy, String url, Properties info) throws SQLException { return new XmlaOlap4jConnectionJdbc4( - this, proxy, url, info); + this, driver, proxy, url, info); } public EmptyResultSet newEmptyResultSet( @@ -73,6 +80,13 @@ public XmlaOlap4jDatabaseMetaData newDatabaseMetaData( // Inner classes private static class EmptyResultSetJdbc4 extends EmptyResultSet { + /** + * Creates a EmptyResultSetJdbc4. + * + * @param olap4jConnection Connection + * @param headerList Column names + * @param rowList List of row values + */ EmptyResultSetJdbc4( XmlaOlap4jConnection olap4jConnection, List headerList, @@ -330,13 +344,24 @@ private static class XmlaOlap4jConnectionJdbc4 extends XmlaOlap4jConnection implements OlapConnection { + /** + * Creates a XmlaOlap4jConnectionJdbc4. + * + * @param factory Factory + * @param driver Driver + * @param proxy Proxy + * @param url URL + * @param info Extra properties + * @throws SQLException on error + */ public XmlaOlap4jConnectionJdbc4( Factory factory, + XmlaOlap4jDriver driver, XmlaOlap4jProxy proxy, String url, Properties info) throws SQLException { - super(factory, proxy, url, info); + super(factory, driver, proxy, url, info); } public OlapStatement createStatement() { @@ -399,6 +424,12 @@ public Struct createStruct( } private static class XmlaOlap4jCellSetJdbc4 extends XmlaOlap4jCellSet { + /** + * Creates an XmlaOlap4jCellSetJdbc4. + * + * @param olap4jStatement Statement + * @throws OlapException on error + */ XmlaOlap4jCellSetJdbc4( XmlaOlap4jStatement olap4jStatement) throws OlapException @@ -645,6 +676,13 @@ public void updateNClob( private static class XmlaOlap4jPreparedStatementJdbc4 extends XmlaOlap4jPreparedStatement { + /** + * Creates a XmlaOlap4jPreparedStatementJdbc4. + * + * @param olap4jConnection Connection + * @param mdx MDX query text + * @throws OlapException on error + */ XmlaOlap4jPreparedStatementJdbc4( XmlaOlap4jConnection olap4jConnection, String mdx) throws OlapException @@ -752,6 +790,11 @@ public void setNClob( private static class XmlaOlap4jDatabaseMetaDataJdbc4 extends XmlaOlap4jDatabaseMetaData { + /** + * Creates an XmlaOlap4jDatabaseMetaDataJdbc4. + * + * @param olap4jConnection Connection + */ XmlaOlap4jDatabaseMetaDataJdbc4( XmlaOlap4jConnection olap4jConnection) { diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java index 9ee32fd..5ca3f25 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java @@ -56,6 +56,8 @@ abstract class XmlaOlap4jConnection implements OlapConnection { private static final String CONNECT_STRING_PREFIX = "jdbc:xmla:"; + final XmlaOlap4jDriver driver; + final Factory factory; final XmlaOlap4jProxy proxy; @@ -120,6 +122,7 @@ abstract class XmlaOlap4jConnection implements OlapConnection { * @pre acceptsURL(url) * * @param factory Factory + * @param driver Driver * @param proxy Proxy object which receives XML requests * @param url Connect-string URL * @param info Additional properties @@ -127,12 +130,14 @@ abstract class XmlaOlap4jConnection implements OlapConnection { */ XmlaOlap4jConnection( Factory factory, + XmlaOlap4jDriver driver, XmlaOlap4jProxy proxy, String url, Properties info) throws SQLException { this.factory = factory; + this.driver = driver; this.proxy = proxy; if (!acceptsURL(url)) { // This is not a URL we can handle. diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java b/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java index 097bee6..cc1fa71 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java @@ -219,19 +219,19 @@ public String getDatabaseProductVersion() throws SQLException { } public String getDriverName() throws SQLException { - return XmlaOlap4jDriver.NAME; + return olap4jConnection.driver.getName(); } public String getDriverVersion() throws SQLException { - return XmlaOlap4jDriver.VERSION; + return olap4jConnection.driver.getVersion(); } public int getDriverMajorVersion() { - return XmlaOlap4jDriver.MAJOR_VERSION; + return olap4jConnection.driver.getMajorVersion(); } public int getDriverMinorVersion() { - return XmlaOlap4jDriver.MINOR_VERSION; + return olap4jConnection.driver.getMinorVersion(); } public boolean usesLocalFiles() throws SQLException { diff --git a/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java b/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java index a85fd41..4a42bd8 100644 --- a/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java +++ b/src/org/olap4j/driver/xmla/XmlaOlap4jDriver.java @@ -90,10 +90,7 @@ * @since May 22, 2007 */ public class XmlaOlap4jDriver implements Driver { - public static final String NAME = "olap4j driver for XML/A"; - public static final String VERSION = "0.9.5"; - public static final int MAJOR_VERSION = 0; - public static final int MINOR_VERSION = 905; + private final Factory factory; /** @@ -141,7 +138,10 @@ protected XmlaOlap4jDriver() { } /** - * Registers this driver. + * Registers an instance of XmlaOlap4jDriver. + * + *

Called implicitly on class load, and implements the traditional + * 'Class.forName' way of registering JDBC drivers. * * @throws SQLException on error */ @@ -163,7 +163,7 @@ public Connection connect(String url, Properties info) throws SQLException { XmlaOlap4jProxy proxy = createProxy(map); // returns a connection object to the java API - return factory.newConnection(proxy, url, info); + return factory.newConnection(this, proxy, url, info); } public boolean acceptsURL(String url) throws SQLException { @@ -187,12 +187,28 @@ public DriverPropertyInfo[] getPropertyInfo( return list.toArray(new DriverPropertyInfo[list.size()]); } + /** + * Returns the driver name. Not in the JDBC API. + * @return Driver name + */ + String getName() { + return XmlaOlap4jDriverVersion.NAME; + } + + /** + * Returns the driver version. Not in the JDBC API. + * @return Driver version + */ + public String getVersion() { + return XmlaOlap4jDriverVersion.VERSION; + } + public int getMajorVersion() { - return MAJOR_VERSION; + return XmlaOlap4jDriverVersion.MAJOR_VERSION; } public int getMinorVersion() { - return MINOR_VERSION; + return XmlaOlap4jDriverVersion.MINOR_VERSION; } public boolean jdbcCompliant() { @@ -216,7 +232,7 @@ protected XmlaOlap4jProxy createProxy(Map map) { return proxy; } } - return new XmlaOlap4jHttpProxy(); + return new XmlaOlap4jHttpProxy(this); } /** diff --git a/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java b/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java index 32ab147..81acfd3 100644 --- a/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java +++ b/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java @@ -32,10 +32,15 @@ */ public class XmlaOlap4jHttpProxy extends XmlaOlap4jAbstractHttpProxy { + private final XmlaOlap4jDriver driver; + /** * Creates a XmlaOlap4jHttpProxy. + * + * @param driver Driver */ - public XmlaOlap4jHttpProxy() { + public XmlaOlap4jHttpProxy(XmlaOlap4jDriver driver) { + this.driver = driver; } @Override @@ -54,7 +59,7 @@ public byte[] getResponse(URL url, String request) urlConnection.setRequestProperty( "User-Agent", "Olap4j(" - .concat(XmlaOlap4jDriver.VERSION) + .concat(driver.getVersion()) .concat(")")); urlConnection.setRequestProperty( "Accept", diff --git a/testsrc/org/olap4j/ConnectionTest.java b/testsrc/org/olap4j/ConnectionTest.java index 1303ad8..bea96c8 100644 --- a/testsrc/org/olap4j/ConnectionTest.java +++ b/testsrc/org/olap4j/ConnectionTest.java @@ -355,6 +355,34 @@ public void testXmlaCatalogParameter() throws Exception { } } + public void testDatabaseMetaData() throws SQLException { + connection = tester.createConnection(); + final OlapConnection olapConnection = + tester.getWrapper().unwrap(connection, OlapConnection.class); + final OlapDatabaseMetaData databaseMetaData = + olapConnection.getMetaData(); + + // as per testDriver + Driver driver = DriverManager.getDriver(tester.getDriverUrlPrefix()); + assertNotNull(driver); + assertEquals( + databaseMetaData.getDriverMajorVersion(), + driver.getMajorVersion()); + assertEquals( + databaseMetaData.getDriverMinorVersion(), + driver.getMinorVersion()); + final String driverName = databaseMetaData.getDriverName(); + // typically a string like "Mondrian olap4j driver" + assertTrue( + driverName != null + && driverName.length() > 10); + final String driverVersion = databaseMetaData.getDriverVersion(); + // typically a string like "0.9" or "3.1.2" + assertTrue( + driverVersion != null + && driverName.length() > 2); + } + public void testStatement() throws SQLException { connection = tester.createConnection(); Statement statement = connection.createStatement(); diff --git a/testsrc/org/olap4j/driver/xmla/proxy/XmlaCachedProxyTest.java b/testsrc/org/olap4j/driver/xmla/proxy/XmlaCachedProxyTest.java index b981bd1..1b6ff33 100644 --- a/testsrc/org/olap4j/driver/xmla/proxy/XmlaCachedProxyTest.java +++ b/testsrc/org/olap4j/driver/xmla/proxy/XmlaCachedProxyTest.java @@ -25,6 +25,7 @@ * @version $Id$ */ public class XmlaCachedProxyTest extends TestCase { + final XmlaOlap4jDriver dummyDriver = new XmlaOlap4jDriver() {}; /** *

Tests if a simple and valid configuration can be used. @@ -32,7 +33,7 @@ public class XmlaCachedProxyTest extends TestCase { */ public void testCacheConfig() throws Exception { - XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(); + XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(dummyDriver); Map driverParameters = new HashMap(); Map cacheProperties = new HashMap(); @@ -66,7 +67,7 @@ public void testCacheConfig() throws Exception * @throws Exception If the test fails. */ public void testCacheModeError() throws Exception { - XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(); + XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(dummyDriver); Map driverParameters = new HashMap(); Map cacheProperties = new HashMap(); @@ -109,7 +110,7 @@ public void testCacheModeError() throws Exception { */ public void testCacheTimeoutError() throws Exception { - XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(); + XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(dummyDriver); Map driverParameters = new HashMap(); Map cacheProperties = new HashMap(); @@ -159,7 +160,7 @@ public void testCacheTimeoutError() throws Exception */ public void testCacheSizeError() throws Exception { - XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(); + XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(dummyDriver); Map driverParameters = new HashMap(); Map cacheProperties = new HashMap(); @@ -208,7 +209,7 @@ public void testCacheSizeError() throws Exception */ public void testCacheNameError() throws Exception { - XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(); + XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(dummyDriver); Map driverParameters = new HashMap(); Map cacheProperties = new HashMap(); @@ -253,7 +254,7 @@ public void testCacheNameError() throws Exception */ public void testCacheSharing() throws Exception { - XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(); + XmlaOlap4jCachedProxy proxy = new XmlaOlap4jHttpProxy(dummyDriver); Map driverParameters = new HashMap(); Map cacheProperties = new HashMap(); @@ -313,7 +314,7 @@ public void testCacheSharing() throws Exception // This endures that 1 - the caches are shared in a static manner // and that 2 - the cache is reused and it's // parameters are not overwritten. - proxy = new XmlaOlap4jHttpProxy(); + proxy = new XmlaOlap4jHttpProxy(dummyDriver); proxy.setCache(driverParameters, cacheProperties); } catch (Throwable e) { fail("The cache is not properly shared since an error should not have been thrown.");