thinkmap.datasource.database
Class DatabaseDataSource

java.lang.Object
  extended by thinkmap.datasource.util.AbstractDataSource
      extended by thinkmap.datasource.database.DatabaseDataSource
All Implemented Interfaces:
EventListener, IContextListener, IDataSource

public class DatabaseDataSource
extends AbstractDataSource
implements IContextListener

A datasource that answers requests by querying a SQL database. It uses a number of QueryDataSources, each one of which responds in specific circumstances.

Version:
$Revision: 1.33 $

Nested Class Summary
 class DatabaseDataSource.DBEdgeEntityModel
          Define an edge entity.
 class DatabaseDataSource.DBNodeEntityModel
          Define a node entity.
 
Field Summary
protected  IThinkmapContext context
           
protected  String databaseVendor
           
protected  DataSource db
           
protected  boolean debug
           
protected  Vector models
           
protected  Vector queryDataSources
           
 
Constructor Summary
DatabaseDataSource()
          Creates a new DatabaseDataSource object.
 
Method Summary
 void addCall(ProcedureCallDataSource source)
           
 void addQuery(QueryDataSource source)
           
protected  void broadcastRequest(Message message, IEntityHandler callback)
           
 void contextDestroyed(IThinkmapContext itc)
          Called when the given context has been destroyed.
 void contextInitializing(IThinkmapContext context)
          Called when the given context is initializing.
 void contextStarting(IThinkmapContext itc)
          Called when the given context is starting.
 void contextStopping(IThinkmapContext itc)
          Called when the given context is stopping.
 QueryDataSource createCall()
           
 EdgeEntityModel createEdge()
           
protected  QueryDataSource createListDataSource(NodeEntityModel nodeModel, Binding[] idKeyBindings, Binding[] propertyBindings)
           
 NodeEntityModel createNode()
           
protected  StringBuffer createNodeSelect(NodeEntityModel nodeModel)
           
 QueryDataSource createQuery()
           
protected  Connection getConnection(Message message)
          This method returns a connection to a database.
 IThinkmapContext getContext()
           
protected  String getDatabaseDriverVendor()
           
 DataSource getDataSource()
          Get the SQL datasource this uses.
 EntityModel getEntityModel(String name)
           
protected  NodeColumnModel getForeignColumn(EdgeColumnModel ecm)
           
protected static int getIdKeyIndex(EntityModel nodeModel, ColumnModel column)
           
 QueryDataSource[] getQueryDataSources()
          Get the QueryDataSources for this DatabaseDataSource
protected  QueryDataSource makeEdgeNodeDataSource(EdgeEntityModel edgeEntity, NodeEntityModel fromNodeEntity, NodeEntityModel toNodeEntity, boolean isInverse)
           
protected  QueryDataSource makeEntityDataSource(NodeEntityModel nodeModel, int[] idKeyColumns, Binding[] idKeyBindings, Binding[] propertyBindings)
           
protected  void makeNodeDataSources(NodeEntityModel nodeModel)
           
protected  Binding[] makeWhereClause(ColumnModel[] edgeCols, ColumnModel[] toNodeCols, String edgeTableName, String toNodeTableName, NodeEntityModel toNodeEntity, NodeEntityModel fromNodeEntity, StringBuffer query, boolean isInverse)
           
protected  void processCustomRequest(Message message, IEntityHandler callback)
          Handle a custom request.
protected  void processEntityRequest(Message message, IEntityHandler callback)
          Handle an Entity request.
protected  void processIdRequest(Message message, IEntityHandler callback)
          Handle an ID request.
protected  void processMetadataRequest(Message message, IEntityHandler callback)
          Handle a metadata request.
protected  void processRelatedRequest(Message message, IEntityHandler callback)
          Handle a related request.
 void setConfig(ThinkmapConfig config)
           
 void setDataSource(DataSource db)
          Set the SQL datasource this uses.
 void setDebug(boolean b)
          Set to true to enable debug output.
 
Methods inherited from class thinkmap.datasource.util.AbstractDataSource
createRequest, processRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected boolean debug

db

protected DataSource db

queryDataSources

protected Vector queryDataSources

models

protected Vector models

databaseVendor

protected String databaseVendor

context

protected IThinkmapContext context
Constructor Detail

DatabaseDataSource

public DatabaseDataSource()
Creates a new DatabaseDataSource object.

Method Detail

setConfig

public void setConfig(ThinkmapConfig config)

contextInitializing

public void contextInitializing(IThinkmapContext context)
                         throws Exception
Description copied from interface: IContextListener
Called when the given context is initializing. Listeners should construct and configure objects that depend on the context at this time. This method will only be called once per context.

Specified by:
contextInitializing in interface IContextListener
Parameters:
context - the context that is initializing
Throws:
Exception - if an error occurs while processing this event.

contextStarting

public void contextStarting(IThinkmapContext itc)
Description copied from interface: IContextListener
Called when the given context is starting. All objects that depend on the context should have been initialized before this method is called. Listeners should start any services they offer at this time. A context may be started, stopped, and started again many times.

Specified by:
contextStarting in interface IContextListener
Parameters:
itc - the context that is starting

contextStopping

public void contextStopping(IThinkmapContext itc)
Description copied from interface: IContextListener
Called when the given context is stopping. Listeners should stop any services they offer at this time.

