Package io.permazen.spring
package io.permazen.spring
Spring Framework integration classes.
Overview
This package provides the following features to facilitate use with Spring:
- Custom XML tags for Spring declarative XML (see below)
- A Spring
PlatformTransactionManager
that integrates into Spring's transaction infrastructure and enables the@Transactional
annotation forPermazen
transactions. - A
PersistenceExceptionTranslator
implementation suitable for use with Permazen - Various
HttpMessageConverter
's that bring Permazen's encoding, indexing, and schema management features to data being sent over a network:KVStoreHttpMessageConverter
for encoding/decoding a rawKVStore
DetachedPermazenTransactionHttpMessageConverter
for encoding/decoding an entireDetachedPermazenTransaction
PermazenObjectHttpMessageConverter
for encoding/decoding a specificPermazenObject
within aDetachedPermazenTransaction
Permazen XML Tags
Permazen makes available the following XML tags to Spring declarative XML. All elements live in the
http://permazen.io/schema/spring/permazen
XML namespace:
Element | Description |
---|---|
<permazen:scan-classes> |
Works just like Spring's <context:component-scan> but finds
@PermazenType -annotated Java model classes.
Returns the classes found in a List . |
<permazen:permazen> |
Simplifies defining and configuring a Permazen database. |
The <permazen:permazen>
element requires a nested <permazen:scan-classes>
element to configure
the Java model classes. The <permazen:permazen>
element supports the following attributes:
Attribute | Type | Required? | Description |
---|---|---|---|
kvstore |
Bean reference | No | The underlying key/value store database. This should be the name of a Spring bean that implements
the KVDatabase interface. If unset, defaults to a new
SimpleKVDatabase instance. |
An example Spring XML configuration using an in-memory key/value store and supporting Spring's
@Transactional
annotation:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:permazen="http://permazen.io/schema/spring/permazen" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c" xsi:schemaLocation=" http://permazen.io/schema/spring/permazen http://permazen.github.io/permazen/permazen-spring/src/main/resources/io/permazen/spring/permazen-1.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- Define the underlying key/value database --> <bean id="kvdb" class="io.permazen.kv.simple.SimpleKVDatabase" p:waitTimeout="5000" p:holdTimeout="10000"/> <!-- Define the Permazen database on top of that --> <permazen:permazen id="permazen" kvstore="kvdb"> <!-- These are our Java model classes --> <permazen:scan-classes base-package="com.example.myapp"> <permazen:exclude-filter type="regex" expression="com\.example\.myapp\.test\..*"/> </permazen:scan-classes> </permazen:permazen> <!-- Create a Permazen transaction manager --> <bean id="transactionManager" class="io.permazen.spring.PermazenTransactionManager" p:Permazen-ref="permazen"/> <!-- Enable @Transactional annotations --> <tx:annotation-driven transaction-manager="transactionManager"/> </beans>
- See Also:
-
ClassDescriptionScans the classpath for classes having one or more configured type annotations.Spring
HttpMessageConverter
capable of encoding and decoding a graph ofPermazenObject
s contained in aDetachedPermazenTransaction
that is backed by aMemoryKVStore
.SpringHttpMessageConverter
capable of encoding and decoding aKVStore
.Scans the classpath for types annotated as@PermazenType
.Permazen implementation of Spring'sPersistenceExceptionTranslator
interface.SpringNamespaceHandler
for thepermazen
XML namespace.SpringHttpMessageConverter
capable of encoding and decoding one or morePermazenObject
s contained in aDetachedPermazenTransaction
.Permazen implementation of Spring'sPlatformTransactionManager
interface, allowing methods annotated with Spring's@Transactional
annotation to perform transactions on aPermazen
database.Adapter class that wraps a SpringTransactionSynchronization
in theTransaction.Callback
interface.XMLKVDatabase
that adds support for loading the default initial content from any SpringResource
.