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