net.jot.persistance
Class JOTModel

java.lang.Object
  extended by net.jot.persistance.JOTModel
Direct Known Subclasses:
DBUser, FSUser, JOTAuthPermission, JOTAuthProfile, JOTAuthUser

public abstract class JOTModel
extends java.lang.Object

Generic Persistance model
Implementation for example include DB, filesystem etc ...
If the table doesn't exists yet, it will be created automatically. Note that if you change your model (add fields, rename fields etc.. you will have to handle changes in the upgrade() method.

Author:
Thibaut Colar http://jot.colar.net/

Field Summary
protected  long dataId
          The "dataId" of the object in the database (ie: primary key)
protected static java.lang.String DEFAULT_STORAGE
           
protected  java.lang.Class queryImplClass
           
 
Constructor Summary
JOTModel()
           
 
Method Summary
protected  void createTable(JOTModelMapping mapping)
          Creates the table in the DB, if it doesn't exists yet
abstract  void customize(JOTModelMapping mapping)
          Implements the customization (User defined tables modifications, ie: fields mappings, etc ...)
abstract  java.lang.String defineStorage()
          Returns the "storage" to be used by this Model.
 void delete()
          Deletes the coresponding record from the database
protected  void deleteTable()
          Deletes the table in the DB
 java.lang.Object getFieldValue(java.lang.String fieldName)
           
 java.lang.Object[] getFieldValues(JOTModelMapping mapping, JOTSQLCondition[] conds)
          Return the fields values
 long getId()
           
 JOTModelMapping getMapping()
          Called once by the QueryManager to get the table mapping.
 java.lang.Class getQueryImplClass()
           
 void initQueryImplClass()
           
 boolean isNew()
           
 void save()
          Save/update the table in teh database.
 void setId(int id)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataId

protected long dataId
The "dataId" of the object in the database (ie: primary key)


queryImplClass

protected java.lang.Class queryImplClass

DEFAULT_STORAGE

protected static final java.lang.String DEFAULT_STORAGE
See Also:
Constant Field Values
Constructor Detail

JOTModel

public JOTModel()
Method Detail

getMapping

public final JOTModelMapping getMapping()
                                 throws java.lang.Exception
Called once by the QueryManager to get the table mapping. This calls all the customization methods in the process. Also creates the table if it hasn't been done yet.

Returns:
Throws:
java.lang.Exception

customize

public abstract void customize(JOTModelMapping mapping)
Implements the customization (User defined tables modifications, ie: fields mappings, etc ...)

Parameters:
mapping -

defineStorage

public abstract java.lang.String defineStorage()
Returns the "storage" to be used by this Model. default is to return JOTModel.DEFAULT_STORAGE (to use the "default" storage).

Parameters:
storageName -

getFieldValues

public java.lang.Object[] getFieldValues(JOTModelMapping mapping,
                                         JOTSQLCondition[] conds)
Return the fields values

Parameters:
mapping -
conds -
Returns:

getFieldValue

public java.lang.Object getFieldValue(java.lang.String fieldName)

getId

public long getId()

setId

public void setId(int id)

delete

public void delete()
            throws java.lang.Exception
Deletes the coresponding record from the database

Throws:
java.lang.Exception

save

public void save()
          throws java.lang.Exception
Save/update the table in teh database.

Throws:
java.lang.Exception

createTable

protected void createTable(JOTModelMapping mapping)
                    throws java.lang.Exception
Creates the table in the DB, if it doesn't exists yet

Throws:
java.lang.Exception

isNew

public boolean isNew()

deleteTable

protected void deleteTable()
                    throws java.lang.Exception
Deletes the table in the DB

Throws:
java.lang.Exception

initQueryImplClass

public void initQueryImplClass()
                        throws java.lang.Exception
Throws:
java.lang.Exception

getQueryImplClass

public java.lang.Class getQueryImplClass()