CloudTran Home

 
  
 
Contents  >   11.  CloudTran Profile Reference
 


11.10 DataSource Object

Used on
application
DescriptionThe data source defines the source of data for the in-memory data grid.

A data-source, by default, defines the link to a database. However, there are plug-in points to define other types of data.

The dataSource model object can be referenced by entities' 'dataSource' property.

The use cases for dataSource are as follows:

  1. Getting started; and unit test with one RDBMS data source.

    In this case, define the dataSource as a child of the application.

    You do not need to set a reference to the dataSource into the entities if you are just using one data source - it will be picked up automatically.

    The values you put in here will be included in the generate code and configuration. If you are testing in Eclipse, the database should available without any more work from you.

  2. Multiple dataSources.

    In this case, you must define the dataSource objects in the model, with unique names.

    You now need to set a reference to the dataSource into all the entities: there is now no default dataSource.

  3. Using messages in a transaction.

    In this case, the transactional part of the process comes when you write a messaging object into the space. To include this in a transaction, you should not use an Entity as the messaging object. Instead, use a regular JavaBean to model the messaging object; if you don't model it yourself, enter the fully-qualified class name in the 'template bean' field of the receiver..

    The default way of doing this is to
Inherited
properties
text (base property)

 11.10.1  Property 'url'
 11.10.2  Property 'name'
 11.10.3  Property 'description'
 11.10.4  Property 'schemaFilename'
 11.10.5  Property 'username'
 11.10.6  Property 'password'
 11.10.7  Property 'databaseType'
 11.10.8  Property 'dataSourceLoaderClass'

11.10.1  Property 'url'
DescriptionThe url should be the complete URL of the target database or other dataSource. If the database is sharded, there will be more than on url: separate the urls with a comma (',').

For example, a MySql database named MyDB on the local machine might have the url

jdbc:mysql://localhost:3306/MyDB

Note that this includes the 'database' name as the last element in the url - that is required if you are using JDBC. The general format for a single URL is

{protocol :}+ //hostname:portNumber/databaseName

There must not be a trailing '/' on the database name.

The database name part of the url is used to create defaults for the 'name' and 'schemaFilename' properties.

Here's an example of three databases, referenced by url, in one 'url' property:

jdbc:mysql://DBServer1:3306/MyDB1,jdbc:mysql://DBServer2:3306/MyDB2,jdbc:mysql://DBServer3:3306/MyDB3

This is three individual database url specifications, separated by commas. Note that these databases are on 3 separate boxes (so we can effectively increase capacity or performance), but they also have distinct database names (MyDB1/2/3) - to reduce the risk of accidents during copying.

If you specify multiple urls on the dataSource, a mapping class will be generated that you will have to supply implementation code for, to tell CloudTran which URL to use for the database. Note that you do not specify multiple usernames and passwords if there are multiple urls
TypeString

11.10.2  Property 'name'
DescriptionEvery dataSource must have a unique name. This is used in two ways:

  • the most important use is for generating part of the unique row ID when a persistent record (i.e. database row) is mapped into the datagrid. The format of this ID is "dataSourceName ~ entityName ~ primaryKey". So there needs to be a unique dataSourceName

  • to give the default for the schemaFilename.
You do not have to specify the name, normally, because the database name (derived from the url) is used as a default name.

In the unusual case that the database name in the url is not unique, you will have to specify a unique name here.

The name, whether you specify it explicitly or it comes from the database name, must be a valid Java name. This means it must match the regular expression [_a-zA-Z0-9]+. In other words, one or more alphanumeric or '_' characters.
TypeString

11.10.3  Property 'description'
DescriptionDescription of the data source.
TypeString

11.10.4  Property 'schemaFilename'
DescriptionCloudTran generates a database schema for JDBC datasources, which is written into the main project's directory.. By default the schema is name 'database.sql', where the 'database' is the database part of the URL. If you want to override this, which you might want to do for example if two datasources have the same database name, then specify the override filename here.
TypeString

11.10.5  Property 'username'
DescriptionThis is the username to connect as. This is required if you use JdbcLoaderFramework (i.e a regular JDBC database).
TypeString
Requiredtrue

11.10.6  Property 'password'
DescriptionThis is the password to use to connect. This is required if you use JdbcLoaderFramework (i.e a regular JDBC database) - even if the password is empty (the zero-length string).
TypeString
Requiredtrue

11.10.7  Property 'databaseType'
DescriptionThis is the type of the database. It must be one of the specified choices.
TypeString
Choices
MySQL (default)
Oracle
SQLServer
ANSI
Requiredtrue

11.10.8  Property 'dataSourceLoaderClass'
DescriptionThis is the class that should be used load this dataSource.

A JDBC loader class is provided in 'com.cloudtran.persist.JdbcLoaderFramework' and this is the default: it covers normal relational databases. If you use the JdbcLoaderFramework, most of the fields here are required - i.e. driverClass, url, databaseType, username and password.

If you create a plug-in for a non-JDBC dataSource, you must specify the appropriate class here. This allows CloudTran to work with non-relational datasources. In this case, the target url is still required.
TypeString
Defaultcom.cloudtran.persist.JdbcLoaderFramework

Copyright (c) 2001-2011 CloudTran Inc.