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 OpenTransactionInViewFilter
, which allowsPermazen
transactions to span an entire web request.- 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
SnapshotJTransactionHttpMessageConverter
for encoding/decoding an entireSnapshotJTransaction
JObjectHttpMessageConverter
for encoding/decoding a specificJObject
within aSnapshotJTransaction
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:scan-field-types> |
Works just like Spring's <context:component-scan> but finds
@JFieldType -annotated custom FieldType 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. A nested <permazen:scan-field-types>
may also be included.
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. |
schema-version |
Integer | No | The schema version corresponding to the configured Java model classes. A value of zero means to use
whatever is the highest schema version already recorded in the database. A value of -1 (the default)
means to auto-generate a version number
based on the compatibility hash of the
SchemaModel generated from the Java model classes. |
storage-id-generator |
Bean reference | No | To use a custom StorageIdGenerator , specify the name of a Spring bean that
implements the StorageIdGenerator interface. By default, a
DefaultStorageIdGenerator is used. If this attribute is set, then
auto-generate-storage-ids must not be set to false. |
auto-generate-storage-ids |
Boolean | No | Whether to auto-generate storage ID's. Default is true |
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.0.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> <!-- We have some custom FieldType's here too --> <permazen:scan-field-types base-package="com.example.myapp.fieldtype"/> </permazen:permazen> <!-- Create a Permazen transaction manager --> <bean id="transactionManager" class="io.permazen.spring.PermazenTransactionManager" p:Permazen-ref="permazen" p:allowNewSchema="true"/> <!-- Enable @Transactional annotations --> <tx:annotation-driven transaction-manager="transactionManager"/> </beans>
- See Also:
- Spring Framework
-
Class Summary Class Description AnnotatedClassScanner Scans the classpath for classes having one or more configured type annotations.JObjectHttpMessageConverter SpringHttpMessageConverter
capable of encoding and decoding one or moreJObject
s contained in aSnapshotJTransaction
.KVStoreHttpMessageConverter SpringHttpMessageConverter
capable of encoding and decoding aKVStore
.OpenTransactionInViewFilter A servletFilter
binds aPermazen
JTransaction
to the current thread for the entire processing of the request.PermazenClassScanner Scans the classpath for types annotated as@PermazenType
.PermazenExceptionTranslator Permazen implementation of Spring'sPersistenceExceptionTranslator
interface.PermazenFieldTypeScanner Scans the classpath for types annotated as@JFieldType
.PermazenNamespaceHandler SpringNamespaceHandler
for thepermazen
XML namespace.PermazenTransactionManager Permazen implementation of Spring'sPlatformTransactionManager
interface, allowing methods annotated with Spring's@Transactional
annotation to perform transactions on aPermazen
database.PermazenTransactionManager.TransactionSynchronizationCallback Adapter class that wraps a SpringTransactionSynchronization
in theTransaction.Callback
interface.SnapshotJTransactionHttpMessageConverter SpringHttpMessageConverter
capable of encoding and decoding a graph ofJObject
s contained in aSnapshotJTransaction
that is backed by aNavigableMapKVStore
.SpringXMLKVDatabase XMLKVDatabase
that adds support for loading the default initial content from any SpringResource
.