Author: rareddy
Date: 2010-08-11 13:51:25 -0400 (Wed, 11 Aug 2010)
New Revision: 2439
Modified:
trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java
trunk/client/src/test/java/org/teiid/jdbc/TestEmbeddedProfile.java
trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
trunk/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java
Log:
TEIID-1198: Allowing to specify the VDB version as the extension to the VDB name in the
JDBC URL connection property.
Modified: trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2010-08-11 16:17:29 UTC
(rev 2438)
+++ trunk/client/src/main/java/org/teiid/jdbc/EmbeddedProfile.java 2010-08-11 17:51:25 UTC
(rev 2439)
@@ -47,7 +47,7 @@
* - jdbc:teiid:BQT
* - jdbc:teiid:BQT;verson=1
*/
- static final String BASE_PATTERN = "jdbc:teiid:([\\w|-]+)(;.*)?";
//$NON-NLS-1$
+ static final String BASE_PATTERN = "jdbc:teiid:([\\w-\\.]+)(;.*)?";
//$NON-NLS-1$
private static Logger logger = Logger.getLogger("org.teiid.jdbc");
//$NON-NLS-1$
Modified: trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java 2010-08-11 16:17:29 UTC
(rev 2438)
+++ trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java 2010-08-11 17:51:25 UTC
(rev 2439)
@@ -61,7 +61,7 @@
// This host/port pattern allows just a . or a - to be in the host part.
static final String HOST_PORT_PATTERN = "[\\p{Alnum}\\.\\-\\_]+:\\d+";
//$NON-NLS-1$
- static final String URL_PATTERN =
"jdbc:(metamatrix|teiid):([\\w|-]+)@mm[s]?://"+HOST_PORT_PATTERN+"(,"+HOST_PORT_PATTERN+")*(;.*)?";
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ static final String URL_PATTERN =
"jdbc:(metamatrix|teiid):([\\w-\\.]+)@mm[s]?://"+HOST_PORT_PATTERN+"(,"+HOST_PORT_PATTERN+")*(;.*)?";
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
static Pattern urlPattern = Pattern.compile(URL_PATTERN);
/**
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestEmbeddedProfile.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestEmbeddedProfile.java 2010-08-11 16:17:29
UTC (rev 2438)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestEmbeddedProfile.java 2010-08-11 17:51:25
UTC (rev 2439)
@@ -48,6 +48,7 @@
assertFalse(org.teiid.jdbc.EmbeddedProfile.acceptsURL("jdbc:teiid:BQT!/path/foo.properties"));
//$NON-NLS-1$
assertTrue(org.teiid.jdbc.EmbeddedProfile.acceptsURL("jdbc:teiid:BQT;"));
//$NON-NLS-1$
assertTrue(org.teiid.jdbc.EmbeddedProfile.acceptsURL("jdbc:teiid:BQT;version=1;logFile=foo.txt"));
//$NON-NLS-1$
+
assertTrue(org.teiid.jdbc.EmbeddedProfile.acceptsURL("jdbc:teiid:BQT.1;version=1;logFile=foo.txt"));
//$NON-NLS-1$
}
@Test public void testParseURL() throws SQLException{
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2010-08-11 16:17:29 UTC
(rev 2438)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2010-08-11 17:51:25 UTC
(rev 2439)
@@ -50,6 +50,8 @@
assertTrue(drv.acceptsURL("jdbc:teiid:8294601c-9fe9-4244-9499-4a012c5e1476_vdb@mm://localhost:12345"));
//$NON-NLS-1$
assertTrue(drv.acceptsURL("jdbc:teiid:test_vdb@mm://local-host:12345"));
//$NON-NLS-1$
assertTrue(drv.acceptsURL("jdbc:teiid:test_vdb@mm://local_host:12345"));
//$NON-NLS-1$
+ assertTrue(drv.acceptsURL("jdbc:teiid:test_vdb.1@mm://local_host:12345"));
//$NON-NLS-1$
+
assertTrue(drv.acceptsURL("jdbc:teiid:test_vdb.10@mm://local_host:12345"));
//$NON-NLS-1$
}
/** Valid format of urls*/
Modified:
trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml
===================================================================
---
trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2010-08-11
16:17:29 UTC (rev 2438)
+++
trunk/documentation/client-developers-guide/src/main/docbook/en-US/content/jdbc-connection.xml 2010-08-11
17:51:25 UTC (rev 2439)
@@ -48,7 +48,11 @@
<para>URL Components</para>
<orderedlist>
- <listitem><para><vdb-name> - Name of the VDB you
are connecting to</para></listitem>
+ <listitem><para><vdb-name> - Name of the VDB you
are connecting to. Optionally VDB
+ name can also contain version information inside it. For example:
"myvdb.2", this is equivalent to supplying the
+ "version=2" connection property defined below. However, use of vdb
name in this format and
+ the "version" property at the same time is not allowed.
+ </para></listitem>
<listitem><para>mm - defines Teiid JDBC protocol, mms defines a
secure channel (see the <link linkend="ssl">SSL chapter</link> for
more)</para></listitem>
<listitem><para><host> - defines the server where
the Teiid Server is installed</para></listitem>
<listitem><para><port> - defines the port on which
the Teiid Server is listening for incoming JDBC
connections.</para></listitem>
@@ -261,7 +265,10 @@
<entry>
<code>String</code>
</entry>
- <entry>The name of a virtual database (VDB) deployed to
Teiid</entry>
+ <entry>The name of a virtual database (VDB) deployed to
Teiid. Optionally Database
+ name can also contain "DatabaseVersion" information inside it. For
example: "myvdb.2", this is equivalent to supplying the
+ "DatabaseVersion" property set to value of 2. However, use of
Database name in this format and use of
+ DatabaseVersion property at the same time is not allowed.</entry>
</row>
<row>
<entry>
Modified: trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2010-08-11
16:17:29 UTC (rev 2438)
+++ trunk/runtime/src/main/java/org/teiid/services/SessionServiceImpl.java 2010-08-11
17:51:25 UTC (rev 2439)
@@ -149,42 +149,29 @@
domains = this.adminSecurityDomains;
}
- if (!domains.isEmpty()) {
- // Authenticate user...
- // if not authenticated, this method throws exception
- boolean onlyAllowPassthrough =
Boolean.valueOf(properties.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION,
"false")); //$NON-NLS-1$
- TeiidLoginContext membership = authenticate(userName, credentials,
applicationName, domains, this.securityHelper, onlyAllowPassthrough);
- loginContext = membership.getLoginContext();
- userName = membership.getUserName();
- securityDomain = membership.getSecurityDomain();
- securityContext = membership.getSecurityContext();
- }
-
// Validate VDB and version if logging on to server product...
VDBMetaData vdb = null;
String vdbName = properties.getProperty(TeiidURL.JDBC.VDB_NAME);
if (vdbName != null) {
String vdbVersion = properties.getProperty(TeiidURL.JDBC.VDB_VERSION);
- if (vdbVersion == null) {
- vdbVersion = "latest"; //$NON-NLS-1$
- try {
- vdb = this.vdbRepository.getVDB(vdbName);
- } catch (VirtualDatabaseException e) {
- throw new
SessionServiceException(RuntimePlugin.Util.getString("VDBService.VDB_does_not_exist._2",
vdbName, vdbVersion)); //$NON-NLS-1$
- }
- }
- else {
- vdb = this.vdbRepository.getVDB(vdbName, Integer.parseInt(vdbVersion));
- }
- if (vdb.getStatus() != VDB.Status.ACTIVE || vdb.getConnectionType() ==
ConnectionType.NONE) {
- throw new
SessionServiceException(RuntimePlugin.Util.getString("VDBService.VDB_does_not_exist._2",
vdbName, vdbVersion)); //$NON-NLS-1$
- }
+ vdb = getActiveVDB(vdbName, vdbVersion);
}
if (sessionMaxLimit > 0 && getActiveSessionsCount() >=
sessionMaxLimit) {
throw new
SessionServiceException(RuntimePlugin.Util.getString("SessionServiceImpl.reached_max_sessions",
new Object[] {new Long(sessionMaxLimit)})); //$NON-NLS-1$
}
+ if (!domains.isEmpty()) {
+ // Authenticate user...
+ // if not authenticated, this method throws exception
+ boolean onlyAllowPassthrough =
Boolean.valueOf(properties.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION,
"false")); //$NON-NLS-1$
+ TeiidLoginContext membership = authenticate(userName, credentials,
applicationName, domains, this.securityHelper, onlyAllowPassthrough);
+ loginContext = membership.getLoginContext();
+ userName = membership.getUserName();
+ securityDomain = membership.getSecurityDomain();
+ securityContext = membership.getSecurityContext();
+ }
+
long creationTime = System.currentTimeMillis();
// Return a new session info object
@@ -211,6 +198,45 @@
return newSession;
}
+ VDBMetaData getActiveVDB(String vdbName, String vdbVersion) throws
SessionServiceException {
+ VDBMetaData vdb = null;
+
+ // handle the situation when the version is part of the vdb name.
+
+ int firstIndex = vdbName.indexOf('.');
+ int lastIndex = vdbName.lastIndexOf('.');
+ if (firstIndex != -1) {
+ if (firstIndex != lastIndex || vdbVersion != null) {
+ throw new
SessionServiceException(RuntimePlugin.Util.getString("ambigious_name", vdbName,
vdbVersion)); //$NON-NLS-1$
+ }
+ vdbVersion = vdbName.substring(firstIndex+1);
+ vdbName = vdbName.substring(0, firstIndex);
+ }
+
+ try {
+ if (vdbVersion == null) {
+ vdbVersion = "latest"; //$NON-NLS-1$
+ vdb = this.vdbRepository.getVDB(vdbName);
+ }
+ else {
+ vdb = this.vdbRepository.getVDB(vdbName, Integer.parseInt(vdbVersion));
+ }
+ } catch (VirtualDatabaseException e) {
+ throw new
SessionServiceException(RuntimePlugin.Util.getString("VDBService.VDB_does_not_exist._2",
vdbName, vdbVersion)); //$NON-NLS-1$
+ } catch (NumberFormatException e) {
+ throw new SessionServiceException(e,
RuntimePlugin.Util.getString("VDBService.VDB_does_not_exist._2", vdbName,
vdbVersion)); //$NON-NLS-1$
+ }
+
+ if (vdb == null) {
+ throw new
SessionServiceException(RuntimePlugin.Util.getString("VDBService.VDB_does_not_exist._1",
vdbName, vdbVersion)); //$NON-NLS-1$
+ }
+
+ if (vdb.getStatus() != VDB.Status.ACTIVE || vdb.getConnectionType() ==
ConnectionType.NONE) {
+ throw new
SessionServiceException(RuntimePlugin.Util.getString("VDBService.VDB_does_not_exist._2",
vdbName, vdbVersion)); //$NON-NLS-1$
+ }
+ return vdb;
+ }
+
protected TeiidLoginContext authenticate(String userName, Credentials credentials,
String applicationName, List<String> domains, SecurityHelper helper, boolean
onlyallowPassthrough)
throws LoginException {
TeiidLoginContext membership = new TeiidLoginContext(helper);
Modified: trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2010-08-11 16:17:29
UTC (rev 2438)
+++ trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2010-08-11 17:51:25
UTC (rev 2439)
@@ -44,7 +44,8 @@
VDBConfigFileReader.Already_contains_connector_type=Configuration has two definitions for
connector \"{0}\".
VDBConfigFileReader.No_connector_binding_in_config = A model \"{0}\" specifies
a connection factory "{1}" for which there is no definition found in the
configuration or VDB definition files.
-VDBService.VDB_does_not_exist._2=VDB \"{0}\" version \"{1}\" is not
active.
+VDBService.VDB_does_not_exist._1=VDB \"{0}\" version \"{1}\" does not
exist.
+VDBService.VDB_does_not_exist._2=VDB \"{0}\" version \"{1}\" is not
in "active" status.
VDBService.VDB_does_not_exist._3=In VDB \"{0}\" version \"{1}\" the
Model \"{2}\" does not exist.
VDBService.Model_does_not_exist._4=Model "{0}" does not exist.
VDBService.0=Error trying to read visibility information from the vdb \"{0}\".
@@ -313,4 +314,5 @@
not_bound=No bound statement found with name {0}
no_stmt_found=No prepared statement found with name {0}
error_closing_stmt=Error closing portal statement {0}
-model_metadata_loading=VDB "{0}" - "{1}" model metadata is currently
being loaded. Start Time: {2}
\ No newline at end of file
+model_metadata_loading=VDB "{0}" - "{1}" model metadata is currently
being loaded. Start Time: {2}
+ambigious_name=Ambiguous VDB name specified. Only single occurrence of the "."
is allowed in the VDB name. Also, when version based vdb name is specified, then a
separate "version" connection option is not allowed:{0}.{1}
\ No newline at end of file
Modified: trunk/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java 2010-08-11
16:17:29 UTC (rev 2438)
+++ trunk/runtime/src/test/java/org/teiid/services/TestSessionServiceImpl.java 2010-08-11
17:51:25 UTC (rev 2439)
@@ -12,8 +12,12 @@
import org.junit.Test;
import org.mockito.Mockito;
+import org.teiid.adminapi.VDB.Status;
import org.teiid.adminapi.impl.SessionMetadata;
+import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.client.security.InvalidSessionException;
+import org.teiid.deployers.VDBRepository;
+import org.teiid.dqp.service.SessionServiceException;
import org.teiid.security.Credentials;
import org.teiid.security.SecurityHelper;
import org.teiid.services.TeiidLoginContext;
@@ -83,4 +87,109 @@
validateSession(false);
}
+ @Test
+ public void testActiveVDBWithNoVersion() throws Exception {
+ VDBRepository repo = Mockito.mock(VDBRepository.class);
+ VDBMetaData vdb = new VDBMetaData();
+ vdb.setName("name");
+ vdb.setVersion(1);
+ vdb.setStatus(Status.ACTIVE);
+
+
+ Mockito.stub(repo.getVDB("name")).toReturn(vdb);
+
+ SessionServiceImpl ssi = new SessionServiceImpl();
+ ssi.setVDBRepository(repo);
+
+ ssi.getActiveVDB("name", null);
+
+ Mockito.verify(repo, Mockito.times(1)).getVDB("name");
+ }
+
+ @Test
+ public void testActiveVDBWithVersion() throws Exception {
+ VDBRepository repo = Mockito.mock(VDBRepository.class);
+ VDBMetaData vdb = new VDBMetaData();
+ vdb.setName("name");
+ vdb.setVersion(1);
+ vdb.setStatus(Status.ACTIVE);
+
+
+ Mockito.stub(repo.getVDB("name", 1)).toReturn(vdb);
+
+ SessionServiceImpl ssi = new SessionServiceImpl();
+ ssi.setVDBRepository(repo);
+
+ ssi.getActiveVDB("name", "1");
+
+ Mockito.verify(repo, Mockito.times(1)).getVDB("name", 1);
+ }
+
+
+ @Test
+ public void testActiveVDBNameWithVersion() throws Exception {
+ VDBRepository repo = Mockito.mock(VDBRepository.class);
+ VDBMetaData vdb = new VDBMetaData();
+ vdb.setName("name");
+ vdb.setVersion(1);
+ vdb.setStatus(Status.ACTIVE);
+
+
+ Mockito.stub(repo.getVDB("name", 1)).toReturn(vdb);
+
+ SessionServiceImpl ssi = new SessionServiceImpl();
+ ssi.setVDBRepository(repo);
+
+ ssi.getActiveVDB("name.1", null);
+
+ Mockito.verify(repo, Mockito.times(1)).getVDB("name", 1);
+ }
+
+ @Test
+ public void testActiveVDBNameWithVersionNonInteger() throws Exception {
+ VDBRepository repo = Mockito.mock(VDBRepository.class);
+ VDBMetaData vdb = new VDBMetaData();
+ vdb.setName("name");
+ vdb.setVersion(1);
+ vdb.setStatus(Status.ACTIVE);
+
+
+ Mockito.stub(repo.getVDB("name", 1)).toReturn(vdb);
+
+ SessionServiceImpl ssi = new SessionServiceImpl();
+ ssi.setVDBRepository(repo);
+
+ try {
+ ssi.getActiveVDB("name.x", null);
+ fail("must have failed with non integer version");
+ } catch (SessionServiceException e) {
+ }
+ }
+
+ @Test
+ public void testActiveVDBNameWithVersionAndVersion() throws Exception {
+ VDBRepository repo = Mockito.mock(VDBRepository.class);
+ VDBMetaData vdb = new VDBMetaData();
+ vdb.setName("name");
+ vdb.setVersion(1);
+ vdb.setStatus(Status.ACTIVE);
+
+
+ Mockito.stub(repo.getVDB("name", 1)).toReturn(vdb);
+
+ SessionServiceImpl ssi = new SessionServiceImpl();
+ ssi.setVDBRepository(repo);
+
+ try {
+ ssi.getActiveVDB("name.1", "1");
+ fail("must have failed with ambigious version info");
+ } catch (SessionServiceException e) {
+ }
+
+ try {
+ ssi.getActiveVDB("name..1", null);
+ fail("must have failed with ambigious version info");
+ } catch (SessionServiceException e) {
+ }
+ }
}