teiid SVN: r1155 - in trunk: client/src/main/java/com/metamatrix/common/comm/api and 6 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2009-07-20 13:46:42 -0400 (Mon, 20 Jul 2009)
New Revision: 1155
Added:
trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java
Modified:
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java
trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java
trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties
trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java
trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java
Log:
TEIID-725: Providing a mechanism in the "embedded" mode is shutdown the instance. This is similar to how derby does the "embedded" shutdown.
Modified: trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client/src/main/java/com/metamatrix/common/api/MMURL.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -32,7 +32,7 @@
import com.metamatrix.common.comm.platform.CommPlatformPlugin;
/**
- * Class to encapsulate URL to a Clustered Metamatrix Server with multiple host
+ * Class defines the URL in the Teiid.
*
* @since 4.2
*/
@@ -62,6 +62,12 @@
* A plugable discovery strategy for the client. Defaults to using the AdminApi.
*/
public static final String DISCOVERY_STRATEGY = "discoveryStategy"; //$NON-NLS-1$
+
+ /**
+ * if "true" in the embedded mode if there is a active instance that instance will be shutdown.
+ */
+ public static final String SHUTDOWN = "shutdown"; //$NON-NLS-1$
+
public static final String SERVER_URL = "serverURL"; //$NON-NLS-1$
/**
* Non-secure MetaMatrix Protocol.
Modified: trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client/src/main/java/com/metamatrix/common/comm/api/ServerConnectionFactory.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -24,9 +24,6 @@
import java.util.Properties;
-import org.teiid.adminapi.Admin;
-import org.teiid.adminapi.AdminException;
-
import com.metamatrix.common.comm.exception.CommunicationException;
import com.metamatrix.common.comm.exception.ConnectionException;
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/EmbeddedDataSource.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -27,6 +27,7 @@
import java.sql.SQLException;
import java.util.Properties;
+import com.metamatrix.common.api.MMURL;
import com.metamatrix.common.protocol.URLHelper;
/**
@@ -45,6 +46,8 @@
// string constant for the embedded configuration file property
public static final String DQP_BOOTSTRAP_FILE = "bootstrapFile"; //$NON-NLS-1$
+ public static final String SHUTDOWN = MMURL.CONNECTION.SHUTDOWN;
+
// The driver used to connect
private final transient EmbeddedDriver driver = new EmbeddedDriver();
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMSQLException.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -56,6 +56,14 @@
super();
}
+ public MMSQLException(String reason) {
+ super(reason, SQLStates.DEFAULT);
+ }
+
+ public MMSQLException(String reason, String state) {
+ super(reason, state);
+ }
+
public static MMSQLException create(Throwable exception) {
if (exception instanceof MMSQLException) {
return (MMSQLException)exception;
@@ -63,6 +71,39 @@
return create(exception, exception.getMessage());
}
+ /**
+ * Constructor used to wrap metamatrix exceptions into MMSQLExceptions.
+ * @param reason String object which is the description of the exception.
+ * @param ex Throwable object which needs to be wrapped.
+ */
+ public MMSQLException(Throwable ex, String reason, String sqlState) {
+ super(reason, sqlState); // passing the message to the super class constructor.
+ initCause(ex);
+ }
+
+ /**
+ * Constructor used to wrap or copy a SQLException into a MMSQLException
+ * @see com.metamatrix.common.util.exception.SQLEXceptionUnroller
+ * @param ex
+ * @param message
+ * @param addChildren
+ */
+ private MMSQLException(SQLException ex, String message, boolean addChildren) {
+ super(message, ex.getSQLState() == null ? SQLStates.DEFAULT : ex.getSQLState(), ex.getErrorCode());
+
+ if (addChildren) {
+ SQLException childException = ex; // this a child to the SQLException constructed from reason
+
+ while (childException != null) {
+ if (childException instanceof MMSQLException) {
+ super.setNextException(ex);
+ break;
+ }
+ super.setNextException(new MMSQLException(childException, getMessage(childException, null),false));
+ childException = childException.getNextException();
+ }
+ }
+ }
public static MMSQLException create(Throwable exception, String message) {
message = getMessage(exception, message);
Throwable origException = exception;
@@ -79,7 +120,7 @@
exception = findRootException(exception);
sqlState = determineSQLState(exception, sqlState);
- return new MMSQLException(message, origException, sqlState);
+ return new MMSQLException(origException, message, sqlState);
}
/**
@@ -169,49 +210,8 @@
}
return message;
}
-
- /**
- * Constructor used to wrap metamatrix exceptions into MMSQLExceptions.
- * @param reason String object which is the description of the exception.
- * @param ex Throwable object which needs to be wrapped.
- */
- private MMSQLException(String reason, Throwable ex, String sqlState) {
- super(reason, sqlState); // passing the message to the super class constructor.
- initCause(ex);
- }
- /**
- * Constructor used to wrap or copy a SQLException into a MMSQLException
- * @see com.metamatrix.common.util.exception.SQLEXceptionUnroller
- * @param ex
- * @param message
- * @param addChildren
- */
- private MMSQLException(SQLException ex, String message, boolean addChildren) {
- super(message, ex.getSQLState() == null ? SQLStates.DEFAULT : ex.getSQLState(), ex.getErrorCode());
-
- if (addChildren) {
- SQLException childException = ex; // this a child to the SQLException constructed from reason
-
- while (childException != null) {
- if (childException instanceof MMSQLException) {
- super.setNextException(ex);
- break;
- }
- super.setNextException(new MMSQLException(childException, getMessage(childException, null),false));
- childException = childException.getNextException();
- }
- }
- }
- /**
- * Constructor a MMSQLException object initialized with reason.
- * @param reason String object which is the description of the exception.
- */
- public MMSQLException(String reason) {
- super(reason, SQLStates.DEFAULT);
- }
-
/**
* @see java.lang.Throwable#getCause()
* @since 4.3.2
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/api/SQLStates.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -100,6 +100,8 @@
// Class 38 - External Routine Exception (as defined by SQL spec):
/** External routine exception. This is the default unknown code */
public static final String DEFAULT = "38000"; //$NON-NLS-1$
+
+ public static final String SUCESS = "00000"; //$NON-NLS-1$
// Class 50 - Query execution errors
public static final SQLStateClass CLASS_USAGE_ERROR = new SQLStateClass("50"); //$NON-NLS-1$
Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/util/MMJDBCURL.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -62,7 +62,8 @@
ConnectionProperties.PROP_CLIENT_SESSION_PAYLOAD,
ConnectionProperties.PROP_CREDENTIALS,
MMURL.CONNECTION.AUTO_FAILOVER,
- MMURL.CONNECTION.DISCOVERY_STRATEGY
+ MMURL.CONNECTION.DISCOVERY_STRATEGY,
+ MMURL.CONNECTION.SHUTDOWN
};
private String vdbName;
Modified: trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
===================================================================
--- trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -42,6 +42,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.teiid.adminapi.Admin;
+import org.teiid.adminapi.AdminException;
+
import com.metamatrix.common.classloader.PostDelegatingClassLoader;
import com.metamatrix.common.comm.api.ServerConnection;
import com.metamatrix.common.comm.api.ServerConnectionFactory;
@@ -53,9 +56,11 @@
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.dqp.embedded.DQPEmbeddedProperties;
import com.metamatrix.jdbc.BaseDataSource;
+import com.metamatrix.jdbc.EmbeddedDataSource;
import com.metamatrix.jdbc.JDBCPlugin;
import com.metamatrix.jdbc.MMConnection;
import com.metamatrix.jdbc.MMSQLException;
+import com.metamatrix.jdbc.api.SQLStates;
import com.metamatrix.jdbc.util.MMJDBCURL;
@@ -90,7 +95,6 @@
*/
public static Connection connect(String url, Properties info)
throws SQLException {
- Connection conn = null;
// create a properties obj if it is null
if (info == null) {
info = new Properties();
@@ -100,8 +104,21 @@
// parse the URL to add it's properties to properties object
parseURL(url, info);
- conn = createConnection(info);
-
+ MMConnection conn = createConnection(info);
+ boolean shutdown = Boolean.parseBoolean(info.getProperty(EmbeddedDataSource.SHUTDOWN, "false")); //$NON-NLS-1$
+ if (shutdown) {
+ Admin admin = conn.getAdminAPI();
+ try {
+ // this will make sure the user has permissions to do the shutdown.
+ admin.shutdown(0);
+ shutdown();
+ throw new MMSQLException(getResourceMessage("EmbeddedDriver.shutdown_sucessful"), SQLStates.SUCESS); //$NON-NLS-1$
+ } catch (AdminException e) {
+ conn.close();
+ throw new MMSQLException(e, getResourceMessage("EmbeddedDriver.shutdown_failure"), SQLStates.DEFAULT); //$NON-NLS-1$
+ }
+ }
+
// logging
String logMsg = JDBCPlugin.Util.getString("JDBCDriver.Connection_sucess"); //$NON-NLS-1$
logger.fine(logMsg);
@@ -110,7 +127,7 @@
}
- static Connection createConnection(Properties info) throws SQLException{
+ static MMConnection createConnection(Properties info) throws SQLException{
// first validate the properties as this may called from the EmbeddedDataSource
// and make sure we have all the properties we need.
@@ -126,7 +143,7 @@
// now create the connection
EmbeddedTransport transport = getDQPTransport(dqpURL, info);
- Connection conn = transport.createConnection(dqpURL, info);
+ MMConnection conn = transport.createConnection(dqpURL, info);
return conn;
}
@@ -183,7 +200,7 @@
String connectionURL = jdbcURL.getConnectionURL();
if (connectionURL == null) {
connectionURL = getDefaultConnectionURL();
- info.setProperty("vdb.definition", jdbcURL.getVDBName()+".vdb"); //$NON-NLS-1$ //$NON-NLS-2$
+ info.setProperty(DQPEmbeddedProperties.VDB_DEFINITION, jdbcURL.getVDBName()+".vdb"); //$NON-NLS-1$
}
info.setProperty(DQPEmbeddedProperties.DQP_BOOTSTRAP_FILE, connectionURL);
@@ -399,7 +416,7 @@
* @param info
* @return Connection
*/
- Connection createConnection(URL url, Properties info) throws SQLException {
+ MMConnection createConnection(URL url, Properties info) throws SQLException {
ClassLoader current = null;
try {
current = Thread.currentThread().getContextClassLoader();
Modified: trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties
===================================================================
--- trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties 2009-07-20 17:45:23 UTC (rev 1154)
+++ trunk/client-jdbc/src/main/resources/com/metamatrix/jdbc/basic_i18n.properties 2009-07-20 17:46:42 UTC (rev 1155)
@@ -37,6 +37,8 @@
EmbeddedDriver.use_new_transport=Embedded driver is creating a new embedded service instance for create connection.
EmbeddedDriver.use_classpath=Embedded driver is using the following classpath to load the embedded service.
EmbeddedDriver.use_properties=Embedded driver is using the following properties to load the embedded service.
+EmbeddedDriver.shutdown_sucessful=Shutdown request successful.
+EmbeddedDriver.shutdown_failure=Shutdown request failed.
EmbeddedDataSource.Unable_to_load_MMDQP_Driver=Unable to load JDBC driver - check class path for jar files.
EmbeddedDataSource.The_configFile_property_is_null=The configFile property is null.
Added: trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java
===================================================================
--- trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java (rev 0)
+++ trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java 2009-07-20 17:46:42 UTC (rev 1155)
@@ -0,0 +1,38 @@
+package com.metamatrix.server.integration;
+
+import java.sql.Connection;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import com.metamatrix.core.util.UnitTestUtil;
+import com.metamatrix.jdbc.api.AbstractMMQueryTestCase;
+
+
+public class TestEmbeddedShutdown extends AbstractMMQueryTestCase {
+
+ private static final String DQP_PROP_FILE = UnitTestUtil.getTestDataPath() + "/authcheck/bqt.properties;"; //$NON-NLS-1$
+ private static final String VDB = "bqt"; //$NON-NLS-1$
+
+
+ @Test public void testShutdown() {
+ try {
+ Connection conn = getConnection(VDB, DQP_PROP_FILE, "user=admin;password=teiid;"); //$NON-NLS-1$
+ execute("select intkey, stringkey from BQT1.smalla"); //$NON-NLS-1$
+ walkResults();
+
+ try {
+ getConnection(VDB, DQP_PROP_FILE, "user=admin;password=teiid;shutdown=true"); //$NON-NLS-1$
+ TestCase.fail("should have failed to connect, as this is request for shutdown"); //$NON-NLS-1$
+ }catch(Exception e) {
+ //pass
+ }
+ if (!conn.isClosed()) {
+ TestCase.fail("should have closed"); //$NON-NLS-1$
+ }
+ } catch (Exception e) {
+ }
+ }
+
+}
Property changes on: trunk/test-integration/src/test/java/com/metamatrix/server/integration/TestEmbeddedShutdown.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 11 months
teiid SVN: r1154 - in trunk: engine/src/main/java/org/teiid/dqp/internal/datamgr/language and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2009-07-20 13:45:23 -0400 (Mon, 20 Jul 2009)
New Revision: 1154
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-514 update of language bridge factory to not set the name of unrelated order by items, so that the element itself will be used by the connector.
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-07-20 16:00:33 UTC (rev 1153)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2009-07-20 17:45:23 UTC (rev 1154)
@@ -203,8 +203,8 @@
@Test
public void testDefect12120() {
helpTestVisitor(getBQTVDB(),
- "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE BQT1.SmallA.BooleanValue IN ({b'false'}, {b'true'}) ORDER BY IntKey", //$NON-NLS-1$
- "SELECT SmallA.IntKey FROM SmallA WHERE SmallA.BooleanValue IN (0, 1) ORDER BY IntKey"); //$NON-NLS-1$
+ "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA WHERE BQT1.SmallA.BooleanValue IN ({b'false'}, {b'true'})", //$NON-NLS-1$
+ "SELECT SmallA.IntKey FROM SmallA WHERE SmallA.BooleanValue IN (0, 1)"); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-07-20 16:00:33 UTC (rev 1153)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2009-07-20 17:45:23 UTC (rev 1154)
@@ -450,7 +450,11 @@
OrderByItemImpl orderByItem = null;
if(symbol instanceof ElementSymbol){
IElement innerElement = translate((ElementSymbol)symbol);
- orderByItem = new OrderByItemImpl(symbol.getOutputName(), direction, innerElement);
+ if (symbol.getOutputName() != null && symbol.getOutputName().indexOf(ElementSymbol.SEPARATOR) != -1) {
+ orderByItem = new OrderByItemImpl(null, direction, innerElement);
+ } else {
+ orderByItem = new OrderByItemImpl(symbol.getOutputName(), direction, innerElement);
+ }
} else {
orderByItem = new OrderByItemImpl(symbol.getOutputName(), direction, null);
}
Modified: trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
===================================================================
--- trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2009-07-20 16:00:33 UTC (rev 1153)
+++ trunk/test-integration/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2009-07-20 17:45:23 UTC (rev 1154)
@@ -457,4 +457,26 @@
insert.setValueSource(command);
assertEquals("INSERT INTO g1 (e1, e2, e3, e4) SELECT g2.e1, g2.e2, g2.e3, g2.e4 FROM g2", insert.toString()); //$NON-NLS-1$
}
+
+ @Test public void testUnrelatedOrderBy() throws Exception {
+ String sql = "select intkey from bqt1.smalla order by stringkey"; //$NON-NLS-1$
+
+ ICommand command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql, true, true);
+ assertEquals("SELECT g_0.IntKey AS c_0 FROM SmallA AS g_0 ORDER BY g_0.StringKey", command.toString()); //$NON-NLS-1$
+ }
+
+ @Test public void testOrderByDerivedColumn() throws Exception {
+ String sql = "select intkey as x from bqt1.smalla order by intkey"; //$NON-NLS-1$
+
+ ICommand command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql, true, true);
+ assertEquals("SELECT g_0.IntKey AS c_0 FROM SmallA AS g_0 ORDER BY c_0", command.toString()); //$NON-NLS-1$
+ }
+
+ @Test public void testOrderByAlias() throws Exception {
+ String sql = "select intkey as x from bqt1.smalla order by x"; //$NON-NLS-1$
+
+ ICommand command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql, true, true);
+ assertEquals("SELECT g_0.IntKey AS c_0 FROM SmallA AS g_0 ORDER BY c_0", command.toString()); //$NON-NLS-1$
+ }
+
}
14 years, 11 months