Initial Commit
This commit is contained in:
parent
cae2b4d5c4
commit
703c8081a3
|
@ -0,0 +1,75 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>li.strolch</groupId>
|
||||||
|
<artifactId>li.strolch.parent</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../li.strolch.parent/pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>li.strolch.persistence.xml</artifactId>
|
||||||
|
|
||||||
|
<name>Reference Persistence Implementation for Strolch</name>
|
||||||
|
<description>Reference Persistence Implementation for Strolch</description>
|
||||||
|
|
||||||
|
<url>https://github.com/eitch/li.strolch.persistence.xml</url>
|
||||||
|
|
||||||
|
<inceptionYear>2011</inceptionYear>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>Github Issues</system>
|
||||||
|
<url>https://github.com/eitch/li.strolch.persistence.xml/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://github.com/eitch/li.strolch.persistence.xml.git</connection>
|
||||||
|
<developerConnection>scm:git:git@github.com:eitch/li.strolch.persistence.xml.git</developerConnection>
|
||||||
|
<url>https://github.com/eitch/li.strolch.persistence.xml</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>li.strolch</groupId>
|
||||||
|
<artifactId>li.strolch.model</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>li.strolch</groupId>
|
||||||
|
<artifactId>li.strolch.persistence.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.eitchnet</groupId>
|
||||||
|
<artifactId>ch.eitchnet.xmlpers</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-eclipse-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,120 @@
|
||||||
|
package li.strolch.persistence.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
|
import li.strolch.persistence.api.StrolchDao;
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import ch.eitchnet.xmlpers.api.PersistenceTransaction;
|
||||||
|
import ch.eitchnet.xmlpers.objref.IdOfSubTypeRef;
|
||||||
|
import ch.eitchnet.xmlpers.objref.SubTypeRef;
|
||||||
|
import ch.eitchnet.xmlpers.objref.TypeRef;
|
||||||
|
|
||||||
|
public abstract class AbstractDao<T extends StrolchElement> implements StrolchDao<T> {
|
||||||
|
|
||||||
|
protected PersistenceTransaction tx;
|
||||||
|
|
||||||
|
protected AbstractDao(StrolchTransaction tx) {
|
||||||
|
XmlStrolchTransaction strolchTx = (XmlStrolchTransaction) tx;
|
||||||
|
this.tx = strolchTx.getTx();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getClassType();
|
||||||
|
|
||||||
|
protected IdOfSubTypeRef getIdRef(String type, String id) {
|
||||||
|
IdOfSubTypeRef idRef = this.tx.getObjectRefCache().getIdOfSubTypeRef(getClassType(), type, id);
|
||||||
|
return idRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SubTypeRef getTypeRef(String type) {
|
||||||
|
SubTypeRef typeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type);
|
||||||
|
return typeRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> queryKeySet() {
|
||||||
|
Set<String> keys = new HashSet<>();
|
||||||
|
Set<String> types = queryTypes();
|
||||||
|
for (String type : types) {
|
||||||
|
keys.addAll(queryKeySet(type));
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> queryKeySet(String type) {
|
||||||
|
SubTypeRef typeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type);
|
||||||
|
Set<String> keys = this.tx.getMetadataDao().queryKeySet(typeRef);
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> queryTypes() {
|
||||||
|
TypeRef typeRef = this.tx.getObjectRefCache().getTypeRef(getClassType());
|
||||||
|
Set<String> types = this.tx.getMetadataDao().queryTypeSet(typeRef);
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T queryBy(String type, String id) {
|
||||||
|
T t = this.tx.getObjectDao().queryById(getIdRef(type, id));
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> queryAll() {
|
||||||
|
List<T> objects = new ArrayList<>();
|
||||||
|
Set<String> types = queryTypes();
|
||||||
|
for (String type : types) {
|
||||||
|
List<T> objectsByType = this.tx.getObjectDao().queryAll(getTypeRef(type));
|
||||||
|
objects.addAll(objectsByType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<T> queryAll(String type) {
|
||||||
|
List<T> objectsByType = this.tx.getObjectDao().queryAll(getTypeRef(type));
|
||||||
|
return objectsByType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(T object) {
|
||||||
|
this.tx.getObjectDao().add(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveAll(List<T> objects) {
|
||||||
|
this.tx.getObjectDao().addAll(objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(T object) {
|
||||||
|
this.tx.getObjectDao().update(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAll(List<T> objects) {
|
||||||
|
this.tx.getObjectDao().updateAll(objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(T object) {
|
||||||
|
this.tx.getObjectDao().remove(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAll(List<T> objects) {
|
||||||
|
this.tx.getObjectDao().removeAll(objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(String type, String id) {
|
||||||
|
IdOfSubTypeRef objectRef = this.tx.getObjectRefCache().getIdOfSubTypeRef(getClassType(), type, id);
|
||||||
|
this.tx.getObjectDao().removeById(objectRef);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the ch.eitchnet.persistence.impl.
|
||||||
|
*
|
||||||
|
* ch.eitchnet.persistence.impl is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ch.eitchnet.persistence.impl is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ch.eitchnet.persistence.impl. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.persistence.impl;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import li.strolch.persistence.api.OrderDao;
|
||||||
|
import li.strolch.persistence.api.ResourceDao;
|
||||||
|
import li.strolch.persistence.api.StrolchPersistenceHandler;
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import ch.eitchnet.xmlpers.api.PersistenceManager;
|
||||||
|
import ch.eitchnet.xmlpers.api.PersistenceManagerLoader;
|
||||||
|
import ch.eitchnet.xmlpers.api.PersistenceTransaction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StrolchPersistenceHandlerImpl implements StrolchPersistenceHandler {
|
||||||
|
|
||||||
|
private PersistenceManager persistenceManager;
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
this.persistenceManager = PersistenceManagerLoader.load(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchTransaction openTx() {
|
||||||
|
return openTx(PersistenceManager.DEFAULT_REALM);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("resource") // caller must close
|
||||||
|
public StrolchTransaction openTx(String realm) {
|
||||||
|
PersistenceTransaction tx = this.persistenceManager.openTx(realm);
|
||||||
|
XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(tx);
|
||||||
|
return strolchTx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderDao getOrderDao(StrolchTransaction tx) {
|
||||||
|
return new XmlOrderDao(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceDao getResourceDao(StrolchTransaction tx) {
|
||||||
|
return new XmlResourceDao(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package li.strolch.persistence.impl;
|
||||||
|
|
||||||
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.persistence.api.OrderDao;
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
|
||||||
|
public class XmlOrderDao extends AbstractDao<Order> implements OrderDao {
|
||||||
|
|
||||||
|
private static final String CLASS_TYPE = Order.class.getName();
|
||||||
|
|
||||||
|
protected XmlOrderDao(StrolchTransaction tx) {
|
||||||
|
super(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getClassType() {
|
||||||
|
return CLASS_TYPE;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package li.strolch.persistence.impl;
|
||||||
|
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.persistence.api.ResourceDao;
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
|
||||||
|
public class XmlResourceDao extends AbstractDao<Resource> implements ResourceDao {
|
||||||
|
|
||||||
|
private static final String CLASS_TYPE = Resource.class.getName();
|
||||||
|
|
||||||
|
protected XmlResourceDao(StrolchTransaction tx) {
|
||||||
|
super(tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getClassType() {
|
||||||
|
return CLASS_TYPE;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package li.strolch.persistence.impl;
|
||||||
|
|
||||||
|
import li.strolch.persistence.api.StrolchPersistenceException;
|
||||||
|
import li.strolch.persistence.api.StrolchTransaction;
|
||||||
|
import li.strolch.persistence.api.TransactionCloseStrategy;
|
||||||
|
import ch.eitchnet.xmlpers.api.PersistenceTransaction;
|
||||||
|
|
||||||
|
public class XmlStrolchTransaction implements StrolchTransaction {
|
||||||
|
|
||||||
|
private PersistenceTransaction tx;
|
||||||
|
private TransactionCloseStrategy closeStrategy;
|
||||||
|
|
||||||
|
public XmlStrolchTransaction(PersistenceTransaction tx) {
|
||||||
|
this.tx = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
PersistenceTransaction getTx() {
|
||||||
|
return this.tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCloseStrategy(TransactionCloseStrategy closeStrategy) {
|
||||||
|
this.closeStrategy = closeStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void autoCloseableCommit() {
|
||||||
|
this.tx.autoCloseableCommit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void autoCloseableRollback() {
|
||||||
|
this.tx.autoCloseableRollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws StrolchPersistenceException {
|
||||||
|
this.closeStrategy.close(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOpen() {
|
||||||
|
return this.tx.isOpen();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.persistence.impl.dao.test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AbstractDaoImplTest {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package li.strolch.persistence.impl.dao.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class XmlOrderDaoTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
fail("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue