com.j256.ormlite.misc
Class BaseDaoEnabled<T,ID>

java.lang.Object
  extended by com.j256.ormlite.misc.BaseDaoEnabled<T,ID>

public abstract class BaseDaoEnabled<T,ID>
extends Object

Base class that your data elements can extend which allow them to refresh, update, etc. themselves. ORMLite will automagically set the appropriate Dao on the class if it is received by a query but if you are trying to create the class, you will need to either create it through the DAO or set the dao on it directly with setDao(Dao).

NOTE: The default pattern is to use the Dao classes to operate on your data classes. This will allow your data classes to have their own hierarchy and isolates the database code in the Daos. However, you are free to use this base class if you prefer this pattern.

NOTE: The internal Dao field has been marked with transient so that it won't be serialized (thanks jc). If you do de-serialize on these classes, you will need to refresh it with the Dao to get it to work again.

Author:
graywatson

Field Summary
protected  Dao<T,ID> dao
           
 
Constructor Summary
BaseDaoEnabled()
           
 
Method Summary
 int create()
          A call through to the Dao.create(Object).
 int delete()
          A call through to the Dao.delete(Object).
 ID extractId()
          A call through to the Dao.extractId(Object).
 boolean objectsEqual(T other)
          A call through to the Dao.objectsEqual(Object, Object).
 String objectToString()
          A call through to the Dao.objectToString(Object).
 int refresh()
          A call through to the Dao.refresh(Object).
 void setDao(Dao<T,ID> dao)
          Set the Dao on the object.
 int update()
          A call through to the Dao.update(Object).
 int updateId(ID newId)
          A call through to the Dao.updateId(Object, Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dao

protected transient Dao<T,ID> dao
Constructor Detail

BaseDaoEnabled

public BaseDaoEnabled()
Method Detail

create

public int create()
           throws SQLException
A call through to the Dao.create(Object).

Throws:
SQLException

refresh

public int refresh()
            throws SQLException
A call through to the Dao.refresh(Object).

Throws:
SQLException

update

public int update()
           throws SQLException
A call through to the Dao.update(Object).

Throws:
SQLException

updateId

public int updateId(ID newId)
             throws SQLException
A call through to the Dao.updateId(Object, Object).

Throws:
SQLException

delete

public int delete()
           throws SQLException
A call through to the Dao.delete(Object).

Throws:
SQLException

objectToString

public String objectToString()
A call through to the Dao.objectToString(Object).


extractId

public ID extractId()
             throws SQLException
A call through to the Dao.extractId(Object).

Throws:
SQLException

objectsEqual

public boolean objectsEqual(T other)
                     throws SQLException
A call through to the Dao.objectsEqual(Object, Object).

Throws:
SQLException

setDao

public void setDao(Dao<T,ID> dao)
Set the Dao on the object. For the create() call to work, this must be done beforehand by the caller. If the object has been received from a query call to the Dao then this should have been set automagically.



Copyright © 2011. All Rights Reserved.