diff --git a/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/create-ucanaccess-ds.cli b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/create-ucanaccess-ds.cli new file mode 100644 index 0000000000..e8f8438cb1 --- /dev/null +++ b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/create-ucanaccess-ds.cli @@ -0,0 +1,9 @@ +# The value of 'driver-module-name' match to the ucanaccess driver module added in JBoss server +/subsystem=datasources/jdbc-driver=ucanaccess:add(driver-name=ucanaccess,driver-module-name=net.ucanaccess,driver-class-name=net.ucanaccess.jdbc.UcanaccessDriver) + +/subsystem=datasources/data-source=ucanaccessDS:add(jndi-name=java:/ucanaccessDS, driver-name=ucanaccess, enabled=true,use-java-context=true, connection-url=jdbc:ucanaccess://{},user-name={user}, password={password}) + +/subsystem=datasources/data-source=ucanaccessDS:test-connection-in-pool() + +## If you are working in a clustered environment, prepend "/profile=ha" to all the above commands that start with "/subsystem=.." + diff --git a/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/modules/net/ucanaccess/main/module.xml b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/modules/net/ucanaccess/main/module.xml new file mode 100644 index 0000000000..a32f1bf37e --- /dev/null +++ b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/modules/net/ucanaccess/main/module.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/readme.txt b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/readme.txt new file mode 100644 index 0000000000..2aaa57156d --- /dev/null +++ b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/readme.txt @@ -0,0 +1,28 @@ +There are two parts to creating a datasource, depending upon whether this is the first time you are doing this, +you can skip the deploying JDBC driver for the database, if you have previously already done this. + +Note that all instances of [version] should be replaced by the appropriate ucanaccess and it's dependency version. + +Step 1: Installing the Driver Module + + 1) Download ucanaccess 2.0.9.4 or later(https://sourceforge.net/projects/ucanaccess/files/) + + 2) Overlay the "modules" directory on the "/modules" directory + + 3) Unzip 1) will get 5 jars(ucanaccess-[version].jar,hsqldb.jar,jackcess-[version].jar,commons-lang-[version].jar,commons-logging-[version].jar), copy all these jars into the "/modules/org/apache/phoenix/main" directory. + + 4) Start server + +Step 2: Creating the datasource + + Option 1: Edit the standalone-teiid.xml or domain-teiid.xml file and add contents of the "ucanaccess.xml" + file under the "datasources" subsystem. You may have to edit contents according to where your Access File + is located and credentials you need to use to access it. + + Option 2: Take a look at create-ucanaccess-ds.cli script, and modify and execute using JBoss CLI tool as below + + ./bin/jboss-cli.sh --connect --file=create-ucanaccess-ds.cli + + Option 3: Deploy ucanaccess-ds.xml file. You may have to edit contents according to where your Access File + is located and credentials you need to use to access it. + diff --git a/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/ucanaccess-ds.xml b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/ucanaccess-ds.xml new file mode 100644 index 0000000000..7386e625c3 --- /dev/null +++ b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/ucanaccess-ds.xml @@ -0,0 +1,16 @@ + + + + jdbc:ucanaccess://{} + ucanaccess + + {user} + {password} + + + + + net.ucanaccess.jdbc.UcanaccessDriver + + + diff --git a/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/ucanaccess.xml b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/ucanaccess.xml new file mode 100644 index 0000000000..f5c3f59bd0 --- /dev/null +++ b/build/kits/jboss-as7/docs/teiid/datasources/ucanaccess/ucanaccess.xml @@ -0,0 +1,21 @@ + + + + + + jdbc:ucanaccess://{} + ucanaccess + + {user} + {password} + + + + + net.ucanaccess.jdbc.UcanaccessDriver + + + + + + diff --git a/connectors/translator-jdbc/pom.xml b/connectors/translator-jdbc/pom.xml index 9349c617b5..db9a49a1b9 100644 --- a/connectors/translator-jdbc/pom.xml +++ b/connectors/translator-jdbc/pom.xml @@ -36,22 +36,7 @@ org.hibernate hibernate-core provided - - - org.jboss.teiid - teiid-runtime - test - - - org.jboss.teiid - teiid-client - test - - - org.codehaus.btm - btm - test - + diff --git a/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ucanaccess/UCanAccessExecutionFactory.java b/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ucanaccess/UCanAccessExecutionFactory.java index 991b02c77b..2cf7bbe8f0 100644 --- a/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ucanaccess/UCanAccessExecutionFactory.java +++ b/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ucanaccess/UCanAccessExecutionFactory.java @@ -1,3 +1,24 @@ +/* + * 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.jdbc.ucanaccess; @@ -21,6 +42,8 @@ @Translator(name="ucanaccess", description="A translator for read/write Microsoft Access Database") public class UCanAccessExecutionFactory extends HsqlExecutionFactory { + public static final String UCANACCESS = "ucanaccess"; //$NON-NLS-1$ + public UCanAccessExecutionFactory() { setSupportsOrderBy(true); setMaxInCriteriaSize(JDBCExecutionFactory.DEFAULT_MAX_IN_CRITERIA); @@ -31,7 +54,13 @@ public UCanAccessExecutionFactory() { public void start() throws TranslatorException { super.start(); - addPushDownFunction("ucanaccess", "DCount", TypeFacility.RUNTIME_NAMES.BIG_INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); + addPushDownFunction(UCANACCESS, "DCount", TypeFacility.RUNTIME_NAMES.BIG_INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); + addPushDownFunction(UCANACCESS, "DSum", TypeFacility.RUNTIME_NAMES.BIG_INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); + addPushDownFunction(UCANACCESS, "DMax", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); + addPushDownFunction(UCANACCESS, "DMin", TypeFacility.RUNTIME_NAMES.BIG_INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); + addPushDownFunction(UCANACCESS, "DAvg", TypeFacility.RUNTIME_NAMES.BIG_INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); + addPushDownFunction(UCANACCESS, "DFirst", TypeFacility.RUNTIME_NAMES.OBJECT, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); + addPushDownFunction(UCANACCESS, "DLast", TypeFacility.RUNTIME_NAMES.OBJECT, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING); } @Override @@ -83,11 +112,6 @@ public InputStream getInputStream() throws IOException { return super.retrieveValue(results, columnIndex, expectedType); } - - @Override - public String getHibernateDialectClassName() { - throw new IllegalStateException("UCanAccess Dialect not set"); //$NON-NLS-1$ - } @Override public boolean supportsDependentJoins() { diff --git a/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ucanaccess/TestUCanAccessTranslator.java b/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ucanaccess/TestUCanAccessTranslator.java index 38b801feba..79c94ed534 100644 --- a/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ucanaccess/TestUCanAccessTranslator.java +++ b/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/ucanaccess/TestUCanAccessTranslator.java @@ -1,241 +1,71 @@ +/* + * 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.jdbc.ucanaccess; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.HashSet; -import java.util.Set; - -import javax.naming.Context; -import javax.transaction.TransactionManager; - -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.teiid.core.util.SimpleMock; -import org.teiid.deployers.VirtualDatabaseException; -import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException; -import org.teiid.runtime.EmbeddedConfiguration; -import org.teiid.runtime.EmbeddedServer; import org.teiid.translator.TranslatorException; - -import bitronix.tm.resource.jdbc.PoolingDataSource; +import org.teiid.translator.jdbc.TranslationHelper; public class TestUCanAccessTranslator { - public static void main(String[] args) throws VirtualDatabaseException, TranslatorException, ConnectorManagerException, FileNotFoundException, IOException, SQLException { - init(); - executeQuery(conn, "SELECT * FROM DATATYPE_TEST"); - } - - static Connection conn = null; + private static UCanAccessExecutionFactory TRANSLATOR; @BeforeClass - public static void init() throws TranslatorException, VirtualDatabaseException, ConnectorManagerException, FileNotFoundException, IOException, SQLException { - - System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "bitronix.tm.jndi.BitronixInitialContextFactory"); - - EmbeddedServer server = new EmbeddedServer(); - - UCanAccessExecutionFactory executionFactory = new UCanAccessExecutionFactory(); - executionFactory.start(); - server.addTranslator("translator-ucanaccess", executionFactory); - - setupTestDataSource(); - - EmbeddedConfiguration config = new EmbeddedConfiguration(); - config.setTransactionManager(SimpleMock.createSimpleMock(TransactionManager.class)); - server.start(config); - server.deployVDB(new FileInputStream(new File("src/test/resources/ucanaccess/vdb.xml"))); - conn = server.getDriver().connect("jdbc:teiid:UCanAccessVDB", null); - } - - @Test - public void testInsert() throws SQLException { - executeUpdate(conn, "INSERT INTO T21 VALUES(100, 't')"); - executeQuery(conn, "SELECT * FROM T21"); - executeUpdate(conn, "DELETE FROM T21 WHERE ID = 100"); - } - - @Test - public void testMetadata() throws SQLException { - - Set nameSet = new HashSet(); - DatabaseMetaData databaseMetaData = conn.getMetaData(); - - ResultSet result = databaseMetaData.getTables("UCanAccessVDB", "TestData", null, null ); - while(result.next()) { - String tableName = result.getString(3); - nameSet.add(tableName); - } - - result = databaseMetaData.getTables("UCanAccessVDB", "TestUCanAccess", null, null ); - while(result.next()) { - String tableName = result.getString(3); - nameSet.add(tableName); - } - - close(result, null); - - assertEquals(6, nameSet.size()); - assertTrue(nameSet.contains("EmpDataView")); - assertTrue(nameSet.contains("EMPDATA")); - assertTrue(nameSet.contains("EMPDATA_TEST")); - assertTrue(nameSet.contains("T20")); - assertTrue(nameSet.contains("T21")); - assertTrue(nameSet.contains("T21View")); - -// assertTrue(nameSet.contains("")); - + public static void setup() throws TranslatorException { + TRANSLATOR = new UCanAccessExecutionFactory(); + TRANSLATOR.start(); } @Test - public void testSelect() throws SQLException { - executeQuery(conn, "SELECT * FROM EMPDATA"); - executeQuery(conn, "SELECT * FROM EMPDATA_TEST"); - executeQuery(conn, "SELECT * FROM EmpDataView"); + public void testPushDownFuctions() throws TranslatorException { - executeQuery(conn, "SELECT * FROM DATATYPE_TEST"); + String input = "SELECT ucanaccess.DCount('*','T20','id > 100') FROM BQT1.MediumA"; //$NON-NLS-1$ + String output = "SELECT DCount('*', 'T20', 'id > 100') FROM MediumA"; //$NON-NLS-1$ + TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR); - try { - JDBCUtil.printTableColumn(conn, "SELECT * FROM DATATYPE_TEST"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + input = "SELECT ucanaccess.DSum('id','T20','id > 100')"; //$NON-NLS-1$ + output = "SELECT DSum('id', 'T20', 'id > 100')"; //$NON-NLS-1$ + TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR); -// executeQuery(conn, ""); - } - - @Test - public void testFunctions() throws SQLException { - executeQuery(conn, "SELECT ASCII('A') FROM T20"); - executeQuery(conn, "SELECT CURDATE() FROM T20"); - executeQuery(conn, "SELECT CURTIME() FROM T20"); - - } - - @Test - public void testAccessLike() throws SQLException { - executeQuery(conn, "SELECT * FROM T21 ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21 WHERE DESCR = 'aba' ORDER BY ID DESC"); - executeQuery(conn, "select * from T21 WHERE DESCR like 'a*a' ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21 WHERE DESCR like 'a*a' AND '1'='1' ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21 WHERE DESCR like 'a%a' ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21 WHERE DESCR like 'a%a' AND '1'='1' ORDER BY ID DESC"); - - executeQuery(conn, "SELECT * FROM T21View ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21View WHERE DESCR = 'aba' ORDER BY ID DESC"); - executeQuery(conn, "select * from T21View WHERE DESCR like 'a*a' ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21View WHERE DESCR like 'a*a' AND '1'='1' ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21View WHERE DESCR like 'a%a' ORDER BY ID DESC"); - executeQuery(conn, "SELECT * FROM T21View WHERE DESCR like 'a%a' AND '1'='1' ORDER BY ID DESC"); - - } - - @Test - public void testAggregateFunctions() throws SQLException { - - executeQuery(conn, "SELECT * FROM T20"); - executeQuery(conn, "SELECT COUNT(*) FROM T20"); - executeQuery(conn, "SELECT COUNT(ID) FROM T20"); - executeQuery(conn, "SELECT SUM(ID) FROM T20"); - executeQuery(conn, "SELECT AVG(ID) FROM T20"); - executeQuery(conn, "SELECT MIN(ID) FROM T20"); - executeQuery(conn, "SELECT MAX(ID) FROM T20"); + input = "SELECT ucanaccess.DMax('id', 'T20')"; //$NON-NLS-1$ + output = "SELECT DMax('id', 'T20')"; //$NON-NLS-1$ + TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR); - } - - private static void setupTestDataSource() { + input = "SELECT ucanaccess.DMin('id', 'T20')"; //$NON-NLS-1$ + output = "SELECT DMin('id', 'T20')"; //$NON-NLS-1$ + TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR); - PoolingDataSource pds = new PoolingDataSource(); - pds.setUniqueName("java:/UCanAccessDS"); - pds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource"); - pds.setMaxPoolSize(5); - pds.setAllowLocalTransactions(true); - pds.getDriverProperties().put("user", ""); - pds.getDriverProperties().put("password", ""); - pds.getDriverProperties().put("url", "jdbc:ucanaccess://src/test/resources/ucanaccess/ODBCTesting.accdb"); - pds.getDriverProperties().put("driverClassName", "net.ucanaccess.jdbc.UcanaccessDriver"); - pds.init(); + input = "SELECT ucanaccess.DAvg('id', 'T20')"; //$NON-NLS-1$ + output = "SELECT DAvg('id', 'T20')"; //$NON-NLS-1$ + TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR); - } - - static void executeQuery(Connection conn, String sql) throws SQLException { + input = "SELECT ucanaccess.DFirst('descr', 'T20')"; //$NON-NLS-1$ + output = "SELECT DFirst('descr', 'T20')"; //$NON-NLS-1$ + TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR); - System.out.println("Query: " + sql); - - Statement stmt = null; - ResultSet rs = null; - - try { - stmt = conn.createStatement(); - rs = stmt.executeQuery(sql); - ResultSetMetaData metadata = rs.getMetaData(); - int columns = metadata.getColumnCount(); - for (int row = 1; rs.next(); row++) { - System.out.print(row + ": "); - for (int i = 0; i < columns; i++) { - if (i > 0) { - System.out.print(", "); - } - System.out.print(rs.getObject(i + 1)); - } - System.out.println(); - } - } finally { - close(rs, stmt); - } - - System.out.println(); - - } - - static boolean executeUpdate(Connection conn, String sql) throws SQLException { - Statement stmt = null; - try { - stmt = conn.createStatement(); - stmt.executeUpdate(sql); - } finally { - close(null, stmt); - } - return true; - } - - static void close(ResultSet rs, Statement stmt) { - - if (null != rs) { - try { - rs.close(); - rs = null; - } catch (SQLException e) { - } - } - - if(null != stmt) { - try { - stmt.close(); - stmt = null; - } catch (SQLException e) { - } - } - } - - @AfterClass - public static void destory() throws SQLException{ - if(null != conn){ - conn.close(); - } + input = "SELECT ucanaccess.DLast('descr', 'T20')"; //$NON-NLS-1$ + output = "SELECT DLast('descr', 'T20')"; //$NON-NLS-1$ + TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR); } } diff --git a/connectors/translator-jdbc/src/test/resources/ucanaccess/ODBCTesting.accdb b/connectors/translator-jdbc/src/test/resources/ucanaccess/ODBCTesting.accdb deleted file mode 100644 index f73eda0ad2..0000000000 Binary files a/connectors/translator-jdbc/src/test/resources/ucanaccess/ODBCTesting.accdb and /dev/null differ diff --git a/connectors/translator-jdbc/src/test/resources/ucanaccess/vdb.xml b/connectors/translator-jdbc/src/test/resources/ucanaccess/vdb.xml deleted file mode 100644 index a49b57de20..0000000000 --- a/connectors/translator-jdbc/src/test/resources/ucanaccess/vdb.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - The UCanAccess Translator Test VDB - - - - - - - - - - - - - 100') FROM T20; - - ]]> - -