TIBCO ActiveSpaces JDBC Driver Last Updated: 2016-06-29
The TIBCO ActiveSpaces JDBC Driver provides Java applications with the ability to interact with ActiveSpaces through the use of SQL commands. The driver can be used to port existing applications, which already use a JDBC driver to interact with a database, to TIBCO ActiveSpaces. The TIBCO ActiveSpaces JDBC Driver can also facilitate the use of TIBCO ActiveSpaces by those users who are familiar with the use of JDBC drivers by reducing their learning curve.
This is a partial implementation of a JDBC driver for TIBCO ActiveSpaces. The driver has been developed to support the following SQL commands:
- CREATE TABLE
- INSERT
- UPDATE
- DELETE
- SELECT
It is important to note that in some cases only partial support for a command has been implemented. This is especially true for the SELECT command. See the sections for each command below for a description of what has or has not been implemented.
The TIBCO ActiveSpaces JDBC Driver is designed to be a layer that sits on top of existing TIBCO ActiveSpaces software and utilizes the Java API of TIBCO ActiveSpaces. This design requires the ActiveSpaces software to be installed on each machine running processes which utilize the TIBCO ActiveSpaces JDBC Driver. Since TIBCO ActiveSpaces is also designed so that each machine running a TIBCO ActiveSpaces application requires TIBCO ActiveSpaces software to be installed, there was no need to design a JDBC driver which communicates to TIBCO ActiveSpaces using a network protocol (JDBC Type 3 driver). Since TIBCO ActiveSpaces does not really have a specific database protocol, it also did not make sense to implement a JDBC Type 4 driver.
The ActiveSpaces JDBC Driver has been developed to support common SQL syntax but the syntax has been simplified and customized for ActiveSpaces. It is not intended that the TIBCO ActiveSpaces JDBC Driver should be a JDBC Driver "adapter" for other databases. Therefore, in some cases the SQL syntax recognized by other databases may not be recognized by the ActiveSpaces JDBC driver. Currently, the ActiveSpaces JDBC Driver really only supports basic SQL command functionality.
The ActiveSpaces JDBC driver provides additional syntax support for cases where a normal SQL command does not provide adequate functionality for ActiveSpaces. For example, the syntax of the CREATE TABLE command has been extended to accept additional parameters which provide full support for defining an ActiveSpaces space.
The ActiveSpaces JDBC Driver does not support the following (this is a partial list):
- Schemas
- Modules
- Unicode String & Identifiers
See the sections on the individual commands for information about the limitations of a particular command.
The TIBCO ActiveSpaces JDBC Driver sources reside in several directories as described below:
src/com/tibco/as/jdbc - Contains the classes which implement the Java JDBC interfaces.
src/com/tibco/as/sql/grammar - Contains the ANTLR grammar and the files automatically
generated by ANTLR which are used to parse SQL commands passed to the JDBC driver.
src/com/tibco/as/sql - Contains the classes which actually process the SQL commands by
making the appropriate calls into ActiveSpaces. The methods of the class ASSQLProcessor
are invoked to cause the processing of each SQL command to occur.
examples - Contain several examples which are intended to help learn about using the
TIBCO ActiveSpaces JDBC Driver.
Several examples are provided with the TIBCO ActiveSpaces JDBC Driver which are intended to help teach you how to use the driver in different scenarios as follows:
- SimpleJDBC uses the TIBCO ActiveSpaces JDBC Driver to interact with ActiveSpaces using
SQL commands.
- MixedASJdbc combines the use of the TIBCO ActiveSpaces Java API with the use of the JDBC driver.
The TIBCO ActiveSpaces Java API is first used to define and connect to a metaspace and space.
Then the JDBC driver is used after that to manipulate the data in the space.
- MixedJdbcAS also combines the use of the TIBCO ActiveSpaces Java API with the use of the
JDBC driver. However, in this example the JDBC driver is used to first define and connect to
a metaspace and space and then the TIBCO ActiveSpaces Java API is used to manipulate the
data in the space.
It is recommended that you start with the example SimpleJDBC. The comments in the example will walk you through setting up your environment, building the driver and the example, and then running the example. The comments throughout the code try to explain what is going on and things you need to pay attention to. However, the comments do not attempt to rewrite the TIBCO ActiveSpaces Developer's Guide. For information on the TIBCO ActiveSpaces objects and the Java API, you should read the developer's guide and the JavaDoc for the API.
Both of the 'mixed' examples point out important things about how to use the TIBCO ActiveSpaces JDBC Driver with the TIBCO ActiveSpaces Java API. Read the comments in the code!
Note: If you get a Java Verify Error when running the examples, you will need to specify the following VM argument to get past the error: -XX:-UseSplitVerifier
The standard syntax for JDBC URLs is:
jdbc:
where:
subprotocol is the name of the driver or the name of a database connectivity mechanism
subname is a way to identify the data source
The ActiveSpaces JDBC URL has been extended from the standard JDBC URL syntax to provide users the ability to specify the various settings for connecting to an ActiveSpaces metaspace. The ActiveSpaces JDBC URL format is:
jdbc:tibco:as[:<data-source-name>][;<propertyName>=<propertyValue>]*
The
jdbc:tibco:as;metaspace=mymetaspace
If the metaspace name is not specified as a property or as
This format for the JDBC URL for ActiveSpaces was chosen because it is similar to the formats used by the MySQL, Microsoft SQL Server and the Oracle Thin Client JDBC URLs.
The following lists the possible properties which can be set for a metaspace. Of these properties, the metaspace property and the discovery property must be identical for all applications trying to connect to the same metaspace. A new metaspace is created for any application which uses a different metaspace or discovery property setting than other applications.
Property Description
--------- ------------
metaspace Metaspace name (default: 'ms')
discovery Metaspace discovery URL - how the metaspace discovers its members (default: tibpgm://239.8.8.8:7888).
To specify several well-known TCP addresses for discovery use tcp://ip1:port1;ip2:port2
security_token Path to a security token file. If specified, any discovery setting specified in the JDBC URL is ignored
as AS will use the discovery setting from the token file.
member_name Unique name to use for the member connecting to the metaspace (default: auto-generated)
listen URL to use for listening for incoming connections from new metaspace members on.
Format: tcp://[interface[:port]] (default: 0.0.0.0 for the interface and the first port available
starting from port 5000 and above.)
remote_listen The URL to use to listen for remote client connections (optional).
remote_discovery Discovery URL for connecting to a metaspace as a remote client. However, it is preferred that the
discovery URL property be used to specify the remote discovery URL as in
discovery=tcp://IP:port?remote=true. (optional)
transport_thread_count The number of threads a metaspace member can use for handling remote invocation calls.
If a security token file has been specified, the following additional properties can also be specified:
Property Description
--------- ------------
authentication_domain The user login domain
authentication_username The user login name
authentication_password The user login password.
Although ActiveSpaces only allows one metaspace connection by a single application, the JDBC driver will allow you to use multiple Connection objects to the same metaspace within a single application.
An ANTLR grammar is used to parse the SQL query strings passed to the ActiveSpaces JDBC Driver. The grammar file is com/tibco/as/sql/grammar/ASSQL.g. Three files are automatically generated by ANTLR for this grammar. They are:
ASSQLLexer.java
ASSQLParser.java
ASSQLTokens.java
Only the grammar file should ever be modified. These three files generated by ANTLR should never be directly modified.
The ASSQL.g grammar file is written to use Java. Since JDBC is Java based, there is no reason to expect that any other language would need to be supported. Inside of the grammar, the appropriate Java class is created to handle each different supported SQL command. It was felt that embedding the Java code inside of the grammar would be easier to understand for those users who do not understand ANTLR.
Sometimes the driver's grammar allows an SQL command but portions of the command syntax are ignored by the driver implementation. The idea in developing the grammar for this driver was to allow common SQL syntax even though full support for the command may not have been implemented in the driver. For example, the following command is successfully parsed by the driver even though support for LIMIT and OFFSET has not been implemented: SELECT * FROM mytable LIMIT 100 OFFSET 0
Important!! SQL WHERE clauses are not fully supported. Currently the WHERE clause is used, in its entirety, as an ActiveSpaces filter. However, the grammar still needs work to completely support the successful parsing of all possible filter formats. Only simple filters are currently supported such as: key=value name='Joe Smith' (Note, the driver converts SQL single quotes to the double-quotes used by filters.) age>50 name = 'John'' Doe' name = 'John'' Doe' and city = 'Bangalore' name = 'John'' Doe' or income = 50150.50 name = 'John'' Doe' or (income > 50150.50 and age > 0) city is not null where city is null where city like 'View'
If you find that you need to modify the grammar and build it yourself, you will need to download the ANTLR v3 task for ant from: http://www.antlr3.org/share/list.html
Extract the contents of the zip file and copy the file ant-antlr3.jar into your ANT lib directory.
Ensure you have both your AS_HOME and ANT_HOME environment variables set. Change to the AS_HOME/examples/java/JDBCDriver directory and type: ant grammar -verbose
This will build the grammar in a temporary 'grammar' directory and if the build is successful, it will then copy the resulting Lexer and Parser files into the AS_HOME/examples/java/JDBCDriver/src/com/tibco/as/sql/grammar directory.
As mentioned above, the following SQL commands are supported:
- CREATE TABLE
- INSERT
- UPDATE
- DELETE
- SELECT
The SQL keywords for each command are case insensitive. For example, the following three SQL commands are equivalent:
SELECT * FROM mytable
select * from mytable
Select * From mytable
When strings are specified as values in an SQL command, strings should be enclosed in single quotes and not double quotes. For example:
INSERT INTO mytable (column1, column2) VALUES (George, Washington)
When you need to use a table name or column name that matches an SQL keyword, you should enclose the name in escaped double-quotes to allow the ANTLR parser to differentiate between the keyword and the name. For example:
CREATE TABLE myspace (\"key\" INTEGER NOT NULL, value VARCHAR, \"time\" DATETIME, PRIMARY KEY (\"key\"))
CREATE TABLE is used to define a TIBCO ActiveSpaces space, which is the equivalent of a database table. Since an ActiveSpaces space is defined using specific space properties other than the normal field definitions of a database table, the CREATE TABLE syntax has been extended to allow users to specify space properties.
Basic Syntax:
CREATE TABLE <table_name> ( <table_element> [, <table_element> ]... )
Where: