Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Setting Up a NuoDB Data Source for Railo

DZone's Guide to

Setting Up a NuoDB Data Source for Railo

· Database Zone ·
Free Resource

Running out of memory? Learn how Redis Enterprise enables large dataset analysis with the highest throughput and lowest latency while reducing costs over 75%! 

Railo is an Open Source ColdFusion Markup Language (CFML) engine.  We’ve had lots of interest from folks using Railo whether it is possible to support the NuoDB NewSQL database as a Railo datasource.  The answer is, indeed, yes. This article details the process of provisioning a NuoDB-specific data source in Railo.  By the end of this article you will have an operational Railo instance that is able to use a NuoDB database connection to retrieve and present database content.

Prerequisites

  • It is assumed that NuoDB 1.1 or later has been installed.
  • For the purposes of demonstration, all steps below were run on Mac OS X, however, other supported operating systems should work, and the instructions should be largely identical.
  • Download a Railo 4.0.4.001 installer.  Get it here: http://www.getrailo.org/index.cfm/download/

Procedure

Follow these steps – note they assume you are developing on Mac (the Linux and Windows procedure is the same, the paths and commands are different):

  1. Install Railo, but do not run the Admin tools just yet.
  2. Copy the NuoDB JDBC Jar to the Railo lib directory:
    sudo cp /opt/nuodb/jar/nuodbjdbc.jar /Library/Railo/lib/
  3. Copy the NuoDB dbdriver CFC file in place (see content at end of article):
    sudo cp NuoDB.cfc /Library/Railo/tomcat/webapps/ROOT/WEB-INF/railo/context/admin/dbdriver/NuoDB.cfc
  4. Shutdown Railo:
    sudo /Library/Railo/tomcat/bin/shutdown.sh
  5. Add a reference to the NuoDB JDBC Jar in the Railo /Library/Railo/lib/versions file:
    <jar version="1.1.1" path="nuodbjdbc.jar" comment=""/>
  6. Copy the NuoDB Startup Script (see end of article) to the local file system where NuoDB will be started up.
  7. When you installed NuoDB on your host a Broker was started for you.  You can use that Broker to start an SM and TE that together provide a complete, ACID database.  Start up your NuoDB Storage Manager and Transaction Engine using the startup script:
java -jar /opt/nuodb/jar/nuodbmanager.jar --broker localhost --password bird --file StartupRailoNuoDb
  1. Start up Railo:
    sudo /Library/Railo/tomcat/bin/startup.sh
  2. Open the following link in your browser: http://localhost:10080/railo-context/admin/server.cfm
  3. Add a new datasource for NuoDB using these parameters:
    Name: test
    Type: NuoDB
    Host/Server: localhost
    Database: test
    Port: 48004
    Username: cloud
    Password: user
    Enable Blob
    Enable Clob
    Verify Connection
    Schema: test
  4. Create a file named listsystemtables.cfm in Railo/tomcat/webapps/ROOT (see content at end of article).
  5. Open the following link in your browser:http://localhost:10080/listsystemtables.cfm

In your browser you should see a complete list of all SQL Tables in your database.  This is only a trivial read-only sample, but following Railo documentation, you can add any sort of database logic to your data-driven ColdFusion scripts.  To download a free version of NuoDB, go to http://www.nuodb.com/download.

Appendix

Content of NuoDB Railo Driver (NuoDB.cfc)

<cfcomponent extends="Driver" implements="IDriver">
  <cfset fields=array()>
  <cfset fields=array(
  field("Schema","schema","USER",true,"Schema name under which objects are created")
  )>
  <cfset this.type.port=this.TYPE_FREE>

  <cfset this.value.host="localhost">
  <cfset this.value.port=48004>
  <cfset this.schema="USER">
  <cfset this.className="com.nuodb.jdbc.Driver">
  <cfset this.dsn="jdbc:com.nuodb://{host}:{port}/{database}?schema={schema}">

  <cffunction name="getName" returntype="string" output="no"
  hint="returns display name of the driver">
  <cfreturn "NuoDB">
  </cffunction>
  <cffunction name="getDescription" returntype="string" output="no"
  hint="returns description for the driver">
  <cfreturn "NuoDB JDBC Driver">
  </cffunction>
  <cffunction name="getFields" returntype="array" output="no"
  hint="returns array of fields">
  <cfreturn fields>
  </cffunction>
  <cffunction name="getClass" returntype="string" output="no"
  hint="return driver Java Class">
  <cfreturn this.className>
  </cffunction>
  <cffunction name="getDSN" returntype="string" output="no"
  hint="return DSN">
  <cfreturn this.dsn>
  </cffunction>
  <cffunction name="getUsername" returntype="string" output="no"
  hint="return Username">
  <cfreturn data.username>
  </cffunction>
  <cffunction name="getPassword" returntype="string" output="no"
  hint="return Password">
  <cfreturn data.password>
  </cffunction>
  <cffunction name="equals" returntype="string" output="no"
  hint="return if String class match this">
  <cfargument name="className" required="true">
  <cfargument name="dsn" required="true">
  <cfreturn this.className EQ arguments.className and this.dsn EQ arguments.dsn>
  </cffunction>
</cfcomponent>

Content for NuoDB Startup Script (StartupRailoNuoDb)

# simple script for starting a complete database
start process sm host localhost database test archive /tmp/railodb initialize true
start process te host localhost options '--dba-user cloud --dba-password user'

Content for ColdFusion File (listsystemtables.cfm)

<!DOCTYPE html>
<html>
  <head>
    <title>Lists NuoDB System Tables</title>
  </head>
  <body>
    <cfquery name="gettables" datasource="test">
      select tablename from system.tables
    </cfquery>
    <cfoutput query="gettables">
      <br>#tablename#
    </cfoutput>
  </body>
</html>

Running out of memory? Never run out of memory with Redis Enterprise databaseStart your free trial today.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}