Jdbc Module

Jdbc Module

The Jdbc Module creates 2-tier, Jdbc implementations of the JBeans Session and Home interfaces.

The Jdbc Module contains the following classes:-

  • com.javelin.generator.jdbc.JdbcSessionClassWriter
  • com.javelin.generator.jdbc.JdbcHomeClassWriter
  • com.javelin.generator.jdbc.JdbcContextPropertiesWriter

In order to use the Jdbc module you need to include the following writer:

$GENERATOR.AggregateWriter jdbc

Class Hierarchy

The top-level Jdbc Writer class hierarchy is illustrated below: -

Jdbc Properties

 

Property Name

Default Value

Example

Description

driver

MANDITORY

sun.jdbc.odbc.JdbcOdbcDriver

The driver class name.

url

MANDITORY

jdbc:odbc:DEMO

The database URL – not including the username and password.

user

""

myname

Defaults to an empty string.

password

""

password

Defaults to an empty string.

minConnections

1

10

The minConnections is the resting state for the connection pool. If more than minConnections are opened then when a connection is returned it is closed.

maxConnections

1

20

The maximum number of connections that can be opened.

waitTimeout

5000

5000

The number of milliseconds to wait for a connection to become available. A range can be specified 5000-10000, which will randomise within that range.

usageLogged

false

true

Are the first/last dates and usage logged;"true" or "false"

debugConnections

false

true

Write the allocation and deallocation to the output stream;"true" or "false"

debugTransactions

false

true

Write the allocation and deallocation to the output stream;"true" or "false"

debugDriver

false

true

Write the DriverManager Log Stream to the System.out;"true" or "false"

verbose

false

true

Write selected output from the code to the System.out;"true" or "false"

catalog

null

mycatalog

This sets the catalog property to null.

readOnly

false

true

"true" or "false"

autoCommit

false

true

"true" or "false"

transactionIsolation

TRANSACTION_NONE    

TRANSACTION_READ_

UNCOMMITTED       

Possible String values are taken from the java.sql.Connection class. One of: -

TRANSACTION_NONE    

TRANSACTION_READ_UNCOMMITTED

TRANSACTION_READ_COMMITTED

TRANSACTION_REPEATABLE_READ

TRANSACTION_SERIALIZABLE

currentDate

CURRENT_DATE

GetDate()

The default syntax for the current date for the database.

currentTime

CURRENT_TIME

GetDate()

The default syntax for the current time for the database.

currentTimeStamp

CURRENT_TIMESTAMP

GetDate()

The default syntax for the current time stamp for the database.

dateFormat

dd/MM/yyyy

dd/MM/yyyy

The default date format for the database.

timeFormat

kk:mm:ss

kk:mm:ss

The default time format for the database.

dateTimeFormat

dd/MM/yyyy kk:mm:ss

yyyy-MM-dd-kk.mm.ss.SSS

The default datetime format for the database.

fatalStates

s1,s2,s2

 

A comma separated list of SQLException states, that will close a connection.

driverPropertiesPath

null

subpackage/mydriver.properties

The relative class path plus the name of the properties file, to the relative class. If the driver properties file is in a subdirectory called xyz. Then this property would be "xyz/mydriver.properties"

batchSize

100

10

The default batch size for the JdbcTableKey. This states how often the batch of primary keys is updated.

tableKeyClass

com.javelin.util.jdbc.JdbcTableKey

 

A subclass of JdbcTableKey for a specific source. This * allows custom key generation for a specific source.

For example:

<dbname>.driver=com.inet.tds.TdsDriver
<dbname>.url=jdbc:inetdae:localhost:1433?database=<dbname>&sql7=true
#<dbname>.driverPropertiesPath=
<dbname>.user=<userName>
<dbname>.password=<password>
<dbname>.transactionIsolation=TRANSACTION_READ_COMMITTED
<dbname>.readOnly=false
<dbname>.autoCommit=false
<dbname>.maxConnections=2
<dbname>.minConnections=1
<dbname>.waitTimeout=5000
<dbname>.keyBatchSize=10
#<dbname>.tableKeyClass=com.javelin.util.jdbc.JdbcTableKey
<dbname>.usageLogged=false
<dbname>.debugTransactions=false
<dbname>.debugConnections=false
<dbname>.dateFormat=dd/MM/yyyy
<dbname>.timeFormat=kk:mm:ss
<dbname>.timeStampFormat=yyyy-MM-dd-kk.mm.ss.SSS
<dbname>.currentDate=GetDate()
<dbname>.currentTime=GetDate()
<dbname>.currentTimeStamp=GetDate()
#<dbname>.debugDriver=true

 

Custom Connection Pool and User Transaction

If you want to use your own connection pool

JdbcHome.getConnection=java code.

This code is written inside a method with the signature:

protected Connection getConnection() throws SQLException

The UserTransaction may also need managing if you want to use your own UserTransaction.

ContextProperties.newUserTransaction=java code.

This code is written inside a method with the signature:

protected UserTransaction newUserTransaction() throws SQLException

Abstract Jdbc Writer (com.javelin.generator.jdbc.AbstractJdbcWriter)

The Abstract Jdbc Writer has the following methods: -

  • public String getJdbcHomeClassName()
  • public String getJdbcSessionClassName()
  • public String getContextPropertiesClassName()

Jdbc Session Class Writer (com.javelin.generator.jdbc.JdbcSessionClassWriter)

The Jdbc Session Class Writer creates BeanSessions that persists beans to a Jdbc storage.

The Sessions are created in the Jdbc package, with the name pattern: -

Jdbc<ClassName>Session

JdbcSessions are responsible for persisting dependent graphs of Beans. JdbcSessions defer loading, finding and counting beans to the JdbcHome classes.

By default the classes generated have the name and pattern: -

$JDBCSESSION=public class $PACKAGE.jdbc.$THIS extends $BEANS.jdbc.JdbcSession implements $PACKAGE

Jdbc Home Class Writer (com.javelin.generator.jdbc.JdbcHomeClassWriter)

The Jdbc Home Class Writer creates BeanHomes.

The Homes are created in the jdbc package, with the name pattern: -

Jdbc<ClassName>Home

JdbcHomes are responsible for persisting, loading, finding and counting individual Beans from a Jdbc store. The Jdbc Home classes currently use the JPool jdbc pooling package to pool connections.

By default the classes generated have the name and pattern: -

$JDBCHOME=public class $PACKAGE.jdbc.$THIS extends $BEANS.jdbc.JdbcHome implements $PACKAGE

Jdbc Context Properties Writer (com.javelin.generator.jdbc.JdbcContextPropertiesWriter)

The Jdbc Context Properties Writer creates a Context Properties file in the jdbc package, with the name: -

JdbcContextProperties

The JdbcContextProperties class is responsible for binding the JBeans interface names to implementations. The binding patterns are as follows: -

<packageName>.<ClassName>=<packageName>.<ClassName>

<packageName>.<ClassName>=<packageName>.Lazy<ClassName>
<packageName>.<ClassName>Session=<packageName>.jdbc.Jdbc<ClassName>Session
<packageName>.<ClassName>Home=<packageName>.jdbc.Jdbc<ClassName>Home
<packageName>.<ClassName>Validator =<packageName>.<ClassName>Validator

To override the bindings in the jdbc properties class do the following: -

<ClassName>.jdbc.Object=<fully qualified class name>

<ClassName>.jdbc.Bean=<fully qualified class name>
<ClassName>.jdbc.Session=<fully qualified class name>
<ClassName>.jdbc.Home=<fully qualified class name>
<ClassName>.jdbc.Validator=<fully qualified class name>