DAO dao = DAOFactory.getInstance().getDAO();
List domainObjects = dao.select(MyDomainObject.class);
For using hibernate mapping mode you need create hibernate mapping files (hbm.xml) for your application domain object. Then place mapping file in hibernate folder inside dbtTier plugin and add <mapping> tag in hibernate.cfg.xml descriptor file. When Eclipse RCP run dbTier create hibernate session with registering object/database mappings. At previous section we use this registration mode. Hibernate mapping registration mode require to modify hibernate.cfg.xml file. In this mode you can`t manage class registrations in runtime. In some cases this limitations may be inconvenient.
EJB3 annotations registration mode don`t require any dbTier plugin modifications. At this mode you can register new classes in runtime. You can registering annotated classes explicit or implicit. If you not registering class explicity dbTier automatically register annotated class at first call. You can explicity register annotated classes by calling registerAnnotatedClass method of DAO interface.
One of the typical development tasks is refreshing GUI accordnly data changes. dbTier have two notification capabilities: centralized data change notification handling and listening data operations.
Centralized data change notification handling allow listen all data change events occured via dbTier. This capability is useful for audit and logging tools.
Implementation is use Publish/Subscribe design pattern with Observer object. For notification listening you need implement Observer interface methods and add you listner to DAOFactory.
Sample of centralized handling usage you can see in dbTier sample application.
First we add Observer interface implementation declaration to Eclipse view class declaration:
public class View extends ViewPart implements Observer {
After this you need subscribe to data changes. At the sample we use createPartControl method for this:
public void createPartControl(Composite parent) {
DAOFactory.getInstance().addObserver(this);
...
}
Often your GUI elements create and destroy dynamically and you need usubscribe GUI elements from notifications on destroy.
Eclipse and SWT have dispose method for this. At the sample we override Eclipse View destroy method to unsubscribe.
public void dispose() {
DAOFactory.getInstance().deleteObserver(this);
super.dispose();
}
The last step is writing code for data change handling inside update method introduced by Observer interface. Second method parameter contain DataChangeEvent object, that contain data change details
public void update(Observable o, Object arg) {
if (arg instanceof DataChangeEvent) {
DataChangeEvent event = (DataChangeEvent)arg;
System.out.println(event.getOperation().name() + " occured with " + event.getObject().getClass().getName());
}
}
Listening data operations mode allow select notification events as you need. You can subscribe only on concrete change operation (insert or delete or update) with some application domain object class.
This mode represented by DataChangeNotificator interface. You can access this initerface via DAOFactory.
DataChangeNotificator notificator = DAOFactory.getInstance().getDataChangeNotificator();