[teiid-commits] teiid SVN: r2874 - in trunk: build/kits/jboss-container/teiid-examples/jca and 11 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Mon Jan 24 17:33:44 EST 2011
Author: rareddy
Date: 2011-01-24 17:33:44 -0500 (Mon, 24 Jan 2011)
New Revision: 2874
Added:
trunk/build/kits/jboss-container/teiid-examples/jca/mondrian-ds.xml
trunk/connectors/translator-olap/
trunk/connectors/translator-olap/pom.xml
trunk/connectors/translator-olap/src/
trunk/connectors/translator-olap/src/main/
trunk/connectors/translator-olap/src/main/java/
trunk/connectors/translator-olap/src/main/java/org/
trunk/connectors/translator-olap/src/main/java/org/teiid/
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java
trunk/connectors/translator-olap/src/main/resources/
trunk/connectors/translator-olap/src/main/resources/META-INF/
trunk/connectors/translator-olap/src/main/resources/META-INF/jboss-beans.xml
Modified:
trunk/build/assembly/jboss-container/dist.xml
Log:
TEIID-1011: initial check in for mondrian olap as the source to the Teiid.
Modified: trunk/build/assembly/jboss-container/dist.xml
===================================================================
--- trunk/build/assembly/jboss-container/dist.xml 2011-01-24 19:30:06 UTC (rev 2873)
+++ trunk/build/assembly/jboss-container/dist.xml 2011-01-24 22:33:44 UTC (rev 2874)
@@ -184,6 +184,7 @@
<include>org.jboss.teiid.connectors:translator-ldap</include>
<include>org.jboss.teiid.connectors:translator-salesforce</include>
<include>org.jboss.teiid.connectors:translator-ws</include>
+ <include>org.jboss.teiid.connectors:translator-olap</include>
</includes>
<binaries>
Added: trunk/build/kits/jboss-container/teiid-examples/jca/mondrian-ds.xml
===================================================================
--- trunk/build/kits/jboss-container/teiid-examples/jca/mondrian-ds.xml (rev 0)
+++ trunk/build/kits/jboss-container/teiid-examples/jca/mondrian-ds.xml 2011-01-24 22:33:44 UTC (rev 2874)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<datasources>
+ <local-tx-datasource>
+ <jndi-name>mondrianDS</jndi-name>
+ <!-- note here that you need to also create datasource for source, this is for mondrian as source for teiid -->
+ <connection-url>jdbc:mondrian:Provider=Mondrian;DataSource=java:foodmart;Catalog=${jboss.server.home.dir}/deploy/mondrian.war/WEB-INF/queries/FoodMart.xml;</connection-url>
+ <driver-class>mondrian.olap4j.MondrianOlap4jDriver</driver-class>
+ <user-name>user</user-name>
+ <password>password</password>
+ <min-pool-size>5</min-pool-size>
+ <max-pool-size>20</max-pool-size>
+ </local-tx-datasource>
+</datasources>
\ No newline at end of file
Property changes on: trunk/build/kits/jboss-container/teiid-examples/jca/mondrian-ds.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Property changes on: trunk/connectors/translator-olap
___________________________________________________________________
Name: svn:ignore
+ .settings
target
.project
.classpath
Added: trunk/connectors/translator-olap/pom.xml
===================================================================
--- trunk/connectors/translator-olap/pom.xml (rev 0)
+++ trunk/connectors/translator-olap/pom.xml 2011-01-24 22:33:44 UTC (rev 2874)
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>connectors</artifactId>
+ <groupId>org.jboss.teiid</groupId>
+ <version>7.4.0.Alpha1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>translator-olap</artifactId>
+ <groupId>org.jboss.teiid.connectors</groupId>
+ <name>OLAP Translator</name>
+ <description>This translator provides access to Query Analysis Cubes</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.olap4j</groupId>
+ <artifactId>olap4j</artifactId>
+ <version>0.9.8.343</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <outputDirectory>target/classes</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.properties</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>false</filtering>
+ <excludes>
+ <exclude>**/*.xml</exclude>
+ <exclude>**/*.properties</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ </build>
+
+</project>
Added: trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java
===================================================================
--- trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java (rev 0)
+++ trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java 2011-01-24 22:33:44 UTC (rev 2874)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.olap;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.olap4j.OlapConnection;
+import org.olap4j.OlapWrapper;
+import org.teiid.language.Call;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.Procedure;
+import org.teiid.metadata.ProcedureParameter;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.BaseColumn.NullType;
+import org.teiid.metadata.ProcedureParameter.Type;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.ProcedureExecution;
+import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
+import org.teiid.translator.TypeFacility;
+
+ at Translator(name="olap", description="A translator for OLAP Cubes")
+public class OlapExecutionFactory extends ExecutionFactory<DataSource, Connection> {
+ private static final String INVOKE_MDX = "invokeMdx"; //$NON-NLS-1$
+
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory, Connection conn) throws TranslatorException {
+ Procedure p = metadataFactory.addProcedure(INVOKE_MDX);
+ p.setAnnotation("Invokes a XMLA webservice with provided MDX query that returns an XML result"); //$NON-NLS-1$
+
+ // mdx query in xml form
+ ProcedureParameter param = metadataFactory.addProcedureParameter("request", TypeFacility.RUNTIME_NAMES.STRING, Type.In, p); //$NON-NLS-1$
+ param.setAnnotation("The MDX query to execute"); //$NON-NLS-1$
+ param.setNullType(NullType.Nullable);
+
+ metadataFactory.addProcedureParameter("result", TypeFacility.RUNTIME_NAMES.XML, Type.ReturnValue, p); //$NON-NLS-1$
+ }
+
+ @Override
+ public ProcedureExecution createProcedureExecution(Call command, ExecutionContext executionContext, RuntimeMetadata metadata, Connection connection) throws TranslatorException {
+ return new OlapQueryExecution(command, unwrap(connection), executionContext, this);
+ }
+
+ private OlapConnection unwrap(Connection conn) throws TranslatorException {
+ try {
+ OlapWrapper wrapper = conn.unwrap(OlapWrapper.class);
+ OlapConnection olapConn = wrapper.unwrap(OlapConnection.class);
+ return olapConn;
+ } catch(SQLException e) {
+ throw new TranslatorException(e);
+ }
+ }
+
+ @Override
+ public Connection getConnection(DataSource ds)
+ throws TranslatorException {
+ try {
+ return ds.getConnection();
+ } catch (SQLException e) {
+ throw new TranslatorException(e);
+ }
+ }
+
+ @Override
+ public void closeConnection(Connection connection, DataSource factory) {
+ if (connection == null) {
+ return;
+ }
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Error closing"); //$NON-NLS-1$
+ }
+ }
+}
Added: trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java
===================================================================
--- trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java (rev 0)
+++ trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java 2011-01-24 22:33:44 UTC (rev 2874)
@@ -0,0 +1,207 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.translator.olap;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.olap4j.Axis;
+import org.olap4j.Cell;
+import org.olap4j.CellSet;
+import org.olap4j.CellSetAxis;
+import org.olap4j.OlapConnection;
+import org.olap4j.OlapStatement;
+import org.olap4j.Position;
+import org.olap4j.metadata.Member;
+import org.teiid.language.Argument;
+import org.teiid.language.Call;
+import org.teiid.language.Command;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.ProcedureExecution;
+import org.teiid.translator.TranslatorException;
+
+ at SuppressWarnings("nls")
+public class OlapQueryExecution implements ProcedureExecution {
+
+ protected Command command;
+ protected OlapConnection connection;
+ protected ExecutionContext context;
+ protected OlapExecutionFactory executionFactory;
+ private OlapStatement stmt;
+ private Source returnValue;
+
+
+ public OlapQueryExecution(Command command, OlapConnection connection, ExecutionContext context, OlapExecutionFactory executionFactory) {
+ this.command = command;
+ this.connection = connection;
+ this.context = context;
+ this.executionFactory = executionFactory;
+ }
+
+ @Override
+ public void execute() throws TranslatorException {
+ try {
+ Call procedure = (Call) this.command;
+ List<Argument> arguments = procedure.getArguments();
+ String mdxQuery = (String) arguments.get(0).getArgumentValue().getValue();
+ OlapStatement stmt = this.connection.createStatement();
+
+ CellSet cellSet = stmt.executeOlapQuery(mdxQuery);
+ this.returnValue = new StreamSource(new MdxResultsReader(cellSet));
+
+
+ } catch (SQLException e) {
+ throw new TranslatorException(e);
+ }
+ }
+
+ @Override
+ public void cancel() throws TranslatorException {
+ try {
+ if (this.stmt != null) {
+ this.stmt.cancel();
+ }
+ } catch (SQLException e) {
+ throw new TranslatorException(e);
+ }
+ }
+
+ @Override
+ public synchronized void close() {
+ try {
+ if (this.stmt != null) {
+ this.stmt.close();
+ this.stmt = null;
+ }
+ } catch (SQLException e) {
+ LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Exception closing"); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public List<?> next() throws TranslatorException {
+ return null;
+ }
+
+ @Override
+ public List<?> getOutputParameterValues() throws TranslatorException {
+ return Arrays.asList(this.returnValue);
+ }
+
+ static class MdxResultsReader extends Reader {
+ private CellSet cellSet;
+ private ListIterator<Position> rows;
+ private Position nextRow;
+ private boolean closed = false;
+ private char[] buffer;
+ private int index = 0;
+
+ public MdxResultsReader(CellSet cellSet) {
+ this.cellSet = cellSet;
+ CellSetAxis rowAxis = cellSet.getAxes().get(Axis.ROWS.axisOrdinal());
+ this.rows = rowAxis.iterator();
+ if (this.rows.hasNext()) {
+ this.nextRow = this.rows.next();
+ this.buffer = "<resultset>".toCharArray();
+ }
+ }
+
+ private String readNextRow() {
+ if (this.nextRow == null) {
+ return null;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ CellSetAxis cols = cellSet.getAxes().get(Axis.COLUMNS.axisOrdinal());
+ sb.append("<row>");
+
+ // add in rows axis
+ List<Member> members = nextRow.getMembers();
+ for (Member member:members) {
+ String columnName = member.getHierarchy().getName();
+ columnName = columnName.replace(' ', '_');
+ sb.append('<').append(columnName).append('>');
+ sb.append(member.getName());
+ sb.append("</").append(columnName).append('>');
+ }
+
+ // add col axis
+ for (Position colPos : cols) {
+ Cell cell = cellSet.getCell(colPos, nextRow);
+ String columnName = colPos.getMembers().get(0).getName();
+ columnName = columnName.replace(' ', '_');
+ sb.append('<').append(columnName).append('>');
+ sb.append(cell.getValue());
+ sb.append("</").append(columnName).append('>');
+ }
+ sb.append("</row>");
+
+ // advance the cursor to next row.
+ if (this.rows.hasNext()) {
+ this.nextRow = this.rows.next();
+ }
+ else {
+ this.nextRow = null;
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ @Override
+ public int read(char[] cbuf, int off, int len) throws IOException {
+ int availble = this.buffer.length - this.index;
+ if (availble == 0) {
+ String next = readNextRow();
+ if (next == null) {
+ if (!this.closed) {
+ this.buffer = "</resultset>".toCharArray();
+ this.closed = true;
+ }
+ else {
+ return -1;
+ }
+ }
+ else {
+ this.buffer = next.toCharArray();
+ }
+ this.index = 0;
+ availble = this.buffer.length;
+ }
+ len = (availble > len) ? len : availble;
+ System.arraycopy(this.buffer, this.index, cbuf, off, len);
+ this.index = this.index + len;
+ return len;
+ }
+ }
+}
Added: trunk/connectors/translator-olap/src/main/resources/META-INF/jboss-beans.xml
===================================================================
--- trunk/connectors/translator-olap/src/main/resources/META-INF/jboss-beans.xml (rev 0)
+++ trunk/connectors/translator-olap/src/main/resources/META-INF/jboss-beans.xml 2011-01-24 22:33:44 UTC (rev 2874)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <!-- OLAP -->
+ <bean name="translator-olap-template" class="org.teiid.templates.TranslatorDeploymentTemplate">
+ <property name="info"><inject bean="translator-olap" /> </property>
+ <property name="managedObjectFactory"> <inject bean="ManagedObjectFactory" /> </property>
+ </bean>
+
+ <bean name="translator-olap" class="org.teiid.templates.TranslatorTemplateInfo">
+ <constructor factoryMethod="createTemplateInfo">
+ <factory bean="TranslatorDeploymentTemplateInfoFactory" />
+ <parameter class="java.lang.Class">org.teiid.templates.TranslatorTemplateInfo</parameter>
+ <parameter class="java.lang.Class">org.teiid.translator.olap.OlapExecutionFactory</parameter>
+ <parameter class="java.lang.String">translator-olap</parameter>
+ <parameter class="java.lang.String">olap</parameter>
+ </constructor>
+ </bean>
+</deployment>
More information about the teiid-commits
mailing list