|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface Database provides access to actual connection with
Cache. The normal way to obtain this connection is by calling one
of methods getDatabase()
in CacheDatabase
class.
This connection can be implemented in different ways
Currently we have 2 implementations:
Because the connection is very implementation specific Database interface is totally opaque. Classes which implement it hold some information, but only implementation knows how to use it. Users are discouraged to use any methods of those classes not defined in this interface.
In applications working with Cache Database Java classes,
generated from Cache classes are usually present. Objects of those
classes held references to Database
server. All
generated classes have
com.intersys.classes.CacheRootObject
as their
superclass.
CacheRootObject
,
ObjectHandle
Field Summary | |
static int |
RET_NONE
|
static int |
RET_OBJECT
|
static int |
RET_PRIM
|
Method Summary | |
boolean |
addListener(EventListener listener)
Adds another listener for messages from server. |
Map |
close()
Closes connection to Database. |
void |
closeAllObjects()
Closes all objects, opened by client. |
void |
closeObject(int oref)
Closes an object with given object reference. |
void |
closeObject(Object zref)
Closes an object with given object reference. |
void |
createObjects(String cacheClassName,
Collection objects)
Saves a collection of previously created new objects in Cache Database. |
Statement |
createStatement()
Creates SQL statement to be run through this connection. |
boolean |
equals(Object obj)
Checks whether two databases refer to the same Cache server connection. |
CacheClass |
getCacheClass(String typeName)
Returns Cache Class corresponding to given type name. |
int |
getCacheType()
Returns type of client side data cache. |
String |
getConnectionString()
Returns connection string for Database. |
int |
getNumberOfOpenObjects()
Returns number of objects opened by client. |
int |
getNumberOfServerCalls()
Returns number of all calls from client to Cache server from Database object creation. |
int |
getNumberOfServerCalls(int i)
Returns number of calls from client to Cache server from Database object creation while profile i was on
(between calls to setProfileOn(i) and setProfileOff(i)). |
ObjectServerInfo |
getServerInfo()
Returns information about Cache Database server. |
long |
getServerTime()
Returns commulative time elapsed during waiting for server response in all calls to Cache server. |
long |
getServerTime(int i)
Returns commulative time elapsed during waiting for server response in calls to Cache server while profile i
was on (between calls to setProfileOn(i) and setProfileOff(i)). |
boolean |
isLightConnection()
Returns information about Cache Database server. |
boolean |
isLowLevelConnectionClosed()
Checks whether a JDBC (or ODBC) driver level connection to Cache Server, which had been used by this Database
object is closed. |
Iterator |
openByQuery(String query)
Opens all objects othat satisfy given SQL query. |
Iterator |
openByQuery(String query,
Object[] args)
Opens all objects othat satisfy given SQL query. |
Iterator |
openByQuery(String cacheClassName,
String condition)
Opens all objects of given class that satisfy given simple condition, specified in SQL syntax. |
Iterator |
openByQuery(String cacheClassName,
String condition,
Object[] args)
Opens all objects of given class that satisfy given simple condition, specified in SQL syntax. |
int |
parseStatus(com.intersys.cache.Dataholder dh)
Parses status, returned by Cache routine. |
int |
parseStatus(StatusCode sc)
Parses status, returned by Cache routine. |
CallableStatement |
prepareCall(String statement)
Prepares SQL stored procedure to be called. |
PreparedStatement |
prepareStatement(String statement)
Prepares SQL statement to be run through this connection. |
void |
printStatistics()
Prints statistics of cache usage to standard out. |
void |
printStatistics(PrintStream out)
Prints statistics of cache usage. |
void |
registerSensitiveObject(CacheServerSensitive obj)
Registers an object which will be informed of any call to Cache Database which changes any of proxy objects in this client. |
void |
registerSensitiveObject(CacheServerSensitive obj,
int ref)
Registers an object which will be informed of any call to Cache Database which changes a particular proxy object in this client. |
void |
registerSensitiveObject(CacheServerSensitive obj,
ObjectHandle ref)
Registers an object which will be informed of any call to Cache Database which changes a particular proxy object in this client. |
void |
registerSensitiveObject(CacheServerSensitive obj,
Set refSet)
Registers an object which will be informed of any call to Cache Database which changes some particular proxy objects in this client. |
boolean |
removeListener(EventListener listener)
Removes a listener for messages from server. |
com.intersys.cache.Dataholder |
runClassMethod(String className,
String methodName,
com.intersys.cache.Dataholder[] argv,
int retType)
Runs static (also known as class) method in cache. |
com.intersys.cache.Dataholder[] |
runClassMethod(String className,
String methodName,
int[] refs,
com.intersys.cache.Dataholder[] argv,
int retType)
Runs static (also known as class) method in cache. |
void |
saveObjects(String cacheClassName,
Collection objects)
Saves changes in objects to Cache Database. |
void |
setClassLoader(ClassLoader newLoader)
Sets custom class loader for loading Java projections of Cache classes. |
void |
setConsoleOutput(PrintStream out)
Sets the stream used for console output by Cache server-side methods. |
void |
setProfileOff(int i)
Disables gathering profile information for cell i . |
void |
setProfileOn(int i)
Enables gathering profile information for cell i . |
void |
transactionCommit()
Commits the transaction |
void |
transactionRollback()
Roll the transaction back |
void |
transactionStart()
Starts a transaction |
boolean |
unRegisterSensitiveObject(CacheServerSensitive obj)
Unregisters object, previously registered with method registerSensitiveObject . |
DatabaseUtilities |
utilities()
Returns an utility object which can import class into Cache, generate Java class from Cache class and do a number of other operations. |
Field Detail |
public static final int RET_OBJECT
public static final int RET_PRIM
public static final int RET_NONE
Method Detail |
public com.intersys.cache.Dataholder[] runClassMethod(String className, String methodName, int[] refs, com.intersys.cache.Dataholder[] argv, int retType) throws CacheException
The first element (index 0) of returned array contains return value. If the method is void first element has undefined value. Elements starting with the second (index 1) contain values for parameters passed by reference. Note, that even if the method is void, values for references start from the second, not the first element of array.
className
- Name of the Cache class.methodName
- Name of static method in the class.refs
- Array containing indexes (in array
argv
) for parameters passed by reference. If there
are no parameters passed by reference it is a zero length
array.argv
- Arguments to the method. If there are no arguments,
it is a zero length array.retType
- Can have 3 possible values:
Database.RET_OBJECT
if method returns an object,
Database.RET_PRIM
if method returns a value of
primitive type or Database.RET_NONE
if method does
not return a value.
CacheException
public com.intersys.cache.Dataholder runClassMethod(String className, String methodName, com.intersys.cache.Dataholder[] argv, int retType) throws CacheException
Wrapper method to run class method when no arguments are passed by reference.
className
- Name of the Cache class.methodName
- Name of static method in the class.argv
- Arguments to the method. If there are no arguments,
it is a zero length array.retType
- Can have 3 possible values:
Database.RET_OBJECT
if method returns an object,
Database.RET_PRIM
if method returns a value of
primitive type or Database.RET_NONE
if method does
not return a value.
Dataholder
.
CacheException
public CacheClass getCacheClass(String typeName) throws CacheException
typeName
- Name of the type
CacheClass
object.
CacheException
com.intersys.objects.reflect
public void printStatistics()
-1
public void printStatistics(PrintStream out)
-1
out
- java.io.PrintStream
to print output to.public boolean equals(Object obj)
obj
- Object which should be an instance of Database
.
true
if obj is an instance of
Database
and it referes to the same Cache server
connection. Otherwise returns false
.public String getConnectionString()
public Statement createStatement() throws CacheException
A set of convenience methods: createStatement
,
prepareStatement
, prepareCall
are
provided here for simple queries and some update operations on
the database. They are intended to use in applications which
mostly use Object Java Projection with Cache but also need
simple SQL functionality.
For full JDBC functioanlity you should use package
java.sql
. In this case it is convenient first to
establish a JDBC connection to Cache and then obtain an
instance of Database
interface using method
CacheDatabase.getDatabase(java.sql.Connection)
.
java.sql.Statement
.
CacheException
- if an error occured during preparation.Connection.createStatement()
,
prepareStatement(java.lang.String)
,
prepareCall(java.lang.String)
,
CacheDatabase.getDatabase(java.sql.Connection)
public PreparedStatement prepareStatement(String statement) throws CacheException
createStatement
,
prepareStatement
, prepareCall
are
provided here for simple queries and some update operations on
the database. They are intended to use in applications which
mostly use Object Java Projection with Cache but also need
simple SQL functionality.
For full JDBC functioanlity you should use package
java.sql
. In this case it is convenient first to
establish a JDBC connection to Cache and then obtain an
instance of Database
interface using method
CacheDatabase.getDatabase(java.sql.Connection)
.
statement
- SQL query string
java.sql.PreparedStatement
.
CacheException
- if an error occured during preparation.Connection.prepareStatement(java.lang.String)
,
createStatement()
,
prepareCall(java.lang.String)
,
CacheDatabase.getDatabase(java.sql.Connection)
public CallableStatement prepareCall(String statement) throws CacheException
createStatement
,
prepareStatement
, prepareCall
are
provided here for simple queries and some update operations on
the database. They are intended to use in applications which
mostly use Object Java Projection with Cache but also need
simple SQL functionality.
For full JDBC functioanlity you should use package
java.sql
. In this case it is convenient first to
establish a JDBC connection to Cache and then obtain an
instance of Database
interface using method
CacheDatabase.getDatabase(java.sql.Connection)
.
statement
- Statement representing call to an SQL procedure.
java.sql.PreparedStatement
.
CacheException
- if SQL stored procedure was not found or
any other error occured during preparation.Connection.prepareCall(java.lang.String)
,
prepareStatement(java.lang.String)
,
CacheDatabase.getDatabase(java.sql.Connection)
public void closeObject(int oref) throws CacheException
oref
- Object reference of object to close.
CacheException
public void closeObject(Object zref) throws CacheException
zref
- Object reference of object to close. Returned by
getZRef() method of ObjectHandle interface.
CacheException
ObjectHandle.getZRef()
public Map close() throws CacheException
CacheException
public void closeAllObjects() throws CacheException
Database object can be used after call to this method but it will have to load again any previously loaded objects. No other resources will be released. It is still advisable to call close() method to release all remaining resources.
CacheException
public boolean isLowLevelConnectionClosed() throws CacheException
Database
object is closed. In case of JDBC it queries
java.sql.Connection
object. Note, that though a
driver level connection can be still open, database connection
maybe already closed. Generally this method can be useful in
connection pooling situation.
CacheException
Connection
public ObjectServerInfo getServerInfo() throws CacheException
ObjectServerInfo
object.
CacheException
- if information is unavailable, e.g. if
connection is not open.public boolean isLightConnection()
true
if the connection was initiated by
calling getLightDatabase() method. Light connection has some
limitations.public int parseStatus(com.intersys.cache.Dataholder dh) throws CacheException
%Library.Status.
dh
- Status object embedded in
Dataholder
. Dataholder
is an internal
way of trepresenting data passed and received from Cache
Server.
CacheException
- in 2 cases: First in case when Status
indicates error and second when communication error occured,
attempting to connect to Cache Server.public int parseStatus(StatusCode sc) throws CacheException
%Library.Status.
sc
- Status object represented as
com.intersys.objects.StatusCode
.
CacheException
- in 2 cases: First in case when Status
indicates error and second when communication error occured,
attempting to connect to Cache Server.public Iterator openByQuery(String cacheClassName, String condition, Object[] args) throws CacheException
If actual object belongs to subclasses of
cacheClassName
, it will be opened
correctly. However in case when there are many such objects
that can degrade performance significantly.
Condition in this method only can be a simple condition that
refers only to properties of a single object (single row in one
SQL table). For example, for class Sample.Person
valid conditions can be "Name %STARTSWITH ?"
,
"Home_City = ?"
or "ID BETWEEN ? AND
?"
. It can also include "ORDER BY"
clause,
for example: "Home_City = ? ORDER BY Name"
. If a
particular ordering was specified in SQL statement, the
ordering is preserved by Itetrator.
In case when a more complex condition is required, method
openByQuery(String,Object[])
should be used.
cacheClassName
- Name of Cache class to which (or its
subclasses) objects belong. It must me a fully qualified class
name including package name.condition
- Simple condition on objects, in SQL syntax. It
can refer only to properties of a single object.args
- Parameters to replace "?" in
condition
. If there are no parameters in condition
may be null or empty array.
java.util.Iterator
, that iterates over all opened
objects in specified order.
CacheException
openByQuery(java.lang.String,java.lang.Object[])
,
openByQuery(java.lang.String,java.lang.String)
public Iterator openByQuery(String cacheClassName, String condition) throws CacheException
If actual object belongs to subclasses of
cacheClassName
, it will be opened
correctly. However in case when there are many such objects
that can degrade performance significantly.
Condition in this method only can be a simple condition that
refers only to properties of a single object (single row in one
SQL table). For example, for class Sample.Person
valid conditions can be "Name %STARTSWITH 'A'"
,
"Home_City = 'BOSTON'"
or "ID BETWEEN 1000
AND 2000"
. It can also include "ORDER BY"
clause, for example: "Home_City = 'BOSTON' ORDER BY
Name"
. If a particular ordering was specified in SQL
statement, the ordering is preserved by Itetrator.
If similar queries with different values of parameters are used
then method
openByQuery(java.lang.String,java.lang.String,java.lang.Object[])
gives better perfromance. In case when a more complex condition
is required, method openByQuery(String,Object[])
should be used.
cacheClassName
- Name of Cache class to which (or its
subclasses) objects belong. It must me a fully qualified class
name including package name.condition
- Simple condition on objects, in SQL syntax. It
can refer only to properties of a single object and can not
have parameters.
java.util.Iterator
, that iterates over all opened
objects in specified order.
CacheException
openByQuery(java.lang.String,java.lang.String,java.lang.Object[])
,
openByQuery(java.lang.String,java.lang.Object[])
public Iterator openByQuery(String query, Object[] args) throws CacheException
Sample.Person
objects, the first coulmn should be
"Sample.Person.%ID".
Example of valid SQL statement for the purpose of opening
objects of class If actual objects belong to subclasses of the class specified
by the first column of SQL statement, they will be opened
correctly. However in case when there are many such objects
performance can be significantly degraded.
SELECT
Sample.Employee.%ID, Sample.Employee.Name, Sample.Company.Name
FROM Sample.Employee, Sample.Company WHERE Revenue > ? AND
Company = Sample.Company.ID Order by Sample.Company.Name,
Sample.Employee.Name
query
- A valid SQL statement, satisfying additional
requirments, described above.args
- Parameters to replace "?" in
query
. If there are no parameters in condition
may be null or empty array.
java.util.Iterator
, that iterates over all opened
objects in specified order.
CacheException
openByQuery(java.lang.String,java.lang.String,java.lang.Object[])
public Iterator openByQuery(String query) throws CacheException
Sample.Person
objects, the first coulmn should be
"Sample.Person.%ID".
"ORDER
BY"
clause should be specified by names, not by numbers.
Example of valid SQL statement for the purpose of opening
objects of class If actual objects belong to subclasses of the class specified
by the first column of SQL statement, they will be opened
correctly. However in case when there are many such objects
performance can be significantly degraded.
If similar queries with different values of parameters are used
then method
SELECT
Sample.Employee.%ID, Sample.Employee.Name, Sample.Company.Name
FROM Sample.Employee, Sample.Company WHERE Revenue > 2100 AND
Company = Sample.Company.ID Order by Sample.Company.Name,
Sample.Employee.Name
openByQuery(java.lang.String,java.lang.Object[])
gives better perfromance.
query
- A valid SQL statement, satisfying additional
requirments, described above.
java.util.Iterator
, that iterates over all opened
objects in specified order.
CacheException
openByQuery(java.lang.String,java.lang.String,java.lang.Object[])
,
openByQuery(java.lang.String,java.lang.Object[])
public void createObjects(String cacheClassName, Collection objects) throws CacheException
saveObjects
method or instance
method save
on the object itself.
cacheClassName
- Name of the Cache class, to which all
objects in given collection belong. Cache class should be a
subclass of %Library.Persistent
.objects
- A collection of newly created objects. None of
the objects in the collection may already exist in database.
CacheException
saveObjects(java.lang.String, java.util.Collection)
,
Persistent.save()
public void saveObjects(String cacheClassName, Collection objects) throws CacheException
createObjects
method or instance method save
on the object
itself.
cacheClassName
- Name of the Cache class, to which all
objects in given collection belong. Cache class should be a
subclass of %Library.Persistent
.objects
- A collection of existing objects. Any object in
collection must already exist in database.
CacheException
createObjects(java.lang.String, java.util.Collection)
,
Persistent.save()
public DatabaseUtilities utilities()
DatabaseUtilities
associated
with this Database
.public void registerSensitiveObject(CacheServerSensitive obj) throws CacheException
onServerCall()
of
registered object will be called.
obj
- an object, implementing
com.intersys.CacheServerSensitive
interface.
CacheException
- if registration fails for any reason.registerSensitiveObject(CacheServerSensitive,ObjectHandle)
,
registerSensitiveObject(CacheServerSensitive,java.util.Set)
,
unRegisterSensitiveObject(com.intersys.objects.CacheServerSensitive)
public void registerSensitiveObject(CacheServerSensitive obj, ObjectHandle ref) throws CacheException
onServerCall()
of registered object will be called.
obj
- an object, implementing
com.intersys.CacheServerSensitive
interface.ref
- a proxy object, in which registering object is
interested.
CacheException
- if registration fails for any reason.registerSensitiveObject(CacheServerSensitive)
,
registerSensitiveObject(CacheServerSensitive,java.util.Set)
,
unRegisterSensitiveObject(com.intersys.objects.CacheServerSensitive)
public void registerSensitiveObject(CacheServerSensitive obj, int ref) throws CacheException
onServerCall()
of registered object will be called.
obj
- an object, implementing
com.intersys.CacheServerSensitive
interface.ref
- an oref of the object in which this object is
interested.
CacheException
- if registration fails for any reason.registerSensitiveObject(CacheServerSensitive)
,
registerSensitiveObject(CacheServerSensitive,java.util.Set)
,
unRegisterSensitiveObject(com.intersys.objects.CacheServerSensitive)
public void registerSensitiveObject(CacheServerSensitive obj, Set refSet) throws CacheException
onServerCall()
of registered object will be called.
obj
- an object, implementing
com.intersys.CacheServerSensitive
interface.refSet
- Set of proxy objects, in which registering object
is interested. All elements of this set must be assignable to
com.intersys.cklasses.ObjectHandle
.
CacheException
- if registration fails for any reason.registerSensitiveObject(CacheServerSensitive)
,
registerSensitiveObject(CacheServerSensitive,ObjectHandle)
,
unRegisterSensitiveObject(com.intersys.objects.CacheServerSensitive)
public boolean unRegisterSensitiveObject(CacheServerSensitive obj) throws CacheException
registerSensitiveObject
.
obj
- an object, implementing
com.intersys.CacheServerSensitive
interface.
CacheException
- if deregistration fails for any reason.registerSensitiveObject(CacheServerSensitive)
,
registerSensitiveObject(CacheServerSensitive,ObjectHandle)
,
registerSensitiveObject(CacheServerSensitive,java.util.Set)
public void transactionStart() throws CacheException
CacheException
public void transactionCommit() throws CacheException
CacheException
public void transactionRollback() throws CacheException
CacheException
public int getCacheType() throws CacheException
int
. In current implementation meaningful is only
whether return value is 0
(means no client side
caching) or greater than 0
(indicates presense of
client side cache).
CacheException
public int getNumberOfOpenObjects()
public long getServerTime() throws CacheException
CacheException
getNumberOfServerCalls()
,
getServerTime(int)
public int getNumberOfServerCalls() throws CacheException
CacheException
getNumberOfServerCalls(int)
,
getServerTime()
public long getServerTime(int i) throws CacheException
i
was on (between calls to setProfileOn(i) and setProfileOff(i)).
i
- Profiling cell number.
i
was on.
CacheException
getNumberOfServerCalls(int)
,
getServerTime()
,
setProfileOn(int)
,
setProfileOff(int)
,
CacheDatabase.setNumberOfProfiles(int)
,
CacheDatabase.getNumberOfProfiles()
public int getNumberOfServerCalls(int i) throws CacheException
i
was on
(between calls to setProfileOn(i) and setProfileOff(i)).
i
- Profiling cell number.
i
was on.
CacheException
getNumberOfServerCalls(int)
,
getServerTime()
,
setProfileOn(int)
,
setProfileOff(int)
,
CacheDatabase.setNumberOfProfiles(int)
,
CacheDatabase.getNumberOfProfiles()
public void setProfileOn(int i) throws CacheException
i
.
i
- Profiling cell number.
CacheException
getNumberOfServerCalls(int)
,
getServerTime(int)
,
setProfileOff(int)
,
CacheDatabase.setNumberOfProfiles(int)
,
CacheDatabase.getNumberOfProfiles()
public void setProfileOff(int i) throws CacheException
i
.
i
- Profiling cell number.
CacheException
getNumberOfServerCalls(int)
,
getServerTime(int)
,
setProfileOn(int)
,
CacheDatabase.setNumberOfProfiles(int)
,
CacheDatabase.getNumberOfProfiles()
public void setClassLoader(ClassLoader newLoader)
The primary intention for this method is to facilitate work inside application servers, which use their own class loaders which may differ from the class loader for Database object, which by default would be used to load all classes for Cache proxy objects.
Another possible application of this method is to generate
Java projections of Cache classes "on the fly", i.e. at the
moment they are required by the application. This is rather
limited use, because generation of classes happen at runtime,
not at compilation time. To achieve automatic generation and
compilation this method should be used in the special form:
setClassLoader(new
com.intersys.cache.CacheClassLoder("scratch directory path",
db));
, where db
is reference to this
database object.
newLoader
- the class loader to use.public void setConsoleOutput(PrintStream out)
Write
command the
output is redirected to specified stream. By default it is
System.out
.
Setting output stream to null
will suppress output.
out
- Stream to be used for console output. If
null
, then output will be suppressed.public boolean addListener(EventListener listener)
setConsoleOutput(java.io.PrintStream)
public boolean removeListener(EventListener listener)
setConsoleOutput(java.io.PrintStream)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |