Java Reference
In-Depth Information
ShrinkWrap Descriptors
There is one more ShrinkWrap family project. A little less popular and not known by many
people, it is called ShrinkWrap Descriptors . Its goal is to provide a fluent API for the cre-
ation of descriptor resources you usually create and insert inside your micro deployments.
Let's start with an example. Let's say you're writing a persistence framework extension.
While doing this, you use an incredible amount of persistence.xml files such as the
following code:
<persistence>
<persistence-unit name="myapp">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto"
value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
With ShrinkWrap Descriptors, instead of putting all these files in src/test/re-
sources and then referencing them from particular tests, you can just put some code in
the test itself:
final PersistenceDescriptor persistence = Descriptors
.create(PersistenceDescriptor.class)
.createPersistenceUnit()
.name("myapp")
.provider("org.hibernate.ejb.HibernatePersistence")
.jtaDataSource("java:/DefaultDS")
.getOrCreateProperties()
.createProperty().name("hibernate.dialect")
.value("org.hibernate.dialect.HSQLDialect").up()
Search WWH ::




Custom Search