asgaard.skid
Class BeanBroker

java.lang.Object
  |
  +--asgaard.skid.BeanBroker

public final class BeanBroker
extends java.lang.Object
implements RemoteBroker, asgaard.utils.test.TestIt

BeanBroker is the transparent objectstorage of "Skid". It is th object-oriented interface of the database and maintain all databean-object-instances at runtime within a common access functionality. CREATE, FIND, UPDATE is done completely transparent, the used database is also hidden.

Important: public static BeanBroker THIS has to be defined within each VM to guarantie regular behavior within Skid!

To become persistent an Object has to implement RemoteBean.

See Also:
SkidBean

Field Summary
static java.util.GregorianCalendar CALENDAR
           
static java.lang.String Dump_Fiele_Name
          Name of the Dumpfile
static byte FILTER_EQ
          exact the same value "="
static byte FILTER_GR
          greater ">"
static byte FILTER_GR_EQ
          greater or equal ">="
static byte FILTER_NONE
          Not used for Search.
static byte FILTER_NOT_EQ
          not equal "!
static byte FILTER_SM
          smaller "<"
static byte FILTER_SM_EQ
          smaller or equal "<="
static int HISTORY_ALL
          All information for the UNDO-mechanism is stored.
static int HISTORY_NONE
          No information for the UNDO-mechanism is stored
static java.lang.String HOST
          String with the ip-Adress of the Host
static int ID_FAIL
           
static int ID_HIGH
           
protected  asgaard.utils.log.LogClient log
           
 SkidMaintain maintain
          Database Maintainanceobject (Backup, Restore, ...)
static int PUBLIC_ID
           
static RemoteBroker THIS
          Global pointer to the BeanBroker (one per VM)
static byte TYPE_BEAN
          Beantypes: A SkidBean, made persistand by complete storage through serialisation
static byte TYPE_CLASS
          Beantypes: Holds Meta-Information about the class
static byte TYPE_HEAVYWEIGHT
          Beantypes: A heavyweight-Bean it's content is stored in an extra table
static byte TYPE_LIGHTWEIGHT
          Beantypes: A lightweight-Bean made persistance storing only parts of itselfe
static byte UPDATE_ALL
          All modifications are done, no difference whether there are changes made or not.
static byte UPDATE_NONE
          No Updates are done.
static byte UPDATE_STRONG
          Only if the Broker-Version of the Bean has not changed in meantime.
static byte UPDATE_WEAK
          Only if there is no newer Bean at the Broker an update is made.
 
Constructor Summary
BeanBroker(java.lang.String driverClass, java.lang.String connStr, java.lang.String connUser, java.lang.String connPwd, java.lang.String localDB, asgaard.utils.log.LogClient log, byte loglevel, boolean runLocal, java.util.ResourceBundle sRes, long nr, java.lang.String xKey)
          Creating Object-Broker and Establishing connection to the database.
 
Method Summary
 void addEvent(RemoteBean producer, RemoteBean event)
          Adding an Event and replicating it to all suscribed Objects.
 boolean beanExist(int key)
          Returns whether an Bean is available within the Broker or not.
 java.lang.String checkUser(java.lang.String userName, java.lang.String encr)
          Checks if the given username exists or not
protected  void connectDatabase(java.lang.String driverClass, java.lang.String connStr, java.lang.String connUser, java.lang.String connPwd, java.lang.String localDB, boolean runLocal, java.util.ResourceBundle sRes)
          Does the connection to the database and creates it if nessecary.
protected  void delEvent()
          Deletes all marked Events
protected  void delEvent(long deadline)
          Deletes all events older than the given time
