Using Jython With DataCaster
DataCaster includes the Jython scripting language as a scripting tool that can be used with DataCaster.
While using DataCaster, scripting support is useful for a number of activities, including performaing administrative tasks, testing, data migration, etc. In additon, a number of users prefer using scriting for many of the programs they intend to write against the database and DataCaster.
Jython is a Java implementation of the Python scripting language. It offers a powerful, fast, object-oriented scripting language that integrates very well with Java. Integrating Jython with any Java application is quite simple, and it allows users complete access to scripting the Java API.
DataCaster users and administrators can use Jython to access the DataCaster API and the database, to get full access to the DataCaster API, as well as run SQL commands.
Note: It is easy to do a lot of damage with the Jython access to the DataCaster API. Use with caution, particularly when using the DataCaster API to work with the database internals.
Jython Shell
Jython is provided in the DataCaster installation directory, where a sub-directory named jython will be created.
To run the Jython shell, on Linux execute the jython executable in the jython sub-directory, or on Windows execute the jython.bat in the jython sub-directory. The environment has been modified to include the DataCaster jar as needed by Jython.
Using Jython With the DataCaster API
To access the DataCaster databases, one can use Jython to access the databases as a user or administrator. Users have access only to the User API, while administrators can use both the User API, and the internal database APIs. For most activities it is advisable that even administrators use the User API.
DataCaster User API Access With Jython
To access the User API to a database, use the DatabaseImpl class. Once a Database instance is accessed, any of the User API methods can be accessed via the database instance. The following are the set of commands to access the Database and a table in the database.
>>> from com.applibase.db.user import DatabaseImpl
>>> db = DatabaseImpl("testdb", "testuser", "testpwd")
>>> table = db.getTable("users")
>>> print table.size()
>>> table.printTable() # Use only for small tables
TABLE users
<... table data ...>
Administrator Access to the DataCaster Internal API
Administrators can access many of the inetrnal packages and classes within the database in order to perform any unusal activities needed for monitoring, maintenance and administration of the database. This needs to be used with caution, to avoid causing any issues with the database data and inner working.
The following are the set of commands to access the internal API with Jython.
>>> from com.applibase.db.dbms import DbSessions
>>> dbsessions = DbSessions()
>>> from com.applibase.db.security import Login
>>> login = Login("testdb", "admin", "admin")
>>> db = dbsessions.getDB("testdb", login.getUserContext())
>>> table = db.getTable("users")
>>> table.checkTable() # Now you have access to the internal APIs