maito.resource
Class Resource

java.lang.Object
  extended by maito.resource.Resource

public class Resource
extends java.lang.Object

An object representing a complete resource in the resource database. This object contains methods for loading & saving resources to database & setting resource fields

Author:
Tuomas Tanner

Field Summary
static int IDLENGTH
           
 
Constructor Summary
Resource(java.lang.String id, java.lang.String type)
          Initialize this resource.
 
Method Summary
 java.lang.String findUniqueID(java.sql.Connection con)
          Finds the unique id for this resource based on the current id.
 java.util.HashSet getExtIDs()
           
 java.lang.String getID()
           
 java.util.HashSet getKeywords()
           
 boolean getOverwrite()
          Get current overwrite status
 java.lang.String getSingleField(java.lang.String key)
           
 java.lang.String getType()
           
 boolean load(java.sql.Connection con)
          Loads the resource data from database into this Resource object.
 boolean save(java.sql.Connection con)
          Save this Resource object's state into the database
 boolean setField(java.lang.String key, java.lang.String value)
          Sets the value for a specified key in this resource.
 void setOverwrite(boolean which)
          Set whether updates to this Record overwrite existing values or not.
 java.lang.StringBuffer toHTML()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDLENGTH

public static final int IDLENGTH
See Also:
Constant Field Values
Constructor Detail

Resource

public Resource(java.lang.String id,
                java.lang.String type)
Initialize this resource. After init the resource has only the id, type and created (current date) values. The created field is overwritten if data is loaded to this resource.

Parameters:
id - a unique id for this resource
type - the type of resource this is. Allowed values: Actor, Document, Channel, Role
Method Detail

setOverwrite

public void setOverwrite(boolean which)
Set whether updates to this Record overwrite existing values or not. If overwrite is true, existing values are overwritten. If false, update will fail

Parameters:
which - true of false

getOverwrite

public boolean getOverwrite()
Get current overwrite status

Returns:
the status

findUniqueID

public java.lang.String findUniqueID(java.sql.Connection con)
Finds the unique id for this resource based on the current id. If the current one is unique, all is well. If not we loop and append a counter to the id (starts from 2).

Parameters:
con - connection to database
Returns:
the unique id that was found

getID

public java.lang.String getID()

setField

public boolean setField(java.lang.String key,
                        java.lang.String value)
Sets the value for a specified key in this resource. The key must be specified in the format "Tablename.Tablecolumn". The table name and column are case sensitive. Both the table name and table column need to be correct - otherwise they are not set. The Records field uses a special format: Key is "Records.source¤record" and value is "YYYY-MM-DD" If overwrite is true the keys will be always set, if not they will only be set if if they are missing.

Parameters:
key - Resource field to be saved
value - the value for the field
Returns:

load

public boolean load(java.sql.Connection con)
Loads the resource data from database into this Resource object.

Parameters:
con - Connection to database
Returns:
true if resource was found and loaded successfully, false otherwise

save

public boolean save(java.sql.Connection con)
Save this Resource object's state into the database

Parameters:
con -
Returns:
true if save was successfull, false otherwise

getSingleField

public java.lang.String getSingleField(java.lang.String key)

getKeywords

public java.util.HashSet getKeywords()

getExtIDs

public java.util.HashSet getExtIDs()

getType

public java.lang.String getType()

toHTML

public java.lang.StringBuffer toHTML()