Joutsen Persistence v0.3.0+1-ga730d6d
Joutsen Persistence

The persistence part of the Joutsen framework offers easy to use base implementations to persist and retrive objects. The framework uses the repository pattern to abstract from the actual persistence technology.

Currently the only available implementation uses NHibernate to manage objects stored in a database.

Installation

Simply download the latest assemblies and add them to your .NET project or build them yourself by cloning the repository and build the projects using the dotnet build from the project's folder.

Example

To use the offered base repositories for NHibernate simply create an instance of them or sub class them and pass the path to the configuration file to the constructor. Different configurations are also supported. Simply pass different paths to the constructor and the objects will be read and written to the databases specified in the configuration files. Once created it is possible to create, store, modify and delete instances in the databse:

Repository<EntityClass,long> repository = new Repository<EntityClass,long>(new NHibernateSchema("path/to/config.file"));
EntityClass instance = repository.Create();
long id = repository.Save(instance);
instance = repository.GetById(id);
instance.Property = "DifferentValue";
repository.Save(instance);
repository.Delete();

If instances cannot be created by a parameterless constructor or if the instances are stored in the database using an interface simply use the InterfacedEntityRepository and implement the Create() method.

If more complex logic is required to retrieve instances from or store instances in the database a subclass can be created with additional methods. In these methods the NHibernate session object can be used directly to implement any kind of logic. To ease the handling of transactions and sessions the repositories offer the methods ExecuteInSession and ExecuteDbCommand which handle the database operations by either executing them in an existing session if available or in a separate session.

Documentation

API documentation is available in the code or here. It can also be generated by using the script docs-html.sh.

Tests

Tests can be run using NUnit by using the projects in the test folder. For unit test simply run dotnet test from the test project's folder.

Build and tests are also automatically run on the Jenkins CI server at https://ci.norsecorby.de/.