Specified by:
contextStopping in interface IContextListener
Parameters:
itc - the context that is starting

contextDestroyed

public void contextDestroyed(IThinkmapContext itc)
Description copied from interface: IContextListener
Called when the given context has been destroyed. Listeners should dispose and de-register objects that depend on the context at this time. This method will only be called once per context.

Specified by:
contextDestroyed in interface IContextListener
Parameters:
itc - the context that is being destroyed

setDebug

public void setDebug(boolean b)
Set to true to enable debug output.

Parameters:
b - true to enable debug output

getContext

public IThinkmapContext getContext()

createQuery

public QueryDataSource createQuery()

addQuery

public void addQuery(QueryDataSource source)

getQueryDataSources

public QueryDataSource[] getQueryDataSources()
Get the QueryDataSources for this DatabaseDataSource


createCall

public QueryDataSource createCall()

addCall

public void addCall(ProcedureCallDataSource source)

setDataSource

public void setDataSource(DataSource db)
Set the SQL datasource this uses.

Parameters:
db - SQL datasource

getDataSource

public DataSource getDataSource()
Get the SQL datasource this uses.

Returns:
SQL datasource

processMetadataRequest

protected void processMetadataRequest(Message message,
                                      IEntityHandler callback)
Description copied from class: AbstractDataSource
Handle a metadata request.

Overrides:
processMetadataRequest in class AbstractDataSource
Parameters:
message - The incoming request, packaged into a handy object.
callback - The IEntityHandler which will receive the response.

processIdRequest

protected void processIdRequest(Message message,
                                IEntityHandler callback)
Description copied from class: AbstractDataSource
Handle an ID request.

Overrides:
processIdRequest in class AbstractDataSource
Parameters:
message - The incoming request, packaged into a handy object.
callback - The IEntityHandler which will receive the response.

processEntityRequest

protected void processEntityRequest(Message message,
                                    IEntityHandler callback)
Description copied from class: AbstractDataSource
Handle an Entity request.

Overrides:
processEntityRequest in class AbstractDataSource
Parameters:
message - The incoming request, packaged into a handy object.
callback - The IEntityHandler which will receive the response.

processRelatedRequest

protected void processRelatedRequest(Message message,
                                     IEntityHandler callback)
Description copied from class: AbstractDataSource
Handle a related request.

Overrides:
processRelatedRequest in class AbstractDataSource
Parameters:
message - The incoming request, packaged into a handy object.
callback - The IEntityHandler which will receive the response.

processCustomRequest

protected void processCustomRequest(Message message,
                                    IEntityHandler callback)
Description copied from class: AbstractDataSource
Handle a custom request. Does nothing by default. Override this to handle requests that are not one of the four for which there are already specific methods.

Overrides:
processCustomRequest in class AbstractDataSource
Parameters:
message - The incoming request, packaged into a handy object.
callback - The IEntityHandler which will receive the response.

broadcastRequest

protected void broadcastRequest(Message message,
                                IEntityHandler callback)

getConnection

protected Connection getConnection(Message message)
                            throws SQLException
This method returns a connection to a database. It accepts a Message object from the client that is making the request. This allows subclasses to override this method to retrieve connections in special ways (eg, per-user connections). Please note: when this class is initializing, a null Message will be sent as a test. You can safely return null to signify that there is no matching connection.

Parameters:
message - A request message from the client side
Returns:
A connection to a database
Throws:
SQLException

createNode

public NodeEntityModel createNode()

createEdge

public EdgeEntityModel createEdge()

getEntityModel

public EntityModel getEntityModel(String name)

makeNodeDataSources

protected void makeNodeDataSources(NodeEntityModel nodeModel)

makeEntityDataSource

protected QueryDataSource makeEntityDataSource(NodeEntityModel nodeModel,
                                               int[] idKeyColumns,
                                               Binding[] idKeyBindings,
                                               Binding[] propertyBindings)

createNodeSelect

protected StringBuffer createNodeSelect(NodeEntityModel nodeModel)

createListDataSource

protected QueryDataSource createListDataSource(NodeEntityModel nodeModel,
                                               Binding[] idKeyBindings,
                                               Binding[] propertyBindings)

makeEdgeNodeDataSource

protected QueryDataSource makeEdgeNodeDataSource(EdgeEntityModel edgeEntity,
                                                 NodeEntityModel fromNodeEntity,
                                                 NodeEntityModel toNodeEntity,
                                                 boolean isInverse)
                                          throws BindingException
Throws:
BindingException

makeWhereClause

protected Binding[] makeWhereClause(ColumnModel[] edgeCols,
                                    ColumnModel[] toNodeCols,
                                    String edgeTableName,
                                    String toNodeTableName,
                                    NodeEntityModel toNodeEntity,
                                    NodeEntityModel fromNodeEntity,
                                    StringBuffer query,
                                    boolean isInverse)
                             throws BindingException
Throws:
BindingException

getIdKeyIndex

protected static int getIdKeyIndex(EntityModel nodeModel,
                                   ColumnModel column)

getForeignColumn

protected NodeColumnModel getForeignColumn(EdgeColumnModel ecm)
                                    throws BindingException
Throws:
BindingException

getDatabaseDriverVendor

protected String getDatabaseDriverVendor()


Copyright © 2013 Thinkmap, Inc. All Rights Reserved.