|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectequip.data.sql.CustomTableDataStore
Implementation of IDataStore interface which
holds data for one specific (run-time configured) tuple type in a
single JDBC table.
See notes for DataDelegate for configuring a dataspace
to make use of a custom data store such as this.
This version is intended to make it relatively easy to expose an existing table of data through Equip. To do this it requires an auxiliary table to contain data-table to Equip mapping information and additional Equip-specific information.
It is configured as follows:
<storeId>.url: <JDBC-URL> [e.g. "jdbc:mysql://serverURL/dbName"] <storeId>.user: <JDBC-username> [default: root] <storeId>.password: <JDBC-password> [Optional] <storeId>.driver: <JDBC-driver-classname> [e.g. "com.mysql.jdbc.Driver"] <storeId>.readonly: <readonly> [default: true] <storeId>.dataTableName: <data-table-name> <storeId>.dataKeyType: <type> [default: int, options: string, float, double, char] <storeId>.dataKeyColumn: <data-table-key-column-name> <storeId>.dataKeyMapClass: <class-to-map-data-key-to-guid> [default: equip.data.sql.DataKeyMapGetUnique] <storeId>.dataKeyAllocateClass: <class-to-get-a-new-data-key> [default: equip.data.sql.DataKeyAllocateMax] <storeId>.dataNameColumn: <data-table-item-data-name-column-name> [optional; defaults to using helper table, column "NAME"] <storeId>.helperTableName: <equip-specific-helper-table-name> [see below for schema] <storeId>.tupleTypeName: <tuple-type-name> [used in field 0 of tuple, StringBox] <storeId>.tupleSize: <N> <storeId>.field<n>Type: <type> [default: int, options: string, float, double, char; n=1..N] <storeId>.field<n>Column: <data-table-colum-name-for-field-n> [required, n=1..N]
The helper table schema is typically something like that produced by:
CREATE DATABASE FOODB; USE FOODB; CREATE TABLE EQUIPFOO ( GUID VARCHAR(100) NOT NULL, NAME VARCHAR(255), DATAKEY INTEGER NOT NULL, PRIMARY KEY (GUID) );where DATAKEY is the foreign key (same type) as the primary key of the data table.
For example, consider the following simple data table:
CREATE TABLE FOO ( SEQUENCE INTEGER NOT NULL, INTVALUE INTEGER NOT NULL, PRIMARY KEY (SEQUENCE) ); INSERT INTO FOO VALUES(1, 10); INSERT INTO FOO VALUES(2, 20); INSERT INTO FOO VALUES(3, 30); GRANT ALL ON FOODB TO 'equip'@127.0.0.1 IDENTIFIED BY 'password'; FLUSH PRIVILEGES;in a mysql database called "
FOODB" on the local host, with account
name "equip" and password "password"...
This could be exposed as a tuple with 3 fields:
storeId
is "FooTable":
FooTable.url: jdbc:mysql://localhost:3306/FOODB FooTable.user: equip FooTable.password: password FooTable.driver: com.mysql.jdbc.Driver FooTable.readonly: false FooTable.dataTableName: FOO FooTable.dataKeyType: int FooTable.dataKeyColumn: SEQUENCE FooTable.dataKeyMapClass: equip.data.sql.DataKeyMapGetUnique FooTable.dataKeyAllocateClass: equip.data.sql.DataKeyAllocateMax #FooTable.dataNameColumn: FooTable.helperTableName: EQUIPFOO FooTable.tupleTypeName: equip.data.sql.CustomTable.FOO FooTable.tupleSize: 2 FooTable.field1Type: int FooTable.field1Column: SEQUENCE FooTable.field2Type: int FooTable.field2Column: INTVALUE
| Field Summary | |
(package private) java.sql.Connection |
conn
single shared connection |
(package private) IDataKeyAllocate |
dataKeyAllocateInstance
config |
(package private) java.lang.String |
dataKeyColumn
config |
(package private) IDataKeyMap |
dataKeyMapInstance
config |
(package private) java.lang.String |
dataKeyType
config |
(package private) java.lang.String |
dataNameColumn
config (null if "NAME" in helper table) |
(package private) java.lang.String |
dataTableName
config |
(package private) static java.lang.String |
DEFAULT_DATAKEY_COLUMN
|
(package private) static java.lang.String |
DEFAULT_ID_COLUMN
|
(package private) static java.lang.String |
DEFAULT_NAME_COLUMN
|
(package private) java.lang.String |
getValuesQuery
SELECT ... |
(package private) java.lang.String |
helperTableName
config |
(package private) boolean |
readonly
readonly? |
(package private) GUID |
responsible
|
(package private) java.lang.String[] |
tupleFieldColumns
config |
(package private) java.lang.String[] |
tupleFieldTypes
config |
(package private) int |
tupleSize
config |
(package private) java.lang.String |
tupleTypeName
config |
(package private) static java.lang.String |
TYPE_CHAR
|
(package private) static java.lang.String |
TYPE_DOUBLE
|
(package private) static java.lang.String |
TYPE_FLOAT
|
(package private) static java.lang.String |
TYPE_INT
|
(package private) static java.lang.String |
TYPE_STRING
|
| Constructor Summary | |
CustomTableDataStore(java.lang.String storeId,
GUID responsible)
default constructor. |
|
| Method Summary | |
boolean |
checkAdd(AddEvent add)
check if store would like to/be prepared to handle this AddEvent. |
protected java.util.Vector |
doSQLQuery(java.lang.String query)
sql query. |
protected void |
doSQLUpdate(java.lang.String update)
sql update. |
protected java.lang.String |
fieldToSQLString(java.lang.String type,
ValueBase field)
|
void |
flush()
Flush any pending persistent records |
java.util.Enumeration |
getCandidateItemBindings(ItemData[] itemTemplates)
get the ItemBinding maintained by this store which should be considered when pattern matching the associated itemTemplates for an add/delete while present pattern. |
java.util.Enumeration |
getExpiredGUIDs(Time now)
returns GUIDs of all leased items expiring at or before time 'now'. |
Time |
getFirstExpireTime()
returns lowest (soonest, or furthest in past) expire time of any leased item in this store. |
ItemBinding |
getItemBinding(GUID id)
get the ItemBinding for the given id iff it is maintained by this store, else null. |
java.util.Enumeration |
getRemoveResponsibleGUIDs(RemoveResponsible remove)
get GUIDs of data items in this store which are process bound to the given responsible ID as per the RemoveResponsible event (or not, according to inverse flag). |
boolean |
handleAdd(AddEvent add)
request that store handle the Add event, adding to itself accordingly. |
boolean |
handleDelete(DeleteEvent del)
request that store handles the given delete, which it must iff it is currently maintaining state for the corresponding data item. |
boolean |
handleUpdate(UpdateEvent update)
request that store handles the given update, which it must iff it is currently maintaining state for it. |
boolean |
holdsGUID(GUID id)
check if store is maintaining state for the given GUID. |
protected ValueBase |
newTupleField(java.lang.String type,
java.lang.String value)
make a correctly typed typle field value |
static GUID |
parseGUID(java.lang.String guid)
string to guid |
protected java.lang.String |
quoteType(java.lang.String type,
java.lang.String value)
to type-specific quoting if required |
void |
terminate()
terminate - tidy up. |
protected java.lang.Object |
toNativeType(java.lang.String type,
java.lang.String value)
to type-specific java type |
void |
truncateExpireTimes(GUID responsible,
Time expire)
reduce lease on all leased items with given responsible id to expire at 'expire time'. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
java.sql.Connection conn
boolean readonly
java.lang.String dataTableName
java.lang.String dataKeyType
static final java.lang.String TYPE_INT
static final java.lang.String TYPE_STRING
static final java.lang.String TYPE_FLOAT
static final java.lang.String TYPE_DOUBLE
static final java.lang.String TYPE_CHAR
java.lang.String dataKeyColumn
IDataKeyMap dataKeyMapInstance
IDataKeyAllocate dataKeyAllocateInstance
java.lang.String dataNameColumn
static final java.lang.String DEFAULT_NAME_COLUMN
static final java.lang.String DEFAULT_ID_COLUMN
static final java.lang.String DEFAULT_DATAKEY_COLUMN
java.lang.String helperTableName
java.lang.String tupleTypeName
int tupleSize
java.lang.String[] tupleFieldTypes
java.lang.String[] tupleFieldColumns
java.lang.String getValuesQuery
GUID responsible
| Constructor Detail |
public CustomTableDataStore(java.lang.String storeId,
GUID responsible)
throws DataStoreConfigurationException
| Method Detail |
public boolean handleAdd(AddEvent add)
handleAdd in interface IDataStoreadd - The AddEvent to be handled.
IDataStore.checkAddpublic boolean checkAdd(AddEvent add)
AddEvent.
checkAdd in interface IDataStoreadd - The AddEvent to be handled.
public boolean holdsGUID(GUID id)
GUID.
holdsGUID in interface IDataStoreid - The GUID of the data item in question.
public boolean handleUpdate(UpdateEvent update)
handleUpdate in interface IDataStoreupdate - the UpdateEvent to be handled.
public boolean handleDelete(DeleteEvent del)
handleDelete in interface IDataStorepublic java.util.Enumeration getRemoveResponsibleGUIDs(RemoveResponsible remove)
getRemoveResponsibleGUIDs in interface IDataStoreremove - the RemoveResponsible event.
public ItemBinding getItemBinding(GUID id)
getItemBinding in interface IDataStoreid - the id of the data item being requested.
ItemBinding for that item, else null iff
unknown to this store.public java.util.Enumeration getCandidateItemBindings(ItemData[] itemTemplates)
getCandidateItemBindings in interface IDataStoreitemTemplates - array of template data items, else
null or zero length list for a wild-card (any item).
public Time getFirstExpireTime()
getFirstExpireTime in interface IDataStorepublic java.util.Enumeration getExpiredGUIDs(Time now)
getExpiredGUIDs in interface IDataStorenow - The current time of the expiration clock.
GUIDs of now expiring data items
which the call might now reasonably issue delete events
for).
public void truncateExpireTimes(GUID responsible,
Time expire)
truncateExpireTimes in interface IDataStoreresponsible - required item responsible idexpire - the new expire time for matched items
public void terminate()
terminate in interface IDataStore
protected java.util.Vector doSQLQuery(java.lang.String query)
throws java.sql.SQLException
java.sql.SQLException
protected void doSQLUpdate(java.lang.String update)
throws java.sql.SQLException
java.sql.SQLException
protected java.lang.String quoteType(java.lang.String type,
java.lang.String value)
protected java.lang.Object toNativeType(java.lang.String type,
java.lang.String value)
public static GUID parseGUID(java.lang.String guid)
protected ValueBase newTupleField(java.lang.String type,
java.lang.String value)
protected java.lang.String fieldToSQLString(java.lang.String type,
ValueBase field)
public void flush()
flush in interface IDataStore
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||