Difference between revisions of "Database Tutorial DB Application"

From RifidiWiki

Jump to: navigation, search
(Dependency Injection)
Line 1: Line 1:
This page explains a few aspects of the DBApp class and it could be extended
+
This page explains a few aspects of the DBApp class and it could be extended.
 +
The DBApp class has two main pieces of functionality:
 +
# Control the lifecycle of the application. It has a start and stop method to do this.
 +
# Submit esper statements to the esper runtime and handle events.
 
=Activator=
 
=Activator=
 
The Activator is a class that implements the <tt>BundleActivator</tt> interface. It has two methods: start and stop. These methods are called by the OSGi runtime when the bundle is started and stopped. One thing to keep in mind about the DBApp is that we need to some clean up when the DBApp bundle is stopped. Therefore in the constructor of the the DBApp class, we give a reference to the Activator:
 
The Activator is a class that implements the <tt>BundleActivator</tt> interface. It has two methods: start and stop. These methods are called by the OSGi runtime when the bundle is started and stopped. One thing to keep in mind about the DBApp is that we need to some clean up when the DBApp bundle is stopped. Therefore in the constructor of the the DBApp class, we give a reference to the Activator:
Line 22: Line 25:
 
</pre>
 
</pre>
 
=Dependency Injection=
 
=Dependency Injection=
The DBApp class
+
The DBApp class needs two important objects to work
 +
;EsperManagementService
 +
: This is the object that allows us to interact with esper
 +
;RFID_DAO
 +
: This allows us to interact with the database.
 +
 
 +
The Rifidi Edge Server encourages the use of dependency injection using spring to get a hold of objects. To use dependency injection, just create public setter methods that take in the object to be injected. For example:
 +
<pre>
 +
/**
 +
* Called by spring
 +
*
 +
* @param esperService
 +
*            the esperService to set
 +
*/
 +
public void setEsperService(EsperManagementService esperService) {
 +
this.esperService = esperService;
 +
 
 +
}
 +
 
 +
/**
 +
* Called by spring
 +
*
 +
* @param rfidDAO
 +
*            the rfidDAO to set
 +
*/
 +
public void setRfidDAO(RFID_DAO rfidDAO) {
 +
this.rfidDAO = rfidDAO;
 +
}
 +
</pre>
 +
 
 +
We will configure which objects get injected in the [[Database Tutorial Spring|spring.xml]] file.
  
 
=Esper Query=
 
=Esper Query=
 
=Esper Listener=
 
=Esper Listener=

Revision as of 19:46, 3 December 2009

This page explains a few aspects of the DBApp class and it could be extended. The DBApp class has two main pieces of functionality:

  1. Control the lifecycle of the application. It has a start and stop method to do this.
  2. Submit esper statements to the esper runtime and handle events.

Activator

The Activator is a class that implements the BundleActivator interface. It has two methods: start and stop. These methods are called by the OSGi runtime when the bundle is started and stopped. One thing to keep in mind about the DBApp is that we need to some clean up when the DBApp bundle is stopped. Therefore in the constructor of the the DBApp class, we give a reference to the Activator:

	/**
	 * The constructor
	 */
	public DBApp() {
		Activator.myApp = this;
	}

Then in the Activator, we can call the stop method of the DBApp when the bundle's stop method is called:

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		myApp.stop();
	}

Dependency Injection

The DBApp class needs two important objects to work

EsperManagementService
This is the object that allows us to interact with esper
RFID_DAO
This allows us to interact with the database.

The Rifidi Edge Server encourages the use of dependency injection using spring to get a hold of objects. To use dependency injection, just create public setter methods that take in the object to be injected. For example:

	/**
	 * Called by spring
	 * 
	 * @param esperService
	 *            the esperService to set
	 */
	public void setEsperService(EsperManagementService esperService) {
		this.esperService = esperService;

	}

	/**
	 * Called by spring
	 * 
	 * @param rfidDAO
	 *            the rfidDAO to set
	 */
	public void setRfidDAO(RFID_DAO rfidDAO) {
		this.rfidDAO = rfidDAO;
	}

We will configure which objects get injected in the spring.xml file.

Esper Query

Esper Listener

Personal tools