From cae2b4d5c4be8ff6f69271f19b84e9b5eb227b70 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 10:46:34 -0700 Subject: [PATCH 01/59] Initial commit --- .gitignore | 1 + LICENSE | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 ++ 3 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2f7896d1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..37ec93a14 --- /dev/null +++ b/LICENSE @@ -0,0 +1,191 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate +notice, with the fields enclosed by brackets "[]" replaced with your own +identifying information. (Don't include the brackets!) The text should be +enclosed in the appropriate comment syntax for the file format. We also +recommend that a file or class name and description of purpose be included on +the same "printed page" as the copyright notice for easier identification within +third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 000000000..fbc7e1574 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +li.strolch.persistence.xml +========================== + +XML Persistence Implementation for Strolch From 703c8081a359668b075b7e1e337ca2c1561082ba Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 19:58:02 +0200 Subject: [PATCH 02/59] Initial Commit --- pom.xml | 75 +++++++++++ .../strolch/persistence/impl/AbstractDao.java | 120 ++++++++++++++++++ .../impl/StrolchPersistenceHandlerImpl.java | 68 ++++++++++ .../strolch/persistence/impl/XmlOrderDao.java | 19 +++ .../persistence/impl/XmlResourceDao.java | 19 +++ .../impl/XmlStrolchTransaction.java | 45 +++++++ .../impl/dao/test/AbstractDaoImplTest.java | 31 +++++ .../impl/dao/test/XmlOrderDaoTest.java | 14 ++ 8 files changed, 391 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/li/strolch/persistence/impl/AbstractDao.java create mode 100644 src/main/java/li/strolch/persistence/impl/StrolchPersistenceHandlerImpl.java create mode 100644 src/main/java/li/strolch/persistence/impl/XmlOrderDao.java create mode 100644 src/main/java/li/strolch/persistence/impl/XmlResourceDao.java create mode 100644 src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java create mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java create mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..2a4b23796 --- /dev/null +++ b/pom.xml @@ -0,0 +1,75 @@ + + + + li.strolch + li.strolch.parent + 0.1.0-SNAPSHOT + ../li.strolch.parent/pom.xml + + + 4.0.0 + + li.strolch.persistence.xml + + Reference Persistence Implementation for Strolch + Reference Persistence Implementation for Strolch + + https://github.com/eitch/li.strolch.persistence.xml + + 2011 + + + Github Issues + https://github.com/eitch/li.strolch.persistence.xml/issues + + + + scm:git:https://github.com/eitch/li.strolch.persistence.xml.git + scm:git:git@github.com:eitch/li.strolch.persistence.xml.git + https://github.com/eitch/li.strolch.persistence.xml + + + + + + li.strolch + li.strolch.model + + + li.strolch + li.strolch.persistence.api + + + + ch.eitchnet + ch.eitchnet.xmlpers + + + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-site-plugin + + + + \ No newline at end of file diff --git a/src/main/java/li/strolch/persistence/impl/AbstractDao.java b/src/main/java/li/strolch/persistence/impl/AbstractDao.java new file mode 100644 index 000000000..fb41b4c16 --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/AbstractDao.java @@ -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 implements StrolchDao { + + 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 queryKeySet() { + Set keys = new HashSet<>(); + Set types = queryTypes(); + for (String type : types) { + keys.addAll(queryKeySet(type)); + } + return keys; + } + + @Override + public Set queryKeySet(String type) { + SubTypeRef typeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type); + Set keys = this.tx.getMetadataDao().queryKeySet(typeRef); + return keys; + } + + @Override + public Set queryTypes() { + TypeRef typeRef = this.tx.getObjectRefCache().getTypeRef(getClassType()); + Set 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 queryAll() { + List objects = new ArrayList<>(); + Set types = queryTypes(); + for (String type : types) { + List objectsByType = this.tx.getObjectDao().queryAll(getTypeRef(type)); + objects.addAll(objectsByType); + } + + return objects; + } + + @Override + public List queryAll(String type) { + List 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 objects) { + this.tx.getObjectDao().addAll(objects); + } + + @Override + public void update(T object) { + this.tx.getObjectDao().update(object); + } + + @Override + public void updateAll(List objects) { + this.tx.getObjectDao().updateAll(objects); + } + + @Override + public void remove(T object) { + this.tx.getObjectDao().remove(object); + } + + @Override + public void removeAll(List 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); + } +} diff --git a/src/main/java/li/strolch/persistence/impl/StrolchPersistenceHandlerImpl.java b/src/main/java/li/strolch/persistence/impl/StrolchPersistenceHandlerImpl.java new file mode 100644 index 000000000..df2a919bc --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/StrolchPersistenceHandlerImpl.java @@ -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 + * . + */ +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 + * + */ +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); + } + +} diff --git a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java new file mode 100644 index 000000000..86e48e844 --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java @@ -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 implements OrderDao { + + private static final String CLASS_TYPE = Order.class.getName(); + + protected XmlOrderDao(StrolchTransaction tx) { + super(tx); + } + + @Override + protected String getClassType() { + return CLASS_TYPE; + } +} diff --git a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java new file mode 100644 index 000000000..64c9e06cf --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java @@ -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 implements ResourceDao { + + private static final String CLASS_TYPE = Resource.class.getName(); + + protected XmlResourceDao(StrolchTransaction tx) { + super(tx); + } + + @Override + protected String getClassType() { + return CLASS_TYPE; + } +} diff --git a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java new file mode 100644 index 000000000..54448d15a --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java @@ -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(); + } +} diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java new file mode 100644 index 000000000..f3beb7faf --- /dev/null +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -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 + * . + */ +package li.strolch.persistence.impl.dao.test; + +/** + * @author Robert von Burg + * + */ +public class AbstractDaoImplTest { + + +} diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java new file mode 100644 index 000000000..a72d156b5 --- /dev/null +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -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"); + } + +} From 08a7f29e1b9be27f2e96485bea33f2a44c4c00d6 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 19:58:24 +0200 Subject: [PATCH 03/59] Added ignores of eclipse files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2f7896d1d..b284c6517 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ target/ +.project +.settings +.classpath From 081937d45369a1cda760ab84cd567d04141207cb Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 23 Oct 2013 23:16:29 +0200 Subject: [PATCH 04/59] [Minor] cleaned up the pom.xml --- pom.xml | 4 ++++ src/test/resources/log4j.xml | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/resources/log4j.xml diff --git a/pom.xml b/pom.xml index 2a4b23796..5909eac11 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,10 @@ li.strolch li.strolch.model + + li.strolch + li.strolch.runtime + li.strolch li.strolch.persistence.api diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml new file mode 100644 index 000000000..a35a3c351 --- /dev/null +++ b/src/test/resources/log4j.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9ad71317f76a81062b534a0bd0c9d3c46bed5579 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 21:49:56 +0200 Subject: [PATCH 05/59] [New] basic implementation of Order and Resource DAOs implemented Including tests for both DAOs. Only for DOM. SAX is not yet supported! --- pom.xml | 6 ++ .../strolch/persistence/impl/XmlOrderDao.java | 5 +- ...erImpl.java => XmlPersistenceHandler.java} | 30 +++++++-- .../persistence/impl/XmlResourceDao.java | 5 +- .../impl/XmlStrolchTransaction.java | 1 + .../impl/model/OrderContextFactory.java | 26 +++++++ .../impl/model/OrderDomParser.java | 47 +++++++++++++ .../impl/model/OrderParserFactory.java | 19 ++++++ .../impl/model/ResourceContextFactory.java | 25 +++++++ .../impl/model/ResourceDomParser.java | 67 +++++++++++++++++++ .../impl/model/ResourceParserFactory.java | 40 +++++++++++ .../impl/dao/test/AbstractDaoImplTest.java | 61 ++++++++++++++++- .../impl/dao/test/XmlOrderDaoTest.java | 64 ++++++++++++++++-- .../impl/dao/test/XmlResourceDaoTest.java | 67 +++++++++++++++++++ 14 files changed, 445 insertions(+), 18 deletions(-) rename src/main/java/li/strolch/persistence/impl/{StrolchPersistenceHandlerImpl.java => XmlPersistenceHandler.java} (61%) create mode 100644 src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java create mode 100644 src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java create mode 100644 src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java create mode 100644 src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java create mode 100644 src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java create mode 100644 src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java create mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java diff --git a/pom.xml b/pom.xml index 5909eac11..bbbe54f35 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,12 @@ ch.eitchnet.xmlpers + + li.strolch + li.strolch.testbase + test + + diff --git a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java index 86e48e844..5942f2ec8 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java +++ b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java @@ -1,19 +1,18 @@ package li.strolch.persistence.impl; import li.strolch.model.Order; +import li.strolch.model.Tags; import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.StrolchTransaction; public class XmlOrderDao extends AbstractDao implements OrderDao { - private static final String CLASS_TYPE = Order.class.getName(); - protected XmlOrderDao(StrolchTransaction tx) { super(tx); } @Override protected String getClassType() { - return CLASS_TYPE; + return Tags.ORDER; } } diff --git a/src/main/java/li/strolch/persistence/impl/StrolchPersistenceHandlerImpl.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java similarity index 61% rename from src/main/java/li/strolch/persistence/impl/StrolchPersistenceHandlerImpl.java rename to src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index df2a919bc..71ca7b338 100644 --- a/src/main/java/li/strolch/persistence/impl/StrolchPersistenceHandlerImpl.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -23,10 +23,18 @@ package li.strolch.persistence.impl; import java.util.Properties; +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.model.Tags; 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 li.strolch.persistence.impl.model.OrderContextFactory; +import li.strolch.persistence.impl.model.ResourceContextFactory; +import li.strolch.runtime.ComponentConfiguration; +import ch.eitchnet.xmlpers.api.IoMode; +import ch.eitchnet.xmlpers.api.PersistenceConstants; import ch.eitchnet.xmlpers.api.PersistenceManager; import ch.eitchnet.xmlpers.api.PersistenceManagerLoader; import ch.eitchnet.xmlpers.api.PersistenceTransaction; @@ -35,20 +43,35 @@ import ch.eitchnet.xmlpers.api.PersistenceTransaction; * @author Robert von Burg * */ -public class StrolchPersistenceHandlerImpl implements StrolchPersistenceHandler { +public class XmlPersistenceHandler implements StrolchPersistenceHandler { + public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; - public void initialize() { + public void initialize(ComponentConfiguration componentConfiguration) { + + String basePath = componentConfiguration.getRuntimeConfiguration().getRootPath(); + basePath = basePath + DB_STORE_PATH; + Properties properties = new Properties(); + properties.setProperty(PersistenceConstants.PROP_VERBOSE, "true"); //$NON-NLS-1$ + properties.setProperty(PersistenceConstants.PROP_XML_IO_MOD, IoMode.DOM.name()); + properties.setProperty(PersistenceConstants.PROP_BASEPATH, basePath); + this.persistenceManager = PersistenceManagerLoader.load(properties); + + this.persistenceManager.getCtxFactory().registerPersistenceContextFactory(Resource.class, Tags.RESOURCE, + new ResourceContextFactory()); + this.persistenceManager.getCtxFactory().registerPersistenceContextFactory(Order.class, Tags.ORDER, + new OrderContextFactory()); } public StrolchTransaction openTx() { return openTx(PersistenceManager.DEFAULT_REALM); } - @SuppressWarnings("resource") // caller must close + @SuppressWarnings("resource") + // caller must close public StrolchTransaction openTx(String realm) { PersistenceTransaction tx = this.persistenceManager.openTx(realm); XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(tx); @@ -64,5 +87,4 @@ public class StrolchPersistenceHandlerImpl implements StrolchPersistenceHandler public ResourceDao getResourceDao(StrolchTransaction tx) { return new XmlResourceDao(tx); } - } diff --git a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java index 64c9e06cf..ed899b352 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java +++ b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java @@ -1,19 +1,18 @@ package li.strolch.persistence.impl; import li.strolch.model.Resource; +import li.strolch.model.Tags; import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; public class XmlResourceDao extends AbstractDao implements ResourceDao { - private static final String CLASS_TYPE = Resource.class.getName(); - protected XmlResourceDao(StrolchTransaction tx) { super(tx); } @Override protected String getClassType() { - return CLASS_TYPE; + return Tags.RESOURCE; } } diff --git a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java index 54448d15a..d37d3b541 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java @@ -12,6 +12,7 @@ public class XmlStrolchTransaction implements StrolchTransaction { public XmlStrolchTransaction(PersistenceTransaction tx) { this.tx = tx; + this.closeStrategy = TransactionCloseStrategy.COMMIT; } PersistenceTransaction getTx() { diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java b/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java new file mode 100644 index 000000000..717a25ff8 --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java @@ -0,0 +1,26 @@ +package li.strolch.persistence.impl.model; + +import li.strolch.model.Order; +import li.strolch.model.Tags; +import ch.eitchnet.xmlpers.api.PersistenceContext; +import ch.eitchnet.xmlpers.api.PersistenceContextFactory; +import ch.eitchnet.xmlpers.objref.IdOfSubTypeRef; +import ch.eitchnet.xmlpers.objref.ObjectRef; +import ch.eitchnet.xmlpers.objref.ObjectReferenceCache; + +public class OrderContextFactory implements PersistenceContextFactory { + + @Override + public PersistenceContext createCtx(ObjectRef objectRef) { + PersistenceContext ctx = new PersistenceContext<>(objectRef); + ctx.setParserFactory(new OrderParserFactory()); + return ctx; + } + + @Override + public PersistenceContext createCtx(ObjectReferenceCache objectRefCache, Order t) { + IdOfSubTypeRef objectRef = objectRefCache.getIdOfSubTypeRef(Tags.ORDER, t.getType(), t.getId()); + return createCtx(objectRef); + } + +} diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java b/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java new file mode 100644 index 000000000..6179dbc34 --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java @@ -0,0 +1,47 @@ +package li.strolch.persistence.impl.model; + +import javax.xml.parsers.DocumentBuilder; + +import li.strolch.model.Order; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import ch.eitchnet.xmlpers.api.DomParser; +import ch.eitchnet.xmlpers.util.DomUtil; + +public class OrderDomParser implements DomParser { + + private Order order; + + @Override + public Order getObject() { + return this.order; + } + + @Override + public void setObject(Order object) { + this.order = object; + + } + + @Override + public Document toDom() { + + DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); + Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); + + Element orderDom = this.order.toDom(document); + document.appendChild(orderDom); + + return document; + } + + @Override + public void fromDom(Document document) { + + Element rootElement = document.getDocumentElement(); + Order order = new Order(rootElement); + this.order = order; + } +} diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java b/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java new file mode 100644 index 000000000..d1ac48bf5 --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java @@ -0,0 +1,19 @@ +package li.strolch.persistence.impl.model; + +import li.strolch.model.Order; +import ch.eitchnet.xmlpers.api.DomParser; +import ch.eitchnet.xmlpers.api.ParserFactory; +import ch.eitchnet.xmlpers.api.SaxParser; + +public class OrderParserFactory implements ParserFactory { + + @Override + public DomParser getDomParser() { + return new OrderDomParser(); + } + + @Override + public SaxParser getSaxParser() { + throw new UnsupportedOperationException("Not yet implemented!"); //$NON-NLS-1$ + } +} diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java b/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java new file mode 100644 index 000000000..72ee41eeb --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java @@ -0,0 +1,25 @@ +package li.strolch.persistence.impl.model; + +import li.strolch.model.Resource; +import li.strolch.model.Tags; +import ch.eitchnet.xmlpers.api.PersistenceContext; +import ch.eitchnet.xmlpers.api.PersistenceContextFactory; +import ch.eitchnet.xmlpers.objref.IdOfSubTypeRef; +import ch.eitchnet.xmlpers.objref.ObjectRef; +import ch.eitchnet.xmlpers.objref.ObjectReferenceCache; + +public class ResourceContextFactory implements PersistenceContextFactory { + + @Override + public PersistenceContext createCtx(ObjectRef objectRef) { + PersistenceContext ctx = new PersistenceContext<>(objectRef); + ctx.setParserFactory(new ResourceParserFactory()); + return ctx; + } + + @Override + public PersistenceContext createCtx(ObjectReferenceCache objectRefCache, Resource t) { + IdOfSubTypeRef objectRef = objectRefCache.getIdOfSubTypeRef(Tags.RESOURCE, t.getType(), t.getId()); + return createCtx(objectRef); + } +} \ No newline at end of file diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java b/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java new file mode 100644 index 000000000..eb16f341b --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java @@ -0,0 +1,67 @@ +/* + * 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 + * . + */ +package li.strolch.persistence.impl.model; + +import javax.xml.parsers.DocumentBuilder; + +import li.strolch.model.Resource; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import ch.eitchnet.xmlpers.api.DomParser; +import ch.eitchnet.xmlpers.util.DomUtil; + +public class ResourceDomParser implements DomParser { + + private Resource resource; + + @Override + public Resource getObject() { + return this.resource; + } + + @Override + public void setObject(Resource resource) { + this.resource = resource; + } + + @Override + public Document toDom() { + + DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); + Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); + + Element resourceDom = this.resource.toDom(document); + document.appendChild(resourceDom); + + return document; + } + + @Override + public void fromDom(Document document) { + + Element rootElement = document.getDocumentElement(); + Resource resource = new Resource(rootElement); + this.resource = resource; + } +} \ No newline at end of file diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java b/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java new file mode 100644 index 000000000..7b0cfc060 --- /dev/null +++ b/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java @@ -0,0 +1,40 @@ +/* + * 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 + * . + */ +package li.strolch.persistence.impl.model; + +import li.strolch.model.Resource; +import ch.eitchnet.xmlpers.api.DomParser; +import ch.eitchnet.xmlpers.api.ParserFactory; +import ch.eitchnet.xmlpers.api.SaxParser; + +public class ResourceParserFactory implements ParserFactory { + + @Override + public DomParser getDomParser() { + return new ResourceDomParser(); + } + + @Override + public SaxParser getSaxParser() { + throw new UnsupportedOperationException("Not yet implemented!"); //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index f3beb7faf..7138ef5fc 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -21,11 +21,66 @@ */ package li.strolch.persistence.impl.dao.test; +import java.io.File; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +import li.strolch.persistence.api.StrolchPersistenceHandler; +import li.strolch.persistence.impl.XmlPersistenceHandler; +import li.strolch.runtime.ComponentConfiguration; +import li.strolch.runtime.RuntimeConfiguration; + +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ch.eitchnet.utils.helper.FileHelper; + /** * @author Robert von Burg - * + * */ -public class AbstractDaoImplTest { +public abstract class AbstractDaoImplTest { + + private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + protected static final Logger logger = LoggerFactory.getLogger(AbstractDaoImplTest.class); + + protected static XmlPersistenceHandler persistenceHandler; + + @BeforeClass + public static void beforeClass() { + + File file = new File(RUNTIME_PATH); + if (file.exists()) { + if (!FileHelper.deleteFile(file, true)) { + String msg = "Failed to delete {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, file.getAbsolutePath()); + throw new RuntimeException(msg); + } + } + + file = new File(file, XmlPersistenceHandler.DB_STORE_PATH); + if (!file.mkdirs()) { + String msg = "Failed to create path {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, file.getAbsolutePath()); + throw new RuntimeException(msg); + } + + // initialize a runtime configuration + Map runtimeConfigurationValues = new HashMap<>(); + String rootPath = RUNTIME_PATH; + RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration(runtimeConfigurationValues, rootPath); + + // initialize the component configuration + String componentName = StrolchPersistenceHandler.class.getName(); + Map configurationValues = new HashMap<>(); + ComponentConfiguration componentConfiguration = new ComponentConfiguration(runtimeConfiguration, componentName, + configurationValues); + + persistenceHandler = new XmlPersistenceHandler(); + persistenceHandler.initialize(componentConfiguration); + + } - } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index a72d156b5..2fe44c51d 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -1,14 +1,68 @@ package li.strolch.persistence.impl.dao.test; -import static org.junit.Assert.*; +import static li.strolch.testbase.model.ModelBuilder.BAG_ID; +import static li.strolch.testbase.model.ModelBuilder.PARAM_STRING_ID; +import static li.strolch.testbase.model.ModelBuilder.createOrder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import li.strolch.model.Order; +import li.strolch.model.State; +import li.strolch.model.parameter.Parameter; +import li.strolch.persistence.api.StrolchTransaction; import org.junit.Test; -public class XmlOrderDaoTest { +public class XmlOrderDaoTest extends AbstractDaoImplTest { + + private static final String ID = "@testOrder"; //$NON-NLS-1$ + private static final String NAME = "Test Order"; //$NON-NLS-1$ + private static final String TYPE = "ToStock"; //$NON-NLS-1$ @Test - public void test() { - fail("Not yet implemented"); - } + public void shouldCrud() { + // create + Order newOrder = createOrder(ID, NAME, TYPE, System.currentTimeMillis(), State.CREATED); + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getOrderDao(tx).save(newOrder); + } + + // read + Order readOrder = null; + try (StrolchTransaction tx = persistenceHandler.openTx();) { + readOrder = persistenceHandler.getOrderDao(tx).queryBy(TYPE, ID); + } + assertNotNull("Should read Order with id " + ID, readOrder); //$NON-NLS-1$ + + // update + Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); + String newStringValue = "Giddiya!"; //$NON-NLS-1$ + sParam.setValue(newStringValue); + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getOrderDao(tx).update(readOrder); + } + + // read updated + Order updatedOrder = null; + try (StrolchTransaction tx = persistenceHandler.openTx();) { + updatedOrder = persistenceHandler.getOrderDao(tx).queryBy(TYPE, ID); + } + assertNotNull("Should read Order with id " + ID, updatedOrder); //$NON-NLS-1$ + assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); //$NON-NLS-1$ + Parameter updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); + assertEquals(newStringValue, updatedParam.getValue()); + + // delete + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getOrderDao(tx).remove(readOrder); + } + + // fail to re-read + try (StrolchTransaction tx = persistenceHandler.openTx();) { + Order order = persistenceHandler.getOrderDao(tx).queryBy(TYPE, ID); + assertNull("Should no read Order with id " + ID, order); //$NON-NLS-1$ + } + } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java new file mode 100644 index 000000000..7832a4759 --- /dev/null +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -0,0 +1,67 @@ +package li.strolch.persistence.impl.dao.test; + +import static li.strolch.testbase.model.ModelBuilder.BAG_ID; +import static li.strolch.testbase.model.ModelBuilder.PARAM_STRING_ID; +import static li.strolch.testbase.model.ModelBuilder.createResource; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import li.strolch.model.Resource; +import li.strolch.model.parameter.Parameter; +import li.strolch.persistence.api.StrolchTransaction; + +import org.junit.Test; + +public class XmlResourceDaoTest extends AbstractDaoImplTest { + + private static final String ID = "@testResource"; //$NON-NLS-1$ + private static final String NAME = "Test Resource"; //$NON-NLS-1$ + private static final String TYPE = "Box"; //$NON-NLS-1$ + + @Test + public void shouldCrud() { + + // create + Resource newResource = createResource(ID, NAME, TYPE); + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getResourceDao(tx).save(newResource); + } + + // read + Resource readResource = null; + try (StrolchTransaction tx = persistenceHandler.openTx();) { + readResource = persistenceHandler.getResourceDao(tx).queryBy(TYPE, ID); + } + assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ + + // update + Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); + String newStringValue = "Giddiya!"; //$NON-NLS-1$ + sParam.setValue(newStringValue); + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getResourceDao(tx).update(readResource); + } + + // read updated + Resource updatedResource = null; + try (StrolchTransaction tx = persistenceHandler.openTx();) { + updatedResource = persistenceHandler.getResourceDao(tx).queryBy(TYPE, ID); + } + assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ + assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ + Parameter updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); + assertEquals(newStringValue, updatedParam.getValue()); + + // delete + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getResourceDao(tx).remove(readResource); + } + + // fail to re-read + try (StrolchTransaction tx = persistenceHandler.openTx();) { + Resource resource = persistenceHandler.getResourceDao(tx).queryBy(TYPE, ID); + assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ + } + } +} From 74887908e27555cb36eab4883585acd9bef0260d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 27 Oct 2013 03:26:19 +0100 Subject: [PATCH 06/59] [Minor] Added StrolchComponent interface to XmlPersistenceHandler --- .../li/strolch/persistence/impl/XmlPersistenceHandler.java | 6 ++++-- .../persistence/impl/dao/test/AbstractDaoImplTest.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 71ca7b338..1decea90c 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -32,7 +32,8 @@ import li.strolch.persistence.api.StrolchPersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.impl.model.OrderContextFactory; import li.strolch.persistence.impl.model.ResourceContextFactory; -import li.strolch.runtime.ComponentConfiguration; +import li.strolch.runtime.component.StrolchComponent; +import li.strolch.runtime.configuration.ComponentConfiguration; import ch.eitchnet.xmlpers.api.IoMode; import ch.eitchnet.xmlpers.api.PersistenceConstants; import ch.eitchnet.xmlpers.api.PersistenceManager; @@ -43,11 +44,12 @@ import ch.eitchnet.xmlpers.api.PersistenceTransaction; * @author Robert von Burg * */ -public class XmlPersistenceHandler implements StrolchPersistenceHandler { +public class XmlPersistenceHandler extends StrolchComponent implements StrolchPersistenceHandler { public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; + @Override public void initialize(ComponentConfiguration componentConfiguration) { String basePath = componentConfiguration.getRuntimeConfiguration().getRootPath(); diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index 7138ef5fc..adb846d93 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -28,8 +28,8 @@ import java.util.Map; import li.strolch.persistence.api.StrolchPersistenceHandler; import li.strolch.persistence.impl.XmlPersistenceHandler; -import li.strolch.runtime.ComponentConfiguration; -import li.strolch.runtime.RuntimeConfiguration; +import li.strolch.runtime.configuration.ComponentConfiguration; +import li.strolch.runtime.configuration.RuntimeConfiguration; import org.junit.BeforeClass; import org.slf4j.Logger; From 5e82fa7fc5c8759128f74a51759bc5a32d2bfde2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 28 Oct 2013 22:07:17 +0100 Subject: [PATCH 07/59] [Minor] added constructor to XmlPersistenceHandler --- .../persistence/impl/XmlPersistenceHandler.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 1decea90c..121de2971 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -21,6 +21,7 @@ */ package li.strolch.persistence.impl; +import java.io.File; import java.util.Properties; import li.strolch.model.Order; @@ -49,16 +50,20 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; + public XmlPersistenceHandler() { + super(StrolchPersistenceHandler.class.getName()); + } + @Override public void initialize(ComponentConfiguration componentConfiguration) { - String basePath = componentConfiguration.getRuntimeConfiguration().getRootPath(); - basePath = basePath + DB_STORE_PATH; + File basePathF = componentConfiguration.getRuntimeConfiguration().getRootPath(); + File dbStorePathF = new File(basePathF, DB_STORE_PATH); Properties properties = new Properties(); properties.setProperty(PersistenceConstants.PROP_VERBOSE, "true"); //$NON-NLS-1$ properties.setProperty(PersistenceConstants.PROP_XML_IO_MOD, IoMode.DOM.name()); - properties.setProperty(PersistenceConstants.PROP_BASEPATH, basePath); + properties.setProperty(PersistenceConstants.PROP_BASEPATH, dbStorePathF.getAbsolutePath()); this.persistenceManager = PersistenceManagerLoader.load(properties); From e415dcd6bf48847cef83f2a2c3f7f38d60c527ba Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Oct 2013 00:43:52 +0100 Subject: [PATCH 08/59] [New] rewrote the abstract test to use mocking of the container --- .../impl/dao/test/AbstractDaoImplTest.java | 41 ++++++------------- .../impl/dao/test/XmlOrderDaoTest.java | 10 +++++ .../impl/dao/test/XmlResourceDaoTest.java | 10 +++++ .../runtime/config/StrolchConfiguration.xml | 17 ++++++++ 4 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 src/test/resources/runtime/config/StrolchConfiguration.xml diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index adb846d93..d9216cd0e 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -23,20 +23,17 @@ package li.strolch.persistence.impl.dao.test; import java.io.File; import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; -import li.strolch.persistence.api.StrolchPersistenceHandler; import li.strolch.persistence.impl.XmlPersistenceHandler; import li.strolch.runtime.configuration.ComponentConfiguration; -import li.strolch.runtime.configuration.RuntimeConfiguration; +import li.strolch.runtime.configuration.ConfigurationParser; +import li.strolch.runtime.configuration.StrolchConfiguration; +import li.strolch.testbase.runtime.RuntimeMock; import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ch.eitchnet.utils.helper.FileHelper; - /** * @author Robert von Burg * @@ -44,6 +41,7 @@ import ch.eitchnet.utils.helper.FileHelper; public abstract class AbstractDaoImplTest { private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + private static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ protected static final Logger logger = LoggerFactory.getLogger(AbstractDaoImplTest.class); protected static XmlPersistenceHandler persistenceHandler; @@ -51,36 +49,23 @@ public abstract class AbstractDaoImplTest { @BeforeClass public static void beforeClass() { - File file = new File(RUNTIME_PATH); - if (file.exists()) { - if (!FileHelper.deleteFile(file, true)) { - String msg = "Failed to delete {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, file.getAbsolutePath()); - throw new RuntimeException(msg); - } - } + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + RuntimeMock.mockRuntime(rootPath, configSrc); - file = new File(file, XmlPersistenceHandler.DB_STORE_PATH); - if (!file.mkdirs()) { + File dbStorePath = new File(rootPath, XmlPersistenceHandler.DB_STORE_PATH); + if (!dbStorePath.mkdirs()) { String msg = "Failed to create path {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, file.getAbsolutePath()); + msg = MessageFormat.format(msg, dbStorePath.getAbsolutePath()); throw new RuntimeException(msg); } - // initialize a runtime configuration - Map runtimeConfigurationValues = new HashMap<>(); - String rootPath = RUNTIME_PATH; - RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration(runtimeConfigurationValues, rootPath); - // initialize the component configuration - String componentName = StrolchPersistenceHandler.class.getName(); - Map configurationValues = new HashMap<>(); - ComponentConfiguration componentConfiguration = new ComponentConfiguration(runtimeConfiguration, componentName, - configurationValues); - + StrolchConfiguration strolchConfiguration = ConfigurationParser.parseConfiguration(rootPath); + ComponentConfiguration componentConfiguration = strolchConfiguration + .getComponentConfiguration("PersistenceHandler"); //$NON-NLS-1$ persistenceHandler = new XmlPersistenceHandler(); persistenceHandler.initialize(componentConfiguration); } - } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index 2fe44c51d..b6c83a0d3 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -20,6 +20,16 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { private static final String NAME = "Test Order"; //$NON-NLS-1$ private static final String TYPE = "ToStock"; //$NON-NLS-1$ + @Test + public void shouldCreateOrder() { + + // create + Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", System.currentTimeMillis(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getOrderDao(tx).save(newOrder); + } + } + @Test public void shouldCrud() { diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index 7832a4759..bb2117d0f 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -19,6 +19,16 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { private static final String NAME = "Test Resource"; //$NON-NLS-1$ private static final String TYPE = "Box"; //$NON-NLS-1$ + @Test + public void shouldCreateOrder() { + + // create + Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getResourceDao(tx).save(newResource); + } + } + @Test public void shouldCrud() { diff --git a/src/test/resources/runtime/config/StrolchConfiguration.xml b/src/test/resources/runtime/config/StrolchConfiguration.xml new file mode 100644 index 000000000..89ea0f543 --- /dev/null +++ b/src/test/resources/runtime/config/StrolchConfiguration.xml @@ -0,0 +1,17 @@ + + + + StrolchPersistenceTest + + true + + + + PersistenceHandler + li.strolch.persistence.api.StrolchPersistenceHandler + li.strolch.persistence.impl.XmlPersistenceHandler + + true + + + \ No newline at end of file From ede49b6d20cf4c0ec59df14f425bf2acbf47e8fa Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 5 Nov 2013 20:42:14 +0100 Subject: [PATCH 09/59] [Devel] busy implementing a component directed acyclic dependency tree This is needed to start/stop in the right order --- .../li/strolch/persistence/impl/XmlPersistenceHandler.java | 5 +++-- .../persistence/impl/dao/test/AbstractDaoImplTest.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 121de2971..bc2ddb1c9 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -33,6 +33,7 @@ import li.strolch.persistence.api.StrolchPersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.impl.model.OrderContextFactory; import li.strolch.persistence.impl.model.ResourceContextFactory; +import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.component.StrolchComponent; import li.strolch.runtime.configuration.ComponentConfiguration; import ch.eitchnet.xmlpers.api.IoMode; @@ -50,8 +51,8 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; - public XmlPersistenceHandler() { - super(StrolchPersistenceHandler.class.getName()); + public XmlPersistenceHandler(ComponentContainer container) { + super(container, StrolchPersistenceHandler.class.getName()); } @Override diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index d9216cd0e..3214c805c 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -25,6 +25,7 @@ import java.io.File; import java.text.MessageFormat; import li.strolch.persistence.impl.XmlPersistenceHandler; +import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.configuration.ConfigurationParser; import li.strolch.runtime.configuration.StrolchConfiguration; @@ -64,7 +65,8 @@ public abstract class AbstractDaoImplTest { StrolchConfiguration strolchConfiguration = ConfigurationParser.parseConfiguration(rootPath); ComponentConfiguration componentConfiguration = strolchConfiguration .getComponentConfiguration("PersistenceHandler"); //$NON-NLS-1$ - persistenceHandler = new XmlPersistenceHandler(); + ComponentContainer container = new ComponentContainer(); + persistenceHandler = new XmlPersistenceHandler(container); persistenceHandler.initialize(componentConfiguration); } From 904b89f80967520928bb4283c556d82f3cffd037 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 14 Nov 2013 21:36:01 +0100 Subject: [PATCH 10/59] [New] Implemented notifying of observers of changed objects after a TX So that components/observers can be notified of changes to the model, the completion of a TX now triggers an ObserverHandler update of the modified objects --- .../impl/XmlPersistenceHandler.java | 12 +- .../impl/XmlStrolchTransaction.java | 51 +++++++++ .../impl/dao/test/AbstractDaoImplTest.java | 33 ++---- .../impl/dao/test/ObserverUpdateTest.java | 104 ++++++++++++++++++ .../runtime/config/StrolchConfiguration.xml | 5 + 5 files changed, 181 insertions(+), 24 deletions(-) create mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index bc2ddb1c9..b283a09cf 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -36,6 +36,7 @@ import li.strolch.persistence.impl.model.ResourceContextFactory; import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.component.StrolchComponent; import li.strolch.runtime.configuration.ComponentConfiguration; +import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.IoMode; import ch.eitchnet.xmlpers.api.PersistenceConstants; import ch.eitchnet.xmlpers.api.PersistenceManager; @@ -51,8 +52,8 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; - public XmlPersistenceHandler(ComponentContainer container) { - super(container, StrolchPersistenceHandler.class.getName()); + public XmlPersistenceHandler(ComponentContainer container, String componentName) { + super(container, componentName); } @Override @@ -72,6 +73,8 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe new ResourceContextFactory()); this.persistenceManager.getCtxFactory().registerPersistenceContextFactory(Order.class, Tags.ORDER, new OrderContextFactory()); + + super.initialize(componentConfiguration); } public StrolchTransaction openTx() { @@ -79,10 +82,13 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe } @SuppressWarnings("resource") - // caller must close + // caller will/must close public StrolchTransaction openTx(String realm) { PersistenceTransaction tx = this.persistenceManager.openTx(realm); XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(tx); + if (getContainer().hasComponent(ObserverHandler.class)) { + strolchTx.setObserverHandler(getContainer().getComponent(ObserverHandler.class)); + } return strolchTx; } diff --git a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java index d37d3b541..a58bb7829 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java @@ -1,20 +1,53 @@ package li.strolch.persistence.impl; +import java.util.Set; + +import li.strolch.model.StrolchElement; import li.strolch.persistence.api.StrolchPersistenceException; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.api.TransactionCloseStrategy; +import li.strolch.runtime.observer.ObserverHandler; +import ch.eitchnet.xmlpers.api.ModificationResult; import ch.eitchnet.xmlpers.api.PersistenceTransaction; +import ch.eitchnet.xmlpers.api.TransactionResult; public class XmlStrolchTransaction implements StrolchTransaction { + private ObserverHandler observerHandler; + private boolean suppressUpdates; private PersistenceTransaction tx; private TransactionCloseStrategy closeStrategy; + private TransactionResult txResult; public XmlStrolchTransaction(PersistenceTransaction tx) { + this.suppressUpdates = false; this.tx = tx; this.closeStrategy = TransactionCloseStrategy.COMMIT; } + /** + * @param observerHandler + * the observerHandler to set + */ + public void setObserverHandler(ObserverHandler observerHandler) { + this.observerHandler = observerHandler; + } + + /** + * @param suppressUpdates + * the suppressUpdates to set + */ + public void setSuppressUpdates(boolean suppressUpdates) { + this.suppressUpdates = suppressUpdates; + } + + /** + * @return the suppressUpdates + */ + public boolean isSuppressUpdates() { + return this.suppressUpdates; + } + PersistenceTransaction getTx() { return this.tx; } @@ -26,7 +59,25 @@ public class XmlStrolchTransaction implements StrolchTransaction { @Override public void autoCloseableCommit() { + + if (!this.suppressUpdates && this.observerHandler != null) { + this.txResult = new TransactionResult(); + this.tx.setTransactionResult(this.txResult); + } + this.tx.autoCloseableCommit(); + + if (!this.suppressUpdates && this.observerHandler != null) { + + Set keys = this.txResult.getKeys(); + for (String key : keys) { + ModificationResult modificationResult = this.txResult.getModificationResult(key); + + this.observerHandler.add(key, modificationResult. getCreated()); + this.observerHandler.update(key, modificationResult. getUpdated()); + this.observerHandler.remove(key, modificationResult. getDeleted()); + } + } } @Override diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index 3214c805c..2204970f6 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -22,15 +22,11 @@ package li.strolch.persistence.impl.dao.test; import java.io.File; -import java.text.MessageFormat; -import li.strolch.persistence.impl.XmlPersistenceHandler; -import li.strolch.runtime.component.ComponentContainer; -import li.strolch.runtime.configuration.ComponentConfiguration; -import li.strolch.runtime.configuration.ConfigurationParser; -import li.strolch.runtime.configuration.StrolchConfiguration; +import li.strolch.persistence.api.StrolchPersistenceHandler; import li.strolch.testbase.runtime.RuntimeMock; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,13 +35,14 @@ import org.slf4j.LoggerFactory; * @author Robert von Burg * */ -public abstract class AbstractDaoImplTest { +public abstract class AbstractDaoImplTest extends RuntimeMock { private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + private static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ private static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ protected static final Logger logger = LoggerFactory.getLogger(AbstractDaoImplTest.class); - protected static XmlPersistenceHandler persistenceHandler; + protected static StrolchPersistenceHandler persistenceHandler; @BeforeClass public static void beforeClass() { @@ -53,21 +50,15 @@ public abstract class AbstractDaoImplTest { File rootPath = new File(RUNTIME_PATH); File configSrc = new File(CONFIG_SRC); RuntimeMock.mockRuntime(rootPath, configSrc); - - File dbStorePath = new File(rootPath, XmlPersistenceHandler.DB_STORE_PATH); - if (!dbStorePath.mkdirs()) { - String msg = "Failed to create path {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, dbStorePath.getAbsolutePath()); - throw new RuntimeException(msg); - } + new File(rootPath, DB_STORE_PATH_DIR).mkdir(); + RuntimeMock.startContainer(rootPath); // initialize the component configuration - StrolchConfiguration strolchConfiguration = ConfigurationParser.parseConfiguration(rootPath); - ComponentConfiguration componentConfiguration = strolchConfiguration - .getComponentConfiguration("PersistenceHandler"); //$NON-NLS-1$ - ComponentContainer container = new ComponentContainer(); - persistenceHandler = new XmlPersistenceHandler(container); - persistenceHandler.initialize(componentConfiguration); + persistenceHandler = getContainer().getComponent(StrolchPersistenceHandler.class); + } + @AfterClass + public static void afterClass() { + RuntimeMock.destroyRuntime(); } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java new file mode 100644 index 000000000..489758ce8 --- /dev/null +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -0,0 +1,104 @@ +/* + * 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 + * . + */ +package li.strolch.persistence.impl.dao.test; + +import static li.strolch.testbase.model.ModelBuilder.createOrder; +import static li.strolch.testbase.model.ModelBuilder.createResource; +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.StrolchElement; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.observer.Observer; +import li.strolch.runtime.observer.ObserverHandler; + +import org.junit.Test; + +import ch.eitchnet.xmlpers.api.ModificationResult; + +/** + * @author Robert von Burg + * + */ +public class ObserverUpdateTest extends AbstractDaoImplTest { + + public final class ElementAddedObserver implements Observer { + + Map results = new HashMap<>(); + + private ModificationResult getModificationResult(String key) { + ModificationResult result = this.results.get(key); + if (result == null) { + result = new ModificationResult(key); + this.results.put(key, result); + } + return result; + } + + @Override + public void update(String key, List elements) { + getModificationResult(key).getUpdated().addAll(elements); + } + + @Override + public void remove(String key, List elements) { + getModificationResult(key).getDeleted().addAll(elements); + } + + @Override + public void add(String key, List elements) { + getModificationResult(key).getCreated().addAll(elements); + } + } + + @Test + public void shouldReceiveUpdates() { + + // register an observer for orders and resources + ElementAddedObserver observer = new ElementAddedObserver(); + getContainer().getComponent(ObserverHandler.class).registerObserver("Order", observer); //$NON-NLS-1$ + getContainer().getComponent(ObserverHandler.class).registerObserver("Resource", observer); //$NON-NLS-1$ + + // create order + Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", System.currentTimeMillis(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getOrderDao(tx).save(newOrder); + } + + // create resource + Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getResourceDao(tx).save(newResource); + } + + assertEquals(2, observer.results.size()); + assertEquals(1, observer.results.get("Order").getCreated().size()); //$NON-NLS-1$ + assertEquals(1, observer.results.get("Resource").getCreated().size()); //$NON-NLS-1$ + + } +} diff --git a/src/test/resources/runtime/config/StrolchConfiguration.xml b/src/test/resources/runtime/config/StrolchConfiguration.xml index 89ea0f543..b3397b6d2 100644 --- a/src/test/resources/runtime/config/StrolchConfiguration.xml +++ b/src/test/resources/runtime/config/StrolchConfiguration.xml @@ -14,4 +14,9 @@ true + + ObserverHandler + li.strolch.runtime.observer.ObserverHandler + li.strolch.runtime.observer.DefaultObserverHandler + \ No newline at end of file From 0741165c71e245ff56717b2f730ee666131e7966 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 14 Nov 2013 22:42:50 +0100 Subject: [PATCH 11/59] [Minor] removed unneeded logger --- .../persistence/impl/dao/test/AbstractDaoImplTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index 2204970f6..c76f1b848 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -28,8 +28,6 @@ import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @author Robert von Burg @@ -40,8 +38,6 @@ public abstract class AbstractDaoImplTest extends RuntimeMock { private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ private static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ private static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ - protected static final Logger logger = LoggerFactory.getLogger(AbstractDaoImplTest.class); - protected static StrolchPersistenceHandler persistenceHandler; @BeforeClass From 6ed0cceffd1cb066bd81b992674c43e48092e705 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 20 Nov 2013 07:50:03 +0100 Subject: [PATCH 12/59] [Minor] fixed compile errors in tests due to refactoring of Dates --- .../persistence/impl/dao/test/ObserverUpdateTest.java | 3 ++- .../strolch/persistence/impl/dao/test/XmlOrderDaoTest.java | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 489758ce8..9c372ba2a 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -25,6 +25,7 @@ import static li.strolch.testbase.model.ModelBuilder.createOrder; import static li.strolch.testbase.model.ModelBuilder.createResource; import static org.junit.Assert.assertEquals; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -85,7 +86,7 @@ public class ObserverUpdateTest extends AbstractDaoImplTest { getContainer().getComponent(ObserverHandler.class).registerObserver("Resource", observer); //$NON-NLS-1$ // create order - Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", System.currentTimeMillis(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = persistenceHandler.openTx();) { persistenceHandler.getOrderDao(tx).save(newOrder); } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index b6c83a0d3..29608adf5 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -7,6 +7,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; + +import java.util.Date; + import li.strolch.model.Order; import li.strolch.model.State; import li.strolch.model.parameter.Parameter; @@ -24,7 +27,7 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { public void shouldCreateOrder() { // create - Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", System.currentTimeMillis(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = persistenceHandler.openTx();) { persistenceHandler.getOrderDao(tx).save(newOrder); } @@ -34,7 +37,7 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { public void shouldCrud() { // create - Order newOrder = createOrder(ID, NAME, TYPE, System.currentTimeMillis(), State.CREATED); + Order newOrder = createOrder(ID, NAME, TYPE, new Date(), State.CREATED); try (StrolchTransaction tx = persistenceHandler.openTx();) { persistenceHandler.getOrderDao(tx).save(newOrder); } From daba472769a8e093dc9f2e1fe8d7e2013038b2a2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 25 Nov 2013 18:54:04 +0100 Subject: [PATCH 13/59] [New] Implemented EMPTY and TRANSIENT dataStoreModes. Refactored Agent to be responsible for starting the container. And it requires the runtime configuration. --- src/test/resources/runtime/config/StrolchConfiguration.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/resources/runtime/config/StrolchConfiguration.xml b/src/test/resources/runtime/config/StrolchConfiguration.xml index b3397b6d2..55d52600b 100644 --- a/src/test/resources/runtime/config/StrolchConfiguration.xml +++ b/src/test/resources/runtime/config/StrolchConfiguration.xml @@ -3,6 +3,7 @@ StrolchPersistenceTest + EMPTY true From a7e17d22d1d7dc80ea02be36bef5e70fb969c9f0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 11 Dec 2013 23:51:45 +0100 Subject: [PATCH 14/59] [Minor] moved the ModelBuilder to li.strolch.model ModelGenerator now generating objects is available everywhere --- .../impl/dao/test/ObserverUpdateTest.java | 4 ++-- .../persistence/impl/dao/test/XmlOrderDaoTest.java | 14 +++++--------- .../impl/dao/test/XmlResourceDaoTest.java | 8 ++++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 9c372ba2a..0a7fabf7e 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -21,8 +21,8 @@ */ package li.strolch.persistence.impl.dao.test; -import static li.strolch.testbase.model.ModelBuilder.createOrder; -import static li.strolch.testbase.model.ModelBuilder.createResource; +import static li.strolch.model.ModelGenerator.createOrder; +import static li.strolch.model.ModelGenerator.createResource; import static org.junit.Assert.assertEquals; import java.util.Date; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index 29608adf5..7f593e0a6 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -1,17 +1,13 @@ package li.strolch.persistence.impl.dao.test; -import static li.strolch.testbase.model.ModelBuilder.BAG_ID; -import static li.strolch.testbase.model.ModelBuilder.PARAM_STRING_ID; -import static li.strolch.testbase.model.ModelBuilder.createOrder; +import static li.strolch.model.ModelGenerator.BAG_ID; +import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; +import static li.strolch.model.ModelGenerator.createOrder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; - -import java.util.Date; - import li.strolch.model.Order; -import li.strolch.model.State; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; @@ -27,7 +23,7 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { public void shouldCreateOrder() { // create - Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = persistenceHandler.openTx();) { persistenceHandler.getOrderDao(tx).save(newOrder); } @@ -37,7 +33,7 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { public void shouldCrud() { // create - Order newOrder = createOrder(ID, NAME, TYPE, new Date(), State.CREATED); + Order newOrder = createOrder(ID, NAME, TYPE); try (StrolchTransaction tx = persistenceHandler.openTx();) { persistenceHandler.getOrderDao(tx).save(newOrder); } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index bb2117d0f..6b9ed3ca9 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -1,8 +1,8 @@ package li.strolch.persistence.impl.dao.test; -import static li.strolch.testbase.model.ModelBuilder.BAG_ID; -import static li.strolch.testbase.model.ModelBuilder.PARAM_STRING_ID; -import static li.strolch.testbase.model.ModelBuilder.createResource; +import static li.strolch.model.ModelGenerator.BAG_ID; +import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; +import static li.strolch.model.ModelGenerator.createResource; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -20,7 +20,7 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { private static final String TYPE = "Box"; //$NON-NLS-1$ @Test - public void shouldCreateOrder() { + public void shouldCreateResource() { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ From 7a2bd6045c2231389486707106e5121dc165f6e1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 15 Dec 2013 13:10:19 +0100 Subject: [PATCH 15/59] [Project] Changed all licence references to Apache License 2.0 --- LICENSE | 309 +++++++++--------- .../strolch/persistence/impl/AbstractDao.java | 15 + .../strolch/persistence/impl/XmlOrderDao.java | 15 + .../impl/XmlPersistenceHandler.java | 32 +- .../persistence/impl/XmlResourceDao.java | 15 + .../impl/XmlStrolchTransaction.java | 15 + .../impl/model/OrderContextFactory.java | 15 + .../impl/model/OrderDomParser.java | 15 + .../impl/model/OrderParserFactory.java | 15 + .../impl/model/ResourceContextFactory.java | 15 + .../impl/model/ResourceDomParser.java | 32 +- .../impl/model/ResourceParserFactory.java | 32 +- .../impl/dao/test/AbstractDaoImplTest.java | 32 +- .../impl/dao/test/ObserverUpdateTest.java | 32 +- .../impl/dao/test/XmlOrderDaoTest.java | 15 + .../impl/dao/test/XmlResourceDaoTest.java | 15 + 16 files changed, 375 insertions(+), 244 deletions(-) diff --git a/LICENSE b/LICENSE index 37ec93a14..d64569567 100644 --- a/LICENSE +++ b/LICENSE @@ -1,180 +1,191 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -1. Definitions. + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. + 1. Definitions. -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct or -indirect, to cause the direction or management of such entity, whether by -contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the -outstanding shares, or (iii) beneficial ownership of such entity. + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this License. + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. -"Object" form shall mean any form resulting from mechanical transformation or -translation of a Source form, including but not limited to compiled object code, -generated documentation, and conversions to other media types. + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. -"Work" shall mean the work of authorship, whether in Source or Object form, made -available under the License, as indicated by a copyright notice that is included -in or attached to the work (an example is provided in the Appendix below). + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. -"Derivative Works" shall mean any work, whether in Source or Object form, that -is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative Works -shall not include works that remain separable from, or merely link (or bind by -name) to the interfaces of, the Work and Derivative Works thereof. + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative Works -thereof, that is intentionally submitted to Licensor for inclusion in the Work -by the copyright owner or by an individual or Legal Entity authorized to submit -on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication sent -to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor for -the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently -incorporated within the Work. + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." -2. Grant of Copyright License. + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable copyright license to reproduce, prepare Derivative Works of, -publicly display, publicly perform, sublicense, and distribute the Work and such -Derivative Works in Source or Object form. + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. -3. Grant of Patent License. + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable (except as stated in this section) patent license to make, have -made, use, offer to sell, sell, import, and otherwise transfer the Work, where -such license applies only to those patent claims licensable by such Contributor -that are necessarily infringed by their Contribution(s) alone or by combination -of their Contribution(s) with the Work to which such Contribution(s) was -submitted. If You institute patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Work or a -Contribution incorporated within the Work constitutes direct or contributory -patent infringement, then any patent licenses granted to You under this License -for that Work shall terminate as of the date such litigation is filed. + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: -4. Redistribution. + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and -You may reproduce and distribute copies of the Work or Derivative Works thereof -in any medium, with or without modifications, and in Source or Object form, -provided that You meet the following conditions: + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source form -of the Work, excluding those notices that do not pertain to any part of the -Derivative Works; and -If the Work includes a "NOTICE" text file as part of its distribution, then any -Derivative Works that You distribute must include a readable copy of the -attribution notices contained within such NOTICE file, excluding those notices -that do not pertain to any part of the Derivative Works, in at least one of the -following places: within a NOTICE text file distributed as part of the -Derivative Works; within the Source form or documentation, if provided along -with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents of -the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works that -You distribute, alongside or as an addendum to the NOTICE text from the Work, -provided that such additional attribution notices cannot be construed as -modifying the License. -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, or -distribution of Your modifications, or for any such Derivative Works as a whole, -provided Your use, reproduction, and distribution of the Work otherwise complies -with the conditions stated in this License. + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and -5. Submission of Contributions. + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. -Unless You explicitly state otherwise, any Contribution intentionally submitted -for inclusion in the Work by You to the Licensor shall be under the terms and -conditions of this License, without any additional terms or conditions. -Notwithstanding the above, nothing herein shall supersede or modify the terms of -any separate license agreement you may have executed with Licensor regarding -such Contributions. + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. -6. Trademarks. + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. -This License does not grant permission to use the trade names, trademarks, -service marks, or product names of the Licensor, except as required for -reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. -7. Disclaimer of Warranty. + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. -Unless required by applicable law or agreed to in writing, Licensor provides the -Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, -including, without limitation, any warranties or conditions of TITLE, -NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are -solely responsible for determining the appropriateness of using or -redistributing the Work and assume any risks associated with Your exercise of -permissions under this License. + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. -8. Limitation of Liability. + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. -In no event and under no legal theory, whether in tort (including negligence), -contract, or otherwise, unless required by applicable law (such as deliberate -and grossly negligent acts) or agreed to in writing, shall any Contributor be -liable to You for damages, including any direct, indirect, special, incidental, -or consequential damages of any character arising as a result of this License or -out of the use or inability to use the Work (including but not limited to -damages for loss of goodwill, work stoppage, computer failure or malfunction, or -any and all other commercial damages or losses), even if such Contributor has -been advised of the possibility of such damages. + END OF TERMS AND CONDITIONS -9. Accepting Warranty or Additional Liability. + APPENDIX: How to apply the Apache License to your work. -While redistributing the Work or Derivative Works thereof, You may choose to -offer, and charge a fee for, acceptance of support, warranty, indemnity, or -other liability obligations and/or rights consistent with this License. However, -in accepting such obligations, You may act only on Your own behalf and on Your -sole responsibility, not on behalf of any other Contributor, and only if You -agree to indemnify, defend, and hold each Contributor harmless for any liability -incurred by, or claims asserted against, such Contributor by reason of your -accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work - -To apply the Apache License to your work, attach the following boilerplate -notice, with the fields enclosed by brackets "[]" replaced with your own -identifying information. (Don't include the brackets!) The text should be -enclosed in the appropriate comment syntax for the file format. We also -recommend that a file or class name and description of purpose be included on -the same "printed page" as the copyright notice for easier identification within -third-party archives. + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. Copyright [yyyy] [name of copyright owner] @@ -182,7 +193,7 @@ third-party archives. you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/li/strolch/persistence/impl/AbstractDao.java b/src/main/java/li/strolch/persistence/impl/AbstractDao.java index fb41b4c16..140a1bbaa 100644 --- a/src/main/java/li/strolch/persistence/impl/AbstractDao.java +++ b/src/main/java/li/strolch/persistence/impl/AbstractDao.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl; import java.util.ArrayList; diff --git a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java index 5942f2ec8..a552a41c4 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java +++ b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl; import li.strolch.model.Order; diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index b283a09cf..1ebae3d7d 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -1,23 +1,17 @@ /* - * 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 - * . + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package li.strolch.persistence.impl; diff --git a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java index ed899b352..aba0d8d0a 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java +++ b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl; import li.strolch.model.Resource; diff --git a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java index a58bb7829..a3f1c89f4 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl; import java.util.Set; diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java b/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java index 717a25ff8..eb4007d6e 100644 --- a/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java +++ b/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl.model; import li.strolch.model.Order; diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java b/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java index 6179dbc34..0e80b8a82 100644 --- a/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java +++ b/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl.model; import javax.xml.parsers.DocumentBuilder; diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java b/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java index d1ac48bf5..029d2da90 100644 --- a/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java +++ b/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl.model; import li.strolch.model.Order; diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java b/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java index 72ee41eeb..f6d8738c3 100644 --- a/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java +++ b/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl.model; import li.strolch.model.Resource; diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java b/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java index eb16f341b..b94ce74aa 100644 --- a/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java +++ b/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java @@ -1,23 +1,17 @@ /* - * 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 - * . + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package li.strolch.persistence.impl.model; diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java b/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java index 7b0cfc060..ebe7d8153 100644 --- a/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java +++ b/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java @@ -1,23 +1,17 @@ /* - * 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 - * . + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package li.strolch.persistence.impl.model; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index c76f1b848..202e886b8 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -1,23 +1,17 @@ /* - * 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 - * . + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package li.strolch.persistence.impl.dao.test; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 0a7fabf7e..4681e75eb 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -1,23 +1,17 @@ /* - * 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 - * . + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package li.strolch.persistence.impl.dao.test; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index 7f593e0a6..2bab875c9 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl.dao.test; import static li.strolch.model.ModelGenerator.BAG_ID; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index 6b9ed3ca9..b4363c9be 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.persistence.impl.dao.test; import static li.strolch.model.ModelGenerator.BAG_ID; From c76d6cebc4f2c20476a0d3a1439fb7ceafc4a454 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 18 Dec 2013 17:47:26 +0100 Subject: [PATCH 16/59] [Minor] moved defaultRealm constant --- .../java/li/strolch/persistence/impl/XmlPersistenceHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 1ebae3d7d..6582ea85d 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -72,7 +72,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe } public StrolchTransaction openTx() { - return openTx(PersistenceManager.DEFAULT_REALM); + return openTx(StrolchTransaction.DEFAULT_REALM); } @SuppressWarnings("resource") From a0d4f2587eac5569d89a8d07484b5ca12e3d3588 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 23 Dec 2013 01:54:07 +0100 Subject: [PATCH 17/59] [New] Using visitor pattern to perform DOM actions --- .../li/strolch/persistence/impl/AbstractDao.java | 6 ------ .../persistence/impl/XmlStrolchTransaction.java | 9 ++++----- .../persistence/impl/model/OrderDomParser.java | 16 ++++------------ .../impl/model/ResourceDomParser.java | 16 ++++------------ 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/AbstractDao.java b/src/main/java/li/strolch/persistence/impl/AbstractDao.java index 140a1bbaa..60a6e0e47 100644 --- a/src/main/java/li/strolch/persistence/impl/AbstractDao.java +++ b/src/main/java/li/strolch/persistence/impl/AbstractDao.java @@ -126,10 +126,4 @@ public abstract class AbstractDao implements StrolchDa public void removeAll(List 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); - } } diff --git a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java index a3f1c89f4..ab4562f5d 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java @@ -32,7 +32,6 @@ public class XmlStrolchTransaction implements StrolchTransaction { private boolean suppressUpdates; private PersistenceTransaction tx; private TransactionCloseStrategy closeStrategy; - private TransactionResult txResult; public XmlStrolchTransaction(PersistenceTransaction tx) { this.suppressUpdates = false; @@ -75,18 +74,18 @@ public class XmlStrolchTransaction implements StrolchTransaction { @Override public void autoCloseableCommit() { + TransactionResult txResult = new TransactionResult(); if (!this.suppressUpdates && this.observerHandler != null) { - this.txResult = new TransactionResult(); - this.tx.setTransactionResult(this.txResult); + this.tx.setTransactionResult(txResult); } this.tx.autoCloseableCommit(); if (!this.suppressUpdates && this.observerHandler != null) { - Set keys = this.txResult.getKeys(); + Set keys = txResult.getKeys(); for (String key : keys) { - ModificationResult modificationResult = this.txResult.getModificationResult(key); + ModificationResult modificationResult = txResult.getModificationResult(key); this.observerHandler.add(key, modificationResult. getCreated()); this.observerHandler.update(key, modificationResult. getUpdated()); diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java b/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java index 0e80b8a82..45cf30440 100644 --- a/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java +++ b/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java @@ -15,15 +15,13 @@ */ package li.strolch.persistence.impl.model; -import javax.xml.parsers.DocumentBuilder; - import li.strolch.model.Order; +import li.strolch.model.xml.OrderToDomVisitor; import org.w3c.dom.Document; import org.w3c.dom.Element; import ch.eitchnet.xmlpers.api.DomParser; -import ch.eitchnet.xmlpers.util.DomUtil; public class OrderDomParser implements DomParser { @@ -42,19 +40,13 @@ public class OrderDomParser implements DomParser { @Override public Document toDom() { - - DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); - Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); - - Element orderDom = this.order.toDom(document); - document.appendChild(orderDom); - - return document; + OrderToDomVisitor orderDomVisitor = new OrderToDomVisitor(); + orderDomVisitor.visit(this.order); + return orderDomVisitor.getDocument(); } @Override public void fromDom(Document document) { - Element rootElement = document.getDocumentElement(); Order order = new Order(rootElement); this.order = order; diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java b/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java index b94ce74aa..497a81d1a 100644 --- a/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java +++ b/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java @@ -15,15 +15,13 @@ */ package li.strolch.persistence.impl.model; -import javax.xml.parsers.DocumentBuilder; - import li.strolch.model.Resource; +import li.strolch.model.xml.ResourceToDomVisitor; import org.w3c.dom.Document; import org.w3c.dom.Element; import ch.eitchnet.xmlpers.api.DomParser; -import ch.eitchnet.xmlpers.util.DomUtil; public class ResourceDomParser implements DomParser { @@ -41,19 +39,13 @@ public class ResourceDomParser implements DomParser { @Override public Document toDom() { - - DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder(); - Document document = documentBuilder.getDOMImplementation().createDocument(null, null, null); - - Element resourceDom = this.resource.toDom(document); - document.appendChild(resourceDom); - - return document; + ResourceToDomVisitor domVisitor = new ResourceToDomVisitor(); + domVisitor.visit(this.resource); + return domVisitor.getDocument(); } @Override public void fromDom(Document document) { - Element rootElement = document.getDocumentElement(); Resource resource = new Resource(rootElement); this.resource = resource; From 4ef8e990a9e36bcc7175407c5b1644930f98cab1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 23 Dec 2013 18:43:11 +0100 Subject: [PATCH 18/59] [Major] refactored Element maps for better handling Now they are not components, now there is an ElementMapHandler which is the component and the OrderMap and ResourceMap can be retrieved from the ElementMapHandler --- .../li/strolch/persistence/impl/XmlPersistenceHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 6582ea85d..34a1d1700 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -27,8 +27,8 @@ import li.strolch.persistence.api.StrolchPersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.impl.model.OrderContextFactory; import li.strolch.persistence.impl.model.ResourceContextFactory; -import li.strolch.runtime.component.ComponentContainer; -import li.strolch.runtime.component.StrolchComponent; +import li.strolch.runtime.agent.ComponentContainerImpl; +import li.strolch.runtime.agent.StrolchComponent; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.IoMode; @@ -46,7 +46,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; - public XmlPersistenceHandler(ComponentContainer container, String componentName) { + public XmlPersistenceHandler(ComponentContainerImpl container, String componentName) { super(container, componentName); } From 96e679c973d44459a6af3279589ad45b904dbfe3 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 00:18:03 +0100 Subject: [PATCH 19/59] [New] Implemented CACHED mode for Strolch --- .../li/strolch/persistence/impl/XmlPersistenceHandler.java | 7 ++++--- .../persistence/impl/dao/test/AbstractDaoImplTest.java | 6 +++--- src/test/resources/runtime/config/StrolchConfiguration.xml | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 34a1d1700..7a9417914 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -23,10 +23,11 @@ import li.strolch.model.Resource; import li.strolch.model.Tags; import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.ResourceDao; -import li.strolch.persistence.api.StrolchPersistenceHandler; +import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.impl.model.OrderContextFactory; import li.strolch.persistence.impl.model.ResourceContextFactory; +import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.agent.ComponentContainerImpl; import li.strolch.runtime.agent.StrolchComponent; import li.strolch.runtime.configuration.ComponentConfiguration; @@ -41,7 +42,7 @@ import ch.eitchnet.xmlpers.api.PersistenceTransaction; * @author Robert von Burg * */ -public class XmlPersistenceHandler extends StrolchComponent implements StrolchPersistenceHandler { +public class XmlPersistenceHandler extends StrolchComponent implements PersistenceHandler { public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; @@ -72,7 +73,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements StrolchPe } public StrolchTransaction openTx() { - return openTx(StrolchTransaction.DEFAULT_REALM); + return openTx(StrolchConstants.DEFAULT_REALM); } @SuppressWarnings("resource") diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index 202e886b8..d85e35a03 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -17,7 +17,7 @@ package li.strolch.persistence.impl.dao.test; import java.io.File; -import li.strolch.persistence.api.StrolchPersistenceHandler; +import li.strolch.persistence.api.PersistenceHandler; import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; @@ -32,7 +32,7 @@ public abstract class AbstractDaoImplTest extends RuntimeMock { private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ private static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ private static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ - protected static StrolchPersistenceHandler persistenceHandler; + protected static PersistenceHandler persistenceHandler; @BeforeClass public static void beforeClass() { @@ -44,7 +44,7 @@ public abstract class AbstractDaoImplTest extends RuntimeMock { RuntimeMock.startContainer(rootPath); // initialize the component configuration - persistenceHandler = getContainer().getComponent(StrolchPersistenceHandler.class); + persistenceHandler = getContainer().getComponent(PersistenceHandler.class); } @AfterClass diff --git a/src/test/resources/runtime/config/StrolchConfiguration.xml b/src/test/resources/runtime/config/StrolchConfiguration.xml index 55d52600b..f7dd1f7b4 100644 --- a/src/test/resources/runtime/config/StrolchConfiguration.xml +++ b/src/test/resources/runtime/config/StrolchConfiguration.xml @@ -3,13 +3,13 @@ StrolchPersistenceTest - EMPTY + CACHED true PersistenceHandler - li.strolch.persistence.api.StrolchPersistenceHandler + li.strolch.persistence.api.PersistenceHandler li.strolch.persistence.impl.XmlPersistenceHandler true From 86dddde1966968093bce8a6f2381a36b0683a211 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 00:36:29 +0100 Subject: [PATCH 20/59] [Major] moved OrderDao and ResourceDao factory methods to transaction It makes using transaction feel easier. --- .../persistence/impl/XmlPersistenceHandler.java | 14 +------------- .../persistence/impl/XmlStrolchTransaction.java | 12 ++++++++++++ .../impl/dao/test/ObserverUpdateTest.java | 4 ++-- .../persistence/impl/dao/test/XmlOrderDaoTest.java | 14 +++++++------- .../impl/dao/test/XmlResourceDaoTest.java | 14 +++++++------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 7a9417914..174482389 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -21,8 +21,6 @@ import java.util.Properties; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.Tags; -import li.strolch.persistence.api.OrderDao; -import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.impl.model.OrderContextFactory; @@ -68,7 +66,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten new ResourceContextFactory()); this.persistenceManager.getCtxFactory().registerPersistenceContextFactory(Order.class, Tags.ORDER, new OrderContextFactory()); - + super.initialize(componentConfiguration); } @@ -86,14 +84,4 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten } return strolchTx; } - - @Override - public OrderDao getOrderDao(StrolchTransaction tx) { - return new XmlOrderDao(tx); - } - - @Override - public ResourceDao getResourceDao(StrolchTransaction tx) { - return new XmlResourceDao(tx); - } } diff --git a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java index ab4562f5d..3a9864b83 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java @@ -18,6 +18,8 @@ package li.strolch.persistence.impl; import java.util.Set; import li.strolch.model.StrolchElement; +import li.strolch.persistence.api.OrderDao; +import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchPersistenceException; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.api.TransactionCloseStrategy; @@ -108,4 +110,14 @@ public class XmlStrolchTransaction implements StrolchTransaction { public boolean isOpen() { return this.tx.isOpen(); } + + @Override + public OrderDao getOrderDao() { + return new XmlOrderDao(this); + } + + @Override + public ResourceDao getResourceDao() { + return new XmlResourceDao(this); + } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 4681e75eb..fb8dc441b 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -82,13 +82,13 @@ public class ObserverUpdateTest extends AbstractDaoImplTest { // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getOrderDao(tx).save(newOrder); + tx.getOrderDao().save(newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getResourceDao(tx).save(newResource); + tx.getResourceDao().save(newResource); } assertEquals(2, observer.results.size()); diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index 2bab875c9..ea8990dbc 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -40,7 +40,7 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getOrderDao(tx).save(newOrder); + tx.getOrderDao().save(newOrder); } } @@ -50,13 +50,13 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { // create Order newOrder = createOrder(ID, NAME, TYPE); try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getOrderDao(tx).save(newOrder); + tx.getOrderDao().save(newOrder); } // read Order readOrder = null; try (StrolchTransaction tx = persistenceHandler.openTx();) { - readOrder = persistenceHandler.getOrderDao(tx).queryBy(TYPE, ID); + readOrder = tx.getOrderDao().queryBy(TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); //$NON-NLS-1$ @@ -65,13 +65,13 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getOrderDao(tx).update(readOrder); + tx.getOrderDao().update(readOrder); } // read updated Order updatedOrder = null; try (StrolchTransaction tx = persistenceHandler.openTx();) { - updatedOrder = persistenceHandler.getOrderDao(tx).queryBy(TYPE, ID); + updatedOrder = tx.getOrderDao().queryBy(TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); //$NON-NLS-1$ assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); //$NON-NLS-1$ @@ -80,12 +80,12 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { // delete try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getOrderDao(tx).remove(readOrder); + tx.getOrderDao().remove(readOrder); } // fail to re-read try (StrolchTransaction tx = persistenceHandler.openTx();) { - Order order = persistenceHandler.getOrderDao(tx).queryBy(TYPE, ID); + Order order = tx.getOrderDao().queryBy(TYPE, ID); assertNull("Should no read Order with id " + ID, order); //$NON-NLS-1$ } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index b4363c9be..2b6728011 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -40,7 +40,7 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getResourceDao(tx).save(newResource); + tx.getResourceDao().save(newResource); } } @@ -50,13 +50,13 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { // create Resource newResource = createResource(ID, NAME, TYPE); try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getResourceDao(tx).save(newResource); + tx.getResourceDao().save(newResource); } // read Resource readResource = null; try (StrolchTransaction tx = persistenceHandler.openTx();) { - readResource = persistenceHandler.getResourceDao(tx).queryBy(TYPE, ID); + readResource = tx.getResourceDao().queryBy(TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -65,13 +65,13 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getResourceDao(tx).update(readResource); + tx.getResourceDao().update(readResource); } // read updated Resource updatedResource = null; try (StrolchTransaction tx = persistenceHandler.openTx();) { - updatedResource = persistenceHandler.getResourceDao(tx).queryBy(TYPE, ID); + updatedResource = tx.getResourceDao().queryBy(TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ @@ -80,12 +80,12 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { // delete try (StrolchTransaction tx = persistenceHandler.openTx();) { - persistenceHandler.getResourceDao(tx).remove(readResource); + tx.getResourceDao().remove(readResource); } // fail to re-read try (StrolchTransaction tx = persistenceHandler.openTx();) { - Resource resource = persistenceHandler.getResourceDao(tx).queryBy(TYPE, ID); + Resource resource = tx.getResourceDao().queryBy(TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } } From 38d1cf61ddf267dc07b00e69d198bca9c6ddc883 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 01:48:09 +0100 Subject: [PATCH 21/59] [New] Added Unit tests to test the bulk operations --- .../impl/dao/test/XmlContainerTest.java | 33 +++++++++ .../impl/dao/test/XmlOrderDaoTest.java | 74 +++++++++++++++++++ .../impl/dao/test/XmlResourceDaoTest.java | 74 +++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java new file mode 100644 index 000000000..fd7e2b9df --- /dev/null +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.persistence.impl.dao.test; + +import li.strolch.persistence.api.StrolchTransaction; + +import org.junit.Test; + +/** + * @author Robert von Burg + */ +public class XmlContainerTest extends AbstractDaoImplTest { + + @Test + public void shouldStartContainer() { + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + tx.getOrderDao().queryKeySet(); + } + } +} diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index ea8990dbc..a91cd7607 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -18,12 +18,22 @@ package li.strolch.persistence.impl.dao.test; import static li.strolch.model.ModelGenerator.BAG_ID; import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; import static li.strolch.model.ModelGenerator.createOrder; +import static li.strolch.model.ModelGenerator.createOrders; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import li.strolch.model.Order; import li.strolch.model.parameter.Parameter; +import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.StrolchTransaction; import org.junit.Test; @@ -89,4 +99,68 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { assertNull("Should no read Order with id " + ID, order); //$NON-NLS-1$ } } + + @SuppressWarnings("nls") + @Test + public void shouldPerformBulkOperations() { + + List orders = new ArrayList<>(); + orders.addAll(createOrders(orders.size(), 5, "@", "My Order ", "MyType1")); + orders.addAll(createOrders(orders.size(), 5, "@", "Other Order ", "MyType2")); + orders.addAll(createOrders(orders.size(), 5, "@", "Further Order ", "MyType3")); + + Comparator comparator = new Comparator() { + @Override + public int compare(Order o1, Order o2) { + return o1.getId().compareTo(o2.getId()); + } + }; + Collections.sort(orders, comparator); + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + tx.getOrderDao().removeAll(tx.getOrderDao().queryAll()); + } + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + tx.getOrderDao().saveAll(orders); + } + + Set expectedTypes = new HashSet<>(); + expectedTypes.add("MyType1"); + expectedTypes.add("MyType2"); + expectedTypes.add("MyType3"); + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + List allOrders = tx.getOrderDao().queryAll(); + Collections.sort(allOrders, comparator); + assertEquals(orders, allOrders); + } + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + OrderDao orderDao = tx.getOrderDao(); + + Set types = orderDao.queryTypes(); + assertEquals(expectedTypes, types); + + Set keySet = orderDao.queryKeySet(); + assertEquals(15, keySet.size()); + + for (String type : types) { + Set idsByType = orderDao.queryKeySet(type); + assertEquals(5, idsByType.size()); + + List ordersByType = orderDao.queryAll(type); + assertEquals(5, ordersByType.size()); + } + } + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + Order order = tx.getOrderDao().queryBy("MyType1", "@_1"); + assertNotNull(order); + order = tx.getOrderDao().queryBy("MyType2", "@_6"); + assertNotNull(order); + order = tx.getOrderDao().queryBy("MyType3", "@_11"); + assertNotNull(order); + } + } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index 2b6728011..192f30174 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -18,12 +18,22 @@ package li.strolch.persistence.impl.dao.test; import static li.strolch.model.ModelGenerator.BAG_ID; import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; import static li.strolch.model.ModelGenerator.createResource; +import static li.strolch.model.ModelGenerator.createResources; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import li.strolch.model.Resource; import li.strolch.model.parameter.Parameter; +import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; import org.junit.Test; @@ -89,4 +99,68 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } } + + @SuppressWarnings("nls") + @Test + public void shouldPerformBulkOperations() { + + List resources = new ArrayList<>(); + resources.addAll(createResources(resources.size(), 5, "@", "My Resource ", "MyType1")); + resources.addAll(createResources(resources.size(), 5, "@", "Other Resource ", "MyType2")); + resources.addAll(createResources(resources.size(), 5, "@", "Further Resource ", "MyType3")); + + Comparator comparator = new Comparator() { + @Override + public int compare(Resource o1, Resource o2) { + return o1.getId().compareTo(o2.getId()); + } + }; + Collections.sort(resources, comparator); + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + tx.getResourceDao().removeAll(tx.getResourceDao().queryAll()); + } + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + tx.getResourceDao().saveAll(resources); + } + + Set expectedTypes = new HashSet<>(); + expectedTypes.add("MyType1"); + expectedTypes.add("MyType2"); + expectedTypes.add("MyType3"); + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + List allResources = tx.getResourceDao().queryAll(); + Collections.sort(allResources, comparator); + assertEquals(resources, allResources); + } + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + ResourceDao resourceDao = tx.getResourceDao(); + + Set types = resourceDao.queryTypes(); + assertEquals(expectedTypes, types); + + Set keySet = resourceDao.queryKeySet(); + assertEquals(15, keySet.size()); + + for (String type : types) { + Set idsByType = resourceDao.queryKeySet(type); + assertEquals(5, idsByType.size()); + + List resourcesByType = resourceDao.queryAll(type); + assertEquals(5, resourcesByType.size()); + } + } + + try (StrolchTransaction tx = persistenceHandler.openTx()) { + Resource resource = tx.getResourceDao().queryBy("MyType1", "@_1"); + assertNotNull(resource); + resource = tx.getResourceDao().queryBy("MyType2", "@_6"); + assertNotNull(resource); + resource = tx.getResourceDao().queryBy("MyType3", "@_11"); + assertNotNull(resource); + } + } } From 76d8d24ebdb2f52b87124b1931a7d2de2127f569 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 02:12:38 +0100 Subject: [PATCH 22/59] [New] Added Unit tests to test the bulk operations --- .../impl/dao/test/AbstractDaoImplTest.java | 7 ++--- .../impl/dao/test/XmlContainerTest.java | 30 +++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index d85e35a03..148065bc6 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -25,13 +25,12 @@ import org.junit.BeforeClass; /** * @author Robert von Burg - * */ public abstract class AbstractDaoImplTest extends RuntimeMock { - private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ - private static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ - private static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ + public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ + public static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ protected static PersistenceHandler persistenceHandler; @BeforeClass diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java index fd7e2b9df..51febda34 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java @@ -15,14 +15,40 @@ */ package li.strolch.persistence.impl.dao.test; -import li.strolch.persistence.api.StrolchTransaction; +import java.io.File; +import li.strolch.persistence.api.PersistenceHandler; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.testbase.runtime.RuntimeMock; + +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** * @author Robert von Burg */ -public class XmlContainerTest extends AbstractDaoImplTest { +public class XmlContainerTest extends RuntimeMock { + + protected static PersistenceHandler persistenceHandler; + + @BeforeClass + public static void beforeClass() { + + File rootPath = new File(AbstractDaoImplTest.RUNTIME_PATH); + File configSrc = new File(AbstractDaoImplTest.CONFIG_SRC); + RuntimeMock.mockRuntime(rootPath, configSrc); + new File(rootPath, AbstractDaoImplTest.DB_STORE_PATH_DIR).mkdir(); + RuntimeMock.startContainer(rootPath); + + // initialize the component configuration + persistenceHandler = getContainer().getComponent(PersistenceHandler.class); + } + + @AfterClass + public static void afterClass() { + RuntimeMock.destroyRuntime(); + } @Test public void shouldStartContainer() { From 5f3b584c3027b8446513c2cccebee994087cf159 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 02:43:55 +0100 Subject: [PATCH 23/59] [Minor] set artifact name to artifactId for easier reading of build log --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bbbe54f35..b03ea24a1 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ li.strolch.persistence.xml - Reference Persistence Implementation for Strolch + li.strolch.persistence.xml Reference Persistence Implementation for Strolch https://github.com/eitch/li.strolch.persistence.xml From ddc91c75f96006583e90ac0f38c9918433dae918 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 02:47:01 +0100 Subject: [PATCH 24/59] [New] methods to generate bulk objects now pad the id This allows for easier lexical sorting --- .../strolch/persistence/impl/dao/test/XmlOrderDaoTest.java | 6 +++--- .../persistence/impl/dao/test/XmlResourceDaoTest.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index a91cd7607..03daaa437 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -155,11 +155,11 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { } try (StrolchTransaction tx = persistenceHandler.openTx()) { - Order order = tx.getOrderDao().queryBy("MyType1", "@_1"); + Order order = tx.getOrderDao().queryBy("MyType1", "@_00000001"); assertNotNull(order); - order = tx.getOrderDao().queryBy("MyType2", "@_6"); + order = tx.getOrderDao().queryBy("MyType2", "@_00000006"); assertNotNull(order); - order = tx.getOrderDao().queryBy("MyType3", "@_11"); + order = tx.getOrderDao().queryBy("MyType3", "@_00000011"); assertNotNull(order); } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index 192f30174..356cd48be 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -155,11 +155,11 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { } try (StrolchTransaction tx = persistenceHandler.openTx()) { - Resource resource = tx.getResourceDao().queryBy("MyType1", "@_1"); + Resource resource = tx.getResourceDao().queryBy("MyType1", "@_00000001"); assertNotNull(resource); - resource = tx.getResourceDao().queryBy("MyType2", "@_6"); + resource = tx.getResourceDao().queryBy("MyType2", "@_00000006"); assertNotNull(resource); - resource = tx.getResourceDao().queryBy("MyType3", "@_11"); + resource = tx.getResourceDao().queryBy("MyType3", "@_00000011"); assertNotNull(resource); } } From d4aa1d96750a036f8f293ab38e6de33de3e485be Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 11:56:13 +0100 Subject: [PATCH 25/59] [Minor] fixed issue where eclipse couldn't validate log4j.xml --- src/test/resources/log4j.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml index a35a3c351..0a2a73d06 100644 --- a/src/test/resources/log4j.xml +++ b/src/test/resources/log4j.xml @@ -1,5 +1,6 @@ - + From 0a4fe91230eb4749def7ea5b607dcdeb26072031 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 17:02:23 +0100 Subject: [PATCH 26/59] [Minor] refactored tests for persistence layers to remove duplicate code --- .../impl/dao/test/AbstractDaoImplTest.java | 18 +-- .../impl/dao/test/ObserverUpdateTest.java | 8 +- .../impl/dao/test/XmlContainerTest.java | 17 +-- .../impl/dao/test/XmlOrderDaoTest.java | 136 +---------------- .../impl/dao/test/XmlResourceDaoTest.java | 138 +----------------- .../config/StrolchConfiguration.xml | 0 .../config/StrolchConfiguration.xml | 23 +++ 7 files changed, 57 insertions(+), 283 deletions(-) rename src/test/resources/{runtime => cachedruntime}/config/StrolchConfiguration.xml (100%) create mode 100644 src/test/resources/transactionalruntime/config/StrolchConfiguration.xml diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index 148065bc6..ecbf17a34 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -17,7 +17,6 @@ package li.strolch.persistence.impl.dao.test; import java.io.File; -import li.strolch.persistence.api.PersistenceHandler; import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; @@ -26,28 +25,27 @@ import org.junit.BeforeClass; /** * @author Robert von Burg */ -public abstract class AbstractDaoImplTest extends RuntimeMock { +public abstract class AbstractDaoImplTest { public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ - public static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ - protected static PersistenceHandler persistenceHandler; + public static final String CONFIG_SRC = "src/test/resources/cachedruntime/config"; //$NON-NLS-1$ + + protected static RuntimeMock runtimeMock; @BeforeClass public static void beforeClass() { File rootPath = new File(RUNTIME_PATH); File configSrc = new File(CONFIG_SRC); - RuntimeMock.mockRuntime(rootPath, configSrc); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); new File(rootPath, DB_STORE_PATH_DIR).mkdir(); - RuntimeMock.startContainer(rootPath); - - // initialize the component configuration - persistenceHandler = getContainer().getComponent(PersistenceHandler.class); + runtimeMock.startContainer(rootPath); } @AfterClass public static void afterClass() { - RuntimeMock.destroyRuntime(); + runtimeMock.destroyRuntime(); } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index fb8dc441b..9bc6e3298 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -76,18 +76,18 @@ public class ObserverUpdateTest extends AbstractDaoImplTest { // register an observer for orders and resources ElementAddedObserver observer = new ElementAddedObserver(); - getContainer().getComponent(ObserverHandler.class).registerObserver("Order", observer); //$NON-NLS-1$ - getContainer().getComponent(ObserverHandler.class).registerObserver("Resource", observer); //$NON-NLS-1$ + runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver("Order", observer); //$NON-NLS-1$ + runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver("Resource", observer); //$NON-NLS-1$ // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = persistenceHandler.openTx();) { + try (StrolchTransaction tx = runtimeMock.getPersistenceHandler().openTx()) { tx.getOrderDao().save(newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = persistenceHandler.openTx();) { + try (StrolchTransaction tx = runtimeMock.getPersistenceHandler().openTx()) { tx.getResourceDao().save(newResource); } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java index 51febda34..dfd82ad7c 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java @@ -17,7 +17,6 @@ package li.strolch.persistence.impl.dao.test; import java.io.File; -import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.testbase.runtime.RuntimeMock; @@ -28,31 +27,29 @@ import org.junit.Test; /** * @author Robert von Burg */ -public class XmlContainerTest extends RuntimeMock { +public class XmlContainerTest { - protected static PersistenceHandler persistenceHandler; + protected static RuntimeMock runtimeMock; @BeforeClass public static void beforeClass() { File rootPath = new File(AbstractDaoImplTest.RUNTIME_PATH); File configSrc = new File(AbstractDaoImplTest.CONFIG_SRC); - RuntimeMock.mockRuntime(rootPath, configSrc); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); new File(rootPath, AbstractDaoImplTest.DB_STORE_PATH_DIR).mkdir(); - RuntimeMock.startContainer(rootPath); - - // initialize the component configuration - persistenceHandler = getContainer().getComponent(PersistenceHandler.class); + runtimeMock.startContainer(rootPath); } @AfterClass public static void afterClass() { - RuntimeMock.destroyRuntime(); + runtimeMock.destroyRuntime(); } @Test public void shouldStartContainer() { - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = runtimeMock.getPersistenceHandler().openTx()) { tx.getOrderDao().queryKeySet(); } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index 03daaa437..89dc1b1f5 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -15,152 +15,30 @@ */ package li.strolch.persistence.impl.dao.test; -import static li.strolch.model.ModelGenerator.BAG_ID; -import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; -import static li.strolch.model.ModelGenerator.createOrder; -import static li.strolch.model.ModelGenerator.createOrders; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import li.strolch.model.Order; -import li.strolch.model.parameter.Parameter; -import li.strolch.persistence.api.OrderDao; -import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.testbase.runtime.OrderModelTestRunner; import org.junit.Test; public class XmlOrderDaoTest extends AbstractDaoImplTest { - private static final String ID = "@testOrder"; //$NON-NLS-1$ - private static final String NAME = "Test Order"; //$NON-NLS-1$ - private static final String TYPE = "ToStock"; //$NON-NLS-1$ - @Test public void shouldCreateOrder() { - // create - Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getOrderDao().save(newOrder); - } + OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock); + testRunner.runCreateOrderTest(); } @Test public void shouldCrud() { - // create - Order newOrder = createOrder(ID, NAME, TYPE); - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getOrderDao().save(newOrder); - } - - // read - Order readOrder = null; - try (StrolchTransaction tx = persistenceHandler.openTx();) { - readOrder = tx.getOrderDao().queryBy(TYPE, ID); - } - assertNotNull("Should read Order with id " + ID, readOrder); //$NON-NLS-1$ - - // update - Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); - String newStringValue = "Giddiya!"; //$NON-NLS-1$ - sParam.setValue(newStringValue); - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getOrderDao().update(readOrder); - } - - // read updated - Order updatedOrder = null; - try (StrolchTransaction tx = persistenceHandler.openTx();) { - updatedOrder = tx.getOrderDao().queryBy(TYPE, ID); - } - assertNotNull("Should read Order with id " + ID, updatedOrder); //$NON-NLS-1$ - assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); //$NON-NLS-1$ - Parameter updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); - assertEquals(newStringValue, updatedParam.getValue()); - - // delete - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getOrderDao().remove(readOrder); - } - - // fail to re-read - try (StrolchTransaction tx = persistenceHandler.openTx();) { - Order order = tx.getOrderDao().queryBy(TYPE, ID); - assertNull("Should no read Order with id " + ID, order); //$NON-NLS-1$ - } + OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock); + testRunner.runCrudTests(); } - @SuppressWarnings("nls") @Test public void shouldPerformBulkOperations() { - List orders = new ArrayList<>(); - orders.addAll(createOrders(orders.size(), 5, "@", "My Order ", "MyType1")); - orders.addAll(createOrders(orders.size(), 5, "@", "Other Order ", "MyType2")); - orders.addAll(createOrders(orders.size(), 5, "@", "Further Order ", "MyType3")); - - Comparator comparator = new Comparator() { - @Override - public int compare(Order o1, Order o2) { - return o1.getId().compareTo(o2.getId()); - } - }; - Collections.sort(orders, comparator); - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - tx.getOrderDao().removeAll(tx.getOrderDao().queryAll()); - } - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - tx.getOrderDao().saveAll(orders); - } - - Set expectedTypes = new HashSet<>(); - expectedTypes.add("MyType1"); - expectedTypes.add("MyType2"); - expectedTypes.add("MyType3"); - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - List allOrders = tx.getOrderDao().queryAll(); - Collections.sort(allOrders, comparator); - assertEquals(orders, allOrders); - } - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - OrderDao orderDao = tx.getOrderDao(); - - Set types = orderDao.queryTypes(); - assertEquals(expectedTypes, types); - - Set keySet = orderDao.queryKeySet(); - assertEquals(15, keySet.size()); - - for (String type : types) { - Set idsByType = orderDao.queryKeySet(type); - assertEquals(5, idsByType.size()); - - List ordersByType = orderDao.queryAll(type); - assertEquals(5, ordersByType.size()); - } - } - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - Order order = tx.getOrderDao().queryBy("MyType1", "@_00000001"); - assertNotNull(order); - order = tx.getOrderDao().queryBy("MyType2", "@_00000006"); - assertNotNull(order); - order = tx.getOrderDao().queryBy("MyType3", "@_00000011"); - assertNotNull(order); - } + OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock); + testRunner.runBulkOperationTests(); } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index 356cd48be..430556463 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -15,152 +15,30 @@ */ package li.strolch.persistence.impl.dao.test; -import static li.strolch.model.ModelGenerator.BAG_ID; -import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; -import static li.strolch.model.ModelGenerator.createResource; -import static li.strolch.model.ModelGenerator.createResources; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import li.strolch.model.Resource; -import li.strolch.model.parameter.Parameter; -import li.strolch.persistence.api.ResourceDao; -import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.testbase.runtime.ResourceModelTestRunner; import org.junit.Test; public class XmlResourceDaoTest extends AbstractDaoImplTest { - private static final String ID = "@testResource"; //$NON-NLS-1$ - private static final String NAME = "Test Resource"; //$NON-NLS-1$ - private static final String TYPE = "Box"; //$NON-NLS-1$ - @Test - public void shouldCreateResource() { + public void shouldCreateOrder() { - // create - Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getResourceDao().save(newResource); - } + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock); + testRunner.runCreateResourceTest(); } @Test public void shouldCrud() { - // create - Resource newResource = createResource(ID, NAME, TYPE); - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getResourceDao().save(newResource); - } - - // read - Resource readResource = null; - try (StrolchTransaction tx = persistenceHandler.openTx();) { - readResource = tx.getResourceDao().queryBy(TYPE, ID); - } - assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ - - // update - Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); - String newStringValue = "Giddiya!"; //$NON-NLS-1$ - sParam.setValue(newStringValue); - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getResourceDao().update(readResource); - } - - // read updated - Resource updatedResource = null; - try (StrolchTransaction tx = persistenceHandler.openTx();) { - updatedResource = tx.getResourceDao().queryBy(TYPE, ID); - } - assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ - assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ - Parameter updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); - assertEquals(newStringValue, updatedParam.getValue()); - - // delete - try (StrolchTransaction tx = persistenceHandler.openTx();) { - tx.getResourceDao().remove(readResource); - } - - // fail to re-read - try (StrolchTransaction tx = persistenceHandler.openTx();) { - Resource resource = tx.getResourceDao().queryBy(TYPE, ID); - assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ - } + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock); + testRunner.runCrudTests(); } - @SuppressWarnings("nls") @Test public void shouldPerformBulkOperations() { - List resources = new ArrayList<>(); - resources.addAll(createResources(resources.size(), 5, "@", "My Resource ", "MyType1")); - resources.addAll(createResources(resources.size(), 5, "@", "Other Resource ", "MyType2")); - resources.addAll(createResources(resources.size(), 5, "@", "Further Resource ", "MyType3")); - - Comparator comparator = new Comparator() { - @Override - public int compare(Resource o1, Resource o2) { - return o1.getId().compareTo(o2.getId()); - } - }; - Collections.sort(resources, comparator); - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - tx.getResourceDao().removeAll(tx.getResourceDao().queryAll()); - } - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - tx.getResourceDao().saveAll(resources); - } - - Set expectedTypes = new HashSet<>(); - expectedTypes.add("MyType1"); - expectedTypes.add("MyType2"); - expectedTypes.add("MyType3"); - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - List allResources = tx.getResourceDao().queryAll(); - Collections.sort(allResources, comparator); - assertEquals(resources, allResources); - } - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - ResourceDao resourceDao = tx.getResourceDao(); - - Set types = resourceDao.queryTypes(); - assertEquals(expectedTypes, types); - - Set keySet = resourceDao.queryKeySet(); - assertEquals(15, keySet.size()); - - for (String type : types) { - Set idsByType = resourceDao.queryKeySet(type); - assertEquals(5, idsByType.size()); - - List resourcesByType = resourceDao.queryAll(type); - assertEquals(5, resourcesByType.size()); - } - } - - try (StrolchTransaction tx = persistenceHandler.openTx()) { - Resource resource = tx.getResourceDao().queryBy("MyType1", "@_00000001"); - assertNotNull(resource); - resource = tx.getResourceDao().queryBy("MyType2", "@_00000006"); - assertNotNull(resource); - resource = tx.getResourceDao().queryBy("MyType3", "@_00000011"); - assertNotNull(resource); - } + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock); + testRunner.runBulkOperationTests(); } } diff --git a/src/test/resources/runtime/config/StrolchConfiguration.xml b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml similarity index 100% rename from src/test/resources/runtime/config/StrolchConfiguration.xml rename to src/test/resources/cachedruntime/config/StrolchConfiguration.xml diff --git a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml new file mode 100644 index 000000000..51b6d9794 --- /dev/null +++ b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml @@ -0,0 +1,23 @@ + + + + StrolchPersistenceTest + + TRANSACTIONAL + true + + + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.impl.XmlPersistenceHandler + + true + + + + ObserverHandler + li.strolch.runtime.observer.ObserverHandler + li.strolch.runtime.observer.DefaultObserverHandler + + \ No newline at end of file From f5f1d85edb2f9040855a3bd1b353c76c0303ed3c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 17:33:59 +0100 Subject: [PATCH 27/59] [Minor] refactored tests for persistence layers to remove duplicate code --- .../impl/dao/test/ObserverUpdateTest.java | 33 ++++++++++- ...DaoImplTest.java => XmlCachedDaoTest.java} | 11 ++-- .../impl/dao/test/XmlContainerTest.java | 56 ------------------- .../impl/dao/test/XmlOrderDaoTest.java | 44 --------------- .../impl/dao/test/XmlResourceDaoTest.java | 44 --------------- 5 files changed, 38 insertions(+), 150 deletions(-) rename src/test/java/li/strolch/persistence/impl/dao/test/{AbstractDaoImplTest.java => XmlCachedDaoTest.java} (88%) delete mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java delete mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java delete mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 9bc6e3298..08a6bde32 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -19,6 +19,7 @@ import static li.strolch.model.ModelGenerator.createOrder; import static li.strolch.model.ModelGenerator.createResource; import static org.junit.Assert.assertEquals; +import java.io.File; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -31,16 +32,44 @@ import li.strolch.model.StrolchElement; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.observer.Observer; import li.strolch.runtime.observer.ObserverHandler; +import li.strolch.testbase.runtime.RuntimeMock; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import ch.eitchnet.xmlpers.api.ModificationResult; /** * @author Robert von Burg - * */ -public class ObserverUpdateTest extends AbstractDaoImplTest { +public class ObserverUpdateTest { + + public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ + public static final String CONFIG_SRC = "src/test/resources/cachedruntime/config"; //$NON-NLS-1$ + + protected static RuntimeMock runtimeMock; + + protected RuntimeMock getRuntimeMock() { + return runtimeMock; + } + + @BeforeClass + public static void beforeClass() { + + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); + new File(rootPath, DB_STORE_PATH_DIR).mkdir(); + runtimeMock.startContainer(rootPath); + } + + @AfterClass + public static void afterClass() { + runtimeMock.destroyRuntime(); + } public final class ElementAddedObserver implements Observer { diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java similarity index 88% rename from src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java rename to src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java index ecbf17a34..bcafb1a50 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java @@ -17,15 +17,13 @@ package li.strolch.persistence.impl.dao.test; import java.io.File; +import li.strolch.testbase.runtime.AbstractModelTest; import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; import org.junit.BeforeClass; -/** - * @author Robert von Burg - */ -public abstract class AbstractDaoImplTest { +public class XmlCachedDaoTest extends AbstractModelTest { public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ @@ -33,6 +31,11 @@ public abstract class AbstractDaoImplTest { protected static RuntimeMock runtimeMock; + @Override + protected RuntimeMock getRuntimeMock() { + return runtimeMock; + } + @BeforeClass public static void beforeClass() { diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java deleted file mode 100644 index dfd82ad7c..000000000 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlContainerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2013 Robert von Burg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package li.strolch.persistence.impl.dao.test; - -import java.io.File; - -import li.strolch.persistence.api.StrolchTransaction; -import li.strolch.testbase.runtime.RuntimeMock; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author Robert von Burg - */ -public class XmlContainerTest { - - protected static RuntimeMock runtimeMock; - - @BeforeClass - public static void beforeClass() { - - File rootPath = new File(AbstractDaoImplTest.RUNTIME_PATH); - File configSrc = new File(AbstractDaoImplTest.CONFIG_SRC); - runtimeMock = new RuntimeMock(); - runtimeMock.mockRuntime(rootPath, configSrc); - new File(rootPath, AbstractDaoImplTest.DB_STORE_PATH_DIR).mkdir(); - runtimeMock.startContainer(rootPath); - } - - @AfterClass - public static void afterClass() { - runtimeMock.destroyRuntime(); - } - - @Test - public void shouldStartContainer() { - try (StrolchTransaction tx = runtimeMock.getPersistenceHandler().openTx()) { - tx.getOrderDao().queryKeySet(); - } - } -} diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java deleted file mode 100644 index 89dc1b1f5..000000000 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013 Robert von Burg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package li.strolch.persistence.impl.dao.test; - -import li.strolch.testbase.runtime.OrderModelTestRunner; - -import org.junit.Test; - -public class XmlOrderDaoTest extends AbstractDaoImplTest { - - @Test - public void shouldCreateOrder() { - - OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock); - testRunner.runCreateOrderTest(); - } - - @Test - public void shouldCrud() { - - OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock); - testRunner.runCrudTests(); - } - - @Test - public void shouldPerformBulkOperations() { - - OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock); - testRunner.runBulkOperationTests(); - } -} diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java deleted file mode 100644 index 430556463..000000000 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2013 Robert von Burg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package li.strolch.persistence.impl.dao.test; - -import li.strolch.testbase.runtime.ResourceModelTestRunner; - -import org.junit.Test; - -public class XmlResourceDaoTest extends AbstractDaoImplTest { - - @Test - public void shouldCreateOrder() { - - ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock); - testRunner.runCreateResourceTest(); - } - - @Test - public void shouldCrud() { - - ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock); - testRunner.runCrudTests(); - } - - @Test - public void shouldPerformBulkOperations() { - - ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock); - testRunner.runBulkOperationTests(); - } -} From b66c0876c5481d663458b9b993eca4c2165c0aae Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 19:04:58 +0100 Subject: [PATCH 28/59] [Major] RuntimeMock now also copies data --- .../impl/dao/test/ObserverUpdateTest.java | 4 +- .../impl/dao/test/XmlCachedDaoTest.java | 4 +- .../dao/test/XmlTransactionalDaoTest.java | 54 +++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 08a6bde32..61424c725 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -45,9 +45,9 @@ import ch.eitchnet.xmlpers.api.ModificationResult; */ public class ObserverUpdateTest { - public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + public static final String RUNTIME_PATH = "target/observerUpdateStrolchRuntime/"; //$NON-NLS-1$ public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ - public static final String CONFIG_SRC = "src/test/resources/cachedruntime/config"; //$NON-NLS-1$ + public static final String CONFIG_SRC = "src/test/resources/cachedruntime"; //$NON-NLS-1$ protected static RuntimeMock runtimeMock; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java index bcafb1a50..3a203102e 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java @@ -25,9 +25,9 @@ import org.junit.BeforeClass; public class XmlCachedDaoTest extends AbstractModelTest { - public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + public static final String RUNTIME_PATH = "target/cachedStrolchRuntime/"; //$NON-NLS-1$ public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ - public static final String CONFIG_SRC = "src/test/resources/cachedruntime/config"; //$NON-NLS-1$ + public static final String CONFIG_SRC = "src/test/resources/cachedruntime"; //$NON-NLS-1$ protected static RuntimeMock runtimeMock; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java new file mode 100644 index 000000000..5fc5442b4 --- /dev/null +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.persistence.impl.dao.test; + +import java.io.File; + +import li.strolch.testbase.runtime.AbstractModelTest; +import li.strolch.testbase.runtime.RuntimeMock; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +public class XmlTransactionalDaoTest extends AbstractModelTest { + + public static final String RUNTIME_PATH = "target/transactionalStrolchRuntime/"; //$NON-NLS-1$ + public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ + public static final String CONFIG_SRC = "src/test/resources/transactionalruntime"; //$NON-NLS-1$ + + protected static RuntimeMock runtimeMock; + + @Override + protected RuntimeMock getRuntimeMock() { + return runtimeMock; + } + + @BeforeClass + public static void beforeClass() { + + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); + new File(rootPath, DB_STORE_PATH_DIR).mkdir(); + runtimeMock.startContainer(rootPath); + } + + @AfterClass + public static void afterClass() { + runtimeMock.destroyRuntime(); + } +} From dce500bcedec925e723587b5102447e6b2747df6 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 22:30:56 +0100 Subject: [PATCH 29/59] [Minor] reorganized classes for Agent into api and impl packages --- .../li/strolch/persistence/impl/XmlPersistenceHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java index 174482389..c9a86560c 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java @@ -26,8 +26,8 @@ import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.impl.model.OrderContextFactory; import li.strolch.persistence.impl.model.ResourceContextFactory; import li.strolch.runtime.StrolchConstants; -import li.strolch.runtime.agent.ComponentContainerImpl; -import li.strolch.runtime.agent.StrolchComponent; +import li.strolch.runtime.agent.api.StrolchComponent; +import li.strolch.runtime.agent.impl.ComponentContainerImpl; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.IoMode; From 2bfeb2ff999a1e84f79ef7a52cb6b3638f298a3a Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 26 Dec 2013 00:05:09 +0100 Subject: [PATCH 30/59] [Major] TXs are opened from ElementMap and all methods need a TX now --- .../strolch/persistence/impl/dao/test/ObserverUpdateTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 61424c725..95cb81ee0 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -110,13 +110,13 @@ public class ObserverUpdateTest { // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = runtimeMock.getOrderMap().openTx()) { tx.getOrderDao().save(newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = runtimeMock.getResourceMap().openTx()) { tx.getResourceDao().save(newResource); } From 3fb804178b476753aad063d0a477e37b32541f66 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 26 Dec 2013 01:12:54 +0100 Subject: [PATCH 31/59] [New] Added doQuery() methods to DAOs and hooked up InMemory querying --- .../java/li/strolch/persistence/impl/XmlOrderDao.java | 9 +++++++++ .../java/li/strolch/persistence/impl/XmlResourceDao.java | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java index a552a41c4..4e0314fac 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java +++ b/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java @@ -15,8 +15,11 @@ */ package li.strolch.persistence.impl; +import java.util.List; + import li.strolch.model.Order; import li.strolch.model.Tags; +import li.strolch.model.query.OrderQuery; import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.StrolchTransaction; @@ -30,4 +33,10 @@ public class XmlOrderDao extends AbstractDao implements OrderDao { protected String getClassType() { return Tags.ORDER; } + + @Override + public List doQuery(OrderQuery query) { + // TODO Auto-generated method stub + return null; + } } diff --git a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java index aba0d8d0a..e7153c36f 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java +++ b/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java @@ -15,8 +15,11 @@ */ package li.strolch.persistence.impl; +import java.util.List; + import li.strolch.model.Resource; import li.strolch.model.Tags; +import li.strolch.model.query.ResourceQuery; import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; @@ -30,4 +33,10 @@ public class XmlResourceDao extends AbstractDao implements ResourceDao protected String getClassType() { return Tags.RESOURCE; } + + @Override + public List doQuery(ResourceQuery query) { + // TODO Auto-generated method stub + return null; + } } From 407ce80eecb07e12d06ce62cc727d3fea11512e3 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 26 Dec 2013 18:07:43 +0100 Subject: [PATCH 32/59] [Project] renamed package li.strolch.persistence.impl to .xml --- .../li/strolch/persistence/{impl => xml}/AbstractDao.java | 2 +- .../li/strolch/persistence/{impl => xml}/XmlOrderDao.java | 2 +- .../persistence/{impl => xml}/XmlPersistenceHandler.java | 6 +++--- .../strolch/persistence/{impl => xml}/XmlResourceDao.java | 2 +- .../persistence/{impl => xml}/XmlStrolchTransaction.java | 2 +- .../{impl => xml}/model/OrderContextFactory.java | 2 +- .../persistence/{impl => xml}/model/OrderDomParser.java | 2 +- .../persistence/{impl => xml}/model/OrderParserFactory.java | 2 +- .../{impl => xml}/model/ResourceContextFactory.java | 2 +- .../persistence/{impl => xml}/model/ResourceDomParser.java | 2 +- .../{impl => xml}/model/ResourceParserFactory.java | 2 +- .../resources/cachedruntime/config/StrolchConfiguration.xml | 2 +- .../transactionalruntime/config/StrolchConfiguration.xml | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) rename src/main/java/li/strolch/persistence/{impl => xml}/AbstractDao.java (98%) rename src/main/java/li/strolch/persistence/{impl => xml}/XmlOrderDao.java (96%) rename src/main/java/li/strolch/persistence/{impl => xml}/XmlPersistenceHandler.java (95%) rename src/main/java/li/strolch/persistence/{impl => xml}/XmlResourceDao.java (97%) rename src/main/java/li/strolch/persistence/{impl => xml}/XmlStrolchTransaction.java (98%) rename src/main/java/li/strolch/persistence/{impl => xml}/model/OrderContextFactory.java (97%) rename src/main/java/li/strolch/persistence/{impl => xml}/model/OrderDomParser.java (96%) rename src/main/java/li/strolch/persistence/{impl => xml}/model/OrderParserFactory.java (96%) rename src/main/java/li/strolch/persistence/{impl => xml}/model/ResourceContextFactory.java (97%) rename src/main/java/li/strolch/persistence/{impl => xml}/model/ResourceDomParser.java (97%) rename src/main/java/li/strolch/persistence/{impl => xml}/model/ResourceParserFactory.java (96%) diff --git a/src/main/java/li/strolch/persistence/impl/AbstractDao.java b/src/main/java/li/strolch/persistence/xml/AbstractDao.java similarity index 98% rename from src/main/java/li/strolch/persistence/impl/AbstractDao.java rename to src/main/java/li/strolch/persistence/xml/AbstractDao.java index 60a6e0e47..dd14a0632 100644 --- a/src/main/java/li/strolch/persistence/impl/AbstractDao.java +++ b/src/main/java/li/strolch/persistence/xml/AbstractDao.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl; +package li.strolch.persistence.xml; import java.util.ArrayList; import java.util.HashSet; diff --git a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java b/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java similarity index 96% rename from src/main/java/li/strolch/persistence/impl/XmlOrderDao.java rename to src/main/java/li/strolch/persistence/xml/XmlOrderDao.java index 4e0314fac..c44934980 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlOrderDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl; +package li.strolch.persistence.xml; import java.util.List; diff --git a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java similarity index 95% rename from src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java rename to src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index c9a86560c..e3ee1dba3 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl; +package li.strolch.persistence.xml; import java.io.File; import java.util.Properties; @@ -23,8 +23,8 @@ import li.strolch.model.Resource; import li.strolch.model.Tags; import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; -import li.strolch.persistence.impl.model.OrderContextFactory; -import li.strolch.persistence.impl.model.ResourceContextFactory; +import li.strolch.persistence.xml.model.OrderContextFactory; +import li.strolch.persistence.xml.model.ResourceContextFactory; import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.agent.api.StrolchComponent; import li.strolch.runtime.agent.impl.ComponentContainerImpl; diff --git a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java b/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java similarity index 97% rename from src/main/java/li/strolch/persistence/impl/XmlResourceDao.java rename to src/main/java/li/strolch/persistence/xml/XmlResourceDao.java index e7153c36f..8ee45d5dc 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlResourceDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl; +package li.strolch.persistence.xml; import java.util.List; diff --git a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java similarity index 98% rename from src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java rename to src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index 3a9864b83..a73955571 100644 --- a/src/main/java/li/strolch/persistence/impl/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl; +package li.strolch.persistence.xml; import java.util.Set; diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java b/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java similarity index 97% rename from src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java rename to src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java index eb4007d6e..73406915f 100644 --- a/src/main/java/li/strolch/persistence/impl/model/OrderContextFactory.java +++ b/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl.model; +package li.strolch.persistence.xml.model; import li.strolch.model.Order; import li.strolch.model.Tags; diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java b/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java similarity index 96% rename from src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java rename to src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java index 45cf30440..df761a362 100644 --- a/src/main/java/li/strolch/persistence/impl/model/OrderDomParser.java +++ b/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl.model; +package li.strolch.persistence.xml.model; import li.strolch.model.Order; import li.strolch.model.xml.OrderToDomVisitor; diff --git a/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java b/src/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java similarity index 96% rename from src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java rename to src/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java index 029d2da90..e7e38543c 100644 --- a/src/main/java/li/strolch/persistence/impl/model/OrderParserFactory.java +++ b/src/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl.model; +package li.strolch.persistence.xml.model; import li.strolch.model.Order; import ch.eitchnet.xmlpers.api.DomParser; diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java b/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java similarity index 97% rename from src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java rename to src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java index f6d8738c3..7090f76ec 100644 --- a/src/main/java/li/strolch/persistence/impl/model/ResourceContextFactory.java +++ b/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl.model; +package li.strolch.persistence.xml.model; import li.strolch.model.Resource; import li.strolch.model.Tags; diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java b/src/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java similarity index 97% rename from src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java rename to src/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java index 497a81d1a..4853df885 100644 --- a/src/main/java/li/strolch/persistence/impl/model/ResourceDomParser.java +++ b/src/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl.model; +package li.strolch.persistence.xml.model; import li.strolch.model.Resource; import li.strolch.model.xml.ResourceToDomVisitor; diff --git a/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java b/src/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java similarity index 96% rename from src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java rename to src/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java index ebe7d8153..197c6903e 100644 --- a/src/main/java/li/strolch/persistence/impl/model/ResourceParserFactory.java +++ b/src/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package li.strolch.persistence.impl.model; +package li.strolch.persistence.xml.model; import li.strolch.model.Resource; import ch.eitchnet.xmlpers.api.DomParser; diff --git a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml index f7dd1f7b4..bec79a297 100644 --- a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml @@ -10,7 +10,7 @@ PersistenceHandler li.strolch.persistence.api.PersistenceHandler - li.strolch.persistence.impl.XmlPersistenceHandler + li.strolch.persistence.xml.XmlPersistenceHandler true diff --git a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml index 51b6d9794..858a6bba3 100644 --- a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml @@ -10,7 +10,7 @@ PersistenceHandler li.strolch.persistence.api.PersistenceHandler - li.strolch.persistence.impl.XmlPersistenceHandler + li.strolch.persistence.xml.XmlPersistenceHandler true From 11403a8d214e649aeca4fcfe742001eac222f939 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 16:50:14 +0100 Subject: [PATCH 33/59] [Major] removed project li.strolch.persistence.api Moved all classes to li.strolch.runtime --- pom.xml | 4 ---- .../li/strolch/persistence/xml/XmlPersistenceHandler.java | 1 - 2 files changed, 5 deletions(-) diff --git a/pom.xml b/pom.xml index b03ea24a1..ffa2bbe7d 100644 --- a/pom.xml +++ b/pom.xml @@ -40,10 +40,6 @@ li.strolch li.strolch.runtime - - li.strolch - li.strolch.persistence.api - ch.eitchnet diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index e3ee1dba3..fef399353 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -38,7 +38,6 @@ import ch.eitchnet.xmlpers.api.PersistenceTransaction; /** * @author Robert von Burg - * */ public class XmlPersistenceHandler extends StrolchComponent implements PersistenceHandler { From 28f43534051ab0f13d5c7474bc55e757f3da9562 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 17:16:59 +0100 Subject: [PATCH 34/59] [Major] renamed project li.strolch.runtime to li.strolch.agent --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ffa2bbe7d..bac105923 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ li.strolch - li.strolch.runtime + li.strolch.agent From 4a0fb74d210892ea36776ef79ea4072ba9e9d86b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 19:10:45 +0100 Subject: [PATCH 35/59] [Major] refactored how transactions are opened Now the ElementMapHandler is the central object and clients do not use access DAOs or the PersistenceHandler anymore. This is now transparent. --- .../persistence/xml/XmlPersistenceHandler.java | 15 +++++---------- .../persistence/xml/XmlStrolchTransaction.java | 8 +++++--- .../impl/dao/test/ObserverUpdateTest.java | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index fef399353..2eb9570d7 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -25,9 +25,9 @@ import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.xml.model.OrderContextFactory; import li.strolch.persistence.xml.model.ResourceContextFactory; -import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.agent.api.StrolchComponent; import li.strolch.runtime.agent.impl.ComponentContainerImpl; +import li.strolch.runtime.agent.impl.StrolchRealm; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.IoMode; @@ -69,15 +69,10 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten super.initialize(componentConfiguration); } - public StrolchTransaction openTx() { - return openTx(StrolchConstants.DEFAULT_REALM); - } - - @SuppressWarnings("resource") - // caller will/must close - public StrolchTransaction openTx(String realm) { - PersistenceTransaction tx = this.persistenceManager.openTx(realm); - XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(tx); + @Override + public StrolchTransaction openTx(StrolchRealm realm) { + PersistenceTransaction tx = this.persistenceManager.openTx(realm.getRealm()); + XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(realm, tx); if (getContainer().hasComponent(ObserverHandler.class)) { strolchTx.setObserverHandler(getContainer().getComponent(ObserverHandler.class)); } diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index a73955571..a29e07451 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -18,24 +18,26 @@ package li.strolch.persistence.xml; import java.util.Set; import li.strolch.model.StrolchElement; +import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchPersistenceException; -import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.api.TransactionCloseStrategy; +import li.strolch.runtime.agent.impl.StrolchRealm; import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.ModificationResult; import ch.eitchnet.xmlpers.api.PersistenceTransaction; import ch.eitchnet.xmlpers.api.TransactionResult; -public class XmlStrolchTransaction implements StrolchTransaction { +public class XmlStrolchTransaction extends AbstractTransaction { private ObserverHandler observerHandler; private boolean suppressUpdates; private PersistenceTransaction tx; private TransactionCloseStrategy closeStrategy; - public XmlStrolchTransaction(PersistenceTransaction tx) { + public XmlStrolchTransaction(StrolchRealm realm, PersistenceTransaction tx) { + super(realm); this.suppressUpdates = false; this.tx = tx; this.closeStrategy = TransactionCloseStrategy.COMMIT; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 95cb81ee0..1eb75f687 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -110,13 +110,13 @@ public class ObserverUpdateTest { // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getOrderMap().openTx()) { + try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { tx.getOrderDao().save(newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getResourceMap().openTx()) { + try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { tx.getResourceDao().save(newResource); } From fa2f9278561016235464c513077e84507d0b7c82 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 23:23:25 +0100 Subject: [PATCH 36/59] [Major] moved the package li.strolch.runtime.agent to li.strolch.agent --- .../li/strolch/persistence/xml/XmlPersistenceHandler.java | 6 +++--- .../li/strolch/persistence/xml/XmlStrolchTransaction.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 2eb9570d7..267531b60 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -18,6 +18,9 @@ package li.strolch.persistence.xml; import java.io.File; import java.util.Properties; +import li.strolch.agent.api.StrolchComponent; +import li.strolch.agent.impl.ComponentContainerImpl; +import li.strolch.agent.impl.StrolchRealm; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.Tags; @@ -25,9 +28,6 @@ import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.xml.model.OrderContextFactory; import li.strolch.persistence.xml.model.ResourceContextFactory; -import li.strolch.runtime.agent.api.StrolchComponent; -import li.strolch.runtime.agent.impl.ComponentContainerImpl; -import li.strolch.runtime.agent.impl.StrolchRealm; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.IoMode; diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index a29e07451..748bdb74d 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -17,13 +17,13 @@ package li.strolch.persistence.xml; import java.util.Set; +import li.strolch.agent.impl.StrolchRealm; import li.strolch.model.StrolchElement; import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchPersistenceException; import li.strolch.persistence.api.TransactionCloseStrategy; -import li.strolch.runtime.agent.impl.StrolchRealm; import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.ModificationResult; import ch.eitchnet.xmlpers.api.PersistenceTransaction; From 5ac8d4f8753e4c535e9ffa7f72952d12b75155fc Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 11 Jan 2014 17:56:07 +0100 Subject: [PATCH 37/59] [Major] Implemented CACHED mode This lead to refactoring of other code: - removed get*Dao() from StrolchTransaction - added StrolchTransaction.getPersistenceHandler() - removed unused variables in TransactionalElementMap - this lead to removal of constructors in subclasses - added ComponentContainer.getDataStoreMode() - added ElementMap.addAll(), removeAll() and updateAll() methods - implemented in all ElementMap implementations --- .../xml/XmlPersistenceHandler.java | 14 +++- .../xml/XmlStrolchTransaction.java | 17 ++--- .../impl/dao/test/ExistingDbTest.java | 65 +++++++++++++++++++ .../impl/dao/test/ObserverUpdateTest.java | 4 +- .../config/StrolchConfiguration.xml | 23 +++++++ .../dbStore/defaultRealm/Order/MyType/@1.xml | 12 ++++ .../defaultRealm/Resource/MyType/@1.xml | 12 ++++ 7 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java create mode 100644 src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml create mode 100644 src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml create mode 100644 src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 267531b60..72df67c53 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -24,7 +24,9 @@ import li.strolch.agent.impl.StrolchRealm; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.Tags; +import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.PersistenceHandler; +import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.persistence.xml.model.OrderContextFactory; import li.strolch.persistence.xml.model.ResourceContextFactory; @@ -72,10 +74,20 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten @Override public StrolchTransaction openTx(StrolchRealm realm) { PersistenceTransaction tx = this.persistenceManager.openTx(realm.getRealm()); - XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(realm, tx); + XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(realm, tx, this); if (getContainer().hasComponent(ObserverHandler.class)) { strolchTx.setObserverHandler(getContainer().getComponent(ObserverHandler.class)); } return strolchTx; } + + @Override + public OrderDao getOrderDao(StrolchTransaction tx) { + return new XmlOrderDao(tx); + } + + @Override + public ResourceDao getResourceDao(StrolchTransaction tx) { + return new XmlResourceDao(tx); + } } diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index 748bdb74d..5c54fca03 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -20,8 +20,7 @@ import java.util.Set; import li.strolch.agent.impl.StrolchRealm; import li.strolch.model.StrolchElement; import li.strolch.persistence.api.AbstractTransaction; -import li.strolch.persistence.api.OrderDao; -import li.strolch.persistence.api.ResourceDao; +import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchPersistenceException; import li.strolch.persistence.api.TransactionCloseStrategy; import li.strolch.runtime.observer.ObserverHandler; @@ -31,13 +30,15 @@ import ch.eitchnet.xmlpers.api.TransactionResult; public class XmlStrolchTransaction extends AbstractTransaction { + private XmlPersistenceHandler persistenceHandler; private ObserverHandler observerHandler; private boolean suppressUpdates; private PersistenceTransaction tx; private TransactionCloseStrategy closeStrategy; - public XmlStrolchTransaction(StrolchRealm realm, PersistenceTransaction tx) { + public XmlStrolchTransaction(StrolchRealm realm, PersistenceTransaction tx, XmlPersistenceHandler persistenceHandler) { super(realm); + this.persistenceHandler = persistenceHandler; this.suppressUpdates = false; this.tx = tx; this.closeStrategy = TransactionCloseStrategy.COMMIT; @@ -84,6 +85,7 @@ public class XmlStrolchTransaction extends AbstractTransaction { } this.tx.autoCloseableCommit(); + logger.info(txResult.getLogMessage()); if (!this.suppressUpdates && this.observerHandler != null) { @@ -114,12 +116,7 @@ public class XmlStrolchTransaction extends AbstractTransaction { } @Override - public OrderDao getOrderDao() { - return new XmlOrderDao(this); - } - - @Override - public ResourceDao getResourceDao() { - return new XmlResourceDao(this); + public PersistenceHandler getPersistenceHandler() { + return this.persistenceHandler; } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java new file mode 100644 index 000000000..dd1c9a5f7 --- /dev/null +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.persistence.impl.dao.test; + +import static org.junit.Assert.assertNotNull; + +import java.io.File; + +import li.strolch.model.Order; +import li.strolch.model.Resource; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.testbase.runtime.RuntimeMock; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class ExistingDbTest { + + public static final String RUNTIME_PATH = "target/existingDbRuntime/"; //$NON-NLS-1$ + public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ + public static final String CONFIG_SRC = "src/test/resources/existingDbRuntime"; //$NON-NLS-1$ + + protected static RuntimeMock runtimeMock; + + @BeforeClass + public static void beforeClass() { + + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + runtimeMock = new RuntimeMock(); + runtimeMock.mockRuntime(rootPath, configSrc); + runtimeMock.startContainer(rootPath); + } + + @AfterClass + public static void afterClass() { + runtimeMock.destroyRuntime(); + } + + @Test + public void shouldQueryExistingData() { + + try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { + Resource resource = tx.getResourceMap().getBy(tx, "MyType", "@1"); + assertNotNull("Should be able to read existing element from db", resource); + + Order order = tx.getOrderMap().getBy(tx, "MyType", "@1"); + assertNotNull("Should be able to read existing element from db", order); + } + } +} diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 1eb75f687..a3a84d598 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -111,13 +111,13 @@ public class ObserverUpdateTest { // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { - tx.getOrderDao().save(newOrder); + tx.getOrderMap().add(tx, newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { - tx.getResourceDao().save(newResource); + tx.getResourceMap().add(tx, newResource); } assertEquals(2, observer.results.size()); diff --git a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml new file mode 100644 index 000000000..bec79a297 --- /dev/null +++ b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml @@ -0,0 +1,23 @@ + + + + StrolchPersistenceTest + + CACHED + true + + + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.xml.XmlPersistenceHandler + + true + + + + ObserverHandler + li.strolch.runtime.observer.ObserverHandler + li.strolch.runtime.observer.DefaultObserverHandler + + \ No newline at end of file diff --git a/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml b/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml new file mode 100644 index 000000000..7c0a4269b --- /dev/null +++ b/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml b/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml new file mode 100644 index 000000000..bc3a21ee7 --- /dev/null +++ b/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + From ace469227d02866c078c1b276f50a3a3d9e79c3f Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 15 Jan 2014 22:09:53 +0100 Subject: [PATCH 38/59] [New] added querySize() methods to ElementMap --- .../strolch/persistence/xml/AbstractDao.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/li/strolch/persistence/xml/AbstractDao.java b/src/main/java/li/strolch/persistence/xml/AbstractDao.java index dd14a0632..f559e8e89 100644 --- a/src/main/java/li/strolch/persistence/xml/AbstractDao.java +++ b/src/main/java/li/strolch/persistence/xml/AbstractDao.java @@ -49,6 +49,24 @@ public abstract class AbstractDao implements StrolchDa return typeRef; } + @Override + public long querySize() { + long size = 0; + Set types = queryTypes(); + for (String type : types) { + + SubTypeRef subTypeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type); + size += this.tx.getMetadataDao().querySize(subTypeRef); + } + return size; + } + + @Override + public long querySize(String type) { + SubTypeRef subTypeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type); + return tx.getMetadataDao().querySize(subTypeRef); + } + @Override public Set queryKeySet() { Set keys = new HashSet<>(); From 5e1dafadc6ab461b42a2064916b8748f509db684 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Jan 2014 22:01:09 +0100 Subject: [PATCH 39/59] [New] added version info metadata to agent --- pom.xml | 4 ++++ src/main/resources/componentVersion.properties | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 src/main/resources/componentVersion.properties diff --git a/pom.xml b/pom.xml index bac105923..3fac72553 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,10 @@ + + org.codehaus.mojo + buildnumber-maven-plugin + org.apache.maven.plugins maven-eclipse-plugin diff --git a/src/main/resources/componentVersion.properties b/src/main/resources/componentVersion.properties new file mode 100644 index 000000000..1f050160f --- /dev/null +++ b/src/main/resources/componentVersion.properties @@ -0,0 +1,6 @@ +groupId=${project.groupId} +artifactId=${project.artifactId} +artifactVersion=${project.version} +scmRevision=r${buildNumber} +scmBranch=${scmBranch} +buildTimestamp=${buildTimestamp} \ No newline at end of file From 39df4cf6cfefee9eaea31b61f0a63238d7d3d68c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Jan 2014 22:52:45 +0100 Subject: [PATCH 40/59] [Project] added Jenkins build badge to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fbc7e1574..35f61b964 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ li.strolch.persistence.xml ========================== +[![Build Status](http://jenkins.eitchnet.ch/buildStatus/icon?job=li.strolch.persistence.xml)](http://jenkins.eitchnet.ch/view/strolch/job/li.strolch.persistence.xml/) + XML Persistence Implementation for Strolch From 2f015592d244440d5ac1bf3de440ba7b963879dc Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 25 Jan 2014 22:14:46 +0100 Subject: [PATCH 41/59] [Major] changed constructor of StrolchComponent Should have interface ComponentContainer in constructor --- .../li/strolch/persistence/xml/XmlPersistenceHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 72df67c53..74c577a7d 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -18,8 +18,8 @@ package li.strolch.persistence.xml; import java.io.File; import java.util.Properties; +import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchComponent; -import li.strolch.agent.impl.ComponentContainerImpl; import li.strolch.agent.impl.StrolchRealm; import li.strolch.model.Order; import li.strolch.model.Resource; @@ -46,7 +46,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten public static final String DB_STORE_PATH = "dbStore/"; //$NON-NLS-1$ private PersistenceManager persistenceManager; - public XmlPersistenceHandler(ComponentContainerImpl container, String componentName) { + public XmlPersistenceHandler(ComponentContainer container, String componentName) { super(container, componentName); } From 262e7e204add841e92610fe7e3f1baa79d0a85e9 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 13 Feb 2014 22:21:40 +0100 Subject: [PATCH 42/59] [Minor] there is no getDefaultRealm() method anymore --- .../strolch/persistence/impl/dao/test/ExistingDbTest.java | 5 +++-- .../persistence/impl/dao/test/ObserverUpdateTest.java | 7 ++++--- .../persistence/impl/dao/test/XmlCachedDaoTest.java | 2 +- .../persistence/impl/dao/test/XmlTransactionalDaoTest.java | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java index dd1c9a5f7..14532517d 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java @@ -22,6 +22,7 @@ import java.io.File; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.StrolchConstants; import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; @@ -43,7 +44,7 @@ public class ExistingDbTest { File configSrc = new File(CONFIG_SRC); runtimeMock = new RuntimeMock(); runtimeMock.mockRuntime(rootPath, configSrc); - runtimeMock.startContainer(rootPath); + runtimeMock.startContainer(); } @AfterClass @@ -54,7 +55,7 @@ public class ExistingDbTest { @Test public void shouldQueryExistingData() { - try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { Resource resource = tx.getResourceMap().getBy(tx, "MyType", "@1"); assertNotNull("Should be able to read existing element from db", resource); diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index a3a84d598..57513955d 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -30,6 +30,7 @@ import li.strolch.model.Resource; import li.strolch.model.State; import li.strolch.model.StrolchElement; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.observer.Observer; import li.strolch.runtime.observer.ObserverHandler; import li.strolch.testbase.runtime.RuntimeMock; @@ -63,7 +64,7 @@ public class ObserverUpdateTest { runtimeMock = new RuntimeMock(); runtimeMock.mockRuntime(rootPath, configSrc); new File(rootPath, DB_STORE_PATH_DIR).mkdir(); - runtimeMock.startContainer(rootPath); + runtimeMock.startContainer(); } @AfterClass @@ -110,13 +111,13 @@ public class ObserverUpdateTest { // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { tx.getOrderMap().add(tx, newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { tx.getResourceMap().add(tx, newResource); } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java index 3a203102e..045a71abd 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java @@ -44,7 +44,7 @@ public class XmlCachedDaoTest extends AbstractModelTest { runtimeMock = new RuntimeMock(); runtimeMock.mockRuntime(rootPath, configSrc); new File(rootPath, DB_STORE_PATH_DIR).mkdir(); - runtimeMock.startContainer(rootPath); + runtimeMock.startContainer(); } @AfterClass diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java index 5fc5442b4..ab785c203 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java @@ -44,7 +44,7 @@ public class XmlTransactionalDaoTest extends AbstractModelTest { runtimeMock = new RuntimeMock(); runtimeMock.mockRuntime(rootPath, configSrc); new File(rootPath, DB_STORE_PATH_DIR).mkdir(); - runtimeMock.startContainer(rootPath); + runtimeMock.startContainer(); } @AfterClass From b9c7278911c77e22b450387366e13b335d6ab4a8 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 17 Feb 2014 22:08:09 +0100 Subject: [PATCH 43/59] [New] Implemented separate DataStoreMode for each StrolchRealm --- .../cachedruntime/config/StrolchConfiguration.xml | 10 +++++++++- .../existingDbRuntime/config/StrolchConfiguration.xml | 10 +++++++++- .../config/StrolchConfiguration.xml | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml index bec79a297..cb7b07605 100644 --- a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml @@ -3,10 +3,18 @@ StrolchPersistenceTest - CACHED true + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + CACHED + + PersistenceHandler li.strolch.persistence.api.PersistenceHandler diff --git a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml index bec79a297..cb7b07605 100644 --- a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml @@ -3,10 +3,18 @@ StrolchPersistenceTest - CACHED true + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + CACHED + + PersistenceHandler li.strolch.persistence.api.PersistenceHandler diff --git a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml index 858a6bba3..f89b40c3a 100644 --- a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml @@ -3,10 +3,18 @@ StrolchPersistenceTest - TRANSACTIONAL true + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + TRANSACTIONAL + + PersistenceHandler li.strolch.persistence.api.PersistenceHandler From e11625998acb4c8ec1949961fcef39d4517a07d9 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Feb 2014 21:49:02 +0100 Subject: [PATCH 44/59] [New] Implemented locking for Strolch elements Also cleaned up hierarchy of StrolchTransaction by moving up everything into AbstractTransaction as made sense and added special delegation methods for the actual commit() and rollback() ind the concrete implementations. --- .../xml/XmlPersistenceHandler.java | 2 +- .../xml/XmlStrolchTransaction.java | 79 +++---------------- .../impl/dao/test/ObserverUpdateTest.java | 10 +-- 3 files changed, 17 insertions(+), 74 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 74c577a7d..3b5ad0461 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -20,7 +20,7 @@ import java.util.Properties; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchComponent; -import li.strolch.agent.impl.StrolchRealm; +import li.strolch.agent.api.StrolchRealm; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.Tags; diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index 5c54fca03..4a8428052 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -17,13 +17,9 @@ package li.strolch.persistence.xml; import java.util.Set; -import li.strolch.agent.impl.StrolchRealm; -import li.strolch.model.StrolchElement; +import li.strolch.agent.api.StrolchRealm; import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.PersistenceHandler; -import li.strolch.persistence.api.StrolchPersistenceException; -import li.strolch.persistence.api.TransactionCloseStrategy; -import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.xmlpers.api.ModificationResult; import ch.eitchnet.xmlpers.api.PersistenceTransaction; import ch.eitchnet.xmlpers.api.TransactionResult; @@ -31,40 +27,12 @@ import ch.eitchnet.xmlpers.api.TransactionResult; public class XmlStrolchTransaction extends AbstractTransaction { private XmlPersistenceHandler persistenceHandler; - private ObserverHandler observerHandler; - private boolean suppressUpdates; private PersistenceTransaction tx; - private TransactionCloseStrategy closeStrategy; public XmlStrolchTransaction(StrolchRealm realm, PersistenceTransaction tx, XmlPersistenceHandler persistenceHandler) { super(realm); this.persistenceHandler = persistenceHandler; - this.suppressUpdates = false; this.tx = tx; - this.closeStrategy = TransactionCloseStrategy.COMMIT; - } - - /** - * @param observerHandler - * the observerHandler to set - */ - public void setObserverHandler(ObserverHandler observerHandler) { - this.observerHandler = observerHandler; - } - - /** - * @param suppressUpdates - * the suppressUpdates to set - */ - public void setSuppressUpdates(boolean suppressUpdates) { - this.suppressUpdates = suppressUpdates; - } - - /** - * @return the suppressUpdates - */ - public boolean isSuppressUpdates() { - return this.suppressUpdates; } PersistenceTransaction getTx() { @@ -72,49 +40,24 @@ public class XmlStrolchTransaction extends AbstractTransaction { } @Override - public void setCloseStrategy(TransactionCloseStrategy closeStrategy) { - this.closeStrategy = closeStrategy; - } - - @Override - public void autoCloseableCommit() { - - TransactionResult txResult = new TransactionResult(); - if (!this.suppressUpdates && this.observerHandler != null) { - this.tx.setTransactionResult(txResult); - } - + protected void commit(li.strolch.persistence.api.TransactionResult txResult) throws Exception { + TransactionResult result = new TransactionResult(); + this.tx.setTransactionResult(result); this.tx.autoCloseableCommit(); - logger.info(txResult.getLogMessage()); - - if (!this.suppressUpdates && this.observerHandler != null) { - - Set keys = txResult.getKeys(); - for (String key : keys) { - ModificationResult modificationResult = txResult.getModificationResult(key); - - this.observerHandler.add(key, modificationResult. getCreated()); - this.observerHandler.update(key, modificationResult. getUpdated()); - this.observerHandler.remove(key, modificationResult. getDeleted()); - } + Set keys = result.getKeys(); + for (String key : keys) { + ModificationResult modificationResult = result.getModificationResult(key); + li.strolch.persistence.api.ModificationResult mr = new li.strolch.persistence.api.ModificationResult(key, + modificationResult.getCreated(), modificationResult.getUpdated(), modificationResult.getDeleted()); + txResult.addModificationResult(mr); } } @Override - public void autoCloseableRollback() { + protected void rollback(li.strolch.persistence.api.TransactionResult txResult) throws Exception { this.tx.autoCloseableRollback(); } - @Override - public void close() throws StrolchPersistenceException { - this.closeStrategy.close(this); - } - - @Override - public boolean isOpen() { - return this.tx.isOpen(); - } - @Override public PersistenceHandler getPersistenceHandler() { return this.persistenceHandler; diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 57513955d..1a155ec55 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -29,6 +29,7 @@ import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.State; import li.strolch.model.StrolchElement; +import li.strolch.model.Tags; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.observer.Observer; @@ -106,8 +107,8 @@ public class ObserverUpdateTest { // register an observer for orders and resources ElementAddedObserver observer = new ElementAddedObserver(); - runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver("Order", observer); //$NON-NLS-1$ - runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver("Resource", observer); //$NON-NLS-1$ + runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.ORDER, observer); //$NON-NLS-1$ + runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.RESOURCE, observer); //$NON-NLS-1$ // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ @@ -122,8 +123,7 @@ public class ObserverUpdateTest { } assertEquals(2, observer.results.size()); - assertEquals(1, observer.results.get("Order").getCreated().size()); //$NON-NLS-1$ - assertEquals(1, observer.results.get("Resource").getCreated().size()); //$NON-NLS-1$ - + assertEquals(1, observer.results.get(Tags.ORDER).getCreated().size()); //$NON-NLS-1$ + assertEquals(1, observer.results.get(Tags.RESOURCE).getCreated().size()); //$NON-NLS-1$ } } From 236ccb801450b53a53ed023e0834ea66a5f92231 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 14 Mar 2014 14:36:57 +0100 Subject: [PATCH 45/59] [Project] fixed urls of projects --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 3fac72553..023321e30 100644 --- a/pom.xml +++ b/pom.xml @@ -15,19 +15,19 @@ li.strolch.persistence.xml Reference Persistence Implementation for Strolch - https://github.com/eitch/li.strolch.persistence.xml + https://github.com/eitchnet/li.strolch.persistence.xml 2011 Github Issues - https://github.com/eitch/li.strolch.persistence.xml/issues + https://github.com/eitchnet/li.strolch.persistence.xml/issues - scm:git:https://github.com/eitch/li.strolch.persistence.xml.git + scm:git:https://github.com/eitchnet/li.strolch.persistence.xml.git scm:git:git@github.com:eitch/li.strolch.persistence.xml.git - https://github.com/eitch/li.strolch.persistence.xml + https://github.com/eitchnet/li.strolch.persistence.xml From 348b2121e981b784bfb23e38a2fea3180d038f9f Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jul 2014 16:12:07 +0200 Subject: [PATCH 46/59] [Major] added new methods ElementMap.removeAll() --- .../strolch/persistence/xml/AbstractDao.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/AbstractDao.java b/src/main/java/li/strolch/persistence/xml/AbstractDao.java index f559e8e89..f9a5ff32d 100644 --- a/src/main/java/li/strolch/persistence/xml/AbstractDao.java +++ b/src/main/java/li/strolch/persistence/xml/AbstractDao.java @@ -55,7 +55,7 @@ public abstract class AbstractDao implements StrolchDa Set types = queryTypes(); for (String type : types) { - SubTypeRef subTypeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type); + SubTypeRef subTypeRef = getTypeRef(type); size += this.tx.getMetadataDao().querySize(subTypeRef); } return size; @@ -63,7 +63,7 @@ public abstract class AbstractDao implements StrolchDa @Override public long querySize(String type) { - SubTypeRef subTypeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type); + SubTypeRef subTypeRef = getTypeRef(type); return tx.getMetadataDao().querySize(subTypeRef); } @@ -79,7 +79,7 @@ public abstract class AbstractDao implements StrolchDa @Override public Set queryKeySet(String type) { - SubTypeRef typeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type); + SubTypeRef typeRef = getTypeRef(type); Set keys = this.tx.getMetadataDao().queryKeySet(typeRef); return keys; } @@ -144,4 +144,16 @@ public abstract class AbstractDao implements StrolchDa public void removeAll(List objects) { this.tx.getObjectDao().removeAll(objects); } + + @Override + public long removeAll() { + TypeRef typeRef = this.tx.getObjectRefCache().getTypeRef(getClassType()); + return this.tx.getObjectDao().removeAllBy(typeRef); + } + + @Override + public long removeAllBy(String type) { + SubTypeRef typeRef = getTypeRef(type); + return this.tx.getObjectDao().removeAllBy(typeRef); + } } From abf2a06b9e77f876372e5ab98b0160c7451f66b2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 4 Aug 2014 11:47:56 +0200 Subject: [PATCH 47/59] [New] Implemented StrolchDao.hasElement() --- src/main/java/li/strolch/persistence/xml/AbstractDao.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/persistence/xml/AbstractDao.java b/src/main/java/li/strolch/persistence/xml/AbstractDao.java index f9a5ff32d..932fa2e1a 100644 --- a/src/main/java/li/strolch/persistence/xml/AbstractDao.java +++ b/src/main/java/li/strolch/persistence/xml/AbstractDao.java @@ -49,6 +49,12 @@ public abstract class AbstractDao implements StrolchDa return typeRef; } + @Override + public boolean hasElement(String type, String id) { + IdOfSubTypeRef ref = getIdRef(type, id); + return this.tx.getObjectDao().hasElement(ref); + } + @Override public long querySize() { long size = 0; @@ -64,7 +70,7 @@ public abstract class AbstractDao implements StrolchDa @Override public long querySize(String type) { SubTypeRef subTypeRef = getTypeRef(type); - return tx.getMetadataDao().querySize(subTypeRef); + return this.tx.getMetadataDao().querySize(subTypeRef); } @Override From 814019244174722dbb36418445a16f46c8535f65 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 6 Aug 2014 18:42:54 +0200 Subject: [PATCH 48/59] [New] Moved *Visitor transformations in query into query method This is better than keeping the Visitor in the instance of the query, where it might be to early to instantiate it. --- src/main/java/li/strolch/persistence/xml/XmlOrderDao.java | 3 ++- src/main/java/li/strolch/persistence/xml/XmlResourceDao.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java b/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java index c44934980..79db5ee6e 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java @@ -18,6 +18,7 @@ package li.strolch.persistence.xml; import java.util.List; import li.strolch.model.Order; +import li.strolch.model.OrderVisitor; import li.strolch.model.Tags; import li.strolch.model.query.OrderQuery; import li.strolch.persistence.api.OrderDao; @@ -35,7 +36,7 @@ public class XmlOrderDao extends AbstractDao implements OrderDao { } @Override - public List doQuery(OrderQuery query) { + public List doQuery(OrderQuery query, OrderVisitor orderVisitor) { // TODO Auto-generated method stub return null; } diff --git a/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java b/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java index 8ee45d5dc..d7827fcfd 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java @@ -18,6 +18,7 @@ package li.strolch.persistence.xml; import java.util.List; import li.strolch.model.Resource; +import li.strolch.model.ResourceVisitor; import li.strolch.model.Tags; import li.strolch.model.query.ResourceQuery; import li.strolch.persistence.api.ResourceDao; @@ -35,7 +36,7 @@ public class XmlResourceDao extends AbstractDao implements ResourceDao } @Override - public List doQuery(ResourceQuery query) { + public List doQuery(ResourceQuery query, ResourceVisitor resourceVisitor) { // TODO Auto-generated method stub return null; } From 6a0199a544343517b766c9af067e262c1a95bb38 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 13 Aug 2014 16:06:14 +0200 Subject: [PATCH 49/59] [Major] Refactored StrolchConfiguration.xml to use environments Now the agent requires an environment parameter to start, and the configuration of that environment is used to load different sections of the configuration file --- .../config/StrolchConfiguration.xml | 58 ++++++++++--------- .../config/StrolchConfiguration.xml | 58 ++++++++++--------- .../config/StrolchConfiguration.xml | 58 ++++++++++--------- 3 files changed, 90 insertions(+), 84 deletions(-) diff --git a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml index cb7b07605..b7fe77021 100644 --- a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml @@ -1,31 +1,33 @@ - - StrolchPersistenceTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - PersistenceHandler - - CACHED - - - - PersistenceHandler - li.strolch.persistence.api.PersistenceHandler - li.strolch.persistence.xml.XmlPersistenceHandler - - true - - - - ObserverHandler - li.strolch.runtime.observer.ObserverHandler - li.strolch.runtime.observer.DefaultObserverHandler - + + + StrolchPersistenceTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + CACHED + + + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.xml.XmlPersistenceHandler + + true + + + + ObserverHandler + li.strolch.runtime.observer.ObserverHandler + li.strolch.runtime.observer.DefaultObserverHandler + + \ No newline at end of file diff --git a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml index cb7b07605..b7fe77021 100644 --- a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml @@ -1,31 +1,33 @@ - - StrolchPersistenceTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - PersistenceHandler - - CACHED - - - - PersistenceHandler - li.strolch.persistence.api.PersistenceHandler - li.strolch.persistence.xml.XmlPersistenceHandler - - true - - - - ObserverHandler - li.strolch.runtime.observer.ObserverHandler - li.strolch.runtime.observer.DefaultObserverHandler - + + + StrolchPersistenceTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + CACHED + + + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.xml.XmlPersistenceHandler + + true + + + + ObserverHandler + li.strolch.runtime.observer.ObserverHandler + li.strolch.runtime.observer.DefaultObserverHandler + + \ No newline at end of file diff --git a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml index f89b40c3a..17f718909 100644 --- a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml @@ -1,31 +1,33 @@ - - StrolchPersistenceTest - - true - - - - RealmHandler - li.strolch.agent.api.RealmHandler - li.strolch.agent.impl.DefaultRealmHandler - PersistenceHandler - - TRANSACTIONAL - - - - PersistenceHandler - li.strolch.persistence.api.PersistenceHandler - li.strolch.persistence.xml.XmlPersistenceHandler - - true - - - - ObserverHandler - li.strolch.runtime.observer.ObserverHandler - li.strolch.runtime.observer.DefaultObserverHandler - + + + StrolchPersistenceTest + + true + + + + RealmHandler + li.strolch.agent.api.RealmHandler + li.strolch.agent.impl.DefaultRealmHandler + PersistenceHandler + + TRANSACTIONAL + + + + PersistenceHandler + li.strolch.persistence.api.PersistenceHandler + li.strolch.persistence.xml.XmlPersistenceHandler + + true + + + + ObserverHandler + li.strolch.runtime.observer.ObserverHandler + li.strolch.runtime.observer.DefaultObserverHandler + + \ No newline at end of file From 78cc5551410156630bac18442621d2cebe024bc9 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 13 Aug 2014 23:37:55 +0200 Subject: [PATCH 50/59] [Project] added resource filtering for componentVersion.properties --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index 023321e30..e1965b14f 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,15 @@ + + + src/main/resources + true + + **/componentVersion.properties + + + org.codehaus.mojo From 72ff553e7430633cab1dcf9701a55e35b0231361 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 23 Aug 2014 20:50:01 +0200 Subject: [PATCH 51/59] [New] Implemented opt-in audit trail in Strolch The audit trail has its own map on the Realm and a trail is written by realm at the end of the transaction. You can write your own audit trail using tx.getAuditTrail(). Enable the audit trail by setting the realm configuration value 'enableAuditTrail'. --- .../strolch/persistence/xml/XmlAuditDao.java | 197 ++++++++++++++++++ .../xml/XmlPersistenceHandler.java | 15 +- .../xml/XmlStrolchTransaction.java | 47 ++++- .../xml/model/AuditContextFactory.java | 43 ++++ .../persistence/xml/model/AuditDomParser.java | 53 +++++ .../xml/model/AuditParserFactory.java | 34 +++ .../xml/model/OrderContextFactory.java | 5 +- .../persistence/xml/model/OrderDomParser.java | 1 - .../xml/model/ResourceContextFactory.java | 4 +- .../impl/dao/test/ExistingDbTest.java | 8 +- .../impl/dao/test/ObserverUpdateTest.java | 9 +- .../cachedruntime/config/PrivilegeConfig.xml | 30 +++ .../cachedruntime/config/PrivilegeModel.xml | 36 ++++ .../config/StrolchConfiguration.xml | 10 + .../config/PrivilegeConfig.xml | 30 +++ .../config/PrivilegeModel.xml | 36 ++++ .../config/StrolchConfiguration.xml | 9 + .../config/PrivilegeConfig.xml | 30 +++ .../config/PrivilegeModel.xml | 36 ++++ .../config/StrolchConfiguration.xml | 10 + 20 files changed, 630 insertions(+), 13 deletions(-) create mode 100644 src/main/java/li/strolch/persistence/xml/XmlAuditDao.java create mode 100644 src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java create mode 100644 src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java create mode 100644 src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java create mode 100644 src/test/resources/cachedruntime/config/PrivilegeConfig.xml create mode 100644 src/test/resources/cachedruntime/config/PrivilegeModel.xml create mode 100644 src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml create mode 100644 src/test/resources/existingDbRuntime/config/PrivilegeModel.xml create mode 100644 src/test/resources/transactionalruntime/config/PrivilegeConfig.xml create mode 100644 src/test/resources/transactionalruntime/config/PrivilegeModel.xml diff --git a/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java b/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java new file mode 100644 index 000000000..75e05f8cc --- /dev/null +++ b/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java @@ -0,0 +1,197 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.persistence.xml; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import li.strolch.model.Tags; +import li.strolch.model.audit.Audit; +import li.strolch.model.audit.AuditQuery; +import li.strolch.model.audit.AuditVisitor; +import li.strolch.persistence.api.AuditDao; +import li.strolch.persistence.api.StrolchTransaction; +import ch.eitchnet.utils.collections.DateRange; +import ch.eitchnet.xmlpers.api.PersistenceContext; +import ch.eitchnet.xmlpers.api.PersistenceTransaction; +import ch.eitchnet.xmlpers.objref.IdOfSubTypeRef; +import ch.eitchnet.xmlpers.objref.ObjectRef; +import ch.eitchnet.xmlpers.objref.SubTypeRef; +import ch.eitchnet.xmlpers.objref.TypeRef; + +/** + * @author Robert von Burg + */ +public class XmlAuditDao implements AuditDao { + + private PersistenceTransaction tx; + + public XmlAuditDao(StrolchTransaction tx) { + XmlStrolchTransaction strolchTx = (XmlStrolchTransaction) tx; + this.tx = strolchTx.getTx(); + } + + protected String getClassType() { + return Tags.AUDIT; + } + + protected IdOfSubTypeRef getIdRef(String type, Long id) { + IdOfSubTypeRef idRef = this.tx.getObjectRefCache().getIdOfSubTypeRef(getClassType(), type, id.toString()); + return idRef; + } + + protected SubTypeRef getTypeRef(String type) { + SubTypeRef typeRef = this.tx.getObjectRefCache().getSubTypeRef(getClassType(), type); + return typeRef; + } + + @Override + public boolean hasElement(String type, Long id) { + IdOfSubTypeRef ref = getIdRef(type, id); + return this.tx.getObjectDao().hasElement(ref); + } + + @Override + public long querySize(DateRange dateRange) { + long size = 0; + Set types = queryTypes(); + for (String type : types) { + // SubTypeRef subTypeRef = getTypeRef(type); + // size += this.tx.getMetadataDao().querySize(subTypeRef); + + size += querySize(type, dateRange); + } + return size; + } + + @Override + public long querySize(String type, DateRange dateRange) { + long size = 0; + + // TODO re-think this nonsense... this has a huge performance penalty + SubTypeRef subTypeRef = getTypeRef(type); + Set keySet = this.tx.getMetadataDao().queryKeySet(subTypeRef); + for (String key : keySet) { + ObjectRef objectRef = subTypeRef.getChildIdRef(tx, key); + Audit audit = this.tx.getObjectDao().queryById(objectRef); + if (dateRange.contains(audit.getDate())) + size++; + } + + // return this.tx.getMetadataDao().querySize(subTypeRef); + return size; + } + + @Override + public Set queryTypes() { + TypeRef typeRef = this.tx.getObjectRefCache().getTypeRef(getClassType()); + Set types = this.tx.getMetadataDao().queryTypeSet(typeRef); + return types; + } + + @Override + public Audit queryBy(String type, Long id) { + Audit t = this.tx.getObjectDao().queryById(getIdRef(type, id)); + return t; + } + + @Override + public List queryAll(String type, DateRange dateRange) { + + List audits = new ArrayList<>(); + + SubTypeRef subTypeRef = getTypeRef(type); + Set keySet = this.tx.getMetadataDao().queryKeySet(subTypeRef); + for (String key : keySet) { + ObjectRef objectRef = subTypeRef.getChildIdRef(tx, key); + Audit audit = this.tx.getObjectDao().queryById(objectRef); + if (dateRange.contains(audit.getDate())) + audits.add(audit); + } + + // this.tx.getObjectDao().queryAll(getTypeRef(type)); + return audits; + } + + @Override + public void save(Audit audit) { + PersistenceContext ctx = this.tx.getObjectDao().createCtx(audit); + this.tx.getFileDao().performCreate(ctx); + } + + @Override + public void saveAll(List audits) { + for (Audit audit : audits) { + PersistenceContext ctx = this.tx.getObjectDao().createCtx(audit); + this.tx.getFileDao().performCreate(ctx); + } + } + + @Override + public void update(Audit audit) { + PersistenceContext ctx = this.tx.getObjectDao().createCtx(audit); + this.tx.getFileDao().performUpdate(ctx); + } + + @Override + public void updateAll(List audits) { + for (Audit audit : audits) { + PersistenceContext ctx = this.tx.getObjectDao().createCtx(audit); + this.tx.getFileDao().performUpdate(ctx); + } + } + + @Override + public void remove(Audit audit) { + PersistenceContext ctx = this.tx.getObjectDao().createCtx(audit); + this.tx.getFileDao().performDelete(ctx); + } + + @Override + public void removeAll(List audits) { + for (Audit audit : audits) { + PersistenceContext ctx = this.tx.getObjectDao().createCtx(audit); + this.tx.getFileDao().performDelete(ctx); + } + } + + @Override + public long removeAll(String type, DateRange dateRange) { + + long removed = 0L; + + SubTypeRef subTypeRef = getTypeRef(type); + Set keySet = this.tx.getMetadataDao().queryKeySet(subTypeRef); + for (String key : keySet) { + ObjectRef objectRef = subTypeRef.getChildIdRef(tx, key); + Audit audit = this.tx.getObjectDao().queryById(objectRef); + if (dateRange.contains(audit.getDate())) { + PersistenceContext ctx = this.tx.getObjectDao().createCtx(objectRef); + this.tx.getFileDao().performDelete(ctx); + removed++; + } + } + + return removed; + } + + @Override + public List doQuery(AuditQuery query, AuditVisitor auditVisitor) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 3b5ad0461..5d49c6e57 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -24,14 +24,18 @@ import li.strolch.agent.api.StrolchRealm; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.Tags; +import li.strolch.model.audit.Audit; +import li.strolch.persistence.api.AuditDao; import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.persistence.xml.model.AuditContextFactory; import li.strolch.persistence.xml.model.OrderContextFactory; import li.strolch.persistence.xml.model.ResourceContextFactory; import li.strolch.runtime.configuration.ComponentConfiguration; import li.strolch.runtime.observer.ObserverHandler; +import ch.eitchnet.privilege.model.Certificate; import ch.eitchnet.xmlpers.api.IoMode; import ch.eitchnet.xmlpers.api.PersistenceConstants; import ch.eitchnet.xmlpers.api.PersistenceManager; @@ -67,14 +71,16 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten new ResourceContextFactory()); this.persistenceManager.getCtxFactory().registerPersistenceContextFactory(Order.class, Tags.ORDER, new OrderContextFactory()); + this.persistenceManager.getCtxFactory().registerPersistenceContextFactory(Audit.class, Tags.AUDIT, + new AuditContextFactory()); super.initialize(componentConfiguration); } @Override - public StrolchTransaction openTx(StrolchRealm realm) { + public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) { PersistenceTransaction tx = this.persistenceManager.openTx(realm.getRealm()); - XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(realm, tx, this); + XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(realm, certificate, action, tx, this); if (getContainer().hasComponent(ObserverHandler.class)) { strolchTx.setObserverHandler(getContainer().getComponent(ObserverHandler.class)); } @@ -90,4 +96,9 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten public ResourceDao getResourceDao(StrolchTransaction tx) { return new XmlResourceDao(tx); } + + @Override + public AuditDao getAuditDao(StrolchTransaction tx) { + return new XmlAuditDao(tx); + } } diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index 4a8428052..67ec26101 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -15,12 +15,17 @@ */ package li.strolch.persistence.xml; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import li.strolch.agent.api.StrolchRealm; +import li.strolch.model.StrolchRootElement; import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.PersistenceHandler; +import ch.eitchnet.privilege.model.Certificate; import ch.eitchnet.xmlpers.api.ModificationResult; +import ch.eitchnet.xmlpers.api.PersistenceContext; import ch.eitchnet.xmlpers.api.PersistenceTransaction; import ch.eitchnet.xmlpers.api.TransactionResult; @@ -29,8 +34,9 @@ public class XmlStrolchTransaction extends AbstractTransaction { private XmlPersistenceHandler persistenceHandler; private PersistenceTransaction tx; - public XmlStrolchTransaction(StrolchRealm realm, PersistenceTransaction tx, XmlPersistenceHandler persistenceHandler) { - super(realm); + public XmlStrolchTransaction(StrolchRealm realm, Certificate certificate, String action, PersistenceTransaction tx, + XmlPersistenceHandler persistenceHandler) { + super(realm, certificate, action); this.persistenceHandler = persistenceHandler; this.tx = tx; } @@ -40,15 +46,43 @@ public class XmlStrolchTransaction extends AbstractTransaction { } @Override - protected void commit(li.strolch.persistence.api.TransactionResult txResult) throws Exception { + protected void writeChanges(li.strolch.persistence.api.TransactionResult txResult) throws Exception { TransactionResult result = new TransactionResult(); this.tx.setTransactionResult(result); this.tx.autoCloseableCommit(); Set keys = result.getKeys(); for (String key : keys) { ModificationResult modificationResult = result.getModificationResult(key); + + List created = new ArrayList<>(); + List updated = new ArrayList<>(); + List deleted = new ArrayList<>(); + + List createdCtx = modificationResult.getCreated(); + for (Object object : createdCtx) { + @SuppressWarnings("unchecked") + PersistenceContext ctx = (PersistenceContext) object; + if (ctx.getObject() != null) + created.add(ctx.getObject()); + } + List updatedCtx = modificationResult.getUpdated(); + for (Object object : updatedCtx) { + @SuppressWarnings("unchecked") + PersistenceContext ctx = (PersistenceContext) object; + if (ctx.getObject() != null) + updated.add(ctx.getObject()); + } + List deletedCtx = modificationResult.getDeleted(); + for (Object object : deletedCtx) { + @SuppressWarnings("unchecked") + PersistenceContext ctx = (PersistenceContext) object; + if (ctx.getObject() != null) + deleted.add(ctx.getObject()); + } + li.strolch.persistence.api.ModificationResult mr = new li.strolch.persistence.api.ModificationResult(key, - modificationResult.getCreated(), modificationResult.getUpdated(), modificationResult.getDeleted()); + created, updated, deleted); + txResult.addModificationResult(mr); } } @@ -58,6 +92,11 @@ public class XmlStrolchTransaction extends AbstractTransaction { this.tx.autoCloseableRollback(); } + @Override + protected void commit() throws Exception { + // no-op + } + @Override public PersistenceHandler getPersistenceHandler() { return this.persistenceHandler; diff --git a/src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java b/src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java new file mode 100644 index 000000000..0cad02fb2 --- /dev/null +++ b/src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.persistence.xml.model; + +import li.strolch.model.Tags; +import li.strolch.model.audit.Audit; +import ch.eitchnet.xmlpers.api.PersistenceContext; +import ch.eitchnet.xmlpers.api.PersistenceContextFactory; +import ch.eitchnet.xmlpers.objref.IdOfSubTypeRef; +import ch.eitchnet.xmlpers.objref.ObjectRef; +import ch.eitchnet.xmlpers.objref.ObjectReferenceCache; + +public class AuditContextFactory implements PersistenceContextFactory { + + @Override + public PersistenceContext createCtx(ObjectRef objectRef) { + PersistenceContext ctx = new PersistenceContext<>(objectRef); + ctx.setParserFactory(new AuditParserFactory()); + return ctx; + } + + @Override + public PersistenceContext createCtx(ObjectReferenceCache objectRefCache, Audit audit) { + IdOfSubTypeRef objectRef = objectRefCache.getIdOfSubTypeRef(Tags.AUDIT, audit.getElementType(), audit.getId() + .toString()); + PersistenceContext ctx = createCtx(objectRef); + ctx.setObject(audit); + return ctx; + } +} diff --git a/src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java b/src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java new file mode 100644 index 000000000..a72e9459d --- /dev/null +++ b/src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java @@ -0,0 +1,53 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.persistence.xml.model; + +import li.strolch.model.audit.Audit; +import li.strolch.model.audit.AuditFromDomReader; +import li.strolch.model.audit.AuditToDomVisitor; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import ch.eitchnet.xmlpers.api.DomParser; + +public class AuditDomParser implements DomParser { + + private Audit audit; + + @Override + public Audit getObject() { + return this.audit; + } + + @Override + public void setObject(Audit audit) { + this.audit = audit; + } + + @Override + public Document toDom() { + AuditToDomVisitor auditDomVisitor = new AuditToDomVisitor(); + return auditDomVisitor.visitAudit(this.audit); + } + + @Override + public void fromDom(Document document) { + Element rootElement = document.getDocumentElement(); + Audit audit = new AuditFromDomReader().from(rootElement); + this.audit = audit; + } +} diff --git a/src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java b/src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java new file mode 100644 index 000000000..67b4f8b66 --- /dev/null +++ b/src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.persistence.xml.model; + +import li.strolch.model.audit.Audit; +import ch.eitchnet.xmlpers.api.DomParser; +import ch.eitchnet.xmlpers.api.ParserFactory; +import ch.eitchnet.xmlpers.api.SaxParser; + +public class AuditParserFactory implements ParserFactory { + + @Override + public DomParser getDomParser() { + return new AuditDomParser(); + } + + @Override + public SaxParser getSaxParser() { + throw new UnsupportedOperationException("Not yet implemented!"); //$NON-NLS-1$ + } +} diff --git a/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java b/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java index 73406915f..5a88e0fec 100644 --- a/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java +++ b/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java @@ -35,7 +35,8 @@ public class OrderContextFactory implements PersistenceContextFactory { @Override public PersistenceContext createCtx(ObjectReferenceCache objectRefCache, Order t) { IdOfSubTypeRef objectRef = objectRefCache.getIdOfSubTypeRef(Tags.ORDER, t.getType(), t.getId()); - return createCtx(objectRef); + PersistenceContext ctx = createCtx(objectRef); + ctx.setObject(t); + return ctx; } - } diff --git a/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java b/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java index df761a362..5abfece4a 100644 --- a/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java +++ b/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java @@ -35,7 +35,6 @@ public class OrderDomParser implements DomParser { @Override public void setObject(Order object) { this.order = object; - } @Override diff --git a/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java b/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java index 7090f76ec..408d68db2 100644 --- a/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java +++ b/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java @@ -35,6 +35,8 @@ public class ResourceContextFactory implements PersistenceContextFactory createCtx(ObjectReferenceCache objectRefCache, Resource t) { IdOfSubTypeRef objectRef = objectRefCache.getIdOfSubTypeRef(Tags.RESOURCE, t.getType(), t.getId()); - return createCtx(objectRef); + PersistenceContext ctx = createCtx(objectRef); + ctx.setObject(t); + return ctx; } } \ No newline at end of file diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java index 14532517d..949acfc52 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java @@ -23,12 +23,15 @@ import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.StrolchConstants; +import li.strolch.runtime.privilege.PrivilegeHandler; import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import ch.eitchnet.privilege.model.Certificate; + public class ExistingDbTest { public static final String RUNTIME_PATH = "target/existingDbRuntime/"; //$NON-NLS-1$ @@ -55,7 +58,10 @@ public class ExistingDbTest { @Test public void shouldQueryExistingData() { - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + PrivilegeHandler privilegeHandler = runtimeMock.getAgent().getContainer().getPrivilegeHandler(); + Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes()); + + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { Resource resource = tx.getResourceMap().getBy(tx, "MyType", "@1"); assertNotNull("Should be able to read existing element from db", resource); diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 1a155ec55..5fd5d6d08 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -34,12 +34,14 @@ import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.StrolchConstants; import li.strolch.runtime.observer.Observer; import li.strolch.runtime.observer.ObserverHandler; +import li.strolch.runtime.privilege.PrivilegeHandler; import li.strolch.testbase.runtime.RuntimeMock; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import ch.eitchnet.privilege.model.Certificate; import ch.eitchnet.xmlpers.api.ModificationResult; /** @@ -110,15 +112,18 @@ public class ObserverUpdateTest { runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.ORDER, observer); //$NON-NLS-1$ runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.RESOURCE, observer); //$NON-NLS-1$ + PrivilegeHandler privilegeHandler = runtimeMock.getAgent().getContainer().getPrivilegeHandler(); + Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes()); + // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { tx.getOrderMap().add(tx, newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { tx.getResourceMap().add(tx, newResource); } diff --git a/src/test/resources/cachedruntime/config/PrivilegeConfig.xml b/src/test/resources/cachedruntime/config/PrivilegeConfig.xml new file mode 100644 index 000000000..9d7a227e3 --- /dev/null +++ b/src/test/resources/cachedruntime/config/PrivilegeConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/cachedruntime/config/PrivilegeModel.xml b/src/test/resources/cachedruntime/config/PrivilegeModel.xml new file mode 100644 index 000000000..14af39def --- /dev/null +++ b/src/test/resources/cachedruntime/config/PrivilegeModel.xml @@ -0,0 +1,36 @@ + + + + + + SYSTEM + + agent + + + + Application + Administrator + ENABLED + en_GB + + PrivilegeAdmin + AppUser + + + + + + + + + true + + + + + true + + + + \ No newline at end of file diff --git a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml index b7fe77021..d3bb5edd6 100644 --- a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml @@ -7,13 +7,23 @@ true + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + RealmHandler li.strolch.agent.api.RealmHandler li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler PersistenceHandler CACHED + true diff --git a/src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml b/src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml new file mode 100644 index 000000000..9d7a227e3 --- /dev/null +++ b/src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml b/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml new file mode 100644 index 000000000..14af39def --- /dev/null +++ b/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml @@ -0,0 +1,36 @@ + + + + + + SYSTEM + + agent + + + + Application + Administrator + ENABLED + en_GB + + PrivilegeAdmin + AppUser + + + + + + + + + true + + + + + true + + + + \ No newline at end of file diff --git a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml index b7fe77021..6236d62b9 100644 --- a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml @@ -7,10 +7,19 @@ true + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + RealmHandler li.strolch.agent.api.RealmHandler li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler PersistenceHandler CACHED diff --git a/src/test/resources/transactionalruntime/config/PrivilegeConfig.xml b/src/test/resources/transactionalruntime/config/PrivilegeConfig.xml new file mode 100644 index 000000000..9d7a227e3 --- /dev/null +++ b/src/test/resources/transactionalruntime/config/PrivilegeConfig.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/transactionalruntime/config/PrivilegeModel.xml b/src/test/resources/transactionalruntime/config/PrivilegeModel.xml new file mode 100644 index 000000000..14af39def --- /dev/null +++ b/src/test/resources/transactionalruntime/config/PrivilegeModel.xml @@ -0,0 +1,36 @@ + + + + + + SYSTEM + + agent + + + + Application + Administrator + ENABLED + en_GB + + PrivilegeAdmin + AppUser + + + + + + + + + true + + + + + true + + + + \ No newline at end of file diff --git a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml index 17f718909..d6bdf4eb0 100644 --- a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml @@ -7,13 +7,23 @@ true + + PrivilegeHandler + li.strolch.runtime.privilege.PrivilegeHandler + li.strolch.runtime.privilege.DefaultStrolchPrivilegeHandler + + PrivilegeConfig.xml + + RealmHandler li.strolch.agent.api.RealmHandler li.strolch.agent.impl.DefaultRealmHandler + PrivilegeHandler PersistenceHandler TRANSACTIONAL + true From e84daf14b7a97c3eba281e3980a8dda22eb304c0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 12:45:20 +0200 Subject: [PATCH 52/59] [Major] Moved the auditing trail to the ElementMaps themselves This means that we can't access the ElementMaps from the Realms, but must use the TX (this was better anyhow) --- .../strolch/persistence/xml/XmlAuditDao.java | 6 +-- .../xml/XmlPersistenceHandler.java | 1 + .../xml/XmlStrolchTransaction.java | 38 ++----------------- .../impl/dao/test/ExistingDbTest.java | 13 ++++--- .../impl/dao/test/ObserverUpdateTest.java | 23 +++++------ 5 files changed, 26 insertions(+), 55 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java b/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java index 75e05f8cc..7aefcdd5e 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java @@ -86,7 +86,7 @@ public class XmlAuditDao implements AuditDao { SubTypeRef subTypeRef = getTypeRef(type); Set keySet = this.tx.getMetadataDao().queryKeySet(subTypeRef); for (String key : keySet) { - ObjectRef objectRef = subTypeRef.getChildIdRef(tx, key); + ObjectRef objectRef = subTypeRef.getChildIdRef(this.tx, key); Audit audit = this.tx.getObjectDao().queryById(objectRef); if (dateRange.contains(audit.getDate())) size++; @@ -117,7 +117,7 @@ public class XmlAuditDao implements AuditDao { SubTypeRef subTypeRef = getTypeRef(type); Set keySet = this.tx.getMetadataDao().queryKeySet(subTypeRef); for (String key : keySet) { - ObjectRef objectRef = subTypeRef.getChildIdRef(tx, key); + ObjectRef objectRef = subTypeRef.getChildIdRef(this.tx, key); Audit audit = this.tx.getObjectDao().queryById(objectRef); if (dateRange.contains(audit.getDate())) audits.add(audit); @@ -177,7 +177,7 @@ public class XmlAuditDao implements AuditDao { SubTypeRef subTypeRef = getTypeRef(type); Set keySet = this.tx.getMetadataDao().queryKeySet(subTypeRef); for (String key : keySet) { - ObjectRef objectRef = subTypeRef.getChildIdRef(tx, key); + ObjectRef objectRef = subTypeRef.getChildIdRef(this.tx, key); Audit audit = this.tx.getObjectDao().queryById(objectRef); if (dateRange.contains(audit.getDate())) { PersistenceContext ctx = this.tx.getObjectDao().createCtx(objectRef); diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 5d49c6e57..0892ed331 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -77,6 +77,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten super.initialize(componentConfiguration); } + @SuppressWarnings("resource") @Override public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) { PersistenceTransaction tx = this.persistenceManager.openTx(realm.getRealm()); diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index 67ec26101..90b8e56aa 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -15,17 +15,13 @@ */ package li.strolch.persistence.xml; -import java.util.ArrayList; -import java.util.List; import java.util.Set; import li.strolch.agent.api.StrolchRealm; -import li.strolch.model.StrolchRootElement; import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.PersistenceHandler; import ch.eitchnet.privilege.model.Certificate; import ch.eitchnet.xmlpers.api.ModificationResult; -import ch.eitchnet.xmlpers.api.PersistenceContext; import ch.eitchnet.xmlpers.api.PersistenceTransaction; import ch.eitchnet.xmlpers.api.TransactionResult; @@ -53,37 +49,9 @@ public class XmlStrolchTransaction extends AbstractTransaction { Set keys = result.getKeys(); for (String key : keys) { ModificationResult modificationResult = result.getModificationResult(key); - - List created = new ArrayList<>(); - List updated = new ArrayList<>(); - List deleted = new ArrayList<>(); - - List createdCtx = modificationResult.getCreated(); - for (Object object : createdCtx) { - @SuppressWarnings("unchecked") - PersistenceContext ctx = (PersistenceContext) object; - if (ctx.getObject() != null) - created.add(ctx.getObject()); - } - List updatedCtx = modificationResult.getUpdated(); - for (Object object : updatedCtx) { - @SuppressWarnings("unchecked") - PersistenceContext ctx = (PersistenceContext) object; - if (ctx.getObject() != null) - updated.add(ctx.getObject()); - } - List deletedCtx = modificationResult.getDeleted(); - for (Object object : deletedCtx) { - @SuppressWarnings("unchecked") - PersistenceContext ctx = (PersistenceContext) object; - if (ctx.getObject() != null) - deleted.add(ctx.getObject()); - } - - li.strolch.persistence.api.ModificationResult mr = new li.strolch.persistence.api.ModificationResult(key, - created, updated, deleted); - - txResult.addModificationResult(mr); + txResult.incCreated(modificationResult.getCreated().size()); + txResult.incUpdated(modificationResult.getUpdated().size()); + txResult.incDeleted(modificationResult.getDeleted().size()); } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java index 949acfc52..a749056fc 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java @@ -34,6 +34,7 @@ import ch.eitchnet.privilege.model.Certificate; public class ExistingDbTest { + private static final String TEST = "test"; //$NON-NLS-1$ public static final String RUNTIME_PATH = "target/existingDbRuntime/"; //$NON-NLS-1$ public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ public static final String CONFIG_SRC = "src/test/resources/existingDbRuntime"; //$NON-NLS-1$ @@ -59,14 +60,14 @@ public class ExistingDbTest { public void shouldQueryExistingData() { PrivilegeHandler privilegeHandler = runtimeMock.getAgent().getContainer().getPrivilegeHandler(); - Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes()); + Certificate certificate = privilegeHandler.authenticate(TEST, TEST.getBytes()); - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { - Resource resource = tx.getResourceMap().getBy(tx, "MyType", "@1"); - assertNotNull("Should be able to read existing element from db", resource); + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, TEST)) { + Resource resource = tx.getResourceMap().getBy(tx, "MyType", "@1"); //$NON-NLS-1$ //$NON-NLS-2$ + assertNotNull("Should be able to read existing element from db", resource); //$NON-NLS-1$ - Order order = tx.getOrderMap().getBy(tx, "MyType", "@1"); - assertNotNull("Should be able to read existing element from db", order); + Order order = tx.getOrderMap().getBy(tx, "MyType", "@1"); //$NON-NLS-1$//$NON-NLS-2$ + assertNotNull("Should be able to read existing element from db", order); //$NON-NLS-1$ } } } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 5fd5d6d08..f8aeed7f7 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -28,7 +28,7 @@ import java.util.Map; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.State; -import li.strolch.model.StrolchElement; +import li.strolch.model.StrolchRootElement; import li.strolch.model.Tags; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.StrolchConstants; @@ -49,6 +49,7 @@ import ch.eitchnet.xmlpers.api.ModificationResult; */ public class ObserverUpdateTest { + private static final String TEST = "test"; //$NON-NLS-1$ public static final String RUNTIME_PATH = "target/observerUpdateStrolchRuntime/"; //$NON-NLS-1$ public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$ public static final String CONFIG_SRC = "src/test/resources/cachedruntime"; //$NON-NLS-1$ @@ -89,17 +90,17 @@ public class ObserverUpdateTest { } @Override - public void update(String key, List elements) { + public void update(String key, List elements) { getModificationResult(key).getUpdated().addAll(elements); } @Override - public void remove(String key, List elements) { + public void remove(String key, List elements) { getModificationResult(key).getDeleted().addAll(elements); } @Override - public void add(String key, List elements) { + public void add(String key, List elements) { getModificationResult(key).getCreated().addAll(elements); } } @@ -109,26 +110,26 @@ public class ObserverUpdateTest { // register an observer for orders and resources ElementAddedObserver observer = new ElementAddedObserver(); - runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.ORDER, observer); //$NON-NLS-1$ - runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.RESOURCE, observer); //$NON-NLS-1$ + runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.ORDER, observer); + runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.RESOURCE, observer); PrivilegeHandler privilegeHandler = runtimeMock.getAgent().getContainer().getPrivilegeHandler(); - Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes()); + Certificate certificate = privilegeHandler.authenticate(TEST, TEST.getBytes()); // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, TEST)) { tx.getOrderMap().add(tx, newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, "test")) { + try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, TEST)) { tx.getResourceMap().add(tx, newResource); } assertEquals(2, observer.results.size()); - assertEquals(1, observer.results.get(Tags.ORDER).getCreated().size()); //$NON-NLS-1$ - assertEquals(1, observer.results.get(Tags.RESOURCE).getCreated().size()); //$NON-NLS-1$ + assertEquals(1, observer.results.get(Tags.ORDER).getCreated().size()); + assertEquals(1, observer.results.get(Tags.RESOURCE).getCreated().size()); } } From 7696a366a27e72105106c6f6be9d5255a4b34cfe Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 17:23:56 +0200 Subject: [PATCH 53/59] [Project] set version to 1.0.0-SNAPSHOT --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e1965b14f..02df6bc80 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ li.strolch li.strolch.parent - 0.1.0-SNAPSHOT + 1.0.0-SNAPSHOT ../li.strolch.parent/pom.xml @@ -31,7 +31,7 @@ - + li.strolch li.strolch.model @@ -40,12 +40,12 @@ li.strolch li.strolch.agent - ch.eitchnet ch.eitchnet.xmlpers + li.strolch li.strolch.testbase From e2629c8f3fb5d5cc50a6b14ab5a0ae3337eae171 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 19:18:20 +0200 Subject: [PATCH 54/59] [Major] moved ObserverHandler to StrolchRealm - no component anymore Now the ObserverHandler is not a StrolchComponent anymore, and can be retrieved from the StrolchRealm. This makes the observer model be part of the realm, not global of the agent. --- .../li/strolch/persistence/xml/XmlPersistenceHandler.java | 7 +------ .../persistence/impl/dao/test/ObserverUpdateTest.java | 4 ++-- .../cachedruntime/config/StrolchConfiguration.xml | 5 ----- .../existingDbRuntime/config/StrolchConfiguration.xml | 5 ----- .../transactionalruntime/config/StrolchConfiguration.xml | 5 ----- 5 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 0892ed331..59663ef41 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -34,7 +34,6 @@ import li.strolch.persistence.xml.model.AuditContextFactory; import li.strolch.persistence.xml.model.OrderContextFactory; import li.strolch.persistence.xml.model.ResourceContextFactory; import li.strolch.runtime.configuration.ComponentConfiguration; -import li.strolch.runtime.observer.ObserverHandler; import ch.eitchnet.privilege.model.Certificate; import ch.eitchnet.xmlpers.api.IoMode; import ch.eitchnet.xmlpers.api.PersistenceConstants; @@ -81,11 +80,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten @Override public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) { PersistenceTransaction tx = this.persistenceManager.openTx(realm.getRealm()); - XmlStrolchTransaction strolchTx = new XmlStrolchTransaction(realm, certificate, action, tx, this); - if (getContainer().hasComponent(ObserverHandler.class)) { - strolchTx.setObserverHandler(getContainer().getComponent(ObserverHandler.class)); - } - return strolchTx; + return new XmlStrolchTransaction(realm, certificate, action, tx, this); } @Override diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index f8aeed7f7..559d1e2e8 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -25,6 +25,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import li.strolch.agent.api.Observer; +import li.strolch.agent.api.ObserverHandler; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.State; @@ -32,8 +34,6 @@ import li.strolch.model.StrolchRootElement; import li.strolch.model.Tags; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.StrolchConstants; -import li.strolch.runtime.observer.Observer; -import li.strolch.runtime.observer.ObserverHandler; import li.strolch.runtime.privilege.PrivilegeHandler; import li.strolch.testbase.runtime.RuntimeMock; diff --git a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml index d3bb5edd6..9eb4d1fcf 100644 --- a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml @@ -34,10 +34,5 @@ true - - ObserverHandler - li.strolch.runtime.observer.ObserverHandler - li.strolch.runtime.observer.DefaultObserverHandler - \ No newline at end of file diff --git a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml index 6236d62b9..eec57334a 100644 --- a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml +++ b/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml @@ -33,10 +33,5 @@ true - - ObserverHandler - li.strolch.runtime.observer.ObserverHandler - li.strolch.runtime.observer.DefaultObserverHandler - \ No newline at end of file diff --git a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml index d6bdf4eb0..017e5165b 100644 --- a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml @@ -34,10 +34,5 @@ true - - ObserverHandler - li.strolch.runtime.observer.ObserverHandler - li.strolch.runtime.observer.DefaultObserverHandler - \ No newline at end of file From 970cf990940f18c5b05bbc72510b8e65174aaaa2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 19:30:07 +0200 Subject: [PATCH 55/59] [Minor] fixed broken tests due to wrong checking for observer updates --- src/test/resources/cachedruntime/config/StrolchConfiguration.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml index 9eb4d1fcf..d29ebd052 100644 --- a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml +++ b/src/test/resources/cachedruntime/config/StrolchConfiguration.xml @@ -24,6 +24,7 @@ CACHED true + true From 0b4a1a921cedaa3c441c95591a80381a9e86fc7e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 19:32:37 +0200 Subject: [PATCH 56/59] [Minor] fixed broken tests due to wrong checking for observer updates --- .../persistence/impl/dao/test/ObserverUpdateTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java index 559d1e2e8..22ff19569 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java @@ -26,7 +26,7 @@ import java.util.List; import java.util.Map; import li.strolch.agent.api.Observer; -import li.strolch.agent.api.ObserverHandler; +import li.strolch.agent.api.StrolchRealm; import li.strolch.model.Order; import li.strolch.model.Resource; import li.strolch.model.State; @@ -110,21 +110,22 @@ public class ObserverUpdateTest { // register an observer for orders and resources ElementAddedObserver observer = new ElementAddedObserver(); - runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.ORDER, observer); - runtimeMock.getContainer().getComponent(ObserverHandler.class).registerObserver(Tags.RESOURCE, observer); + StrolchRealm realm = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM); + realm.getObserverHandler().registerObserver(Tags.ORDER, observer); + realm.getObserverHandler().registerObserver(Tags.RESOURCE, observer); PrivilegeHandler privilegeHandler = runtimeMock.getAgent().getContainer().getPrivilegeHandler(); Certificate certificate = privilegeHandler.authenticate(TEST, TEST.getBytes()); // create order Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", new Date(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, TEST)) { + try (StrolchTransaction tx = realm.openTx(certificate, TEST)) { tx.getOrderMap().add(tx, newOrder); } // create resource Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx(certificate, TEST)) { + try (StrolchTransaction tx = realm.openTx(certificate, TEST)) { tx.getResourceMap().add(tx, newResource); } From d8a7231855e03b4f7bea6fd7a1d5f10d2729814c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 25 Aug 2014 22:52:52 +0200 Subject: [PATCH 57/59] [Minor] throw an exception for not implemented method --- src/main/java/li/strolch/persistence/xml/XmlAuditDao.java | 6 +++--- src/main/java/li/strolch/persistence/xml/XmlOrderDao.java | 4 ++-- .../java/li/strolch/persistence/xml/XmlResourceDao.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java b/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java index 7aefcdd5e..47695ece7 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java @@ -82,7 +82,7 @@ public class XmlAuditDao implements AuditDao { public long querySize(String type, DateRange dateRange) { long size = 0; - // TODO re-think this nonsense... this has a huge performance penalty + // TODO re-think this nonsense... this might have a huge performance penalty SubTypeRef subTypeRef = getTypeRef(type); Set keySet = this.tx.getMetadataDao().queryKeySet(subTypeRef); for (String key : keySet) { @@ -191,7 +191,7 @@ public class XmlAuditDao implements AuditDao { @Override public List doQuery(AuditQuery query, AuditVisitor auditVisitor) { - // TODO Auto-generated method stub - return null; + // TODO implement XML file based querying... + throw new UnsupportedOperationException("not yet implemented!"); } } diff --git a/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java b/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java index 79db5ee6e..a5b109d50 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java @@ -37,7 +37,7 @@ public class XmlOrderDao extends AbstractDao implements OrderDao { @Override public List doQuery(OrderQuery query, OrderVisitor orderVisitor) { - // TODO Auto-generated method stub - return null; + // TODO implement XML file based querying... + throw new UnsupportedOperationException("not yet implemented!"); } } diff --git a/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java b/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java index d7827fcfd..1e8c1f114 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java +++ b/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java @@ -37,7 +37,7 @@ public class XmlResourceDao extends AbstractDao implements ResourceDao @Override public List doQuery(ResourceQuery query, ResourceVisitor resourceVisitor) { - // TODO Auto-generated method stub - return null; + // TODO implement XML file based querying... + throw new UnsupportedOperationException("not yet implemented!"); } } From 4f28ec129facb4220446cfdc236ef42463904aea Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 8 Sep 2014 13:36:00 +0200 Subject: [PATCH 58/59] [New] Added privilege checking for StrolchQueries --- .../li/strolch/persistence/xml/XmlPersistenceHandler.java | 2 +- .../li/strolch/persistence/xml/XmlStrolchTransaction.java | 7 ++++--- src/test/resources/cachedruntime/config/PrivilegeModel.xml | 3 +++ .../resources/existingDbRuntime/config/PrivilegeModel.xml | 3 +++ .../transactionalruntime/config/PrivilegeModel.xml | 3 +++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java index 59663ef41..a281bb768 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java +++ b/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java @@ -80,7 +80,7 @@ public class XmlPersistenceHandler extends StrolchComponent implements Persisten @Override public StrolchTransaction openTx(StrolchRealm realm, Certificate certificate, String action) { PersistenceTransaction tx = this.persistenceManager.openTx(realm.getRealm()); - return new XmlStrolchTransaction(realm, certificate, action, tx, this); + return new XmlStrolchTransaction(getContainer().getPrivilegeHandler(), realm, certificate, action, tx, this); } @Override diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java index 90b8e56aa..92098bd6f 100644 --- a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java +++ b/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java @@ -20,6 +20,7 @@ import java.util.Set; import li.strolch.agent.api.StrolchRealm; import li.strolch.persistence.api.AbstractTransaction; import li.strolch.persistence.api.PersistenceHandler; +import li.strolch.runtime.privilege.PrivilegeHandler; import ch.eitchnet.privilege.model.Certificate; import ch.eitchnet.xmlpers.api.ModificationResult; import ch.eitchnet.xmlpers.api.PersistenceTransaction; @@ -30,9 +31,9 @@ public class XmlStrolchTransaction extends AbstractTransaction { private XmlPersistenceHandler persistenceHandler; private PersistenceTransaction tx; - public XmlStrolchTransaction(StrolchRealm realm, Certificate certificate, String action, PersistenceTransaction tx, - XmlPersistenceHandler persistenceHandler) { - super(realm, certificate, action); + public XmlStrolchTransaction(PrivilegeHandler privilegeHandler, StrolchRealm realm, Certificate certificate, + String action, PersistenceTransaction tx, XmlPersistenceHandler persistenceHandler) { + super(privilegeHandler, realm, certificate, action); this.persistenceHandler = persistenceHandler; this.tx = tx; } diff --git a/src/test/resources/cachedruntime/config/PrivilegeModel.xml b/src/test/resources/cachedruntime/config/PrivilegeModel.xml index 14af39def..0ed6ce7b2 100644 --- a/src/test/resources/cachedruntime/config/PrivilegeModel.xml +++ b/src/test/resources/cachedruntime/config/PrivilegeModel.xml @@ -31,6 +31,9 @@ true + + true + \ No newline at end of file diff --git a/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml b/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml index 14af39def..0ed6ce7b2 100644 --- a/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml +++ b/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml @@ -31,6 +31,9 @@ true + + true + \ No newline at end of file diff --git a/src/test/resources/transactionalruntime/config/PrivilegeModel.xml b/src/test/resources/transactionalruntime/config/PrivilegeModel.xml index 14af39def..0ed6ce7b2 100644 --- a/src/test/resources/transactionalruntime/config/PrivilegeModel.xml +++ b/src/test/resources/transactionalruntime/config/PrivilegeModel.xml @@ -31,6 +31,9 @@ true + + true + \ No newline at end of file From 4427d660992c98ce743f1f981ad12453d2c2b257 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 16 Sep 2014 08:56:24 +0200 Subject: [PATCH 59/59] moved everything to a subdirectory for repo merge --- .gitignore => li.strolch.persistence.xml/.gitignore | 0 LICENSE => li.strolch.persistence.xml/LICENSE | 0 README.md => li.strolch.persistence.xml/README.md | 0 pom.xml => li.strolch.persistence.xml/pom.xml | 0 .../src}/main/java/li/strolch/persistence/xml/AbstractDao.java | 0 .../src}/main/java/li/strolch/persistence/xml/XmlAuditDao.java | 0 .../src}/main/java/li/strolch/persistence/xml/XmlOrderDao.java | 0 .../java/li/strolch/persistence/xml/XmlPersistenceHandler.java | 0 .../src}/main/java/li/strolch/persistence/xml/XmlResourceDao.java | 0 .../java/li/strolch/persistence/xml/XmlStrolchTransaction.java | 0 .../li/strolch/persistence/xml/model/AuditContextFactory.java | 0 .../java/li/strolch/persistence/xml/model/AuditDomParser.java | 0 .../java/li/strolch/persistence/xml/model/AuditParserFactory.java | 0 .../li/strolch/persistence/xml/model/OrderContextFactory.java | 0 .../java/li/strolch/persistence/xml/model/OrderDomParser.java | 0 .../java/li/strolch/persistence/xml/model/OrderParserFactory.java | 0 .../li/strolch/persistence/xml/model/ResourceContextFactory.java | 0 .../java/li/strolch/persistence/xml/model/ResourceDomParser.java | 0 .../li/strolch/persistence/xml/model/ResourceParserFactory.java | 0 .../src}/main/resources/componentVersion.properties | 0 .../java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java | 0 .../li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java | 0 .../li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java | 0 .../persistence/impl/dao/test/XmlTransactionalDaoTest.java | 0 .../src}/test/resources/cachedruntime/config/PrivilegeConfig.xml | 0 .../src}/test/resources/cachedruntime/config/PrivilegeModel.xml | 0 .../test/resources/cachedruntime/config/StrolchConfiguration.xml | 0 .../test/resources/existingDbRuntime/config/PrivilegeConfig.xml | 0 .../test/resources/existingDbRuntime/config/PrivilegeModel.xml | 0 .../resources/existingDbRuntime/config/StrolchConfiguration.xml | 0 .../existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml | 0 .../existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml | 0 {src => li.strolch.persistence.xml/src}/test/resources/log4j.xml | 0 .../resources/transactionalruntime/config/PrivilegeConfig.xml | 0 .../test/resources/transactionalruntime/config/PrivilegeModel.xml | 0 .../transactionalruntime/config/StrolchConfiguration.xml | 0 36 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => li.strolch.persistence.xml/.gitignore (100%) rename LICENSE => li.strolch.persistence.xml/LICENSE (100%) rename README.md => li.strolch.persistence.xml/README.md (100%) rename pom.xml => li.strolch.persistence.xml/pom.xml (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/AbstractDao.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/XmlAuditDao.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/XmlOrderDao.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/XmlResourceDao.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/AuditDomParser.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/OrderDomParser.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java (100%) rename {src => li.strolch.persistence.xml/src}/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java (100%) rename {src => li.strolch.persistence.xml/src}/main/resources/componentVersion.properties (100%) rename {src => li.strolch.persistence.xml/src}/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java (100%) rename {src => li.strolch.persistence.xml/src}/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java (100%) rename {src => li.strolch.persistence.xml/src}/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java (100%) rename {src => li.strolch.persistence.xml/src}/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/cachedruntime/config/PrivilegeConfig.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/cachedruntime/config/PrivilegeModel.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/cachedruntime/config/StrolchConfiguration.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/existingDbRuntime/config/PrivilegeConfig.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/existingDbRuntime/config/PrivilegeModel.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/existingDbRuntime/config/StrolchConfiguration.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/log4j.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/transactionalruntime/config/PrivilegeConfig.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/transactionalruntime/config/PrivilegeModel.xml (100%) rename {src => li.strolch.persistence.xml/src}/test/resources/transactionalruntime/config/StrolchConfiguration.xml (100%) diff --git a/.gitignore b/li.strolch.persistence.xml/.gitignore similarity index 100% rename from .gitignore rename to li.strolch.persistence.xml/.gitignore diff --git a/LICENSE b/li.strolch.persistence.xml/LICENSE similarity index 100% rename from LICENSE rename to li.strolch.persistence.xml/LICENSE diff --git a/README.md b/li.strolch.persistence.xml/README.md similarity index 100% rename from README.md rename to li.strolch.persistence.xml/README.md diff --git a/pom.xml b/li.strolch.persistence.xml/pom.xml similarity index 100% rename from pom.xml rename to li.strolch.persistence.xml/pom.xml diff --git a/src/main/java/li/strolch/persistence/xml/AbstractDao.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/AbstractDao.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/AbstractDao.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/AbstractDao.java diff --git a/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/XmlAuditDao.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlAuditDao.java diff --git a/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/XmlOrderDao.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlOrderDao.java diff --git a/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlPersistenceHandler.java diff --git a/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/XmlResourceDao.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlResourceDao.java diff --git a/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/XmlStrolchTransaction.java diff --git a/src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/AuditContextFactory.java diff --git a/src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/AuditDomParser.java diff --git a/src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/AuditParserFactory.java diff --git a/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/OrderContextFactory.java diff --git a/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/OrderDomParser.java diff --git a/src/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/OrderParserFactory.java diff --git a/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/ResourceContextFactory.java diff --git a/src/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/ResourceDomParser.java diff --git a/src/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java b/li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java similarity index 100% rename from src/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java rename to li.strolch.persistence.xml/src/main/java/li/strolch/persistence/xml/model/ResourceParserFactory.java diff --git a/src/main/resources/componentVersion.properties b/li.strolch.persistence.xml/src/main/resources/componentVersion.properties similarity index 100% rename from src/main/resources/componentVersion.properties rename to li.strolch.persistence.xml/src/main/resources/componentVersion.properties diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java similarity index 100% rename from src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java rename to li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ExistingDbTest.java diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java similarity index 100% rename from src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java rename to li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/ObserverUpdateTest.java diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java similarity index 100% rename from src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java rename to li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/XmlCachedDaoTest.java diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java b/li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java similarity index 100% rename from src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java rename to li.strolch.persistence.xml/src/test/java/li/strolch/persistence/impl/dao/test/XmlTransactionalDaoTest.java diff --git a/src/test/resources/cachedruntime/config/PrivilegeConfig.xml b/li.strolch.persistence.xml/src/test/resources/cachedruntime/config/PrivilegeConfig.xml similarity index 100% rename from src/test/resources/cachedruntime/config/PrivilegeConfig.xml rename to li.strolch.persistence.xml/src/test/resources/cachedruntime/config/PrivilegeConfig.xml diff --git a/src/test/resources/cachedruntime/config/PrivilegeModel.xml b/li.strolch.persistence.xml/src/test/resources/cachedruntime/config/PrivilegeModel.xml similarity index 100% rename from src/test/resources/cachedruntime/config/PrivilegeModel.xml rename to li.strolch.persistence.xml/src/test/resources/cachedruntime/config/PrivilegeModel.xml diff --git a/src/test/resources/cachedruntime/config/StrolchConfiguration.xml b/li.strolch.persistence.xml/src/test/resources/cachedruntime/config/StrolchConfiguration.xml similarity index 100% rename from src/test/resources/cachedruntime/config/StrolchConfiguration.xml rename to li.strolch.persistence.xml/src/test/resources/cachedruntime/config/StrolchConfiguration.xml diff --git a/src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml b/li.strolch.persistence.xml/src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml similarity index 100% rename from src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml rename to li.strolch.persistence.xml/src/test/resources/existingDbRuntime/config/PrivilegeConfig.xml diff --git a/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml b/li.strolch.persistence.xml/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml similarity index 100% rename from src/test/resources/existingDbRuntime/config/PrivilegeModel.xml rename to li.strolch.persistence.xml/src/test/resources/existingDbRuntime/config/PrivilegeModel.xml diff --git a/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml b/li.strolch.persistence.xml/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml similarity index 100% rename from src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml rename to li.strolch.persistence.xml/src/test/resources/existingDbRuntime/config/StrolchConfiguration.xml diff --git a/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml b/li.strolch.persistence.xml/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml similarity index 100% rename from src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml rename to li.strolch.persistence.xml/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Order/MyType/@1.xml diff --git a/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml b/li.strolch.persistence.xml/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml similarity index 100% rename from src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml rename to li.strolch.persistence.xml/src/test/resources/existingDbRuntime/dbStore/defaultRealm/Resource/MyType/@1.xml diff --git a/src/test/resources/log4j.xml b/li.strolch.persistence.xml/src/test/resources/log4j.xml similarity index 100% rename from src/test/resources/log4j.xml rename to li.strolch.persistence.xml/src/test/resources/log4j.xml diff --git a/src/test/resources/transactionalruntime/config/PrivilegeConfig.xml b/li.strolch.persistence.xml/src/test/resources/transactionalruntime/config/PrivilegeConfig.xml similarity index 100% rename from src/test/resources/transactionalruntime/config/PrivilegeConfig.xml rename to li.strolch.persistence.xml/src/test/resources/transactionalruntime/config/PrivilegeConfig.xml diff --git a/src/test/resources/transactionalruntime/config/PrivilegeModel.xml b/li.strolch.persistence.xml/src/test/resources/transactionalruntime/config/PrivilegeModel.xml similarity index 100% rename from src/test/resources/transactionalruntime/config/PrivilegeModel.xml rename to li.strolch.persistence.xml/src/test/resources/transactionalruntime/config/PrivilegeModel.xml diff --git a/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml b/li.strolch.persistence.xml/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml similarity index 100% rename from src/test/resources/transactionalruntime/config/StrolchConfiguration.xml rename to li.strolch.persistence.xml/src/test/resources/transactionalruntime/config/StrolchConfiguration.xml