static java.lang.String encryptPwd(java.lang.String clearPwd)
          Encrypts an password for Database connection with the built in key.
 RemoteBean getBean(int key)
          Searches for a Bean by a given key.
 RemoteBean[] getBean(int[] key)
          Searches for Beans by a given set of keys.
 int[] getBeanKey(java.lang.String aClass, java.lang.String[] paramName, java.lang.Object[] searchValue, byte[] searchOp)
          Searches for a Bean by a given key.
 BeanKeyCall getBeanKeyCall(java.lang.Class aClass)
          Returns the Key-Call-Adapter for a asked Class (represented by it's key).
 BeanKeyCall getBeanKeyCall(int pClass)
          Returns the Key-Call-Adapter for a asked Class (represented by it's key).
 int getClassKey(java.lang.Class aClass)
          Class-Key of the Bean, differ between different classes.
 int getClassKey(RemoteBean aBean)
          Class-Key of the Bean, differ between different classes.
 int getClassKey(java.lang.String classname)
          Class-Key of the Bean, differ between different classes.
 SkidEvent[] getEvent(RemoteBean consumer, long newer)
          Returns the Events for a consumer object which are newer than the given time
 BeanLink[] getLink(BeanLinkFilter filter)
          Searches for a set of Links using the filter - capabilities of BeanLink.
 BeanLink getLink(int from, int to, int by)
          Searches for a specific Link using it's primary key.
 java.lang.Object[][] getTestScript()
          Returns the Test-Script for this Class
 java.lang.Object getUser(java.lang.Object o, java.lang.String name, java.lang.String encr)
          Excanges an user with an authorised object (hardcoded)
 java.lang.Object getUser(java.lang.String name, java.lang.String encr)
          Excanges an user with an authorised object (hardcoded)
 java.lang.Object invokeCall(java.lang.Class beanClass, java.lang.String name, java.lang.Object[] args, java.lang.String[] classnames)
          Invokes the called method of the filterinterface.
 boolean linkExist(int from, int to, int by)
          Returns if a specific Key exists, hiding all Exceptions.
 boolean logMsg(java.lang.String server, java.lang.String point, byte typ, boolean ok, java.lang.String msg)
          Puts a Message to the LOG-Server if available and returns whether it was sent or not
 java.lang.Object[] putBean(RemoteBean aObj)
          Puts the Bean into the Chache and saves it do not use manually.
 boolean putLink(BeanLink link)
          Adds a new Relation between Beans.
 boolean putUser(java.lang.Object o)
          Excanges an user with an authorised object (hardcoded)
protected  void reconnect()
          Resonnecting to the database after a timeout
 void setEvent(RemoteBean producer, RemoteBean event, RemoteBean consumer, byte fromState, byte toState)
          Changing the State of an specific event.
 void suscribeEvent(RemoteBean producer, RemoteBean event, RemoteBean consumer)
          Adding an Event-Pattern and suscribing this type of event.
 boolean testIt(java.lang.Object local_handle)
          Performs some Tests on the living Object
 void testMode(boolean on)
          Switches the test - mode on / off.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THIS

public static RemoteBroker THIS
Global pointer to the BeanBroker (one per VM)

HOST

public static java.lang.String HOST
String with the ip-Adress of the Host

FILTER_NONE

public static final byte FILTER_NONE
Not used for Search.

FILTER_EQ

public static final byte FILTER_EQ
exact the same value "="

FILTER_GR

public static final byte FILTER_GR
greater ">"

FILTER_GR_EQ

public static final byte FILTER_GR_EQ
greater or equal ">="

FILTER_SM

public static final byte FILTER_SM
smaller "<"

FILTER_SM_EQ

public static final byte FILTER_SM_EQ
smaller or equal "<="

FILTER_NOT_EQ

public static final byte FILTER_NOT_EQ
not equal "!="

HISTORY_NONE

public static final int HISTORY_NONE
No information for the UNDO-mechanism is stored

HISTORY_ALL

public static final int HISTORY_ALL
All information for the UNDO-mechanism is stored.

UPDATE_NONE

public static final byte UPDATE_NONE
No Updates are done.

UPDATE_ALL

public static final byte UPDATE_ALL
All modifications are done, no difference whether there are changes made or not.

UPDATE_WEAK

public static final byte UPDATE_WEAK
Only if there is no newer Bean at the Broker an update is made.

UPDATE_STRONG

public static final byte UPDATE_STRONG
Only if the Broker-Version of the Bean has not changed in meantime.

TYPE_CLASS

public static final byte TYPE_CLASS
Beantypes: Holds Meta-Information about the class

TYPE_BEAN

public static final byte TYPE_BEAN
Beantypes: A SkidBean, made persistand by complete storage through serialisation

TYPE_LIGHTWEIGHT

public static final byte TYPE_LIGHTWEIGHT
Beantypes: A lightweight-Bean made persistance storing only parts of itselfe

TYPE_HEAVYWEIGHT

public static final byte TYPE_HEAVYWEIGHT
Beantypes: A heavyweight-Bean it's content is stored in an extra table

Dump_Fiele_Name

public static java.lang.String Dump_Fiele_Name
Name of the Dumpfile

CALENDAR

public static final java.util.GregorianCalendar CALENDAR

ID_HIGH

public static final int ID_HIGH

ID_FAIL

public static final int ID_FAIL

PUBLIC_ID

public static final int PUBLIC_ID

log

protected asgaard.utils.log.LogClient log

maintain

public SkidMaintain maintain
Database Maintainanceobject (Backup, Restore, ...)
See Also:
asgaard.Skid.SkidMaintain
Constructor Detail

BeanBroker

public BeanBroker(java.lang.String driverClass,
                  java.lang.String connStr,
                  java.lang.String connUser,
                  java.lang.String connPwd,
                  java.lang.String localDB,
                  asgaard.utils.log.LogClient log,
                  byte loglevel,
                  boolean runLocal,
                  java.util.ResourceBundle sRes,
                  long nr,
                  java.lang.String xKey)
           throws java.lang.Exception
Creating Object-Broker and Establishing connection to the database. Decrypting password for establishing connection if available.
Parameters:
driverClass - zu ladende Treiberklasse
connStr - Connection-String um an der DB anzumelden
connUser - Username
connPwd - Paßwort
output - Anzeige
log - LogClient
loglevel - which statements shall be created
nr - serialnumber
xKey - encrypted key in HEX-Format, empty keys are invalid
See Also:
DataObjectCollection#DataObjectCollection, asgaard.utils.cryptography.IDEA
Method Detail

encryptPwd

public static final java.lang.String encryptPwd(java.lang.String clearPwd)
Encrypts an password for Database connection with the built in key.
Parameters:
clearPwd - clear password
Returns:
encrypted password
See Also:
asgaard.utils.cryptography.IDEA

reconnect

protected void reconnect()
                  throws java.lang.Exception
Resonnecting to the database after a timeout

connectDatabase

protected void connectDatabase(java.lang.String driverClass,
                               java.lang.String connStr,
                               java.lang.String connUser,
                               java.lang.String connPwd,
                               java.lang.String localDB,
                               boolean runLocal,
                               java.util.ResourceBundle sRes)
                        throws java.lang.Exception
Does the connection to the database and creates it if nessecary.

getClassKey

public int getClassKey(java.lang.String classname)
Class-Key of the Bean, differ between different classes.
Parameters:
classname - the name of the class

getClassKey

public int getClassKey(RemoteBean aBean)
Class-Key of the Bean, differ between different classes.
Specified by:
getClassKey in interface RemoteBroker
Parameters:
aBean - a Bean asked for the class-id

getClassKey

public int getClassKey(java.lang.Class aClass)
Class-Key of the Bean, differ between different classes.
Specified by:
getClassKey in interface RemoteBroker
Parameters:
aClass - the Bean-Class asked for the class-id

putBean

public java.lang.Object[] putBean(RemoteBean aObj)
                           throws java.lang.Exception
Puts the Bean into the Chache and saves it do not use manually. Checks the Timestamps according to a update-policy given by the Bean and saves al modifications permanently. To enforce a Bean's saving use the Bean's saving method. flush

Remark: A System-Object cannot be modified and carries the created-Timestamp 0

Specified by:
putBean in interface RemoteBroker
Parameters:
aObj - the calling Bean
Returns:
null if the update was not possible or [key, classkey and modified if successfull]
Throws:
java.lang.Exception - if an error occoured during the writeback.
See Also:
asgaard.skid.RemoteBean#saveflush

getBeanKeyCall

public BeanKeyCall getBeanKeyCall(java.lang.Class aClass)
                           throws java.lang.Exception
Returns the Key-Call-Adapter for a asked Class (represented by it's key).
Specified by:
getBeanKeyCall in interface RemoteBroker
Parameters:
classkey - the id of the class
Throws:
java.lang.Exception - if the key's couldn't be mapped

getBeanKeyCall

public BeanKeyCall getBeanKeyCall(int pClass)
                           throws java.lang.Exception
Returns the Key-Call-Adapter for a asked Class (represented by it's key).
Parameters:
classkey - the id of the class
Throws:
java.lang.Exception - if the key's couldn't be mapped

getBeanKey

public int[] getBeanKey(java.lang.String aClass,
                        java.lang.String[] paramName,
                        java.lang.Object[] searchValue,
                        byte[] searchOp)
                 throws SkidException
Searches for a Bean by a given key.
Specified by:
getBeanKey in interface RemoteBroker
Parameters:
aClass - the searched class
paramName - list of the parameter to search for
searchValues - values to fit
search-operator -  
Returns:
a set of Bean as result of the search
Throws:
java.lang.Exception - if anything fails

getBean

public RemoteBean getBean(int key)
                   throws java.lang.Exception
Searches for a Bean by a given key.
Specified by:
getBean in interface RemoteBroker
Parameters:
key - the primary key of the object
Returns:
the searched Bean if the key exist
Throws:
java.lang.Exception - if anything fails

getBean

public RemoteBean[] getBean(int[] key)
                     throws java.lang.Exception
Searches for Beans by a given set of keys. Simply calles the primitive getBean method.
Specified by:
getBean in interface RemoteBroker
Parameters:
key - the primary key of the object
Returns:
the searched Bean if the key exist
Throws:
java.lang.Exception - if anything fails

beanExist

public boolean beanExist(int key)
Returns whether an Bean is available within the Broker or not.
Specified by:
beanExist in interface RemoteBroker
Parameters:
key - the unique key of the Bean
Returns:
true for an existing Bean with the given key

putLink

public boolean putLink(BeanLink link)
                throws java.lang.Exception
Adds a new Relation between Beans.
Specified by:
putLink in interface RemoteBroker
Parameters:
link - one relation
Returns:
wether an update is possible or not.
Throws:
java.lang.Exception - if the key is not valid or anything else fails

getLink

public BeanLink getLink(int from,
                        int to,
                        int by)
                 throws java.lang.Exception
Searches for a specific Link using it's primary key.
Specified by:
getLink in interface RemoteBroker
Parameters:
from - key of the origin Bean
to - key of the target Bean
by - key of the link-Bean (kind of Link)
Returns:
the link if found
Throws:
java.lang.Exception - if anything goes wrong.

getLink

public BeanLink[] getLink(BeanLinkFilter filter)
                   throws java.lang.Exception
Searches for a set of Links using the filter - capabilities of BeanLink.
Specified by:
getLink in interface RemoteBroker
Parameters:
filter - the BeanLink used as Filter
Returns:
the links if any found
Throws:
java.lang.Exception - if anything goes wrong.

linkExist

public boolean linkExist(int from,
                         int to,
                         int by)
Returns if a specific Key exists, hiding all Exceptions.
Specified by:
linkExist in interface RemoteBroker
Parameters:
from - key of the origin Bean
to - key of the target Bean
by - key of the link-Bean (kind of Link)
Returns:
the link if found

addEvent

public void addEvent(RemoteBean producer,
                     RemoteBean event)
              throws java.lang.Exception
Adding an Event and replicating it to all suscribed Objects.
Specified by:
addEvent in interface RemoteBroker
Parameters:
producer - of the event (not null)
event - the kond of the event (not null)
Throws:
java.lang.Exception - if it doesen't work

setEvent

public void setEvent(RemoteBean producer,
                     RemoteBean event,
                     RemoteBean consumer,
                     byte fromState,
                     byte toState)
              throws java.lang.Exception
Changing the State of an specific event.
Specified by:
setEvent in interface RemoteBroker
Parameters:
producer - of the event (not null)
event - the kond of the event (not null)
consumer - of the event (not null)
fromState - ols State of the event
toState - ols State of the event
Throws:
java.lang.Exception - if it doesen't work

suscribeEvent

public void suscribeEvent(RemoteBean producer,
                          RemoteBean event,
                          RemoteBean consumer)
                   throws java.lang.Exception
Adding an Event-Pattern and suscribing this type of event.
Specified by:
suscribeEvent in interface RemoteBroker
Parameters:
producer - of the event (not null)
event - the kond of the event (not null)
consumer - of the event (not null)
Throws:
java.lang.Exception - if it doesen't work

delEvent

protected void delEvent()
                 throws java.lang.Exception
Deletes all marked Events
Throws:
java.lang.Exception -  

delEvent

protected void delEvent(long deadline)
                 throws java.lang.Exception
Deletes all events older than the given time
Parameters:
deadline - oldest event allowed
Throws:
java.lang.Exception -  

getEvent

public SkidEvent[] getEvent(RemoteBean consumer,
                            long newer)
                     throws java.lang.Exception
Returns the Events for a consumer object which are newer than the given time
Specified by:
getEvent in interface RemoteBroker
Parameters:
consumer - of the events
newer - than the given time
Throws:
java.lang.Exception -  

checkUser

public final java.lang.String checkUser(java.lang.String userName,
                                        java.lang.String encr)
                                 throws SkidException,
                                        java.rmi.RemoteException,
                                        java.sql.SQLException
Checks if the given username exists or not
Specified by:
checkUser in interface RemoteBroker
Parameters:
userName - name of the user
encr - the encrypted password (optional)
Throws:
java.rmi.RemoteException - if RMI doesen't work
java.sql.SQLException - the db doesen't work

getUser

public final java.lang.Object getUser(java.lang.Object o,
                                      java.lang.String name,
                                      java.lang.String encr)
                               throws SkidException,
                                      java.rmi.RemoteException,
                                      java.sql.SQLException
Excanges an user with an authorised object (hardcoded)
Specified by:
getUser in interface RemoteBroker

getUser

public final java.lang.Object getUser(java.lang.String name,
                                      java.lang.String encr)
                               throws SkidException,
                                      java.rmi.RemoteException,
                                      java.sql.SQLException
Excanges an user with an authorised object (hardcoded)
Specified by:
getUser in interface RemoteBroker

putUser

public final boolean putUser(java.lang.Object o)
                      throws SkidException,
                             java.rmi.RemoteException,
                             java.sql.SQLException
Excanges an user with an authorised object (hardcoded)
Specified by:
putUser in interface RemoteBroker

invokeCall

public java.lang.Object invokeCall(java.lang.Class beanClass,
                                   java.lang.String name,
                                   java.lang.Object[] args,
                                   java.lang.String[] classnames)
                            throws java.lang.Exception
Invokes the called method of the filterinterface. The BeanKeyCall-Objects are cached by the BeanBroker and available via this one-method interface
Specified by:
invokeCall in interface RemoteBroker
Parameters:
beanClass - the class which the asked BeanKeyCall object is for
name - the name of the Method
args - the Arguments
Returns:
a result returned (if any)
Throws:
java.lang.IllegalAccessException - if the underlying method is inaccessible.
java.lang.IllegalArgumentException - if the number of actual and formal parameters differ, or if an unwrapping conversion fails.
java.lang.reflect.InvocationTargetException - if the underlying method throws an exception.
java.lang.NoSuchMethodException - if there is no Method with this name
See Also:
Method.invoke(java.lang.Object, java.lang.Object[])

getTestScript

public java.lang.Object[][] getTestScript()
Returns the Test-Script for this Class
Specified by:
getTestScript in interface asgaard.utils.test.TestIt

testMode

public void testMode(boolean on)
Switches the test - mode on / off. All changes at the Database between on and off will be deleted.
Specified by:
testMode in interface RemoteBroker

testIt

public boolean testIt(java.lang.Object local_handle)
Performs some Tests on the living Object
Specified by:
testIt in interface asgaard.utils.test.TestIt

logMsg

public boolean logMsg(java.lang.String server,
                      java.lang.String point,
                      byte typ,
                      boolean ok,
                      java.lang.String msg)
Puts a Message to the LOG-Server if available and returns whether it was sent or not
Specified by:
logMsg in interface RemoteBroker
Parameters:
server - The calling Java-Serverclass
point - The Method / place where the statement was created
typ - The Type of the LOG-Statement
ok - Was the ServicePoint passed successfuly
msg - Human redable Message of the Statement
See Also:
LogMsg