Java Reference
In-Depth Information
You've already seen how to add Blueprint metadata to an OSG i bundle in section 2.3.8.
Set up a new bundle, fancyfoods.datasource , with a blueprint.xml file in OSGI-INF /
blueprint.
Do you really need a whole bundle?
Isn't a bundle with nothing inside it but a manifest and a Blueprint file a bit of a heavy-
weight way of setting up a datasource? Well, if we're honest, perhaps! But the data-
source configuration is closely tied to the database implementation. The Apache
Aries sandbox that we're using comes with the Apache Derby database, but as you
explore other stacks (chapter 13) you may wish to switch databases, or move to an
application server with built-in admin support for configuring datasources. Isolating
the datasource ensures you won't have to rewrite or rip out datasource configuration
from another bundle as you update your stack.
Listing 3.1 shows the Blueprint for setting up the datasources. It defines two data-
sources, one for transactional writes, and one for optimized nontransactional reads. A
lot is going on in this Blueprint file, so we'll walk through the parts in detail.
Listing 3.1
An OSGI-INF/blueprint/blueprint.xml file that defines a Derby datasource
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean
id="derbyDataSource"
class="org.apache.derby.jdbc.EmbeddedDataSource">
<property
name="databaseName"
value="memory:fancyfoodsDB" />
<property
name="createDatabase"
value="create" />
B
Use Blueprint to construct
datasource bean
C
Autocreate
database
D
Another bean for
XA datasource
</bean>
<bean
id="derbyXADataSource"
class="org.apache.derby.jdbc.EmbeddedXADataSource">
<property
name="databaseName"
value="memory:fancyfoodsDB" />
<property
name="createDatabase"
value="create" />
Properties are same
as for non-XA bean
Expose bean as
DataSource service
</bean>
<service
ref="derbyDataSource"
interface="javax.sql.DataSource">
<service-properties>
<entry
key="osgi.jndi.service.name"
value="jdbc/fancyfoodsdb" />
Use nondefault
JNDI name
Search WWH ::




Custom Search