org.mentabean
Class AbstractMentaBean

java.lang.Object
  extended by org.mentabean.AbstractMentaBean
All Implemented Interfaces:
MentaBean

public abstract class AbstractMentaBean
extends Object
implements MentaBean

A abstract implementation of the MentaBean interface. Your beans might choose to inherit from this class to be able to persist themselves.

Author:
sergio.oliveira.jr@gmail.com

Constructor Summary
AbstractMentaBean()
           
AbstractMentaBean(BeanSession session)
          You can inject the bean session through the constructor.
 
Method Summary
 boolean delete()
          Attempt to delete a bean from the database.
 BeanSession getBeanSession()
          Return the bean session being used by this menta bean.
 void insert()
          Attempt to insert a bean to the database.
 boolean load()
          Attempt to load the bean properties from the database.
 int save(Object... forceNull)
          Attempt to save a bean in the database.
 void setBeanSession(BeanSession session)
          You can inject the bean session through the setter.
 boolean update()
          Attempt to update the bean properties in the database.
 boolean updateAll()
          Attempt to update ALL the bean properties in the database, not just the ones that have been changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMentaBean

public AbstractMentaBean()

AbstractMentaBean

public AbstractMentaBean(BeanSession session)
You can inject the bean session through the constructor.

Parameters:
session - the bean session to inject
Method Detail

setBeanSession

public void setBeanSession(BeanSession session)
You can inject the bean session through the setter.

Parameters:
session - the bean session to inject

getBeanSession

public BeanSession getBeanSession()
Description copied from interface: MentaBean
Return the bean session being used by this menta bean.

Specified by:
getBeanSession in interface MentaBean
Returns:
the bean session

insert

public void insert()
Description copied from interface: MentaBean
Attempt to insert a bean to the database. Note: This method can be called multiple times in the same bean. Of course the PK constraints will be enforced by the database, so you can change the PK by hand and call this method multiple times, to insert multiple beans. If the PK is an auto-generated database field (e.g. auto-increment), you will not change the PK by hand and a new PK will be automatically assigned to the bean.

Specified by:
insert in interface MentaBean

load

public boolean load()
Description copied from interface: MentaBean
Attempt to load the bean properties from the database. This method will throw an exception if you try to load a bean without its primary key set.

Specified by:
load in interface MentaBean
Returns:
true if the bean was loaded

update

public boolean update()
Description copied from interface: MentaBean
Attempt to update the bean properties in the database. If this bean was previously loaded, this method will update only the properties that were modified (dirty).

Specified by:
update in interface MentaBean
Returns:
true if it was updated

updateAll

public boolean updateAll()
Description copied from interface: MentaBean
Attempt to update ALL the bean properties in the database, not just the ones that have been changed.

Specified by:
updateAll in interface MentaBean
Returns:
true if it was updated

delete

public boolean delete()
Description copied from interface: MentaBean
Attempt to delete a bean from the database. It will throw an exception if the bean does not have its PK set.

Specified by:
delete in interface MentaBean
Returns:
true if it was deleted

save

public int save(Object... forceNull)
Description copied from interface: MentaBean
Attempt to save a bean in the database. It will try update first, then insert.

Specified by:
save in interface MentaBean
Returns:
0 when UPDATE and 1 if operation was an INSERT
See Also:
BeanSession.save(Object, Object...)


Copyright © 2013. All Rights Reserved.