Informix has four protocols, or communication channels, which you can use to access the server, SQLI, DRDA, JSON, and RESTful. If you are familiar with one of these and want to know how to perform the same basic operations using one of the others, consider this post to be your Rosetta stone.
The sample application is written in Java. It iterates through using the Informix JDBC driver (which uses the SQLI protocol), the DB2 JCC driver (which uses DRDA), the MongoDB driver for Java (JSON), and native Java HTTP classes (REST). For each of these protocols, it goes through the steps to:
- Create a user
- Create a database
- Create a table/collection
- Create a row or document (entry)
- Read an entry
- Update an entry
- Delete entries
- Drop a table/collection
- Drop a database
- Drop a user
The code should be self-explanatory, but there are some differences between the APIs worth noting.
Using the SQLI and DRDA protocols, connections are stateful. There is an open channel maintained between the port listening for commands on the server and the port on the client sending commands. So, transaction states are easily maintained, and multiple commands can be executed without re-authenticating. Most operations are identical between these two, except the URLs are different. Informix JDBC requires an INFORMIXSERVER setting. You can not drop the database you are currently accessing. Authentication takes place at the server level, allowing you to access whatever database for which you have appropriate privileges.
The MongoDB clients are what I'll call semi-stateful. Client and db objects have the appearance of maintaining a connection with the database server, but really the connection information is cached on the client side and as far as the listener is concerned every operation is independent. (Exceptions to this model are beyond the scope of this write-up.) The database you are dropping must be the current database. Authentication takes place at the database level.
Fitting the REST model, there is no concept of a stateful connection in the RESTful API. However, there are two ways to authenticate: Providing a user name and password as is common, and sending a session id cookie from a previously authenticated operation. Using a session cookie is how you can, say, authenticate against the admin database, and use your userAdminAnyDatabase privilege to create a new user within another database.
Users with the ability to create other users must already exist for this demo to work. Examples:
Informix DBSA: create user dbsauser with password 'a1b2c3d4e5' properties user 'nobody' authorization(DBSA)
MongoDB
2.4: use admin
db.addUser( { user: "userAdmin", pwd: "1RDSRDS", roles: [ "userAdminAnyDatabase" ] } )
2.6: db.createUser({user: "userAdmin", pwd: "1RDSRDS", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })
The download file contains the source code and Eclipse project that can be used to build it. It also contains all the required drivers; it is your choice whether to use the ones included or use more modern ones you have installed. Included in the project is an ANT script for building the jar.
Run the demo with the command: java -jar basicChecks.jar connSettings.properties
Running the demo without the required properties file will give you instructions for what the file should contain.
$ java -jar basicChecks.jar
Usage: java Main <connection properties file>
The connection properties file should contain lines of <name>=<value> pairs.
Example:
host=myHost.domain.com
sqli_port=9088
informixserver=myServerName
drda_port=9089
mongodb_port=27017
rest_port=27018
user_admin=jane
user_admin_pwd=54cba
dbsa_user=bob
dbsa_user_pwd=abc45
-Chris Golledge