diff --git a/build.xml b/build.xml index 056d902..0fc74f1 100644 --- a/build.xml +++ b/build.xml @@ -152,8 +152,6 @@ ${jar-jdk14.file}"/> classpathref="project.classpath" source="1.5"> - - diff --git a/src/mondrian/olap4j/EmptyResultSet.java b/src/mondrian/olap4j/EmptyResultSet.java deleted file mode 100644 index 36f0682..0000000 --- a/src/mondrian/olap4j/EmptyResultSet.java +++ /dev/null @@ -1,738 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.OlapWrapper; - -import javax.sql.rowset.RowSetMetaDataImpl; -import java.sql.*; -import java.sql.Date; -import java.math.BigDecimal; -import java.io.InputStream; -import java.io.Reader; -import java.util.*; -import java.net.URL; - -/** - * Implementation of {@link ResultSet} which returns 0 rows. - * - *

This class is used to implement {@link java.sql.DatabaseMetaData} - * methods for querying object types where those object types never have - * any instances for this particular driver.

- * - *

This class has sub-classes which implement JDBC 3.0 and JDBC 4.0 APIs; - * it is instantiated using {@link Factory#newEmptyResultSet}.

- * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -abstract class EmptyResultSet implements ResultSet, OlapWrapper { - final MondrianOlap4jConnection olap4jConnection; - private final List headerList; - private final List> rowList; - private int rowOrdinal = -1; - private final RowSetMetaDataImpl metaData = new RowSetMetaDataImpl(); - - EmptyResultSet( - MondrianOlap4jConnection olap4jConnection, - List headerList, - List> rowList) - { - this.olap4jConnection = olap4jConnection; - this.headerList = headerList; - this.rowList = rowList; - try { - metaData.setColumnCount(headerList.size()); - for (int i = 0; i < headerList.size(); i++) { - metaData.setColumnName(i + 1, headerList.get(i)); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - // helper methods - - /** - * Returns the value of a given column - * @param columnOrdinal 0-based ordinal - * @return Value - */ - private Object getColumn(int columnOrdinal) { - return rowList.get(rowOrdinal).get(columnOrdinal); - } - - private Object getColumn(String columnLabel) throws SQLException { - int column = headerList.indexOf(columnLabel); - if (column < 0) { - throw new SQLException("Column not found: " + columnLabel); - } - return rowList.get(rowOrdinal).get(column); - } - - // implement ResultSet - - public boolean next() throws SQLException { - // note that if rowOrdinal == rowList.size - 1, we move but then return - // false - if (rowOrdinal < rowList.size()) { - ++rowOrdinal; - } - return rowOrdinal < rowList.size(); - } - - public void close() throws SQLException { - } - - public boolean wasNull() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getString(int columnIndex) throws SQLException { - return String.valueOf(getColumn(columnIndex - 1)); - } - - public boolean getBoolean(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - if (o instanceof Boolean) { - return (Boolean) o; - } else if (o instanceof String) { - return Boolean.valueOf((String) o); - } else { - return !o.equals(0); - } - } - - public byte getByte(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return ((Number) o).byteValue(); - } - - public short getShort(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return ((Number) o).shortValue(); - } - - public int getInt(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return ((Number) o).intValue(); - } - - public long getLong(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return ((Number) o).longValue(); - } - - public float getFloat(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return ((Number) o).floatValue(); - } - - public double getDouble(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return ((Number) o).doubleValue(); - } - - public BigDecimal getBigDecimal( - int columnIndex, int scale) throws SQLException { - throw new UnsupportedOperationException(); - } - - public byte[] getBytes(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return (byte[]) o; - } - - public Date getDate(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return (Date) o; - } - - public Time getTime(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return (Time) o; - } - - public Timestamp getTimestamp(int columnIndex) throws SQLException { - Object o = getColumn(columnIndex - 1); - return (Timestamp) o; - } - - public InputStream getAsciiStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getBinaryStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getString(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return String.valueOf(o); - } - - public boolean getBoolean(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - if (o instanceof Boolean) { - return (Boolean) o; - } else if (o instanceof String) { - return Boolean.valueOf((String) o); - } else { - return !o.equals(0); - } - } - - public byte getByte(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return ((Number) o).byteValue(); - } - - public short getShort(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return ((Number) o).shortValue(); - } - - public int getInt(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return ((Number) o).intValue(); - } - - public long getLong(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return ((Number) o).longValue(); - } - - public float getFloat(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return ((Number) o).floatValue(); - } - - public double getDouble(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return ((Number) o).doubleValue(); - } - - public BigDecimal getBigDecimal( - String columnLabel, int scale) throws SQLException { - throw new UnsupportedOperationException(); - } - - public byte[] getBytes(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return (byte[]) o; - } - - public Date getDate(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return (Date) o; - } - - public Time getTime(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return (Time) o; - } - - public Timestamp getTimestamp(String columnLabel) throws SQLException { - Object o = getColumn(columnLabel); - return (Timestamp) o; - } - - public InputStream getAsciiStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getBinaryStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLWarning getWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void clearWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getCursorName() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSetMetaData getMetaData() throws SQLException { - return metaData; - } - - public Object getObject(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Object getObject(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int findColumn(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getCharacterStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getCharacterStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isBeforeFirst() throws SQLException { - return rowOrdinal < 0; - } - - public boolean isAfterLast() throws SQLException { - return rowOrdinal >= rowList.size(); - } - - public boolean isFirst() throws SQLException { - return rowOrdinal == 0; - } - - public boolean isLast() throws SQLException { - return rowOrdinal == rowList.size() - 1; - } - - public void beforeFirst() throws SQLException { - rowOrdinal = -1; - } - - public void afterLast() throws SQLException { - rowOrdinal = rowList.size(); - } - - public boolean first() throws SQLException { - if (rowList.size() == 0) { - return false; - } else { - rowOrdinal = 0; - return true; - } - } - - public boolean last() throws SQLException { - if (rowList.size() == 0) { - return false; - } else { - rowOrdinal = rowList.size() - 1; - return true; - } - } - - public int getRow() throws SQLException { - return rowOrdinal + 1; // 1-based - } - - public boolean absolute(int row) throws SQLException { - int newRowOrdinal = row - 1;// convert to 0-based - if (newRowOrdinal >= 0 && newRowOrdinal < rowList.size()) { - rowOrdinal = newRowOrdinal; - return true; - } else { - return false; - } - } - - public boolean relative(int rows) throws SQLException { - int newRowOrdinal = rowOrdinal + (rows - 1); - if (newRowOrdinal >= 0 && newRowOrdinal < rowList.size()) { - rowOrdinal = newRowOrdinal; - return true; - } else { - return false; - } - } - - public boolean previous() throws SQLException { - // converse of next(); note that if rowOrdinal == 0, we decrement - // but return false - if (rowOrdinal >= 0) { - --rowOrdinal; - } - return rowOrdinal >= 0; - } - - public void setFetchDirection(int direction) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getFetchDirection() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setFetchSize(int rows) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getFetchSize() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getType() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getConcurrency() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean rowUpdated() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean rowInserted() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean rowDeleted() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNull(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateByte(int columnIndex, byte x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateShort(int columnIndex, short x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateInt(int columnIndex, int x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateLong(int columnIndex, long x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateFloat(int columnIndex, float x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDouble(int columnIndex, double x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBigDecimal( - int columnIndex, BigDecimal x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateString(int columnIndex, String x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBytes(int columnIndex, byte x[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDate(int columnIndex, Date x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTime(int columnIndex, Time x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTimestamp( - int columnIndex, Timestamp x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - int columnIndex, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - int columnIndex, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - int columnIndex, Reader x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject( - int columnIndex, Object x, int scaleOrLength) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject(int columnIndex, Object x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNull(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBoolean( - String columnLabel, boolean x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateByte(String columnLabel, byte x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateShort(String columnLabel, short x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateInt(String columnLabel, int x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateLong(String columnLabel, long x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateFloat(String columnLabel, float x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDouble(String columnLabel, double x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBigDecimal( - String columnLabel, BigDecimal x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateString(String columnLabel, String x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBytes(String columnLabel, byte x[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDate(String columnLabel, Date x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTime(String columnLabel, Time x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTimestamp( - String columnLabel, Timestamp x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - String columnLabel, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - String columnLabel, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - String columnLabel, Reader reader, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject( - String columnLabel, Object x, int scaleOrLength) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject(String columnLabel, Object x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void insertRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void deleteRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void refreshRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void cancelRowUpdates() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void moveToInsertRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void moveToCurrentRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Statement getStatement() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Object getObject( - int columnIndex, Map> map) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Ref getRef(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Blob getBlob(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Clob getClob(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Array getArray(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Object getObject( - String columnLabel, Map> map) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Ref getRef(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Blob getBlob(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Clob getClob(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Array getArray(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Timestamp getTimestamp( - int columnIndex, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Timestamp getTimestamp( - String columnLabel, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public URL getURL(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public URL getURL(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRef(int columnIndex, Ref x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRef(String columnLabel, Ref x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob(int columnIndex, Blob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob(String columnLabel, Blob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob(int columnIndex, Clob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob(String columnLabel, Clob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateArray(int columnIndex, Array x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateArray(String columnLabel, Array x) throws SQLException { - throw new UnsupportedOperationException(); - } - - // implement Wrapper - - public T unwrap(Class iface) throws SQLException { - if (iface.isInstance(this)) { - return iface.cast(this); - } - throw olap4jConnection.helper.createException("cannot cast"); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return iface.isInstance(this); - } -} - -// End EmptyResultSet.java diff --git a/src/mondrian/olap4j/Factory.java b/src/mondrian/olap4j/Factory.java deleted file mode 100644 index 4f1f48f..0000000 --- a/src/mondrian/olap4j/Factory.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.olap.Query; - -import java.util.Properties; -import java.util.List; -import java.sql.*; - -/** - * Instantiates classes to implement the olap4j API against the - * Mondrian OLAP engine. - * - *

There are implementations for JDBC 3.0 (which occurs in JDK 1.5) - * and JDBC 4.0 (which occurs in JDK 1.6). - * - * @author jhyde - * @version $Id$ - * @since Jun 14, 2007 - */ -interface Factory { - Connection newConnection(String url, Properties info) throws SQLException; - - EmptyResultSet newEmptyResultSet( - MondrianOlap4jConnection olap4jConnection); - - ResultSet newFixedResultSet( - MondrianOlap4jConnection olap4jConnection, - List headerList, - List> rowList); - - MondrianOlap4jCellSet newCellSet( - MondrianOlap4jStatement olap4jStatement, - Query query); - - MondrianOlap4jPreparedStatement newPreparedStatement( - String mdx, MondrianOlap4jConnection olap4jConnection); - - MondrianOlap4jDatabaseMetaData newDatabaseMetaData( - MondrianOlap4jConnection olap4jConnection); -} - -// End Factory.java diff --git a/src/mondrian/olap4j/FactoryJdbc3Impl.java b/src/mondrian/olap4j/FactoryJdbc3Impl.java deleted file mode 100644 index 0b2f04b..0000000 --- a/src/mondrian/olap4j/FactoryJdbc3Impl.java +++ /dev/null @@ -1,125 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.olap.Query; - -import java.sql.*; -import java.util.*; - -/** - * Implementation of {@link mondrian.olap4j.Factory} for JDBC 3.0. - * - * @author jhyde - * @version $Id$ - * @since Jun 14, 2007 - */ -class FactoryJdbc3Impl implements Factory { - public Connection newConnection( - String url, - Properties info) - throws SQLException - { - return new MondrianOlap4jConnectionJdbc3(url, info); - } - - public EmptyResultSet newEmptyResultSet( - MondrianOlap4jConnection olap4jConnection) - { - List headerList = Collections.emptyList(); - List> rowList = Collections.emptyList(); - return new EmptyResultSetJdbc3( - olap4jConnection, headerList, rowList); - } - - public ResultSet newFixedResultSet( - MondrianOlap4jConnection olap4jConnection, - List headerList, - List> rowList) - { - return new EmptyResultSetJdbc3( - olap4jConnection, headerList, rowList); - } - - public MondrianOlap4jCellSet newCellSet( - MondrianOlap4jStatement olap4jStatement, - Query query) - { - return new MondrianOlap4jCellSetJdbc3(olap4jStatement, query); - } - - public MondrianOlap4jPreparedStatement newPreparedStatement( - String mdx, - MondrianOlap4jConnection olap4jConnection) - { - return new MondrianOlap4jPreparedStatementJdbc3(olap4jConnection, mdx); - } - - public MondrianOlap4jDatabaseMetaData newDatabaseMetaData( - MondrianOlap4jConnection olap4jConnection) - { - return new MondrianOlap4jDatabaseMetaDataJdbc3(olap4jConnection); - } - - // Inner classes - - private static class MondrianOlap4jPreparedStatementJdbc3 - extends MondrianOlap4jPreparedStatement - { - public MondrianOlap4jPreparedStatementJdbc3( - MondrianOlap4jConnection olap4jConnection, - String mdx) { - super(olap4jConnection, mdx); - } - } - - private static class MondrianOlap4jCellSetJdbc3 - extends MondrianOlap4jCellSet - { - public MondrianOlap4jCellSetJdbc3( - MondrianOlap4jStatement olap4jStatement, Query query) - { - super(olap4jStatement, query); - } - } - - private static class EmptyResultSetJdbc3 extends EmptyResultSet { - public EmptyResultSetJdbc3( - MondrianOlap4jConnection olap4jConnection, - List headerList, - List> rowList) - { - super(olap4jConnection, headerList, rowList); - } - } - - private class MondrianOlap4jConnectionJdbc3 - extends MondrianOlap4jConnection - { - public MondrianOlap4jConnectionJdbc3( - String url, - Properties info) throws SQLException - { - super(FactoryJdbc3Impl.this, url, info); - } - } - - private static class MondrianOlap4jDatabaseMetaDataJdbc3 - extends MondrianOlap4jDatabaseMetaData - { - public MondrianOlap4jDatabaseMetaDataJdbc3( - MondrianOlap4jConnection olap4jConnection) - { - super(olap4jConnection); - } - } -} - -// End FactoryJdbc3Impl.java diff --git a/src/mondrian/olap4j/FactoryJdbc4Impl.java b/src/mondrian/olap4j/FactoryJdbc4Impl.java deleted file mode 100644 index b081af4..0000000 --- a/src/mondrian/olap4j/FactoryJdbc4Impl.java +++ /dev/null @@ -1,801 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.OlapConnection; -import org.olap4j.OlapStatement; -import org.olap4j.CellSetMetaData; -import org.olap4j.OlapDatabaseMetaData; - -import java.sql.*; -import java.util.*; -import java.io.Reader; -import java.io.InputStream; - -import mondrian.olap.Query; - -/** - * Implementation of {@link Factory} for JDBC 4.0. - * - * @author jhyde - * @version $Id$ - * @since Jun 14, 2007 - */ -class FactoryJdbc4Impl implements Factory { - public Connection newConnection( - String url, - Properties info) - throws SQLException - { - return new MondrianOlap4jConnectionJdbc4(this, url, info); - } - - public EmptyResultSet newEmptyResultSet( - MondrianOlap4jConnection olap4jConnection) - { - List headerList = Collections.emptyList(); - List> rowList = Collections.emptyList(); - return new EmptyResultSetJdbc4( - olap4jConnection, headerList, rowList); - } - - public ResultSet newFixedResultSet( - MondrianOlap4jConnection olap4jConnection, - List headerList, - List> rowList) - { - return new EmptyResultSetJdbc4( - olap4jConnection, headerList, rowList); - } - - public MondrianOlap4jCellSet newCellSet( - MondrianOlap4jStatement olap4jStatement, - Query query) - { - return new MondrianOlap4jCellSetJdbc4(olap4jStatement, query); - } - - public MondrianOlap4jPreparedStatement newPreparedStatement( - String mdx, - MondrianOlap4jConnection olap4jConnection) - { - return new MondrianOlap4jPreparedStatementJdbc4(olap4jConnection, mdx); - } - - public MondrianOlap4jDatabaseMetaData newDatabaseMetaData( - MondrianOlap4jConnection olap4jConnection) - { - return new MondrianOlap4jDatabaseMetaDataJdbc4(olap4jConnection); - } - - // Inner classes - - private static class EmptyResultSetJdbc4 extends EmptyResultSet { - EmptyResultSetJdbc4( - MondrianOlap4jConnection olap4jConnection, - List headerList, - List> rowList) - { - super(olap4jConnection, headerList, rowList); - } - - // implement java.sql.ResultSet methods - // introduced in JDBC 4.0/JDK 1.6 - - public RowId getRowId(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public RowId getRowId(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRowId(int columnIndex, RowId x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRowId(String columnLabel, RowId x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getHoldability() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isClosed() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNString( - int columnIndex, String nString) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNString( - String columnLabel, String nString) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - String columnLabel, NClob nClob) throws SQLException { - throw new UnsupportedOperationException(); - } - - public NClob getNClob(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public NClob getNClob(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLXML getSQLXML(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLXML getSQLXML(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateSQLXML( - int columnIndex, SQLXML xmlObject) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateSQLXML( - String columnLabel, SQLXML xmlObject) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getNString(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getNString(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getNCharacterStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getNCharacterStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - int columnIndex, Reader x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - int columnIndex, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - int columnIndex, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - int columnIndex, Reader x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - String columnLabel, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - String columnLabel, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - int columnIndex, - InputStream inputStream, - long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - String columnLabel, - InputStream inputStream, - long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob( - int columnIndex, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - int columnIndex, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - int columnIndex, Reader x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - int columnIndex, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - int columnIndex, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - int columnIndex, Reader x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - String columnLabel, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - String columnLabel, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - int columnIndex, InputStream inputStream) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - String columnLabel, InputStream inputStream) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob(int columnIndex, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - int columnIndex, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - } - - private static class MondrianOlap4jConnectionJdbc4 - extends MondrianOlap4jConnection - implements OlapConnection - { - MondrianOlap4jConnectionJdbc4( - Factory factory, - String url, - Properties info) throws SQLException - { - super(factory, url, info); - } - - public OlapStatement createStatement() { - return super.createStatement(); - } - - public OlapDatabaseMetaData getMetaData() { - return super.getMetaData(); - } - - // implement java.sql.Connection methods - // introduced in JDBC 4.0/JDK 1.6 - - public Clob createClob() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Blob createBlob() throws SQLException { - throw new UnsupportedOperationException(); - } - - public NClob createNClob() throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLXML createSQLXML() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isValid(int timeout) throws SQLException { - return !isClosed(); - } - - public void setClientInfo( - String name, String value) throws SQLClientInfoException { - throw new UnsupportedOperationException(); - } - - public void setClientInfo(Properties properties) throws SQLClientInfoException { - throw new UnsupportedOperationException(); - } - - public String getClientInfo(String name) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Properties getClientInfo() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Array createArrayOf( - String typeName, Object[] elements) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Struct createStruct( - String typeName, Object[] attributes) throws SQLException { - throw new UnsupportedOperationException(); - } - } - - private static class MondrianOlap4jCellSetJdbc4 - extends MondrianOlap4jCellSet - { - public MondrianOlap4jCellSetJdbc4( - MondrianOlap4jStatement olap4jStatement, - Query query) - { - super(olap4jStatement, query); - } - - public CellSetMetaData getMetaData() { - return super.getMetaData(); - } - - // implement java.sql.CellSet methods - // introduced in JDBC 4.0/JDK 1.6 - - public RowId getRowId(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public RowId getRowId(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRowId(int columnIndex, RowId x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRowId(String columnLabel, RowId x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getHoldability() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isClosed() throws SQLException { - return closed; - } - - public void updateNString( - int columnIndex, String nString) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNString( - String columnLabel, String nString) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - String columnLabel, NClob nClob) throws SQLException { - throw new UnsupportedOperationException(); - } - - public NClob getNClob(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public NClob getNClob(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLXML getSQLXML(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLXML getSQLXML(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateSQLXML( - int columnIndex, SQLXML xmlObject) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateSQLXML( - String columnLabel, SQLXML xmlObject) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getNString(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getNString(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getNCharacterStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getNCharacterStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - int columnIndex, Reader x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - int columnIndex, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - int columnIndex, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - int columnIndex, Reader x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - String columnLabel, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - String columnLabel, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - int columnIndex, - InputStream inputStream, - long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - String columnLabel, - InputStream inputStream, - long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob( - int columnIndex, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - int columnIndex, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - String columnLabel, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - int columnIndex, Reader x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNCharacterStream( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - int columnIndex, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - int columnIndex, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - int columnIndex, Reader x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - String columnLabel, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - String columnLabel, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - int columnIndex, InputStream inputStream) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob( - String columnLabel, InputStream inputStream) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob(int columnIndex, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - int columnIndex, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNClob( - String columnLabel, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - } - - private static class MondrianOlap4jPreparedStatementJdbc4 - extends MondrianOlap4jPreparedStatement - { - public MondrianOlap4jPreparedStatementJdbc4( - MondrianOlap4jConnection olap4jConnection, - String mdx) - { - super(olap4jConnection, mdx); - } - - public CellSetMetaData getMetaData() { - return super.getMetaData(); - } - - // implement java.sql.PreparedStatement methods - // introduced in JDBC 4.0/JDK 1.6 - - public void setRowId(int parameterIndex, RowId x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNString( - int parameterIndex, String value) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNCharacterStream( - int parameterIndex, Reader value, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNClob(int parameterIndex, NClob value) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setClob( - int parameterIndex, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setBlob( - int parameterIndex, - InputStream inputStream, - long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNClob( - int parameterIndex, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setSQLXML( - int parameterIndex, SQLXML xmlObject) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setAsciiStream( - int parameterIndex, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setBinaryStream( - int parameterIndex, InputStream x, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setCharacterStream( - int parameterIndex, Reader reader, long length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setAsciiStream( - int parameterIndex, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setBinaryStream( - int parameterIndex, InputStream x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setCharacterStream( - int parameterIndex, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNCharacterStream( - int parameterIndex, Reader value) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setClob(int parameterIndex, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setBlob( - int parameterIndex, InputStream inputStream) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNClob( - int parameterIndex, Reader reader) throws SQLException { - throw new UnsupportedOperationException(); - } - } - - private static class MondrianOlap4jDatabaseMetaDataJdbc4 - extends MondrianOlap4jDatabaseMetaData - { - public MondrianOlap4jDatabaseMetaDataJdbc4( - MondrianOlap4jConnection olap4jConnection) - { - super(olap4jConnection); - } - - public OlapConnection getConnection() { - return super.getConnection(); - } - - // implement java.sql.DatabaseMetaData methods - // introduced in JDBC 4.0/JDK 1.6 - - public RowIdLifetime getRowIdLifetime() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getSchemas( - String catalog, String schemaPattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean autoCommitFailureClosesAllResultSets() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getClientInfoProperties() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getFunctions( - String catalog, - String schemaPattern, - String functionNamePattern) throws SQLException - { - throw new UnsupportedOperationException(); - } - - public ResultSet getFunctionColumns( - String catalog, - String schemaPattern, - String functionNamePattern, - String columnNamePattern) throws SQLException - { - throw new UnsupportedOperationException(); - } - } -} - -// End FactoryJdbc4Impl.java diff --git a/src/mondrian/olap4j/MondrianOlap4jCatalog.java b/src/mondrian/olap4j/MondrianOlap4jCatalog.java deleted file mode 100644 index 59db329..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jCatalog.java +++ /dev/null @@ -1,56 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.Catalog; -import org.olap4j.metadata.NamedList; -import org.olap4j.metadata.Schema; -import org.olap4j.OlapException; -import org.olap4j.OlapDatabaseMetaData; -import org.olap4j.impl.*; - -/** - * Implementation of {@link Catalog} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 23, 2007 - */ -class MondrianOlap4jCatalog implements Catalog, Named { - final MondrianOlap4jDatabaseMetaData olap4jDatabaseMetaData; - - MondrianOlap4jCatalog( - MondrianOlap4jDatabaseMetaData olap4jDatabaseMetaData) { - this.olap4jDatabaseMetaData = olap4jDatabaseMetaData; - } - - public NamedList getSchemas() throws OlapException { - // A mondrian instance contains one schema, so implicitly it contains - // one catalog - NamedList list = - new NamedListImpl(); - final mondrian.olap.Schema schema = - olap4jDatabaseMetaData.olap4jConnection.connection.getSchema(); - list.add( - olap4jDatabaseMetaData.olap4jConnection.toOlap4j(schema)); - return Olap4jUtil.cast(list); - } - - public String getName() { - return MondrianOlap4jConnection.LOCALDB_CATALOG_NAME; - } - - public OlapDatabaseMetaData getMetaData() { - return olap4jDatabaseMetaData; - } -} - -// End MondrianOlap4jCatalog.java diff --git a/src/mondrian/olap4j/MondrianOlap4jCell.java b/src/mondrian/olap4j/MondrianOlap4jCell.java deleted file mode 100644 index 18ab829..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jCell.java +++ /dev/null @@ -1,163 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.Cell; -import org.olap4j.CellSet; -import org.olap4j.OlapException; -import org.olap4j.metadata.Property; - -import javax.sql.DataSource; -import java.util.List; -import java.util.ArrayList; -import java.sql.*; -import java.lang.reflect.Proxy; - -import mondrian.util.DelegatingInvocationHandler; - -/** - * Implementation of {@link Cell} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -class MondrianOlap4jCell implements Cell { - private final int[] coordinates; - private final MondrianOlap4jCellSet olap4jCellSet; - private final mondrian.olap.Cell cell; - - MondrianOlap4jCell( - int[] coordinates, - MondrianOlap4jCellSet olap4jCellSet, - mondrian.olap.Cell cell) - { - assert coordinates != null; - assert olap4jCellSet != null; - assert cell != null; - this.coordinates = coordinates; - this.olap4jCellSet = olap4jCellSet; - this.cell = cell; - } - - public CellSet getCellSet() { - return olap4jCellSet; - } - - public int getOrdinal() { - return (Integer) cell.getPropertyValue( - mondrian.olap.Property.CELL_ORDINAL.name); - } - - public List getCoordinateList() { - ArrayList list = new ArrayList(coordinates.length); - for (int coordinate : coordinates) { - list.add(coordinate); - } - return list; - } - - public Object getPropertyValue(Property property) { - // We assume that mondrian properties have the same name as olap4j - // properties. - return cell.getPropertyValue(property.getName()); - } - - public boolean isEmpty() { - // FIXME - return cell.isNull(); - } - - public boolean isError() { - return cell.isError(); - } - - public boolean isNull() { - return cell.isNull(); - } - - public double getDoubleValue() throws OlapException { - Object o = cell.getValue(); - if (o instanceof Number) { - Number number = (Number) o; - return number.doubleValue(); - } - throw olap4jCellSet.olap4jStatement.olap4jConnection.helper - .createException(this, "not a number"); - } - - public String getErrorText() { - Object o = cell.getValue(); - if (o instanceof Throwable) { - return ((Throwable) o).getMessage(); - } else { - return null; - } - } - - public Object getValue() { - return cell.getValue(); - } - - public String getFormattedValue() { - return cell.getFormattedValue(); - } - - public ResultSet drillThrough() throws OlapException { - if (!cell.canDrillThrough()) { - return null; - } - final String sql = cell.getDrillThroughSQL(false); - final MondrianOlap4jConnection olap4jConnection = - this.olap4jCellSet.olap4jStatement.olap4jConnection; - final DataSource dataSource = - olap4jConnection.connection.getDataSource(); - try { - final Connection connection = dataSource.getConnection(); - final Statement statement = connection.createStatement(); - final ResultSet resultSet = statement.executeQuery(sql); - - // To prevent a connection leak, wrap the result set in a proxy - // which automatically closes the connection (and hence also the - // statement and result set) when the result set is closed. - // The caller still has to remember to call ResultSet.close(), of - // course. - return (ResultSet) Proxy.newProxyInstance( - null, - new Class[] {ResultSet.class}, - new MyDelegatingInvocationHandler(resultSet)); - } catch (SQLException e) { - throw olap4jConnection.helper.toOlapException(e); - } - } - - // must be public for reflection to work - public static class MyDelegatingInvocationHandler - extends DelegatingInvocationHandler - { - private final ResultSet resultSet; - - MyDelegatingInvocationHandler(ResultSet resultSet) { - this.resultSet = resultSet; - } - - protected Object getTarget() { - return resultSet; - } - - // implement ResultSet.close() - public void close() throws SQLException { - resultSet.getStatement().getConnection().close(); - } - } -} - -// End MondrianOlap4jCell.java diff --git a/src/mondrian/olap4j/MondrianOlap4jCellSet.java b/src/mondrian/olap4j/MondrianOlap4jCellSet.java deleted file mode 100644 index 0440c05..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jCellSet.java +++ /dev/null @@ -1,810 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.*; -import org.olap4j.Cell; -import org.olap4j.Position; -import mondrian.olap.*; -import mondrian.olap.Axis; - -import java.util.*; -import java.sql.*; -import java.sql.Date; -import java.math.BigDecimal; -import java.io.InputStream; -import java.io.Reader; -import java.net.URL; - -/** - * Implementation of {@link CellSet} - * for the Mondrian OLAP engine. - * - *

This class has sub-classes which implement JDBC 3.0 and JDBC 4.0 APIs; - * it is instantiated using {@link Factory#newCellSet}.

- * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -abstract class MondrianOlap4jCellSet implements CellSet { - final MondrianOlap4jStatement olap4jStatement; - final Query query; - private Result result; - protected boolean closed; - private final MondrianOlap4jCellSetMetaData metaData; - private final List axisList = - new ArrayList(); - private CellSetAxis filterAxis; - - public MondrianOlap4jCellSet( - MondrianOlap4jStatement olap4jStatement, - Query query) - { - assert olap4jStatement != null; - assert query != null; - this.olap4jStatement = olap4jStatement; - this.query = query; - this.closed = false; - if (olap4jStatement instanceof MondrianOlap4jPreparedStatement) { - this.metaData = - ((MondrianOlap4jPreparedStatement) olap4jStatement) - .cellSetMetaData; - } else { - this.metaData = - new MondrianOlap4jCellSetMetaData( - olap4jStatement, query); - } - } - - /** - * Executes a query. Not part of the olap4j API; internal to the mondrian - * driver. - * - *

This method may take some time. While it is executing, a client may - * execute {@link MondrianOlap4jStatement#cancel()}. - */ - void execute() { - query.setQueryTimeoutMillis(olap4jStatement.timeoutSeconds * 1000); - result = olap4jStatement.olap4jConnection.connection.execute(query); - - // initialize axes - mondrian.olap.Axis[] axes = result.getAxes(); - QueryAxis[] queryAxes = result.getQuery().getAxes(); - assert axes.length == queryAxes.length; - for (int i = 0; i < axes.length; i++) { - Axis axis = axes[i]; - QueryAxis queryAxis = queryAxes[i]; - axisList.add(new MondrianOlap4jCellSetAxis(this, queryAxis, axis)); - } - - // initialize filter axis - final QueryAxis queryAxis = result.getQuery().getSlicerAxis(); - final Axis axis = result.getSlicerAxis(); - if (queryAxis == null) { - filterAxis = null; - } else { - filterAxis = new MondrianOlap4jCellSetAxis(this, queryAxis, axis); - } - } - - public CellSetMetaData getMetaData() { - return metaData; - } - - public List getAxes() { - return axisList; - } - - public CellSetAxis getFilterAxis() { - return filterAxis; - } - - public Cell getCell(List coordinates) { - int[] coords = new int[coordinates.size()]; - for (int i = 0; i < coords.length; i++) { - coords[i] = coordinates.get(i); - } - return getCellInternal(coords); - } - - public Cell getCell(int ordinal) { - final int[] pos = ordinalToCoordinateArray(ordinal); - return getCellInternal(pos); - } - - private int[] ordinalToCoordinateArray(int ordinal) { - Axis[] axes = result.getAxes(); - final int[] pos = new int[axes.length]; - int modulo = 1; - for (int i = 0; i < axes.length; i++) { - int prevModulo = modulo; - modulo *= axes[i].getPositions().size(); - pos[i] = (ordinal % modulo) / prevModulo; - } - if (ordinal < 0 || ordinal >= modulo) { - throw new IndexOutOfBoundsException( - "Cell ordinal " + ordinal - + ") lies outside CellSet bounds (" - + getBoundsAsString() + ")"); - } - return pos; - } - - public Cell getCell(Position... positions) { - int[] coords = new int[positions.length]; - for (int i = 0; i < coords.length; i++) { - coords[i] = positions[i].getOrdinal(); - } - return getCellInternal(coords); - } - - private Cell getCellInternal(int[] pos) { - mondrian.olap.Cell cell; - try { - cell = result.getCell(pos); - } catch (MondrianException e) { - if (e.getMessage().indexOf("coordinates out of range") >= 0) { - throw new IndexOutOfBoundsException( - "Cell coordinates (" + getCoordsAsString(pos) - + ") fall outside CellSet bounds (" - + getCoordsAsString(pos) + ")"); - } else if (e.getMessage().indexOf("coordinates should have dimension") >= 0) { - throw new IllegalArgumentException( - "Cell coordinates should have dimension " - + axisList.size() + ")"); - } else { - throw e; - } - } - return new MondrianOlap4jCell(pos, this, cell); - } - - private String getBoundsAsString() { - StringBuilder buf = new StringBuilder(); - Axis[] axes = result.getAxes(); - for (int i = 0; i < axes.length; i++) { - if (i > 0) { - buf.append(", "); - } - buf.append(axes[i].getPositions().size()); - } - return buf.toString(); - } - - private static String getCoordsAsString(int[] pos) { - StringBuilder buf = new StringBuilder(); - for (int i = 0; i < pos.length; i++) { - int po = pos[i]; - if (i > 0) { - buf.append(", "); - } - buf.append(po); - } - return buf.toString(); - } - - public List ordinalToCoordinates(int ordinal) { - final int[] ints = ordinalToCoordinateArray(ordinal); - final List list = new ArrayList(ints.length); - for (int i : ints) { - list.add(i); - } - return list; - } - - public int coordinatesToOrdinal(List coordinates) { - List axes = getAxes(); - if (coordinates.size() != axes.size()) { - throw new IllegalArgumentException( - "Coordinates have different dimension " + coordinates.size() - + " than axes " + axes.size()); - } - int modulo = 1; - int ordinal = 0; - int k = 0; - for (CellSetAxis axis : axes) { - final Integer coordinate = coordinates.get(k++); - if (coordinate < 0 || coordinate >= axis.getPositionCount()) { - throw new IndexOutOfBoundsException( - "Coordinate " + coordinate - + " of axis " + k - + " is out of range (" - + getBoundsAsString() + ")"); - } - ordinal += coordinate * modulo; - modulo *= axis.getPositionCount(); - } - return ordinal; - } - - public boolean next() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void close() throws SQLException { - this.closed = true; - } - - public boolean wasNull() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getString(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean getBoolean(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public byte getByte(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public short getShort(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getInt(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public long getLong(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public float getFloat(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public double getDouble(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public BigDecimal getBigDecimal( - int columnIndex, int scale) throws SQLException { - throw new UnsupportedOperationException(); - } - - public byte[] getBytes(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Date getDate(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Time getTime(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Timestamp getTimestamp(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getAsciiStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getBinaryStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getString(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean getBoolean(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public byte getByte(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public short getShort(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getInt(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public long getLong(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public float getFloat(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public double getDouble(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public BigDecimal getBigDecimal( - String columnLabel, int scale) throws SQLException { - throw new UnsupportedOperationException(); - } - - public byte[] getBytes(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Date getDate(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Time getTime(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Timestamp getTimestamp(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getAsciiStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public InputStream getBinaryStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLWarning getWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void clearWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getCursorName() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Object getObject(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Object getObject(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int findColumn(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getCharacterStream(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Reader getCharacterStream(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isBeforeFirst() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isAfterLast() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isFirst() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isLast() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void beforeFirst() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void afterLast() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean first() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean last() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean absolute(int row) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean relative(int rows) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean previous() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setFetchDirection(int direction) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getFetchDirection() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setFetchSize(int rows) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getFetchSize() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getType() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getConcurrency() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean rowUpdated() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean rowInserted() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean rowDeleted() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNull(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateByte(int columnIndex, byte x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateShort(int columnIndex, short x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateInt(int columnIndex, int x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateLong(int columnIndex, long x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateFloat(int columnIndex, float x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDouble(int columnIndex, double x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBigDecimal( - int columnIndex, BigDecimal x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateString(int columnIndex, String x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBytes(int columnIndex, byte x[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDate(int columnIndex, Date x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTime(int columnIndex, Time x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTimestamp( - int columnIndex, Timestamp x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - int columnIndex, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - int columnIndex, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - int columnIndex, Reader x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject( - int columnIndex, Object x, int scaleOrLength) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject(int columnIndex, Object x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateNull(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBoolean( - String columnLabel, boolean x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateByte(String columnLabel, byte x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateShort(String columnLabel, short x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateInt(String columnLabel, int x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateLong(String columnLabel, long x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateFloat(String columnLabel, float x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDouble(String columnLabel, double x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBigDecimal( - String columnLabel, BigDecimal x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateString(String columnLabel, String x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBytes(String columnLabel, byte x[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateDate(String columnLabel, Date x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTime(String columnLabel, Time x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateTimestamp( - String columnLabel, Timestamp x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateAsciiStream( - String columnLabel, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBinaryStream( - String columnLabel, InputStream x, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateCharacterStream( - String columnLabel, Reader reader, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject( - String columnLabel, Object x, int scaleOrLength) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateObject(String columnLabel, Object x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void insertRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void deleteRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void refreshRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void cancelRowUpdates() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void moveToInsertRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void moveToCurrentRow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Statement getStatement() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Object getObject( - int columnIndex, Map> map) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Ref getRef(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Blob getBlob(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Clob getClob(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Array getArray(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Object getObject( - String columnLabel, Map> map) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Ref getRef(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Blob getBlob(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Clob getClob(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Array getArray(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Timestamp getTimestamp( - int columnIndex, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Timestamp getTimestamp( - String columnLabel, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public URL getURL(int columnIndex) throws SQLException { - throw new UnsupportedOperationException(); - } - - public URL getURL(String columnLabel) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRef(int columnIndex, Ref x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateRef(String columnLabel, Ref x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob(int columnIndex, Blob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateBlob(String columnLabel, Blob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob(int columnIndex, Clob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateClob(String columnLabel, Clob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateArray(int columnIndex, Array x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void updateArray(String columnLabel, Array x) throws SQLException { - throw new UnsupportedOperationException(); - } - - // implement Wrapper - - public T unwrap(Class iface) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - throw new UnsupportedOperationException(); - } -} - -// End MondrianOlap4jCellSet.java diff --git a/src/mondrian/olap4j/MondrianOlap4jCellSetAxis.java b/src/mondrian/olap4j/MondrianOlap4jCellSetAxis.java deleted file mode 100644 index 26844bc..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jCellSetAxis.java +++ /dev/null @@ -1,124 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.*; -import org.olap4j.metadata.*; - -import java.util.*; - -import mondrian.olap.AxisOrdinal; - -/** - * Implementation of {@link org.olap4j.CellSetAxis} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -class MondrianOlap4jCellSetAxis implements CellSetAxis { - private final MondrianOlap4jCellSet olap4jCellSet; - private final mondrian.olap.QueryAxis queryAxis; - private final mondrian.olap.Axis axis; - - MondrianOlap4jCellSetAxis( - MondrianOlap4jCellSet olap4jCellSet, - mondrian.olap.QueryAxis queryAxis, - mondrian.olap.Axis axis) - { - assert olap4jCellSet != null; - assert queryAxis != null; - assert axis != null; - this.olap4jCellSet = olap4jCellSet; - this.queryAxis = queryAxis; - this.axis = axis; - } - - public Axis getAxisOrdinal() { - switch (queryAxis.getAxisOrdinal()) { - case SLICER: - return Axis.FILTER; - default: - return Axis.valueOf(queryAxis.getAxisOrdinal().name()); - } - } - - public CellSet getCellSet() { - return olap4jCellSet; - } - - public CellSetAxisMetaData getAxisMetaData() { - final AxisOrdinal axisOrdinal = queryAxis.getAxisOrdinal(); - switch (axisOrdinal) { - case SLICER: - return olap4jCellSet.getMetaData().getFilterAxisMetaData(); - default: - return olap4jCellSet.getMetaData().getAxesMetaData().get( - axisOrdinal.logicalOrdinal()); - } - } - - public List getPositions() { - return new AbstractList() { - public Position get(final int index) { - final mondrian.olap.Position mondrianPosition = - axis.getPositions().get(index); - return new MondrianOlap4jPosition(mondrianPosition, index); - } - - public int size() { - return axis.getPositions().size(); - } - }; - } - - public int getPositionCount() { - return getPositions().size(); - } - - public ListIterator iterator() { - return getPositions().listIterator(); - } - - private class MondrianOlap4jPosition implements Position { - private final mondrian.olap.Position mondrianPosition; - private final int index; - - public MondrianOlap4jPosition( - mondrian.olap.Position mondrianPosition, int index) { - this.mondrianPosition = mondrianPosition; - this.index = index; - } - - public List getMembers() { - return new AbstractList() { - - public Member get(int index) { - final mondrian.olap.Member mondrianMember = - mondrianPosition.get(index); - return new MondrianOlap4jMember( - olap4jCellSet.olap4jStatement.olap4jConnection.olap4jSchema, - mondrianMember); - } - - public int size() { - return mondrianPosition.size(); - } - }; - } - - public int getOrdinal() { - return index; - } - } -} - -// End MondrianOlap4jCellSetAxis.java diff --git a/src/mondrian/olap4j/MondrianOlap4jCellSetAxisMetaData.java b/src/mondrian/olap4j/MondrianOlap4jCellSetAxisMetaData.java deleted file mode 100644 index dbe8ef6..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jCellSetAxisMetaData.java +++ /dev/null @@ -1,95 +0,0 @@ -/* -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.CellSetAxisMetaData; -import org.olap4j.Axis; -import org.olap4j.metadata.Hierarchy; -import org.olap4j.metadata.Property; -import mondrian.olap.*; -import mondrian.olap.type.*; - -import java.util.List; -import java.util.ArrayList; - -/** - * Implementation of {@link org.olap4j.CellSetMetaData} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ -* @since Nov 17, 2007 -*/ -class MondrianOlap4jCellSetAxisMetaData implements CellSetAxisMetaData { - private final QueryAxis queryAxis; - private final MondrianOlap4jConnection olap4jConnection; - private final List propertyList = new ArrayList(); - - MondrianOlap4jCellSetAxisMetaData( - MondrianOlap4jConnection olap4jConnection, - QueryAxis queryAxis) - { - if (queryAxis == null) { - queryAxis = new QueryAxis( - false, null, AxisOrdinal.SLICER, - QueryAxis.SubtotalVisibility.Undefined); - } - this.queryAxis = queryAxis; - this.olap4jConnection = olap4jConnection; - - // populate property list - for (Id id : queryAxis.getDimensionProperties()) { - propertyList.add( - Property.StandardMemberProperty.valueOf( - id.toStringArray()[0])); - } - } - - public Axis getAxisOrdinal() { - switch (queryAxis.getAxisOrdinal()) { - case SLICER: - return Axis.FILTER; - default: - return Axis.valueOf(queryAxis.getAxisOrdinal().name()); - } - } - - public List getHierarchies() { - final Type type; - switch (queryAxis.getAxisOrdinal()) { - case SLICER: - type = queryAxis.getSet().getType(); - break; - default: - final SetType setType = - (SetType) queryAxis.getSet().getType(); - type = setType.getElementType(); - } - List hierarchyList = - new ArrayList(); - if (type instanceof TupleType) { - final TupleType tupleType = (TupleType) type; - for (Type elementType : tupleType.elementTypes) { - hierarchyList.add( - olap4jConnection.toOlap4j( - elementType.getHierarchy())); - } - } else { - hierarchyList.add( - olap4jConnection.toOlap4j(type.getHierarchy())); - } - return hierarchyList; - } - - public List getProperties() { - return propertyList; - } -} - -// End MondrianOlap4jCellSetAxisMetaData.java diff --git a/src/mondrian/olap4j/MondrianOlap4jCellSetMetaData.java b/src/mondrian/olap4j/MondrianOlap4jCellSetMetaData.java deleted file mode 100644 index bff7cc4..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jCellSetMetaData.java +++ /dev/null @@ -1,191 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.olap.Query; -import mondrian.olap.QueryAxis; -import org.olap4j.*; -import org.olap4j.impl.ArrayNamedListImpl; -import org.olap4j.metadata.*; - -import java.sql.SQLException; - -/** - * Implementation of {@link org.olap4j.CellSetMetaData} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since Jun 13, 2007 - */ -class MondrianOlap4jCellSetMetaData implements CellSetMetaData { - private final MondrianOlap4jStatement olap4jStatement; - private final Query query; - private final NamedList axesMetaData = - new ArrayNamedListImpl() { - protected String getName(CellSetAxisMetaData axisMetaData) { - return axisMetaData.getAxisOrdinal().name(); - } - }; - private final MondrianOlap4jCellSetAxisMetaData filterAxisMetaData; - - MondrianOlap4jCellSetMetaData( - MondrianOlap4jStatement olap4jStatement, - Query query) - { - this.olap4jStatement = olap4jStatement; - this.query = query; - - final MondrianOlap4jConnection olap4jConnection = - olap4jStatement.olap4jConnection; - for (final QueryAxis queryAxis : query.getAxes()) { - axesMetaData.add( - new MondrianOlap4jCellSetAxisMetaData( - olap4jConnection, queryAxis)); - } - filterAxisMetaData = - new MondrianOlap4jCellSetAxisMetaData( - olap4jConnection, query.getSlicerAxis()); - } - - // implement CellSetMetaData - - public NamedList getCellProperties() { - final ArrayNamedListImpl list = - new ArrayNamedListImpl() { - protected String getName(Property property) { - return property.getName(); - } - }; - for (Property.StandardCellProperty property : - Property.StandardCellProperty.values()) - { - if (query.hasCellProperty(property.getName())) { - list.add(property); - } - } - return list; - } - - public Cube getCube() { - return olap4jStatement.olap4jConnection.toOlap4j(query.getCube()); - } - - public NamedList getAxesMetaData() { - return axesMetaData; - } - - public CellSetAxisMetaData getFilterAxisMetaData() { - return filterAxisMetaData; - } - - // implement ResultSetMetaData - - public int getColumnCount() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isAutoIncrement(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isCaseSensitive(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isSearchable(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isCurrency(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int isNullable(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isSigned(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getColumnDisplaySize(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getColumnLabel(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getColumnName(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getSchemaName(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getPrecision(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getScale(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getTableName(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getCatalogName(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getColumnType(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getColumnTypeName(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isReadOnly(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isWritable(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isDefinitelyWritable(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getColumnClassName(int column) throws SQLException { - throw new UnsupportedOperationException(); - } - - // implement Wrapper - - public T unwrap(Class iface) throws SQLException { - if (iface.isInstance(this)) { - return iface.cast(this); - } - throw this.olap4jStatement.olap4jConnection.helper.createException( - "does not implement '" + iface + "'"); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return iface.isInstance(this); - } - -} - -// End MondrianOlap4jCellSetMetaData.java diff --git a/src/mondrian/olap4j/MondrianOlap4jConnection.java b/src/mondrian/olap4j/MondrianOlap4jConnection.java deleted file mode 100644 index 099e2ef..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jConnection.java +++ /dev/null @@ -1,782 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.mdx.*; -import mondrian.olap.*; -import mondrian.rolap.RolapStoredMeasure; -import org.olap4j.Axis; -import org.olap4j.Cell; -import org.olap4j.*; -import org.olap4j.mdx.*; -import org.olap4j.mdx.parser.*; -import org.olap4j.mdx.parser.impl.DefaultMdxParserImpl; -import org.olap4j.metadata.*; -import org.olap4j.metadata.Schema; -import org.olap4j.type.*; -import org.olap4j.type.DimensionType; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.sql.*; -import java.util.*; - -/** - * Implementation of {@link org.olap4j.OlapConnection} - * for the Mondrian OLAP engine. - * - *

This class has sub-classes which implement JDBC 3.0 and JDBC 4.0 APIs; - * it is instantiated using {@link Factory#newConnection}.

- * - * @author jhyde - * @version $Id$ - * @since May 23, 2007 - */ -abstract class MondrianOlap4jConnection implements OlapConnection { - /** - * Handler for errors. - */ - final Helper helper = new Helper(); - - /** - * Underlying mondrian connection. Set on creation, cleared on close. - */ - mondrian.olap.Connection connection; - - /** - * Current schema. - */ - MondrianOlap4jSchema olap4jSchema; - - /** - * Map from mondrian schema objects to olap4j schemas. - */ - final Map schemaMap = - new HashMap(); - - private final MondrianOlap4jDatabaseMetaData olap4jDatabaseMetaData; - - /** - * The name of the sole catalog. - */ - static final String LOCALDB_CATALOG_NAME = "LOCALDB"; - private static final String CONNECT_STRING_PREFIX = "jdbc:mondrian:"; - - final Factory factory; - private Locale locale; - - /** - * Creates an Olap4j connection to Mondrian. - * - *

This method is intentionally package-protected. The public API - * uses the traditional JDBC {@link java.sql.DriverManager}. - * See {@link mondrian.olap4j.MondrianOlap4jDriver} for more details. - * - * @pre acceptsURL(url) - * - * @param factory Factory - * @param url Connect-string URL - * @param info Additional properties - * @throws SQLException if there is an error - */ - MondrianOlap4jConnection( - Factory factory, - String url, - Properties info) - throws SQLException - { - this.factory = factory; - if (!acceptsURL(url)) { - // This is not a URL we can handle. - // DriverManager should not have invoked us. - throw new AssertionError( - "does not start with '" + CONNECT_STRING_PREFIX + "'"); - } - String x = url.substring(CONNECT_STRING_PREFIX.length()); - Util.PropertyList list = Util.parseConnectString(x); - for (Map.Entry entry : toMap(info).entrySet()) { - list.put(entry.getKey(), entry.getValue()); - } - this.connection = - mondrian.olap.DriverManager.getConnection(list, null); - this.olap4jDatabaseMetaData = - factory.newDatabaseMetaData(this); - this.olap4jSchema = toOlap4j(connection.getSchema()); - } - - static boolean acceptsURL(String url) { - return url.startsWith(CONNECT_STRING_PREFIX); - } - - public OlapStatement createStatement() { - return new MondrianOlap4jStatement(this); - } - - public PreparedStatement prepareStatement(String sql) throws SQLException { - throw new UnsupportedOperationException(); - } - - public CallableStatement prepareCall(String sql) throws SQLException { - throw new UnsupportedOperationException(); - } - - public String nativeSQL(String sql) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setAutoCommit(boolean autoCommit) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean getAutoCommit() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void commit() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void rollback() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void close() throws SQLException { - if (connection != null) { - mondrian.olap.Connection c = connection; - connection = null; - c.close(); - } - } - - public boolean isClosed() throws SQLException { - return connection == null; - } - - public OlapDatabaseMetaData getMetaData() { - return olap4jDatabaseMetaData; - } - - public NamedList getCatalogs() { - return olap4jDatabaseMetaData.getCatalogObjects(); - } - - public void setReadOnly(boolean readOnly) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isReadOnly() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setCatalog(String catalog) throws SQLException { - if (!catalog.equals(LOCALDB_CATALOG_NAME)) { - throw new UnsupportedOperationException(); - } - } - - public String getCatalog() throws SQLException { - return LOCALDB_CATALOG_NAME; - } - - public void setTransactionIsolation(int level) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getTransactionIsolation() throws SQLException { - throw new UnsupportedOperationException(); - } - - public SQLWarning getWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void clearWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Statement createStatement( - int resultSetType, int resultSetConcurrency) throws SQLException { - throw new UnsupportedOperationException(); - } - - public PreparedStatement prepareStatement( - String sql, - int resultSetType, - int resultSetConcurrency) throws SQLException { - throw new UnsupportedOperationException(); - } - - public CallableStatement prepareCall( - String sql, - int resultSetType, - int resultSetConcurrency) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Map> getTypeMap() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setTypeMap(Map> map) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setHoldability(int holdability) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getHoldability() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Savepoint setSavepoint() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Savepoint setSavepoint(String name) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void rollback(Savepoint savepoint) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void releaseSavepoint(Savepoint savepoint) throws SQLException { - throw new UnsupportedOperationException(); - } - - public Statement createStatement( - int resultSetType, - int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - throw new UnsupportedOperationException(); - } - - public PreparedStatement prepareStatement( - String sql, - int resultSetType, - int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - throw new UnsupportedOperationException(); - } - - public CallableStatement prepareCall( - String sql, - int resultSetType, - int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - throw new UnsupportedOperationException(); - } - - public PreparedStatement prepareStatement( - String sql, int autoGeneratedKeys) throws SQLException { - throw new UnsupportedOperationException(); - } - - public PreparedStatement prepareStatement( - String sql, int columnIndexes[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public PreparedStatement prepareStatement( - String sql, String columnNames[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - // implement Wrapper - - public T unwrap(Class iface) throws SQLException { - if (iface.isInstance(this)) { - return iface.cast(this); - } else if (iface.isInstance(connection)) { - return iface.cast(connection); - } - throw helper.createException("does not implement '" + iface + "'"); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return iface.isInstance(this) || - iface.isInstance(connection); - } - - // implement OlapConnection - - public PreparedOlapStatement prepareOlapStatement( - String mdx) - throws OlapException - { - return factory.newPreparedStatement(mdx, this); - } - - public MdxParserFactory getParserFactory() { - return new MdxParserFactory() { - public MdxParser createMdxParser(OlapConnection connection) { - return new DefaultMdxParserImpl(connection); - } - - public MdxValidator createMdxValidator(OlapConnection connection) { - return new MondrianOlap4jMdxValidator(connection); - } - }; - } - - public Schema getSchema() throws OlapException { - return olap4jSchema; - } - - MondrianOlap4jCube toOlap4j(mondrian.olap.Cube cube) { - MondrianOlap4jSchema schema = toOlap4j(cube.getSchema()); - return new MondrianOlap4jCube(cube, schema); - } - - MondrianOlap4jDimension toOlap4j(mondrian.olap.Dimension dimension) { - return new MondrianOlap4jDimension( - toOlap4j(dimension.getSchema()), - dimension); - } - - synchronized MondrianOlap4jSchema toOlap4j(mondrian.olap.Schema schema) { - MondrianOlap4jSchema olap4jSchema = schemaMap.get(schema); - if (olap4jSchema == null) { - final MondrianOlap4jCatalog olap4jCatalog = - (MondrianOlap4jCatalog) getCatalogs().get(LOCALDB_CATALOG_NAME); - olap4jSchema = - new MondrianOlap4jSchema( - olap4jCatalog, - schema.getSchemaReader(), - schema); - schemaMap.put(schema, olap4jSchema); - } - return olap4jSchema; - } - - Type toOlap4j(mondrian.olap.type.Type type) { - if (type instanceof mondrian.olap.type.BooleanType) { - return new BooleanType(); - } else if (type instanceof mondrian.olap.type.CubeType) { - final mondrian.olap.Cube mondrianCube = - ((mondrian.olap.type.CubeType) type).getCube(); - return new CubeType(toOlap4j(mondrianCube)); - } else if (type instanceof mondrian.olap.type.DecimalType) { - mondrian.olap.type.DecimalType decimalType = - (mondrian.olap.type.DecimalType) type; - return new DecimalType( - decimalType.getPrecision(), - decimalType.getScale()); - } else if (type instanceof mondrian.olap.type.DimensionType) { - mondrian.olap.type.DimensionType dimensionType = - (mondrian.olap.type.DimensionType) type; - return new DimensionType( - toOlap4j(dimensionType.getDimension())); - } else if (type instanceof mondrian.olap.type.HierarchyType) { - return new BooleanType(); - } else if (type instanceof mondrian.olap.type.LevelType) { - return new BooleanType(); - } else if (type instanceof mondrian.olap.type.MemberType) { - final mondrian.olap.type.MemberType memberType = - (mondrian.olap.type.MemberType) type; - return new MemberType( - toOlap4j(memberType.getDimension()), - toOlap4j(memberType.getHierarchy()), - toOlap4j(memberType.getLevel()), - toOlap4j(memberType.getMember())); - } else if (type instanceof mondrian.olap.type.NullType) { - return new NullType(); - } else if (type instanceof mondrian.olap.type.NumericType) { - return new NumericType(); - } else if (type instanceof mondrian.olap.type.SetType) { - final mondrian.olap.type.SetType setType = - (mondrian.olap.type.SetType) type; - return new SetType(toOlap4j(setType.getElementType())); - } else if (type instanceof mondrian.olap.type.StringType) { - return new StringType(); - } else if (type instanceof mondrian.olap.type.TupleType) { - mondrian.olap.type.TupleType tupleType = - (mondrian.olap.type.TupleType) type; - final Type[] types = toOlap4j(tupleType.elementTypes); - return new TupleType(types); - } else if (type instanceof mondrian.olap.type.SymbolType) { - return new SymbolType(); - } else { - throw new UnsupportedOperationException(); - } - } - - MondrianOlap4jMember toOlap4j(mondrian.olap.Member member) { - if (member == null) { - return null; - } - if (member instanceof RolapStoredMeasure) { - RolapStoredMeasure measure = (RolapStoredMeasure) member; - return new MondrianOlap4jMeasure( - toOlap4j(member.getDimension().getSchema()), - measure); - } - return new MondrianOlap4jMember( - toOlap4j(member.getDimension().getSchema()), - member); - } - - - - MondrianOlap4jLevel toOlap4j(mondrian.olap.Level level) { - if (level == null) { - return null; - } - return new MondrianOlap4jLevel( - toOlap4j(level.getDimension().getSchema()), - level); - } - - MondrianOlap4jHierarchy toOlap4j(mondrian.olap.Hierarchy hierarchy) { - if (hierarchy == null) { - return null; - } - return new MondrianOlap4jHierarchy( - toOlap4j(hierarchy.getDimension().getSchema()), - hierarchy); - } - - Type[] toOlap4j(mondrian.olap.type.Type[] mondrianTypes) { - final Type[] types = new Type[mondrianTypes.length]; - for (int i = 0; i < types.length; i++) { - types[i] = toOlap4j(mondrianTypes[i]); - } - return types; - } - - /** - * Converts a Properties object to a Map with String keys and values. - * - * @param properties Properties - * @return Map backed by the given Properties object - */ - public static Map toMap(final Properties properties) { - return new AbstractMap() { - public Set> entrySet() { - return (Set) properties.entrySet(); - } - }; - } - - MondrianOlap4jNamedSet toOlap4j( - mondrian.olap.Cube cube, - mondrian.olap.NamedSet namedSet) - { - if (namedSet == null) { - return null; - } - return new MondrianOlap4jNamedSet( - toOlap4j(cube), - namedSet); - } - - ParseTreeNode toOlap4j(Exp exp) { - return new MondrianToOlap4jNodeConverter(this).toOlap4j(exp); - } - - SelectNode toOlap4j(Query query) { - return new MondrianToOlap4jNodeConverter(this).toOlap4j(query); - } - - public void setLocale(Locale locale) { - if (locale == null) { - throw new IllegalArgumentException("locale must not be null"); - } - this.locale = locale; - } - - public Locale getLocale() { - if (locale == null) { - return Locale.getDefault(); - } - return locale; - } - - // inner classes - - /** - * Package-private helper class which encapsulates policies which are - * common throughout the driver. These policies include exception handling - * and factory methods. - */ - static class Helper { - OlapException createException(String msg) { - return new OlapException(msg); - } - - /** - * Creates an exception in the context of a particular Cell. - * - * @param context Cell context for exception - * @param msg Message - * @return New exception - */ - OlapException createException(Cell context, String msg) { - OlapException exception = new OlapException(msg); - exception.setContext(context); - return exception; - } - - /** - * Creates an exception in the context of a particular Cell and with - * a given cause. - * - * @param context Cell context for exception - * @param msg Message - * @param cause Causing exception - * @return New exception - */ - OlapException createException( - Cell context, String msg, Throwable cause) - { - OlapException exception = new OlapException(msg, cause); - exception.setContext(context); - return exception; - } - - /** - * Creates an exception with a given cause. - * - * @param msg Message - * @param cause Causing exception - * @return New exception - */ - OlapException createException( - String msg, Throwable cause) - { - return new OlapException(msg, cause); - } - - /** - * Converts a SQLException to an OlapException. Casts the exception - * if it is already an OlapException, wraps otherwise. - * - *

This method is typically used as an adapter for SQLException - * instances coming from a base class, where derived interface declares - * that it throws the more specific OlapException. - * - * @param e Exception - * @return Exception as an OlapException - */ - public OlapException toOlapException(SQLException e) { - if (e instanceof OlapException) { - return (OlapException) e; - } else { - return new OlapException(null, e); - } - } - } - - private static class MondrianOlap4jMdxValidator implements MdxValidator { - private final OlapConnection connection; - - public MondrianOlap4jMdxValidator(OlapConnection connection) { - this.connection = connection; - } - - public SelectNode validateSelect(SelectNode selectNode) throws OlapException { - StringWriter sw = new StringWriter(); - selectNode.unparse(new ParseTreeWriter(new PrintWriter(sw))); - String mdx = sw.toString(); - final MondrianOlap4jConnection olap4jConnection = - (MondrianOlap4jConnection) connection; - Query query = - olap4jConnection.connection - .parseQuery(mdx); - query.resolve(); - return olap4jConnection.toOlap4j(query); - } - } - - static Axis toOlap4j(String axisName) { - if (axisName.equals("SLICER")) { - axisName = "FILTER"; - } - return Axis.valueOf(axisName); - } - - private static class MondrianToOlap4jNodeConverter { - private final MondrianOlap4jConnection olap4jConnection; - - MondrianToOlap4jNodeConverter( - MondrianOlap4jConnection olap4jConnection) - { - this.olap4jConnection = olap4jConnection; - } - - public SelectNode toOlap4j(Query query) { - List list = Collections.emptyList(); - return new SelectNode( - null, - toOlap4j(query.getFormulas()), - toOlap4j(query.getAxes()), - new CubeNode( - null, - olap4jConnection.toOlap4j(query.getCube())), - query.getSlicerAxis() == null - ? null - : toOlap4j(query.getSlicerAxis()), - list); - } - - private AxisNode toOlap4j(QueryAxis axis) { - return new AxisNode( - null, - axis.isNonEmpty(), - toOlap4j(axis.getSet()), - MondrianOlap4jConnection.toOlap4j(axis.getAxisName()), - toOlap4j(axis.getDimensionProperties())); - } - - private List toOlap4j(Id[] dimensionProperties) { - final List list = new ArrayList(); - for (Id property : dimensionProperties) { - list.add(toOlap4j(property)); - } - return list; - } - - private ParseTreeNode toOlap4j(Exp exp) { - if (exp instanceof Id) { - Id id = (Id) exp; - return toOlap4j(id); - } - if (exp instanceof ResolvedFunCall) { - ResolvedFunCall call = (ResolvedFunCall) exp; - return toOlap4j(call); - } - if (exp instanceof DimensionExpr) { - DimensionExpr dimensionExpr = (DimensionExpr) exp; - return new DimensionNode( - null, - olap4jConnection.toOlap4j(dimensionExpr.getDimension())); - } - if (exp instanceof HierarchyExpr) { - HierarchyExpr hierarchyExpr = (HierarchyExpr) exp; - return new HierarchyNode( - null, - olap4jConnection.toOlap4j(hierarchyExpr.getHierarchy())); - } - if (exp instanceof LevelExpr) { - LevelExpr levelExpr = (LevelExpr) exp; - return new LevelNode( - null, - olap4jConnection.toOlap4j(levelExpr.getLevel())); - } - if (exp instanceof MemberExpr) { - MemberExpr memberExpr = (MemberExpr) exp; - return new MemberNode( - null, - olap4jConnection.toOlap4j(memberExpr.getMember())); - } - if (exp instanceof Literal) { - Literal literal = (Literal) exp; - final Object value = literal.getValue(); - if (literal.getCategory() == Category.Symbol) { - return LiteralNode.createSymbol( - null, (String) literal.getValue()); - } else if (value instanceof Double) { - return LiteralNode.create(null, (Double) value); - } else if (value instanceof Integer) { - return LiteralNode.create(null, (Integer) value); - } else if (value instanceof String) { - return LiteralNode.createString(null, (String) value); - } else if (value == null) { - return LiteralNode.createNull(null); - } else { - throw new RuntimeException("unknown literal " + literal); - } - } - throw Util.needToImplement(exp.getClass()); - } - - private ParseTreeNode toOlap4j(ResolvedFunCall call) { - final CallNode callNode = new CallNode( - null, - call.getFunName(), - toOlap4j(call.getSyntax()), - toOlap4j(Arrays.asList(call.getArgs()))); - if (call.getType() != null) { - callNode.setType(olap4jConnection.toOlap4j(call.getType())); - } - return callNode; - } - - private List toOlap4j(List exprList) { - final List result = new ArrayList(); - for (Exp expr : exprList) { - result.add(toOlap4j(expr)); - } - return result; - } - - private org.olap4j.mdx.Syntax toOlap4j(mondrian.olap.Syntax syntax) { - return org.olap4j.mdx.Syntax.valueOf(syntax.name()); - } - - private List toOlap4j(QueryAxis[] axes) { - final ArrayList axisList = new ArrayList(); - for (QueryAxis axis : axes) { - axisList.add(toOlap4j(axis)); - } - return axisList; - } - - private List toOlap4j(Formula[] formulas) { - final List list = new ArrayList(); - for (Formula formula : formulas) { - if (formula.isMember()) { - List memberPropertyList = - new ArrayList(); - for (Object child : formula.getChildren()) { - if (child instanceof MemberProperty) { - MemberProperty memberProperty = - (MemberProperty) child; - memberPropertyList.add( - new PropertyValueNode( - null, - memberProperty.getName(), - toOlap4j(memberProperty.getExp()))); - } - } - list.add( - new WithMemberNode( - null, - toOlap4j(formula.getIdentifier()), - toOlap4j(formula.getExpression()), - memberPropertyList)); - } - } - return list; - } - - private IdentifierNode toOlap4j(Id id) { - List list = - new ArrayList(); - for (Id.Segment segment : id.getSegments()) { - list.add( - new IdentifierNode.Segment( - null, - segment.name, - toOlap4j(segment.quoting))); - } - return new IdentifierNode( - list.toArray( - new IdentifierNode.Segment[list.size()])); - } - - private IdentifierNode.Quoting toOlap4j(Id.Quoting quoting) { - return IdentifierNode.Quoting.valueOf(quoting.name()); - } - } -} - -// End MondrianOlap4jConnection.java diff --git a/src/mondrian/olap4j/MondrianOlap4jCube.java b/src/mondrian/olap4j/MondrianOlap4jCube.java deleted file mode 100644 index 3767baa..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jCube.java +++ /dev/null @@ -1,228 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.*; -import org.olap4j.OlapException; -import org.olap4j.impl.*; - -import java.util.*; - -/** - * Implementation of {@link Cube} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -class MondrianOlap4jCube implements Cube, Named { - private final mondrian.olap.Cube cube; - final MondrianOlap4jSchema olap4jSchema; - - MondrianOlap4jCube( - mondrian.olap.Cube cube, - MondrianOlap4jSchema olap4jSchema) - { - this.cube = cube; - this.olap4jSchema = olap4jSchema; - } - - public Schema getSchema() { - return olap4jSchema; - } - - public int hashCode() { - return olap4jSchema.hashCode() - ^ cube.hashCode(); - } - - public boolean equals(Object obj) { - if (obj instanceof MondrianOlap4jCube) { - MondrianOlap4jCube that = (MondrianOlap4jCube) obj; - return this.olap4jSchema == that.olap4jSchema - && this.cube.equals(that.cube); - } - return false; - } - - public NamedList getDimensions() { - NamedList list = - new NamedListImpl(); - for (mondrian.olap.Dimension dimension : cube.getDimensions()) { - list.add( - new MondrianOlap4jDimension( - olap4jSchema, dimension)); - } - return Olap4jUtil.cast(list); - } - - public NamedList getHierarchies() { - NamedList list = - new NamedListImpl(); - for (mondrian.olap.Dimension dimension : cube.getDimensions()) { - for (mondrian.olap.Hierarchy hierarchy : dimension.getHierarchies()) { - list.add( - new MondrianOlap4jHierarchy( - olap4jSchema, hierarchy)); - } - } - return Olap4jUtil.cast(list); - } - - public List getMeasures() { - final MondrianOlap4jLevel measuresLevel = - (MondrianOlap4jLevel) - getDimensions().get("Measures").getDefaultHierarchy() - .getLevels().get(0); - return Olap4jUtil.cast(measuresLevel.getMembers()); - } - - public NamedList getSets() { - final NamedListImpl list = - new NamedListImpl(); - final MondrianOlap4jConnection olap4jConnection = - olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - for (mondrian.olap.NamedSet namedSet : cube.getNamedSets()) { - list.add(olap4jConnection.toOlap4j(cube, namedSet)); - } - return Olap4jUtil.cast(list); - } - - public Collection getSupportedLocales() { - throw new UnsupportedOperationException(); - } - - public String getName() { - return cube.getName(); - } - - public String getUniqueName() { - return cube.getUniqueName(); - } - - public String getCaption(Locale locale) { - // todo: i81n - return cube.getCaption(); - } - - public String getDescription(Locale locale) { - // todo: i81n - return cube.getDescription(); - } - - public MondrianOlap4jMember lookupMember(String... nameParts) { - final MondrianOlap4jConnection olap4jConnection = - olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - final mondrian.olap.SchemaReader schemaReader = - cube.getSchemaReader(olap4jConnection.connection.getRole()); - - final List segmentList = - new ArrayList(); - for (String namePart : nameParts) { - segmentList.add( - new mondrian.olap.Id.Segment( - namePart, mondrian.olap.Id.Quoting.QUOTED)); - } - final mondrian.olap.Member member = - schemaReader.getMemberByUniqueName(segmentList, false); - if (member == null) { - return null; - } - return olap4jConnection.toOlap4j(member); - } - - public List lookupMembers( - Set treeOps, - String... nameParts) throws OlapException - { - final MondrianOlap4jMember member = lookupMember(nameParts); - if (member == null) { - return Collections.emptyList(); - } - - // Add ancestors and/or the parent. Ancestors are prepended, to ensure - // hierarchical order. - final List list = - new ArrayList(); - if (treeOps.contains(Member.TreeOp.ANCESTORS)) { - for (MondrianOlap4jMember m = member.getParentMember(); - m != null; - m = m.getParentMember()) { - list.add(0, m); - } - } else if (treeOps.contains(Member.TreeOp.PARENT)) { - final MondrianOlap4jMember parentMember = member.getParentMember(); - if (parentMember != null) { - list.add(parentMember); - } - } - - // Add siblings. Siblings which occur after the member are deferred, - // because they occur after children and descendants in the - // hierarchical ordering. - List remainingSiblingsList = null; - if (treeOps.contains(Member.TreeOp.SIBLINGS)) { - final MondrianOlap4jMember parentMember = member.getParentMember(); - NamedList siblingMembers; - if (parentMember != null) { - siblingMembers = parentMember.getChildMembers(); - } else { - siblingMembers = - Olap4jUtil.cast(member.getHierarchy().getRootMembers()); - } - List targetList = list; - for (MondrianOlap4jMember siblingMember : siblingMembers) { - if (siblingMember.equals(member)) { - targetList = - remainingSiblingsList = - new ArrayList(); - } else { - targetList.add(siblingMember); - } - } - } - - // Add the member itself. - if (treeOps.contains(Member.TreeOp.SELF)) { - list.add(member); - } - - // Add descendants and/or children. - if (treeOps.contains(Member.TreeOp.DESCENDANTS)) { - for (MondrianOlap4jMember childMember : member.getChildMembers()) { - list.add(childMember); - addDescendants(list, childMember); - } - } else if (treeOps.contains(Member.TreeOp.CHILDREN)) { - for (MondrianOlap4jMember childMember : member.getChildMembers()) { - list.add(childMember); - } - } - // Lastly, add siblings which occur after the member itself. They - // occur after all of the descendants in the hierarchical ordering. - if (remainingSiblingsList != null) { - list.addAll(remainingSiblingsList); - } - return Olap4jUtil.cast(list); - } - - private static void addDescendants( - List list, - MondrianOlap4jMember member) - { - for (MondrianOlap4jMember childMember : member.getChildMembers()) { - list.add(childMember); - addDescendants(list, childMember); - } - } -} - -// End MondrianOlap4jCube.java diff --git a/src/mondrian/olap4j/MondrianOlap4jDatabaseMetaData.java b/src/mondrian/olap4j/MondrianOlap4jDatabaseMetaData.java deleted file mode 100644 index 776a545..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jDatabaseMetaData.java +++ /dev/null @@ -1,1073 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.olap.MondrianServer; -import mondrian.xmla.XmlaUtil; - -import org.olap4j.OlapDatabaseMetaData; -import org.olap4j.OlapException; -import org.olap4j.OlapConnection; -import org.olap4j.impl.NamedListImpl; -import org.olap4j.impl.Olap4jUtil; -import org.olap4j.metadata.*; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; - -/** - * Implementation of {@link org.olap4j.OlapDatabaseMetaData} - * for the Mondrian OLAP engine. - * - *

This class has sub-classes which implement JDBC 3.0 and JDBC 4.0 APIs; - * it is instantiated using {@link Factory#newDatabaseMetaData}.

- * - * @author jhyde - * @version $Id$ - * @since May 23, 2007 - */ -abstract class MondrianOlap4jDatabaseMetaData implements OlapDatabaseMetaData { - final MondrianOlap4jConnection olap4jConnection; - final MondrianServer mondrianServer; - - // A mondrian instance contains only one catalog (and one schema). - private final MondrianOlap4jCatalog olap4jCatalog = - new MondrianOlap4jCatalog(this); - - MondrianOlap4jDatabaseMetaData( - MondrianOlap4jConnection olap4jConnection) - { - this.olap4jConnection = olap4jConnection; - mondrianServer = - MondrianServer.forConnection(olap4jConnection.connection); - } - - // helpers - - /** - * Executes a metadata query and returns the result as a JDBC - * {@link ResultSet}. - * - * @param methodName Name of the metadata request. Corresponds to the XMLA - * method name, e.g. "MDSCHEMA_CUBES" - * - * @param patternValues Array of alternating parameter name and value - * pairs. If the parameter value is null, it is ignored. - * - * @return Result set of metadata - */ - private ResultSet getMetadata( - String methodName, - Object... patternValues) - { - Map restrictionMap = - new HashMap(); - assert patternValues.length % 2 == 0; - for (int i = 0; i < patternValues.length / 2; ++i) { - final String key = (String) patternValues[i * 2]; - Object value = patternValues[i * 2 + 1]; - if (value != null) { - if (value instanceof String) { - value = Collections.singletonList((String) value); - } - restrictionMap.put(key, value); - } - } - XmlaUtil.MetadataRowset rowset = - XmlaUtil.getMetadataRowset( - olap4jConnection.connection, - MondrianOlap4jConnection.LOCALDB_CATALOG_NAME, - methodName, - restrictionMap); - return olap4jConnection.factory.newFixedResultSet( - olap4jConnection, rowset.headerList, rowset.rowList); - } - - private XmlaUtil.Wildcard wildcard(String pattern) { - return pattern == null - ? null - : new XmlaUtil.Wildcard(pattern); - } - - // package-protected - NamedList getCatalogObjects() { - NamedList list = - new NamedListImpl(); - list.add(olap4jCatalog); - return Olap4jUtil.cast(list); - } - - // implement DatabaseMetaData - - public boolean allProceduresAreCallable() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean allTablesAreSelectable() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getURL() throws SQLException { - return olap4jConnection.connection.getConnectString(); - } - - public String getUserName() throws SQLException { - // mondrian does not support a user name property - return null; - } - - public boolean isReadOnly() throws SQLException { - // all mondrian databases are read-only - return true; - } - - public boolean nullsAreSortedHigh() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean nullsAreSortedLow() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean nullsAreSortedAtStart() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean nullsAreSortedAtEnd() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getDatabaseProductName() throws SQLException { - return mondrianServer.getVersion().getProductName(); - } - - public String getDatabaseProductVersion() throws SQLException { - return mondrianServer.getVersion().getVersionString(); - } - - public String getDriverName() throws SQLException { - return MondrianOlap4jDriver.NAME; - } - - public String getDriverVersion() throws SQLException { - return MondrianOlap4jDriver.VERSION; - } - - public int getDriverMajorVersion() { - return MondrianOlap4jDriver.MAJOR_VERSION; - } - - public int getDriverMinorVersion() { - return MondrianOlap4jDriver.MINOR_VERSION; - } - - public boolean usesLocalFiles() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean usesLocalFilePerTable() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsMixedCaseIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean storesUpperCaseIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean storesLowerCaseIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean storesMixedCaseIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getIdentifierQuoteString() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getSQLKeywords() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getNumericFunctions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getStringFunctions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getSystemFunctions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getTimeDateFunctions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getSearchStringEscape() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getExtraNameCharacters() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsAlterTableWithAddColumn() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsAlterTableWithDropColumn() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsColumnAliasing() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean nullPlusNonNullIsNull() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsConvert() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsConvert( - int fromType, int toType) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsTableCorrelationNames() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsDifferentTableCorrelationNames() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsExpressionsInOrderBy() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsOrderByUnrelated() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsGroupBy() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsGroupByUnrelated() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsGroupByBeyondSelect() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsLikeEscapeClause() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsMultipleResultSets() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsMultipleTransactions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsNonNullableColumns() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsMinimumSQLGrammar() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsCoreSQLGrammar() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsExtendedSQLGrammar() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsANSI92EntryLevelSQL() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsANSI92IntermediateSQL() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsANSI92FullSQL() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsIntegrityEnhancementFacility() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsOuterJoins() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsFullOuterJoins() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsLimitedOuterJoins() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getSchemaTerm() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getProcedureTerm() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getCatalogTerm() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isCatalogAtStart() throws SQLException { - throw new UnsupportedOperationException(); - } - - public String getCatalogSeparator() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSchemasInDataManipulation() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSchemasInProcedureCalls() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSchemasInTableDefinitions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSchemasInIndexDefinitions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsCatalogsInDataManipulation() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsCatalogsInProcedureCalls() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsCatalogsInTableDefinitions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsPositionedDelete() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsPositionedUpdate() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSelectForUpdate() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsStoredProcedures() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSubqueriesInComparisons() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSubqueriesInExists() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSubqueriesInIns() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsSubqueriesInQuantifieds() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsCorrelatedSubqueries() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsUnion() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsUnionAll() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsOpenCursorsAcrossCommit() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsOpenCursorsAcrossRollback() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsOpenStatementsAcrossCommit() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsOpenStatementsAcrossRollback() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxBinaryLiteralLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxCharLiteralLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxColumnNameLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxColumnsInGroupBy() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxColumnsInIndex() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxColumnsInOrderBy() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxColumnsInSelect() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxColumnsInTable() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxConnections() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxCursorNameLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxIndexLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxSchemaNameLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxProcedureNameLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxCatalogNameLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxRowSize() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxStatementLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxStatements() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxTableNameLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxTablesInSelect() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxUserNameLength() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getDefaultTransactionIsolation() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsTransactions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsTransactionIsolationLevel(int level) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsDataManipulationTransactionsOnly() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean dataDefinitionCausesTransactionCommit() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean dataDefinitionIgnoredInTransactions() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getProcedures( - String catalog, - String schemaPattern, - String procedureNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getProcedureColumns( - String catalog, - String schemaPattern, - String procedureNamePattern, - String columnNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getTables( - String catalog, - String schemaPattern, - String tableNamePattern, - String types[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getSchemas() throws SQLException { - if (false) { - // Do not use DBSCHEMA_SCHEMATA: it has different columns than the - // JDBC spec requires - return getMetadata("DBSCHEMA_SCHEMATA"); - } - List headerList = - Arrays.asList("TABLE_SCHEM", "TABLE_CAT"); - List> rowList = new ArrayList>(); - for (Schema schema : olap4jCatalog.getSchemas()) { - rowList.add( - Arrays.asList( - (Object) schema.getName(), - schema.getCatalog().getName())); - } - return olap4jConnection.factory.newFixedResultSet( - olap4jConnection, headerList, rowList); - } - - public ResultSet getCatalogs() throws SQLException { - if (false) { - // Do not use DBSCHEMA_CATALOGS: it has different columns than the - // JDBC spec requires - return getMetadata("DBSCHEMA_CATALOGS"); - } - - List headerList = - Arrays.asList("TABLE_CAT"); - List> rowList = - Collections.singletonList( - Arrays.asList((Object) olap4jCatalog.getName())); - return olap4jConnection.factory.newFixedResultSet( - olap4jConnection, headerList, rowList); - } - - public ResultSet getTableTypes() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getColumns( - String catalog, - String schemaPattern, - String tableNamePattern, - String columnNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getColumnPrivileges( - String catalog, - String schema, - String table, - String columnNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getTablePrivileges( - String catalog, - String schemaPattern, - String tableNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getBestRowIdentifier( - String catalog, - String schema, - String table, - int scope, - boolean nullable) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getVersionColumns( - String catalog, String schema, String table) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getPrimaryKeys( - String catalog, String schema, String table) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getImportedKeys( - String catalog, String schema, String table) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getExportedKeys( - String catalog, String schema, String table) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getCrossReference( - String parentCatalog, - String parentSchema, - String parentTable, - String foreignCatalog, - String foreignSchema, - String foreignTable) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getTypeInfo() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getIndexInfo( - String catalog, - String schema, - String table, - boolean unique, - boolean approximate) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsResultSetType(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsResultSetConcurrency( - int type, int concurrency) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean ownUpdatesAreVisible(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean ownDeletesAreVisible(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean ownInsertsAreVisible(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean othersUpdatesAreVisible(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean othersDeletesAreVisible(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean othersInsertsAreVisible(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean updatesAreDetected(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean deletesAreDetected(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean insertsAreDetected(int type) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsBatchUpdates() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getUDTs( - String catalog, - String schemaPattern, - String typeNamePattern, - int[] types) throws SQLException { - throw new UnsupportedOperationException(); - } - - public OlapConnection getConnection() { - return olap4jConnection; - } - - public boolean supportsSavepoints() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsNamedParameters() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsMultipleOpenResults() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsGetGeneratedKeys() throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getSuperTypes( - String catalog, - String schemaPattern, - String typeNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getSuperTables( - String catalog, - String schemaPattern, - String tableNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getAttributes( - String catalog, - String schemaPattern, - String typeNamePattern, - String attributeNamePattern) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsResultSetHoldability(int holdability) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getResultSetHoldability() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getDatabaseMajorVersion() throws SQLException { - return mondrianServer.getVersion().getMajorVersion(); - } - - public int getDatabaseMinorVersion() throws SQLException { - return mondrianServer.getVersion().getMajorVersion(); - } - - public int getJDBCMajorVersion() throws SQLException { - // mondrian olap4j supports jdbc 4.0 - return 4; - } - - public int getJDBCMinorVersion() throws SQLException { - // mondrian olap4j supports jdbc 4.0 - return 0; - } - - public int getSQLStateType() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean locatorsUpdateCopy() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean supportsStatementPooling() throws SQLException { - throw new UnsupportedOperationException(); - } - - // implement java.sql.Wrapper - - // straightforward implementation of unwrap and isWrapperFor, since this - // class already implements the interface they most likely require: - // DatabaseMetaData and OlapDatabaseMetaData - - public T unwrap(Class iface) throws SQLException { - if (iface.isInstance(this)) { - return iface.cast(this); - } - throw olap4jConnection.helper.createException( - "does not implement '" + iface + "'"); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return iface.isInstance(this); - } - - // implement OlapDatabaseMetaData - - public ResultSet getActions( - String catalog, - String schemaPattern, - String cubeNamePattern, - String actionNamePattern) throws OlapException - { - return getMetadata( - "MDSCHEMA_ACTIONS", - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "ACTION_NAME", wildcard(actionNamePattern)); - } - - public ResultSet getDatasources() throws OlapException { - return getMetadata("DISCOVER_DATASOURCES"); - } - - public ResultSet getLiterals() throws OlapException { - return getMetadata("DISCOVER_LITERALS"); - } - - public ResultSet getDatabaseProperties( - String dataSourceName, - String propertyNamePattern) throws OlapException - { - return getMetadata("DISCOVER_PROPERTIES"); - } - - public ResultSet getProperties( - String catalog, - String schemaPattern, - String cubeNamePattern, - String dimensionUniqueName, - String hierarchyUniqueName, - String levelUniqueName, - String memberUniqueName, - String propertyNamePattern) throws OlapException - { - return getMetadata( - "MDSCHEMA_PROPERTIES", - "CATALOG_NAME", catalog, - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "DIMENSION_UNIQUE_NAME", dimensionUniqueName, - "HIERARCHY_UNIQUE_NAME", hierarchyUniqueName, - "LEVEL_UNIQUE_NAME", levelUniqueName, - "MEMBER_UNIQUE_NAME", memberUniqueName, - "PROPERTY_NAME", wildcard(propertyNamePattern)); - } - - public String getMdxKeywords() throws OlapException { - StringBuilder buf = new StringBuilder(); - for (String keyword : mondrianServer.getKeywords()) { - if (buf.length() > 0) { - buf.append(','); - } - buf.append(keyword); - } - return buf.toString(); - } - - public ResultSet getCubes( - String catalog, - String schemaPattern, - String cubeNamePattern) - throws OlapException - { - return getMetadata( - "MDSCHEMA_CUBES", - "CATALOG_NAME", catalog, - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern)); - } - - public ResultSet getDimensions( - String catalog, - String schemaPattern, - String cubeNamePattern, - String dimensionNamePattern) - throws OlapException - { - return getMetadata( - "MDSCHEMA_DIMENSIONS", - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "DIMSENSION_NAME", wildcard(dimensionNamePattern)); - } - - public ResultSet getOlapFunctions( - String functionNamePattern) throws OlapException - { - return getMetadata( - "MDSCHEMA_FUNCTIONS", - "FUNCTION_NAME", wildcard(functionNamePattern)); - } - - public ResultSet getHierarchies( - String catalog, - String schemaPattern, - String cubeNamePattern, - String dimensionNamePattern, - String hierarchyNamePattern) - throws OlapException - { - return getMetadata( - "MDSCHEMA_HIERARCHIES", - "CATALOG_NAME", catalog, - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "DIMENSION_NAME", wildcard(dimensionNamePattern), - "HIERARCHY_NAME", wildcard(hierarchyNamePattern)); - } - - public ResultSet getMeasures( - String catalog, - String schemaPattern, - String cubeNamePattern, - String measureNamePattern, - String measureUniqueName) throws OlapException - { - return getMetadata( - "MDSCHEMA_MEASURES", - "CATALOG_NAME", catalog, - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "MEASURE_NAME", wildcard(measureNamePattern), - "MEASURE_UNIQUE_NAME", measureUniqueName); - } - - public ResultSet getMembers( - String catalog, - String schemaPattern, - String cubeNamePattern, - String dimensionUniqueName, - String hierarchyUniqueName, - String levelUniqueName, - String memberUniqueName, - Set treeOps) throws OlapException - { - String treeOpString; - if (treeOps != null) { - int op = 0; - for (Member.TreeOp treeOp : treeOps) { - op |= treeOp.xmlaOrdinal(); - } - treeOpString = String.valueOf(op); - } else { - treeOpString = null; - } - return getMetadata( - "MDSCHEMA_MEMBERS", - "CATALOG_NAME", catalog, - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "DIMENSION_UNIQUE_NAME", dimensionUniqueName, - "HIERARCHY_UNIQUE_NAME", hierarchyUniqueName, - "LEVEL_UNIQUE_NAME", levelUniqueName, - "MEMBER_UNIQUE_NAME", memberUniqueName, - "TREE_OP", treeOpString); - } - - public ResultSet getLevels( - String catalog, - String schemaPattern, - String cubeNamePattern, - String dimensionUniqueName, - String hierarchyUniqueName, - String levelNamePattern) throws OlapException - { - return getMetadata( - "MDSCHEMA_LEVELS", - "CATALOG_NAME", catalog, - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "DIMENSION_UNIQUE_NAME", dimensionUniqueName, - "HIERARCHY_UNIQUE_NAME", hierarchyUniqueName, - "LEVEL_NAME", wildcard(levelNamePattern)); - } - - public ResultSet getSets( - String catalog, - String schemaPattern, - String cubeNamePattern, - String setNamePattern) throws OlapException - { - return getMetadata( - "MDSCHEMA_SETS", - "CATALOG_NAME", catalog, - "SCHEMA_NAME", wildcard(schemaPattern), - "CUBE_NAME", wildcard(cubeNamePattern), - "SET_NAME", wildcard(setNamePattern)); - } -} - -// End MondrianOlap4jDatabaseMetaData.java diff --git a/src/mondrian/olap4j/MondrianOlap4jDimension.java b/src/mondrian/olap4j/MondrianOlap4jDimension.java deleted file mode 100644 index e0aeb01..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jDimension.java +++ /dev/null @@ -1,97 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.olap.DimensionType; -import mondrian.olap.Util; -import org.olap4j.OlapException; -import org.olap4j.impl.*; -import org.olap4j.metadata.*; - -import java.util.Locale; - -/** - * Implementation of {@link org.olap4j.metadata.Dimension} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -class MondrianOlap4jDimension implements Dimension, Named { - private final MondrianOlap4jSchema olap4jSchema; - private final mondrian.olap.Dimension dimension; - - MondrianOlap4jDimension( - MondrianOlap4jSchema olap4jSchema, - mondrian.olap.Dimension dimension) - { - this.olap4jSchema = olap4jSchema; - this.dimension = dimension; - } - - public boolean equals(Object obj) { - return obj instanceof MondrianOlap4jDimension && - dimension.equals(((MondrianOlap4jDimension) obj).dimension); - } - - public int hashCode() { - return dimension.hashCode(); - } - - public NamedList getHierarchies() { - final NamedList list = - new NamedListImpl(); - final MondrianOlap4jConnection olap4jConnection = - olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - for (mondrian.olap.Hierarchy hierarchy : dimension.getHierarchies()) { - list.add(olap4jConnection.toOlap4j(hierarchy)); - } - return Olap4jUtil.cast(list); - } - - public Hierarchy getDefaultHierarchy() { - return getHierarchies().get(0); - } - - public Type getDimensionType() throws OlapException { - final DimensionType dimensionType = dimension.getDimensionType(); - switch (dimensionType) { - case StandardDimension: - return Type.OTHER; - case MeasuresDimension: - return Type.MEASURE; - case TimeDimension: - return Type.TIME; - default: - throw Util.unexpected(dimensionType); - } - } - - public String getName() { - return dimension.getName(); - } - - public String getUniqueName() { - return dimension.getUniqueName(); - } - - public String getCaption(Locale locale) { - // TODO: locale caption - return dimension.getCaption(); - } - - public String getDescription(Locale locale) { - // TODO: locale description - return dimension.getDescription(); - } -} - -// End MondrianOlap4jDimension.java diff --git a/src/mondrian/olap4j/MondrianOlap4jDriver.java b/src/mondrian/olap4j/MondrianOlap4jDriver.java deleted file mode 100644 index beec928..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jDriver.java +++ /dev/null @@ -1,154 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.rolap.RolapConnectionProperties; - -import java.sql.*; -import java.util.Properties; -import java.util.List; -import java.util.ArrayList; -import java.util.Map; - -/** - * Olap4j driver for Mondrian. - * - *

Since olap4j is a superset of JDBC, you register this driver as you would - * any JDBC driver: - * - *

- * Class.forName("mondrian.olap4j.MondrianOlap4jDriver"); - *
- * - * Then create a connection using a URL with the prefix "jdbc:mondrian:". - * For example, - * - *
- * import java.sql.Connection;
- * import java.sql.DriverManager;
- * import org.olap4j.OlapConnection;
- *
- * Connection connection =
- *    DriverManager.getConnection(
- *       "jdbc:mondrian:Jdbc=jdbc:odbc:MondrianFoodMart; Catalog=file:/mondrian/demo/FoodMart.xml; JdbcDrivers=sun.jdbc.odbc.JdbcOdbcDriver");
- * OlapConnection olapConnection =
- *    connection.unwrap(OlapConnection.class);
- *
- * - *

Note how we use the {@link Connection#unwrap(Class)} method to down-cast - * the JDBC connection object to the extension {@link org.olap4j.OlapConnection} - * object. This method is only available in the JDBC 4.0 (JDK 1.6 onwards). - * - *

Connection properties

- * - *

The driver supports the same set of properties as a traditional mondrian - * connection. See {@link mondrian.rolap.RolapConnectionProperties}. - * - *

Catalogs and schemas

- * - *

Mondrian has a sole catalog, called "LOCALDB". You will get an error - * if you attempt to use {@link java.sql.Connection#setCatalog(String)} to set - * it to anything else. - * - * @author jhyde - * @version $Id$ - * @since May 22, 2007 - */ -public class MondrianOlap4jDriver implements Driver { - public static final String NAME = "Mondrian olap4j driver"; - public static final String VERSION = "2.4"; - public static final int MAJOR_VERSION = 2; - public static final int MINOR_VERSION = 4; - private final Factory factory; - - static { - try { - register(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - MondrianOlap4jDriver() { - String factoryClassName; - try { - Class.forName("java.sql.Wrapper"); - factoryClassName = "mondrian.olap4j.FactoryJdbc4Impl"; - } catch (ClassNotFoundException e) { - // java.sql.Wrapper is not present. This means we are running JDBC - // 3.0 or earlier (probably JDK 1.5). Load the JDBC 3.0 factory - factoryClassName = "mondrian.olap4j.FactoryJdbc3Impl"; - } - try { - final Class clazz = Class.forName(factoryClassName); - factory = (Factory) clazz.newInstance(); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } - } - - private static void register() throws SQLException { - DriverManager.registerDriver(new MondrianOlap4jDriver()); - } - - public Connection connect(String url, Properties info) throws SQLException { - if (!MondrianOlap4jConnection.acceptsURL(url)) { - return null; - } - return factory.newConnection(url, info); - } - - public boolean acceptsURL(String url) throws SQLException { - return MondrianOlap4jConnection.acceptsURL(url); - } - - public DriverPropertyInfo[] getPropertyInfo( - String url, Properties info) throws SQLException - { - List list = new ArrayList(); - - // First, add the contents of info - for (Map.Entry entry : info.entrySet()) { - list.add( - new DriverPropertyInfo( - (String) entry.getKey(), - (String) entry.getValue())); - } - // Next, add property defns not mentioned in info - for (RolapConnectionProperties p : RolapConnectionProperties.values()) { - if (info.containsKey(p.name())) { - continue; - } - list.add( - new DriverPropertyInfo( - p.name(), - null)); - } - return list.toArray(new DriverPropertyInfo[list.size()]); - } - - public int getMajorVersion() { - return MAJOR_VERSION; - } - - public int getMinorVersion() { - return MINOR_VERSION; - } - - public boolean jdbcCompliant() { - return false; - } -} - -// End MondrianOlap4jDriver.java diff --git a/src/mondrian/olap4j/MondrianOlap4jHierarchy.java b/src/mondrian/olap4j/MondrianOlap4jHierarchy.java deleted file mode 100644 index f7c458a..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jHierarchy.java +++ /dev/null @@ -1,112 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.*; -import org.olap4j.impl.*; - -import java.util.Locale; - -/** - * Implementation of {@link org.olap4j.metadata.Hierarchy} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 25, 2007 - */ -class MondrianOlap4jHierarchy implements Hierarchy, Named { - private final MondrianOlap4jSchema olap4jSchema; - private final mondrian.olap.Hierarchy hierarchy; - - MondrianOlap4jHierarchy( - MondrianOlap4jSchema olap4jSchema, - mondrian.olap.Hierarchy hierarchy) - { - this.olap4jSchema = olap4jSchema; - this.hierarchy = hierarchy; - } - - public boolean equals(Object obj) { - return obj instanceof MondrianOlap4jHierarchy && - hierarchy.equals(((MondrianOlap4jHierarchy) obj).hierarchy); - } - - public int hashCode() { - return hierarchy.hashCode(); - } - - public Dimension getDimension() { - return new MondrianOlap4jDimension( - olap4jSchema, hierarchy.getDimension()); - } - - public NamedList getLevels() { - final NamedList list = - new NamedListImpl(); - final MondrianOlap4jConnection olap4jConnection = - olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - for (mondrian.olap.Level level : hierarchy.getLevels()) { - list.add(olap4jConnection.toOlap4j(level)); - } - return Olap4jUtil.cast(list); - } - - public boolean hasAll() { - return hierarchy.hasAll(); - } - - public Member getDefaultMember() { - final MondrianOlap4jConnection olap4jConnection = - olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - return olap4jConnection.toOlap4j(hierarchy.getDefaultMember()); - } - - public NamedList getRootMembers() { - final MondrianOlap4jConnection olap4jConnection = - olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - final mondrian.olap.Member[] levelMembers = - olap4jConnection.connection.getSchemaReader().getLevelMembers( - hierarchy.getLevels()[0], false); - return new AbstractNamedList() { - protected String getName(Member member) { - return member.getName(); - } - - public Member get(int index) { - return olap4jConnection.toOlap4j(levelMembers[index]); - } - - public int size() { - return levelMembers.length; - } - }; - } - - public String getName() { - return hierarchy.getName(); - } - - public String getUniqueName() { - return hierarchy.getUniqueName(); - } - - public String getCaption(Locale locale) { - // todo: localize caption - return hierarchy.getCaption(); - } - - public String getDescription(Locale locale) { - // todo: localize description - return hierarchy.getDescription(); - } -} - -// End MondrianOlap4jHierarchy.java diff --git a/src/mondrian/olap4j/MondrianOlap4jLevel.java b/src/mondrian/olap4j/MondrianOlap4jLevel.java deleted file mode 100644 index 25644d3..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jLevel.java +++ /dev/null @@ -1,120 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.*; -import org.olap4j.impl.ArrayNamedListImpl; -import org.olap4j.impl.Named; - -import java.util.*; - -/** - * Implementation of {@link Level} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 25, 2007 - */ -class MondrianOlap4jLevel implements Level, Named { - private final MondrianOlap4jSchema olap4jSchema; - private final mondrian.olap.Level level; - - MondrianOlap4jLevel( - MondrianOlap4jSchema olap4jSchema, - mondrian.olap.Level level) - { - this.olap4jSchema = olap4jSchema; - this.level = level; - } - - public boolean equals(Object obj) { - return obj instanceof MondrianOlap4jLevel && - level.equals(((MondrianOlap4jLevel) obj).level); - } - - public int hashCode() { - return level.hashCode(); - } - - public int getDepth() { - return level.getDepth(); - } - - public Hierarchy getHierarchy() { - return new MondrianOlap4jHierarchy(olap4jSchema, level.getHierarchy()); - } - - public Dimension getDimension() { - return new MondrianOlap4jDimension(olap4jSchema, level.getDimension()); - } - - public Type getLevelType() { - throw new UnsupportedOperationException(); - } - - public NamedList getProperties() { - final NamedList list = new ArrayNamedListImpl() { - protected String getName(Property property) { - return property.getName(); - } - }; - // standard properties first - list.addAll( - Arrays.asList(Property.StandardMemberProperty.values())); - // then level-specific properties - for (mondrian.olap.Property property : level.getProperties()) { - list.add(new MondrianOlap4jProperty(property)); - } - return list; - } - - public List getMembers() { - final MondrianOlap4jConnection olap4jConnection = - olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - final mondrian.olap.SchemaReader schemaReader = - olap4jConnection.connection.getSchemaReader(); - final mondrian.olap.Member[] levelMembers = - schemaReader.getLevelMembers(level, true); - return new AbstractList() { - public Member get(int index) { - return olap4jConnection.toOlap4j(levelMembers[index]); - } - - public int size() { - return levelMembers.length; - } - }; - } - - public String getName() { - return level.getName(); - } - - public String getUniqueName() { - return level.getUniqueName(); - } - - public String getCaption(Locale locale) { - // todo: localized captions - return level.getCaption(); - } - - public String getDescription(Locale locale) { - // todo: localize - return level.getDescription(); - } - - public int getCardinality() { - return level.getApproxRowCount(); - } -} - -// End MondrianOlap4jLevel.java diff --git a/src/mondrian/olap4j/MondrianOlap4jMeasure.java b/src/mondrian/olap4j/MondrianOlap4jMeasure.java deleted file mode 100644 index 4b950dd..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jMeasure.java +++ /dev/null @@ -1,62 +0,0 @@ -/* -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.olap.Property; -import mondrian.rolap.RolapAggregator; -import mondrian.rolap.RolapStoredMeasure; -import org.olap4j.metadata.Datatype; -import org.olap4j.metadata.Measure; - -/** - * Implementation of {@link org.olap4j.metadata.Measure} - * for the Mondrian OLAP engine, - * as a wrapper around a mondrian - * {@link mondrian.rolap.RolapStoredMeasure}. - * - * @author jhyde - * @version $Id: $ - * @since Dec 10, 2007 - */ -public class MondrianOlap4jMeasure - extends MondrianOlap4jMember - implements Measure -{ - MondrianOlap4jMeasure( - MondrianOlap4jSchema olap4jSchema, - RolapStoredMeasure measure) - { - super(olap4jSchema, measure); - } - - public Aggregator getAggregator() { - final RolapAggregator aggregator = - ((RolapStoredMeasure) member).getAggregator(); - return Aggregator.valueOf(aggregator.getName().toUpperCase()); - } - - public Datatype getDatatype() { - final String datatype = - (String) member.getPropertyValue(Property.DATATYPE.getName()); - if (datatype != null) { - if (datatype.equals("Integer")) { - return Datatype.INTEGER; - } else if (datatype.equals("Numeric")) { - return Datatype.DOUBLE; - } - } - return Datatype.STRING; - } - - public boolean isVisible() { - return (Boolean) member.getPropertyValue(Property.VISIBLE.getName()); - } -} - -// End MondrianOlap4jMeasure.java diff --git a/src/mondrian/olap4j/MondrianOlap4jMember.java b/src/mondrian/olap4j/MondrianOlap4jMember.java deleted file mode 100644 index 57284b1..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jMember.java +++ /dev/null @@ -1,182 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.*; -import org.olap4j.OlapException; -import org.olap4j.impl.Named; -import org.olap4j.impl.AbstractNamedList; -import org.olap4j.mdx.ParseTreeNode; - -import java.util.List; -import java.util.Locale; - -/** - * Implementation of {@link Member} - * for the Mondrian OLAP engine, - * as a wrapper around a mondrian - * {@link mondrian.olap.Member}. - * - * @author jhyde - * @version $Id$ - * @since May 25, 2007 - */ -class MondrianOlap4jMember implements Member, Named { - final mondrian.olap.Member member; - private final MondrianOlap4jSchema olap4jSchema; - - MondrianOlap4jMember( - MondrianOlap4jSchema olap4jSchema, - mondrian.olap.Member mondrianMember) - { - assert mondrianMember != null; - this.olap4jSchema = olap4jSchema; - this.member = mondrianMember; - } - - public boolean equals(Object obj) { - return obj instanceof MondrianOlap4jMember && - member.equals(((MondrianOlap4jMember) obj).member); - } - - public int hashCode() { - return member.hashCode(); - } - - public NamedList getChildMembers() { - final mondrian.olap.Member[] children = - olap4jSchema.schemaReader.getMemberChildren( - member); - return new AbstractNamedList() { - protected String getName(MondrianOlap4jMember member) { - return member.getName(); - } - - public MondrianOlap4jMember get(int index) { - return new MondrianOlap4jMember(olap4jSchema, children[index]); - } - - public int size() { - return children.length; - } - }; - } - - public int getChildMemberCount() { - return olap4jSchema.schemaReader.getMemberChildren(member).length; - } - - public MondrianOlap4jMember getParentMember() { - final mondrian.olap.Member parentMember = member.getParentMember(); - if (parentMember == null) { - return null; - } - return new MondrianOlap4jMember(olap4jSchema, parentMember); - } - - public Level getLevel() { - return new MondrianOlap4jLevel(olap4jSchema, member.getLevel()); - } - - public Hierarchy getHierarchy() { - return new MondrianOlap4jHierarchy( - olap4jSchema, member.getHierarchy()); - } - - public Dimension getDimension() { - return new MondrianOlap4jDimension( - olap4jSchema, member.getDimension()); - } - - public Type getMemberType() { - return Type.valueOf(member.getMemberType().name()); - } - - public boolean isAll() { - return member.isAll(); - } - - public boolean isChildOrEqualTo(Member member) { - throw new UnsupportedOperationException(); - } - - public boolean isCalculated() { - throw new UnsupportedOperationException(); - } - - public int getSolveOrder() { - throw new UnsupportedOperationException(); - } - - public ParseTreeNode getExpression() { - throw new UnsupportedOperationException(); - } - - public List getAncestorMembers() { - throw new UnsupportedOperationException(); - } - - public boolean isCalculatedInQuery() { - throw new UnsupportedOperationException(); - } - - public Object getPropertyValue(Property property) { - return member.getPropertyValue(property.getName()); - } - - public String getPropertyFormattedValue(Property property) { - return member.getPropertyFormattedValue(property.getName()); - } - - public void setProperty(Property property, Object value) throws OlapException { - member.setProperty(property.getName(), value); - } - - public NamedList getProperties() { - return getLevel().getProperties(); - } - - public int getOrdinal() { - final Number ordinal = - (Number) member.getPropertyValue( - Property.StandardMemberProperty.MEMBER_ORDINAL.getName()); - return ordinal.intValue(); - } - - public boolean isHidden() { - throw new UnsupportedOperationException(); - } - - public int getDepth() { - throw new UnsupportedOperationException(); - } - - public Member getDataMember() { - throw new UnsupportedOperationException(); - } - - public String getName() { - return member.getName(); - } - - public String getUniqueName() { - return member.getUniqueName(); - } - - public String getCaption(Locale locale) { - throw new UnsupportedOperationException(); - } - - public String getDescription(Locale locale) { - throw new UnsupportedOperationException(); - } -} - -// End MondrianOlap4jMember.java diff --git a/src/mondrian/olap4j/MondrianOlap4jNamedSet.java b/src/mondrian/olap4j/MondrianOlap4jNamedSet.java deleted file mode 100644 index 25ed43d..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jNamedSet.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.NamedSet; -import org.olap4j.metadata.Cube; -import org.olap4j.mdx.ParseTreeNode; -import org.olap4j.impl.Named; - -import java.util.Locale; - -/** - * Implementation of {@link org.olap4j.metadata.NamedSet} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since Nov 12, 2007 - */ -public class MondrianOlap4jNamedSet implements NamedSet, Named { - private final MondrianOlap4jCube olap4jCube; - private mondrian.olap.NamedSet namedSet; - - MondrianOlap4jNamedSet( - MondrianOlap4jCube olap4jCube, - mondrian.olap.NamedSet namedSet) - { - this.olap4jCube = olap4jCube; - this.namedSet = namedSet; - } - - public Cube getCube() { - return olap4jCube; - } - - public ParseTreeNode getExpression() { - final MondrianOlap4jConnection olap4jConnection = - olap4jCube.olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData - .olap4jConnection; - return olap4jConnection.toOlap4j(namedSet.getExp()); - } - - public String getName() { - return namedSet.getName(); - } - - public String getUniqueName() { - return namedSet.getUniqueName(); - } - - public String getCaption(Locale locale) { - // todo: i18n - return namedSet.getCaption(); - } - - public String getDescription(Locale locale) { - // todo: i18n - return namedSet.getDescription(); - } -} - -// End MondrianOlap4jNamedSet.java diff --git a/src/mondrian/olap4j/MondrianOlap4jPreparedStatement.java b/src/mondrian/olap4j/MondrianOlap4jPreparedStatement.java deleted file mode 100644 index cb5b182..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jPreparedStatement.java +++ /dev/null @@ -1,424 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.*; -import org.olap4j.type.*; -import org.olap4j.metadata.*; - -import java.sql.*; -import java.math.BigDecimal; -import java.io.InputStream; -import java.io.Reader; -import java.util.Calendar; -import java.net.URL; - -import mondrian.olap.Query; -import mondrian.olap.Parameter; - -/** - * Implementation of {@link PreparedOlapStatement} - * for the Mondrian OLAP engine. - * - *

This class has sub-classes which implement JDBC 3.0 and JDBC 4.0 APIs; - * it is instantiated using {@link Factory#newPreparedStatement}.

- * - * @author jhyde - * @version $Id$ - * @since Jun 12, 2007 - */ -abstract class MondrianOlap4jPreparedStatement - extends MondrianOlap4jStatement - implements PreparedOlapStatement, OlapParameterMetaData -{ - private final String mdx; - private Query query; - MondrianOlap4jCellSetMetaData cellSetMetaData; - - public MondrianOlap4jPreparedStatement( - MondrianOlap4jConnection olap4jConnection, - String mdx) - { - super(olap4jConnection); - this.mdx = mdx; - this.query = olap4jConnection.connection.parseQuery(mdx); - this.cellSetMetaData = new MondrianOlap4jCellSetMetaData(this, query); - } - - // override OlapStatement - - public CellSet executeOlapQuery(String mdx) throws OlapException { - this.query = olap4jConnection.connection.parseQuery(mdx); - this.cellSetMetaData = new MondrianOlap4jCellSetMetaData(this, query); - return executeOlapQueryInternal(query); - } - - // implement PreparedOlapStatement - - public CellSet executeQuery() throws OlapException { - return executeOlapQueryInternal(query); - } - - public OlapParameterMetaData getParameterMetaData() throws OlapException { - return this; - } - - public Cube getCube() { - throw new UnsupportedOperationException(); - } - - // implement PreparedStatement - - public int executeUpdate() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNull(int parameterIndex, int sqlType) throws SQLException { - getParameter(parameterIndex).setValue(null); - } - - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setByte(int parameterIndex, byte x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setShort(int parameterIndex, short x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setInt(int parameterIndex, int x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setLong(int parameterIndex, long x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setFloat(int parameterIndex, float x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setDouble(int parameterIndex, double x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setBigDecimal( - int parameterIndex, BigDecimal x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setString(int parameterIndex, String x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setBytes(int parameterIndex, byte x[]) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setDate(int parameterIndex, Date x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setTime(int parameterIndex, Time x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setTimestamp( - int parameterIndex, Timestamp x) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setAsciiStream( - int parameterIndex, InputStream x, int length) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setUnicodeStream( - int parameterIndex, InputStream x, int length) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setBinaryStream( - int parameterIndex, InputStream x, int length) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void clearParameters() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setObject( - int parameterIndex, Object x, int targetSqlType) throws SQLException { - getParameter(parameterIndex).setValue(x); - } - - public void setObject(int parameterIndex, Object x) throws SQLException { - final Parameter parameter = getParameter(parameterIndex); - if (x instanceof MondrianOlap4jMember) { - MondrianOlap4jMember mondrianOlap4jMember = - (MondrianOlap4jMember) x; - x = mondrianOlap4jMember.member; - } - parameter.setValue(x); - } - - public boolean execute() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void addBatch() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setCharacterStream( - int parameterIndex, Reader reader, int length) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setRef(int parameterIndex, Ref x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setBlob(int parameterIndex, Blob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setClob(int parameterIndex, Clob x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setArray(int parameterIndex, Array x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public CellSetMetaData getMetaData() { - return cellSetMetaData; - } - - public void setDate( - int parameterIndex, Date x, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setTime( - int parameterIndex, Time x, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setTimestamp( - int parameterIndex, Timestamp x, Calendar cal) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setNull( - int parameterIndex, int sqlType, String typeName) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setURL(int parameterIndex, URL x) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setObject( - int parameterIndex, - Object x, - int targetSqlType, - int scaleOrLength) throws SQLException { - throw new UnsupportedOperationException(); - } - - // implement OlapParameterMetaData - - public String getParameterName(int param) throws OlapException { - Parameter paramDef = getParameter(param); - return paramDef.getName(); - } - - private Parameter getParameter(int param) throws OlapException { - final Parameter[] parameters = query.getParameters(); - if (param < 1 || param > parameters.length) { - throw this.olap4jConnection.helper.toOlapException( - this.olap4jConnection.helper.createException( - "parameter ordinal " + param + " out of range")); - } - return parameters[param - 1]; - } - - public Type getParameterOlapType(int param) throws OlapException { - Parameter paramDef = getParameter(param); - return olap4jConnection.toOlap4j(paramDef.getType()); - } - - public int getParameterCount() { - return query.getParameters().length; - } - - public int isNullable(int param) throws SQLException { - return ParameterMetaData.parameterNullableUnknown; - } - - public boolean isSigned(int param) throws SQLException { - final Type type = getParameterOlapType(param); - return type instanceof NumericType; - } - - public int getPrecision(int param) throws SQLException { - final Type type = getParameterOlapType(param); - if (type instanceof NumericType) { - return 0; // precision not applicable - } - if (type instanceof StringType) { - return Integer.MAX_VALUE; - } - return 0; - } - - public int getScale(int param) throws SQLException { - return 0; // scale not applicable - } - - public int getParameterType(int param) throws SQLException { - final Type type = getParameterOlapType(param); - if (type instanceof NumericType) { - return Types.NUMERIC; - } else if (type instanceof StringType) { - return Types.VARCHAR; - } else if (type instanceof NullType) { - return Types.NULL; - } else { - return Types.OTHER; - } - } - - public String getParameterTypeName(int param) throws SQLException { - final Type type = getParameterOlapType(param); - return type.toString(); - } - - public String getParameterClassName(int param) throws SQLException { - final Type type = getParameterOlapType(param); - return foo( - new TypeHelper() { - public Class booleanType(BooleanType type) { - return Boolean.class; - } - - public Class cubeType(CubeType cubeType) { - return Cube.class; - } - - public Class decimalType(DecimalType decimalType) { - return Number.class; - } - - public Class dimensionType(DimensionType dimensionType) { - return Dimension.class; - } - - public Class hierarchyType(HierarchyType hierarchyType) { - return Hierarchy.class; - } - - public Class levelType(LevelType levelType) { - return Level.class; - } - - public Class memberType(MemberType memberType) { - return Member.class; - } - - public Class nullType(NullType nullType) { - return Void.class; - } - - public Class numericType(NumericType numericType) { - return Number.class; - } - - public Class setType(SetType setType) { - return Iterable.class; - } - - public Class stringType(StringType stringType) { - return String.class; - } - - public Class tupleType(TupleType tupleType) { - return Member[].class; - } - - public Class symbolType(SymbolType symbolType) { - // parameters cannot be of this type - throw new UnsupportedOperationException(); - } - }, - type).getName(); - } - - public int getParameterMode(int param) throws SQLException { - Parameter paramDef = getParameter(param); // forces param range check - return ParameterMetaData.parameterModeIn; - } - - // Helper classes - - private interface TypeHelper { - T booleanType(BooleanType type); - T cubeType(CubeType cubeType); - T decimalType(DecimalType decimalType); - T dimensionType(DimensionType dimensionType); - T hierarchyType(HierarchyType hierarchyType); - T levelType(LevelType levelType); - T memberType(MemberType memberType); - T nullType(NullType nullType); - T numericType(NumericType numericType); - T setType(SetType setType); - T stringType(StringType stringType); - T tupleType(TupleType tupleType); - T symbolType(SymbolType symbolType); - } - - T foo(TypeHelper helper, Type type) { - if (type instanceof BooleanType) { - return helper.booleanType((BooleanType) type); - } else if (type instanceof CubeType) { - return helper.cubeType((CubeType) type); - } else if (type instanceof DecimalType) { - return helper.decimalType((DecimalType) type); - } else if (type instanceof DimensionType) { - return helper.dimensionType((DimensionType) type); - } else if (type instanceof HierarchyType) { - return helper.hierarchyType((HierarchyType) type); - } else if (type instanceof LevelType) { - return helper.levelType((LevelType) type); - } else if (type instanceof MemberType) { - return helper.memberType((MemberType) type); - } else if (type instanceof NullType) { - return helper.nullType((NullType) type); - } else if (type instanceof NumericType) { - return helper.numericType((NumericType) type); - } else if (type instanceof SetType) { - return helper.setType((SetType) type); - } else if (type instanceof StringType) { - return helper.stringType((StringType) type); - } else if (type instanceof TupleType) { - return helper.tupleType((TupleType) type); - } else if (type instanceof SymbolType) { - return helper.symbolType((SymbolType) type); - } else { - throw new UnsupportedOperationException(); - } - } -} - -// End MondrianOlap4jPreparedStatement.java diff --git a/src/mondrian/olap4j/MondrianOlap4jProperty.java b/src/mondrian/olap4j/MondrianOlap4jProperty.java deleted file mode 100644 index 3995542..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jProperty.java +++ /dev/null @@ -1,79 +0,0 @@ -/* -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.Property; -import org.olap4j.metadata.Datatype; -import org.olap4j.impl.Named; - -import java.util.*; - -/** - * Implementation of {@link org.olap4j.metadata.Property} - * for the Mondrian OLAP engine, - * as a wrapper around a mondrian - * {@link mondrian.olap.Property}. - * - * @author jhyde - * @version $Id$ - * @since Nov 12, 2007 - */ -class MondrianOlap4jProperty implements Property, Named { - private final mondrian.olap.Property property; - - MondrianOlap4jProperty(mondrian.olap.Property property) { - this.property = property; - } - - public Datatype getDatatype() { - switch (property.getType()) { - case TYPE_BOOLEAN: - return Datatype.BOOLEAN; - case TYPE_NUMERIC: - return Datatype.UNSIGNED_INTEGER; - case TYPE_STRING: - return Datatype.STRING; - case TYPE_OTHER: - return Datatype.VARIANT; - default: - throw new RuntimeException("unexpected: " + property.getType()); - } - } - - public Set getType() { - return TypeFlag.forMask( - property.isCellProperty() - ? TypeFlag.CELL.xmlaOrdinal - : TypeFlag.MEMBER.xmlaOrdinal); - } - - public String getName() { - return property.name; - } - - public String getUniqueName() { - return property.name; - } - - public String getCaption(Locale locale) { - // todo: i18n - return property.getCaption(); - } - - public String getDescription(Locale locale) { - // todo: i18n - return property.getDescription(); - } - - public ContentType getContentType() { - return ContentType.REGULAR; - } -} - -// End MondrianOlap4jProperty.java diff --git a/src/mondrian/olap4j/MondrianOlap4jSchema.java b/src/mondrian/olap4j/MondrianOlap4jSchema.java deleted file mode 100644 index 0b56d41..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jSchema.java +++ /dev/null @@ -1,84 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import org.olap4j.metadata.*; -import org.olap4j.metadata.Cube; -import org.olap4j.metadata.Dimension; -import org.olap4j.metadata.Schema; -import org.olap4j.OlapException; -import org.olap4j.impl.*; - -import java.util.Locale; -import java.util.Collection; -import java.util.Collections; - -import mondrian.olap.*; -import mondrian.olap.Hierarchy; - -/** - * Implementation of {@link org.olap4j.metadata.Schema} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -class MondrianOlap4jSchema implements Schema, Named { - final MondrianOlap4jCatalog olap4jCatalog; - private final mondrian.olap.Schema schema; - final SchemaReader schemaReader; - - MondrianOlap4jSchema( - MondrianOlap4jCatalog olap4jCatalog, - SchemaReader schemaReader, - mondrian.olap.Schema schema) - { - this.olap4jCatalog = olap4jCatalog; - this.schemaReader = schemaReader; - this.schema = schema; - } - - public Catalog getCatalog() { - return olap4jCatalog; - } - - public NamedList getCubes() throws OlapException { - NamedList list = - new NamedListImpl(); - final MondrianOlap4jConnection olap4jConnection = - olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - for (mondrian.olap.Cube cube : schema.getCubes()) { - list.add(olap4jConnection.toOlap4j(cube)); - } - return Olap4jUtil.cast(list); - } - - public NamedList getSharedDimensions() throws OlapException { - NamedList list = - new NamedListImpl(); - final MondrianOlap4jConnection olap4jConnection = - olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection; - for (Hierarchy hierarchy : schema.getSharedHierarchies()) { - list.add(olap4jConnection.toOlap4j(hierarchy.getDimension())); - } - return Olap4jUtil.cast(list); - } - - public Collection getSupportedLocales() throws OlapException { - return Collections.emptyList(); - } - - public String getName() { - return schema.getName(); - } -} - -// End MondrianOlap4jSchema.java diff --git a/src/mondrian/olap4j/MondrianOlap4jStatement.java b/src/mondrian/olap4j/MondrianOlap4jStatement.java deleted file mode 100644 index 6edf622..0000000 --- a/src/mondrian/olap4j/MondrianOlap4jStatement.java +++ /dev/null @@ -1,321 +0,0 @@ -/* -// $Id$ -// This software is subject to the terms of the Common Public License -// Agreement, available at the following URL: -// http://www.opensource.org/licenses/cpl.html. -// Copyright (C) 2007-2007 Julian Hyde -// All Rights Reserved. -// You must accept the terms of that agreement to use this software. -*/ -package mondrian.olap4j; - -import mondrian.olap.*; -import org.olap4j.*; -import org.olap4j.mdx.*; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.sql.*; -import java.sql.Connection; - -/** - * Implementation of {@link org.olap4j.OlapStatement} - * for the Mondrian OLAP engine. - * - * @author jhyde - * @version $Id$ - * @since May 24, 2007 - */ -class MondrianOlap4jStatement implements OlapStatement { - final MondrianOlap4jConnection olap4jConnection; - private boolean closed; - - /** - * Current cell set, or null if the statement is not executing anything. - * Any method which modifies this member must synchronize - * on the MondrianOlap4jStatement. - */ - MondrianOlap4jCellSet openCellSet; - int timeoutSeconds; - - MondrianOlap4jStatement( - MondrianOlap4jConnection olap4jConnection) - { - assert olap4jConnection != null; - this.olap4jConnection = olap4jConnection; - this.closed = false; - } - - // implement Statement - - public ResultSet executeQuery(String sql) throws SQLException { - throw new UnsupportedOperationException(); - } - - private void checkOpen() throws SQLException { - if (closed) { - throw olap4jConnection.helper.createException("closed"); - } - } - - public int executeUpdate(String sql) throws SQLException { - throw new UnsupportedOperationException(); - } - - public synchronized void close() throws SQLException { - if (!closed) { - closed = true; - if (openCellSet != null) { - CellSet c = openCellSet; - openCellSet = null; - c.close(); - } - } - } - - public int getMaxFieldSize() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setMaxFieldSize(int max) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getMaxRows() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setMaxRows(int max) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setEscapeProcessing(boolean enable) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getQueryTimeout() throws SQLException { - return timeoutSeconds; - } - - public void setQueryTimeout(int seconds) throws SQLException { - if (seconds < 0) { - throw olap4jConnection.helper.createException( - "illegal timeout value " + seconds); - } - this.timeoutSeconds = seconds; - } - - public synchronized void cancel() throws SQLException { - if (openCellSet != null) { - openCellSet.query.cancel(); - } - } - - public SQLWarning getWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void clearWarnings() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setCursorName(String name) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean execute(String sql) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getResultSet() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getUpdateCount() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean getMoreResults() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setFetchDirection(int direction) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getFetchDirection() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void setFetchSize(int rows) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getFetchSize() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getResultSetConcurrency() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getResultSetType() throws SQLException { - throw new UnsupportedOperationException(); - } - - public void addBatch(String sql) throws SQLException { - throw new UnsupportedOperationException(); - } - - public void clearBatch() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int[] executeBatch() throws SQLException { - throw new UnsupportedOperationException(); - } - - public Connection getConnection() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean getMoreResults(int current) throws SQLException { - throw new UnsupportedOperationException(); - } - - public ResultSet getGeneratedKeys() throws SQLException { - throw new UnsupportedOperationException(); - } - - public int executeUpdate( - String sql, int autoGeneratedKeys) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int executeUpdate( - String sql, int columnIndexes[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int executeUpdate( - String sql, String columnNames[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean execute( - String sql, int autoGeneratedKeys) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean execute( - String sql, int columnIndexes[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean execute( - String sql, String columnNames[]) throws SQLException { - throw new UnsupportedOperationException(); - } - - public int getResultSetHoldability() throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isClosed() throws SQLException { - return closed; - } - - public void setPoolable(boolean poolable) throws SQLException { - throw new UnsupportedOperationException(); - } - - public boolean isPoolable() throws SQLException { - throw new UnsupportedOperationException(); - } - - // implement Wrapper - - public T unwrap(Class iface) throws SQLException { - if (iface.isInstance(this)) { - return iface.cast(this); - } - throw olap4jConnection.helper.createException( - "does not implement '" + iface + "'"); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return iface.isInstance(this); - } - - // implement OlapStatement - - public CellSet executeOlapQuery(String mdx) throws OlapException { - Query query; - try { - query = olap4jConnection.connection.parseQuery(mdx); - } catch (MondrianException e) { - throw olap4jConnection.helper.createException( - "mondrian gave exception while parsing query", e); - } - return executeOlapQueryInternal(query); - } - - /** - * Executes a parsed query, closing any previously open cellset. - * - * @param query Parsed query - * @return Cell set - * @throws OlapException if a database error occurs - */ - protected CellSet executeOlapQueryInternal( - Query query) throws OlapException - { - // Close the previous open CellSet, if there is one. - synchronized (this) { - if (openCellSet != null) { - final MondrianOlap4jCellSet cs = openCellSet; - openCellSet = null; - try { - cs.close(); - } catch (SQLException e) { - throw olap4jConnection.helper.createException( - null, "Error while closing previous CellSet", e); - } - } - - openCellSet = olap4jConnection.factory.newCellSet(this, query); - } - // Release the monitor before executing, to give another thread the - // opportunity to call cancel. - try { - openCellSet.execute(); - } catch (QueryCanceledException e) { - throw olap4jConnection.helper.createException("Query canceled"); - } catch (QueryTimeoutException e) { - throw olap4jConnection.helper.createException(e.getMessage()); - } - return openCellSet; - } - - public CellSet executeOlapQuery(SelectNode selectNode) throws OlapException { - final String mdx = toString(selectNode); - return executeOlapQuery(mdx); - } - - /** - * Converts a {@link org.olap4j.mdx.ParseTreeNode} to MDX string. - * - * @param node Parse tree node - * @return MDX text - */ - private static String toString(ParseTreeNode node) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - ParseTreeWriter parseTreeWriter = new ParseTreeWriter(pw); - node.unparse(parseTreeWriter); - pw.flush(); - return sw.toString(); - } -} - -// End MondrianOlap4jStatement.java diff --git a/src/mondrian/olap4j/package.html b/src/mondrian/olap4j/package.html deleted file mode 100755 index 08b40b7..0000000 --- a/src/mondrian/olap4j/package.html +++ /dev/null @@ -1,5 +0,0 @@ - - -olap4j driver for the Mondrian OLAP engine. - - diff --git a/testsrc/org/olap4j/ConnectionTest.java b/testsrc/org/olap4j/ConnectionTest.java index f29e00b..604c145 100644 --- a/testsrc/org/olap4j/ConnectionTest.java +++ b/testsrc/org/olap4j/ConnectionTest.java @@ -237,9 +237,20 @@ public void testConnectionUnwrap() throws SQLException { // Unwrap the mondrian connection. switch (tester.getFlavor()) { case MONDRIAN: - final mondrian.olap.Connection mondrianConnection = - ((OlapWrapper) connection).unwrap(mondrian.olap.Connection.class); + // mondrian.olap.Connection does not extend java.sql.Connection + // but we should be able to unwrap it regardless + final Class mondrianConnectionClass; + try { + mondrianConnectionClass = + Class.forName("mondrian.olap.Connection"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + final Object mondrianConnection = + ((OlapWrapper) connection).unwrap( + mondrianConnectionClass); assertNotNull(mondrianConnection); + assert mondrianConnectionClass.isInstance(mondrianConnection); } } diff --git a/testsrc/org/olap4j/XmlaTester.java b/testsrc/org/olap4j/XmlaTester.java index 185459d..7bfdf4f 100644 --- a/testsrc/org/olap4j/XmlaTester.java +++ b/testsrc/org/olap4j/XmlaTester.java @@ -8,17 +8,13 @@ */ package org.olap4j; -import mondrian.tui.XmlaSupport; import org.olap4j.driver.xmla.XmlaOlap4jDriver; import org.olap4j.test.TestContext; -import org.xml.sax.SAXException; -import javax.servlet.ServletException; -import java.io.IOException; -import java.net.URL; import java.sql.*; import java.util.*; -import java.util.concurrent.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; /** * Implementation of {@link org.olap4j.test.TestContext.Tester} which speaks @@ -28,8 +24,30 @@ * @version $Id$ */ public class XmlaTester implements TestContext.Tester { - XmlaOlap4jDriver.Proxy proxy = - new MondrianInprocProxy(); + final XmlaOlap4jDriver.Proxy proxy; + + public XmlaTester() + throws ClassNotFoundException, IllegalAccessException, + InstantiationException, NoSuchMethodException, + InvocationTargetException + { + final Properties properties = TestContext.getTestProperties(); + final String catalogUrl = + properties.getProperty( + "org.olap4j.XmlaTester.CatalogUrl"); + Map catalogNameUrls = + new HashMap(); + catalogNameUrls.put("FoodMart", catalogUrl); + String urlString = + properties.getProperty("org.olap4j.test.connectUrl"); + + final Class clazz = Class.forName("mondrian.olap4j.MondrianInprocProxy"); + final Constructor constructor = + clazz.getConstructor(Map.class, String.class); + this.proxy = + (XmlaOlap4jDriver.Proxy) constructor.newInstance( + catalogNameUrls, urlString); + } public Connection createConnection() throws SQLException { try { @@ -92,58 +110,6 @@ public Flavor getFlavor() { public static final String DRIVER_URL_PREFIX = "jdbc:xmla:"; private static final String USER = "user"; private static final String PASSWORD = "password"; - - /** - * Proxy which implements XMLA requests by talking to mondrian - * in-process. This is more convenient to debug than an inter-process - * request using HTTP. - */ - private static class MondrianInprocProxy - implements XmlaOlap4jDriver.Proxy - { - // Use single-threaded executor for ease of debugging. - private static final ExecutorService singleThreadExecutor = - Executors.newSingleThreadExecutor(); - - public byte[] get(URL url, String request) throws IOException { - try { - final Properties properties = TestContext.testProperties; - final String catalogUrl = - properties.getProperty( - "org.olap4j.XmlaTester.CatalogUrl"); - Map catalogNameUrls = - new HashMap(); - catalogNameUrls.put("FoodMart", catalogUrl); - String urlString = - properties.getProperty("org.olap4j.test.connectUrl"); - if (!urlString.startsWith("jdbc:mondrian:")) { - throw new IllegalArgumentException(); - } - urlString = urlString.substring("jdbc:mondrian:".length()); - return XmlaSupport.processSoapXmla( - request, urlString, catalogNameUrls, null); - } catch (ServletException e) { - throw new RuntimeException( - "Error while reading '" + url + "'", e); - } catch (SAXException e) { - throw new RuntimeException( - "Error while reading '" + url + "'", e); - } - } - - public Future submit( - final URL url, - final String request) - { - return singleThreadExecutor.submit( - new Callable() { - public byte[] call() throws Exception { - return get(url, request); - } - } - ); - } - } } // End XmlaTester.java diff --git a/testsrc/org/olap4j/impl/ConnectStringParserTest.java b/testsrc/org/olap4j/impl/ConnectStringParserTest.java index 772c7d8..a510e82 100644 --- a/testsrc/org/olap4j/impl/ConnectStringParserTest.java +++ b/testsrc/org/olap4j/impl/ConnectStringParserTest.java @@ -13,7 +13,7 @@ import java.util.*; /** - * Tests for methods in {@link mondrian.olap.Util}. + * Unit test for {@link org.olap4j.impl.ConnectStringParser}. * * @version $Id: $ * @author jhyde diff --git a/testsrc/org/olap4j/test/TestContext.java b/testsrc/org/olap4j/test/TestContext.java index b9d5a99..9479e2e 100644 --- a/testsrc/org/olap4j/test/TestContext.java +++ b/testsrc/org/olap4j/test/TestContext.java @@ -18,10 +18,10 @@ import org.olap4j.metadata.Member; import org.olap4j.*; +import org.olap4j.impl.Olap4jUtil; import org.olap4j.mdx.ParseTreeNode; import org.olap4j.mdx.ParseTreeWriter; import junit.framework.ComparisonFailure; -import mondrian.olap.Util; /** * Context for olap4j tests. @@ -243,8 +243,8 @@ static String toJavaString(String s) { // into ["string with \"quotes\" split\n" + // "across lines // - s = Util.replace(s, "\\", "\\\\"); - s = Util.replace(s, "\"", "\\\""); + s = Olap4jUtil.replace(s, "\\", "\\\\"); + s = Olap4jUtil.replace(s, "\"", "\\\""); s = LineBreakPattern.matcher(s).replaceAll(lineBreak2); s = TabPattern.matcher(s).replaceAll("\\\\t"); s = "\"" + s + "\"";