From f631d636230719e78c338ec3ce8f19812ef59297 Mon Sep 17 00:00:00 2001 From: datanucleus Date: Wed, 4 Dec 2013 16:03:27 +0000 Subject: [PATCH] merge JDO samples --- jdoql_typesafe/LICENSE.txt | 191 +++++++++++++ jdoql_typesafe/README.md | 19 ++ jdoql_typesafe/assembly.xml | 28 ++ jdoql_typesafe/pom.xml | 151 ++++++++++ .../samples/jdo/query/Inventory.java | 57 ++++ .../datanucleus/samples/jdo/query/Main.java | 237 ++++++++++++++++ .../datanucleus/samples/jdo/query/Person.java | 25 ++ .../samples/jdo/query/Product.java | 44 +++ .../main/resources/META-INF/persistence.xml | 23 ++ .../src/main/resources/log4j.properties | 20 ++ many_to_many/LICENSE.txt | 191 +++++++++++++ many_to_many/README.md | 20 ++ many_to_many/assembly.xml | 28 ++ many_to_many/pom.xml | 145 ++++++++++ .../samples/jdo/many_many/Customer.java | 59 ++++ .../samples/jdo/many_many/Main.java | 161 +++++++++++ .../samples/jdo/many_many/Supplier.java | 69 +++++ .../main/resources/META-INF/persistence.xml | 22 ++ .../src/main/resources/log4j.properties | 20 ++ .../samples/jdo/many_many/package-h2.orm | 37 +++ .../samples/jdo/many_many/package.jdo | 22 ++ many_to_many_attributed/LICENSE.txt | 191 +++++++++++++ many_to_many_attributed/README.md | 20 ++ many_to_many_attributed/pom.xml | 145 ++++++++++ .../BusinessRelation.java | 100 +++++++ .../jdo/many_many_attributed/Customer.java | 58 ++++ .../jdo/many_many_attributed/Main.java | 122 ++++++++ .../jdo/many_many_attributed/Supplier.java | 63 +++++ .../main/resources/META-INF/persistence.xml | 22 ++ .../src/main/resources/log4j.properties | 20 ++ .../jdo/many_many_attributed/package.jdo | 30 ++ one_to_many_fk_bidir/LICENSE.txt | 191 +++++++++++++ one_to_many_fk_bidir/README.md | 16 ++ one_to_many_fk_bidir/assembly.xml | 28 ++ one_to_many_fk_bidir/pom.xml | 145 ++++++++++ .../samples/jdo/one_many_bidir/Card.java | 103 +++++++ .../samples/jdo/one_many_bidir/Pack.java | 38 +++ .../main/resources/META-INF/persistence.xml | 22 ++ .../src/main/resources/log4j.properties | 20 ++ .../samples/jdo/one_many_bidir/package-h2.orm | 25 ++ .../samples/jdo/one_many_bidir/package.jdo | 19 ++ one_to_many_join_bidir/LICENSE.txt | 191 +++++++++++++ one_to_many_join_bidir/README.md | 20 ++ one_to_many_join_bidir/assembly.xml | 28 ++ one_to_many_join_bidir/pom.xml | 145 ++++++++++ .../samples/jdo/one_many_bidir/Card.java | 103 +++++++ .../samples/jdo/one_many_bidir/Pack.java | 38 +++ .../main/resources/META-INF/persistence.xml | 22 ++ .../src/main/resources/log4j.properties | 20 ++ .../samples/jdo/one_many_bidir/package-h2.orm | 26 ++ .../samples/jdo/one_many_bidir/package.jdo | 17 ++ one_to_one_embedded/LICENSE.txt | 191 +++++++++++++ one_to_one_embedded/README.md | 22 ++ one_to_one_embedded/assembly.xml | 28 ++ one_to_one_embedded/pom.xml | 145 ++++++++++ .../samples/jdo/one_one_embedded/Account.java | 72 +++++ .../samples/jdo/one_one_embedded/Login.java | 56 ++++ .../samples/jdo/one_one_embedded/Main.java | 93 ++++++ .../main/resources/META-INF/persistence.xml | 23 ++ .../src/main/resources/log4j.properties | 20 ++ .../jdo/one_one_embedded/package-h2.orm | 22 ++ spatial/LICENSE.txt | 191 +++++++++++++ spatial/README.md | 23 ++ spatial/assembly.xml | 28 ++ spatial/pom.xml | 180 ++++++++++++ .../datanucleus/samples/jdo/spatial/Main.java | 95 +++++++ .../samples/jdo/spatial/Position.java | 31 ++ .../main/resources/META-INF/persistence.xml | 21 ++ spatial/src/main/resources/log4j.properties | 20 ++ .../samples/jdo/spatial/package.jdo | 12 + tutorial/LICENSE.txt | 191 +++++++++++++ tutorial/README.md | 40 +++ tutorial/assembly.xml | 29 ++ tutorial/build.xml | 151 ++++++++++ tutorial/log4j.properties | 24 ++ tutorial/pom.xml | 267 ++++++++++++++++++ .../samples/jdo/tutorial/Book.java | 76 +++++ .../samples/jdo/tutorial/Inventory.java | 56 ++++ .../samples/jdo/tutorial/Main.java | 176 ++++++++++++ .../samples/jdo/tutorial/Product.java | 88 ++++++ .../main/resources/META-INF/persistence.xml | 55 ++++ tutorial/src/main/resources/hbase-site.xml | 10 + tutorial/src/main/resources/package-excel.orm | 44 +++ tutorial/src/main/resources/package-h2.orm | 37 +++ tutorial/src/main/resources/package-hbase.orm | 44 +++ tutorial/src/main/resources/package-hsql.orm | 40 +++ .../src/main/resources/package-mongodb.orm | 44 +++ tutorial/src/main/resources/package-mysql.orm | 37 +++ tutorial/src/main/resources/package-neo4j.orm | 44 +++ tutorial/src/main/resources/package-odf.orm | 46 +++ 90 files changed, 6329 insertions(+) create mode 100644 jdoql_typesafe/LICENSE.txt create mode 100644 jdoql_typesafe/README.md create mode 100644 jdoql_typesafe/assembly.xml create mode 100644 jdoql_typesafe/pom.xml create mode 100644 jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Inventory.java create mode 100644 jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Main.java create mode 100644 jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Person.java create mode 100644 jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Product.java create mode 100644 jdoql_typesafe/src/main/resources/META-INF/persistence.xml create mode 100644 jdoql_typesafe/src/main/resources/log4j.properties create mode 100644 many_to_many/LICENSE.txt create mode 100644 many_to_many/README.md create mode 100644 many_to_many/assembly.xml create mode 100644 many_to_many/pom.xml create mode 100644 many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Customer.java create mode 100644 many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Main.java create mode 100644 many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Supplier.java create mode 100644 many_to_many/src/main/resources/META-INF/persistence.xml create mode 100644 many_to_many/src/main/resources/log4j.properties create mode 100644 many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package-h2.orm create mode 100644 many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package.jdo create mode 100644 many_to_many_attributed/LICENSE.txt create mode 100644 many_to_many_attributed/README.md create mode 100644 many_to_many_attributed/pom.xml create mode 100644 many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/BusinessRelation.java create mode 100644 many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Customer.java create mode 100644 many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Main.java create mode 100644 many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Supplier.java create mode 100644 many_to_many_attributed/src/main/resources/META-INF/persistence.xml create mode 100644 many_to_many_attributed/src/main/resources/log4j.properties create mode 100644 many_to_many_attributed/src/main/resources/org/datanucleus/samples/jdo/many_many_attributed/package.jdo create mode 100644 one_to_many_fk_bidir/LICENSE.txt create mode 100644 one_to_many_fk_bidir/README.md create mode 100644 one_to_many_fk_bidir/assembly.xml create mode 100644 one_to_many_fk_bidir/pom.xml create mode 100644 one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java create mode 100644 one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java create mode 100644 one_to_many_fk_bidir/src/main/resources/META-INF/persistence.xml create mode 100644 one_to_many_fk_bidir/src/main/resources/log4j.properties create mode 100644 one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm create mode 100644 one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo create mode 100644 one_to_many_join_bidir/LICENSE.txt create mode 100644 one_to_many_join_bidir/README.md create mode 100644 one_to_many_join_bidir/assembly.xml create mode 100644 one_to_many_join_bidir/pom.xml create mode 100644 one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java create mode 100644 one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java create mode 100644 one_to_many_join_bidir/src/main/resources/META-INF/persistence.xml create mode 100644 one_to_many_join_bidir/src/main/resources/log4j.properties create mode 100644 one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm create mode 100644 one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo create mode 100644 one_to_one_embedded/LICENSE.txt create mode 100644 one_to_one_embedded/README.md create mode 100644 one_to_one_embedded/assembly.xml create mode 100644 one_to_one_embedded/pom.xml create mode 100644 one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Account.java create mode 100644 one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Login.java create mode 100644 one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Main.java create mode 100644 one_to_one_embedded/src/main/resources/META-INF/persistence.xml create mode 100644 one_to_one_embedded/src/main/resources/log4j.properties create mode 100644 one_to_one_embedded/src/main/resources/org/datanucleus/samples/jdo/one_one_embedded/package-h2.orm create mode 100644 spatial/LICENSE.txt create mode 100644 spatial/README.md create mode 100644 spatial/assembly.xml create mode 100644 spatial/pom.xml create mode 100644 spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Main.java create mode 100644 spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Position.java create mode 100644 spatial/src/main/resources/META-INF/persistence.xml create mode 100644 spatial/src/main/resources/log4j.properties create mode 100644 spatial/src/main/resources/org/datanucleus/samples/jdo/spatial/package.jdo create mode 100644 tutorial/LICENSE.txt create mode 100644 tutorial/README.md create mode 100644 tutorial/assembly.xml create mode 100644 tutorial/build.xml create mode 100644 tutorial/log4j.properties create mode 100644 tutorial/pom.xml create mode 100644 tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Book.java create mode 100644 tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Inventory.java create mode 100644 tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Main.java create mode 100644 tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Product.java create mode 100644 tutorial/src/main/resources/META-INF/persistence.xml create mode 100644 tutorial/src/main/resources/hbase-site.xml create mode 100644 tutorial/src/main/resources/package-excel.orm create mode 100644 tutorial/src/main/resources/package-h2.orm create mode 100644 tutorial/src/main/resources/package-hbase.orm create mode 100644 tutorial/src/main/resources/package-hsql.orm create mode 100644 tutorial/src/main/resources/package-mongodb.orm create mode 100644 tutorial/src/main/resources/package-mysql.orm create mode 100644 tutorial/src/main/resources/package-neo4j.orm create mode 100644 tutorial/src/main/resources/package-odf.orm diff --git a/jdoql_typesafe/LICENSE.txt b/jdoql_typesafe/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/jdoql_typesafe/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/jdoql_typesafe/README.md b/jdoql_typesafe/README.md new file mode 100644 index 0000000..b377293 --- /dev/null +++ b/jdoql_typesafe/README.md @@ -0,0 +1,19 @@ +jdoql_typesafe +============== +The prerequisite is that you need the DataNucleus Maven2 plugin installed. +You can download this plugin from the DataNucleus downloads area. + +1. Set the database configuration in "src/main/resources/META-INF/persistence.xml" + +2. Make sure you have the JDBC driver jar specified in the "pom.xml" file + +3. Run the command: "mvn clean compile" + This builds everything, and enhances the classes + +4. Run the command: "mvn datanucleus:schema-create" + This creates the schema + +5. Run "mvn exec:java" + +6. Run the command: "mvn datanucleus:schema-delete" + This deletes the schema diff --git a/jdoql_typesafe/assembly.xml b/jdoql_typesafe/assembly.xml new file mode 100644 index 0000000..353c232 --- /dev/null +++ b/jdoql_typesafe/assembly.xml @@ -0,0 +1,28 @@ + + src + + zip + + + + + + README* + *.txt + *.xml + *.properties + + + assembly.xml + datanucleus.log + + + + src + + + + + diff --git a/jdoql_typesafe/pom.xml b/jdoql_typesafe/pom.xml new file mode 100644 index 0000000..d3a538f --- /dev/null +++ b/jdoql_typesafe/pom.xml @@ -0,0 +1,151 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-jdo-typesafe_query + jar + 3.2 + DataNucleus AccessPlatform JDO Typesafe Query Sample + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + [3.2.0, ) + + + org.datanucleus + datanucleus-api-jdo + [3.2.0, ) + + + org.datanucleus + datanucleus-rdbms + [3.2.0, ) + + + org.datanucleus + datanucleus-jdo-query + [3.0.2, ) + + + javax.jdo + jdo-api + [3.0, ) + + + + com.h2database + h2 + 1.3.168 + + + junit + junit + 4.9 + test + + + log4j + log4j + [1.2, 1.3) + + + + + + target/classes + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + *.ods + + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + -AqueryMode=FIELD + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + MyTest + ${basedir}/src/main/resources/log4j.properties + false + + + + compile + + enhance + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.query.Main + + + log4j.configuration + file:${basedir}/src/main/resources/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Inventory.java b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Inventory.java new file mode 100644 index 0000000..2e603de --- /dev/null +++ b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Inventory.java @@ -0,0 +1,57 @@ +/********************************************************************** +Copyright (c) 2010 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.query; + +import java.net.URL; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable +public class Inventory +{ + @PrimaryKey + long id; + + String name; + + Set products = new HashSet(); + + Date saleDate; + + URL website; + + public Inventory(long id, String name) + { + this.id = id; + this.name = name; + } + + public void addProduct(Product prod) + { + this.products.add(prod); + } + + public Set getProducts() + { + return this.products; + } +} \ No newline at end of file diff --git a/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Main.java b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Main.java new file mode 100644 index 0000000..c40b27b --- /dev/null +++ b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Main.java @@ -0,0 +1,237 @@ +/********************************************************************** +Copyright (c) 2010 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.query; + +import java.util.Iterator; +import java.util.List; + +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; +import javax.jdo.JDOHelper; +import javax.jdo.Transaction; + +import org.datanucleus.api.jdo.JDOPersistenceManager; +import org.datanucleus.query.typesafe.*; +import org.datanucleus.util.*; + +public class Main +{ + public static void main(String args[]) + { + // Create a PersistenceManagerFactory for this datastore + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("MyTest"); + + System.out.println("DataNucleus AccessPlatform with JDO Query"); + System.out.println("========================================="); + + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx=pm.currentTransaction(); + try + { + tx.begin(); + System.out.println("Persisting Inventory and Products"); + + Inventory inv = new Inventory(1, "Main Shop Inventory"); + Product prd1 = new Product(1, "Walkman", 12.99); + Product prd2 = new Product(2, "Samsonite Suitcase", 53.99); + Product prd3 = new Product(3, "Phillips HD TV", 329.99); + inv.addProduct(prd1); + inv.addProduct(prd2); + inv.addProduct(prd3); + pm.makePersistent(inv); + System.out.println("Inventory and Products have been persisted"); + + Person p1 = new Person(1, "Fred"); + Person p2 = new Person(2, "George"); + Person p3 = new Person(3, "Harry"); + Person p4 = new Person(4, "Simone"); + Person p5 = new Person(5, "Georgia"); + p1.setBestFriend(p2); + p2.setBestFriend(p3); + p3.setBestFriend(p4); + p4.setBestFriend(p5); + pm.makePersistent(p1); + System.out.println("Persons have been persisted"); + + tx.commit(); + } + catch (Exception e) + { + NucleusLogger.GENERAL.error(">> Exception persisting objects", e); + return; + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + System.out.println(""); + + // Perform some query operations + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + + System.out.println("Performing JDO API queries"); + + // TODO Remove this when part of JDO API + JDOPersistenceManager jdopm = (JDOPersistenceManager)pm; + + // Filter + param + result + ordering + // "SELECT FROM Product WHERE this.value < :criticalValue && this.name.startsWith('Wal') + // ORDER BY this.name ASCENDING" + NucleusLogger.GENERAL.info(">> Query1 : Products with filter, ordering, param and result"); + TypesafeQuery tq1 = jdopm.newTypesafeQuery(Product.class); + QProduct cand = QProduct.candidate(); + tq1.filter(cand.value.lt(tq1.doubleParameter("criticalValue")).and(cand.name.startsWith("Wal"))) + .orderBy(cand.name.asc()).setParameter("criticalValue", 40.0); + List results1 = tq1.executeResultList(true, cand.name, cand.value); + if (results1 != null) + { + Iterator iter = results1.iterator(); + while (iter.hasNext()) + { + NucleusLogger.GENERAL.info(">> Result1 " + StringUtils.objectArrayToString(iter.next())); + } + } + + // Ordering + range + // "SELECT FROM Product ORDER BY this.name ASCENDING RANGE 0,2" + NucleusLogger.GENERAL.info(">> Query2 : Products with ordering and range"); + TypesafeQuery tq2 = jdopm.newTypesafeQuery(Product.class); + cand = QProduct.candidate(); + tq2.orderBy(cand.name.asc()).range(0, 2); + List results2 = tq2.executeList(); + if (results2 != null) + { + Iterator iter = results2.iterator(); + while (iter.hasNext()) + { + NucleusLogger.GENERAL.info(">> Result2 " + iter.next()); + } + } + + // Filter using variable + // "SELECT FROM Inventory WHERE this.products.contains(var) && var.name.startsWith('Wal')" + NucleusLogger.GENERAL.info(">> Query3 : Inventory with filter using variable"); + TypesafeQuery tq3 = jdopm.newTypesafeQuery(Inventory.class); + QProduct var3 = QProduct.variable("var"); + QInventory cand3 = QInventory.candidate(); + tq3.filter(cand3.products.contains(var3).and(var3.name.startsWith("Wal"))); + List results3 = tq3.executeList(); + if (results3 != null) + { + Iterator iter = results3.iterator(); + while (iter.hasNext()) + { + NucleusLogger.GENERAL.info(">> Result3 " + iter.next()); + } + } + + // Subquery + // "SELECT FROM Product WHERE this.value < (SELECT AVG(p.value) FROM Product p)" + TypesafeQuery tq4 = jdopm.newTypesafeQuery(Product.class); + QProduct cand4 = QProduct.candidate(); + TypesafeSubquery tqsub4 = tq4.subquery(Product.class, "p"); + QProduct candsub4 = QProduct.candidate("p"); + tq4.filter(cand4.value.lt(tqsub4.selectUnique(candsub4.value.avg()))); + List results4 = tq4.executeList(); + if (results4 != null) + { + Iterator iter = results4.iterator(); + while (iter.hasNext()) + { + NucleusLogger.GENERAL.info(">> Result4 " + iter.next()); + } + } + + // Recursion + NucleusLogger.GENERAL.info(">> Person recursion query"); + TypesafeQuery tq5 = jdopm.newTypesafeQuery(Person.class); + QPerson cand5 = QPerson.candidate(); + NucleusLogger.GENERAL.info(">> Person recursion START"); + tq5.filter(cand5.bestFriend.bestFriend.name.startsWith("George")); + NucleusLogger.GENERAL.info(">> Person recursion done filter"); + List results5 = tq5.executeList(); + if (results5 != null) + { + Iterator iter = results5.iterator(); + while (iter.hasNext()) + { + NucleusLogger.GENERAL.info(">> Result5 " + iter.next()); + } + } + + + tx.commit(); + } + catch (Error er) + { + NucleusLogger.GENERAL.error(">> Error querying objects", er); + return; + } + catch (Exception e) + { + NucleusLogger.GENERAL.error(">> Exception querying objects", e); + return; + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + System.out.println(""); + + // Clean out the database + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + System.out.println("Deleting Inventory+Product from persistence"); + Query q = pm.newQuery(Inventory.class); + long numberInstancesDeleted = q.deletePersistentAll(); + System.out.println("Deleted " + numberInstancesDeleted + " inventories"); + Query q2 = pm.newQuery(Product.class); + numberInstancesDeleted = q2.deletePersistentAll(); + System.out.println("Deleted " + numberInstancesDeleted + " products"); + + tx.commit(); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + + System.out.println(""); + System.out.println("End of Sample"); + } +} diff --git a/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Person.java b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Person.java new file mode 100644 index 0000000..f44316a --- /dev/null +++ b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Person.java @@ -0,0 +1,25 @@ +package org.datanucleus.samples.jdo.query; + +import javax.jdo.annotations.*; + +@PersistenceCapable +public class Person +{ + @PrimaryKey + long id; + + String name; + + Person bestFriend; + + public Person(long id, String name) + { + this.id = id; + this.name = name; + } + + public void setBestFriend(Person per) + { + this.bestFriend = per; + } +} diff --git a/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Product.java b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Product.java new file mode 100644 index 0000000..1dae4a8 --- /dev/null +++ b/jdoql_typesafe/src/main/java/org/datanucleus/samples/jdo/query/Product.java @@ -0,0 +1,44 @@ +/********************************************************************** +Copyright (c) 2010 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.query; + +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable +public class Product +{ + @PrimaryKey + long id; + + String name; + + double value; + + public Product(long id, String name, double value) + { + this.id = id; + this.name = name; + this.value = value; + } + + public String toString() + { + return "Product: " + id + " name=" + name + " value=" + value; + } +} \ No newline at end of file diff --git a/jdoql_typesafe/src/main/resources/META-INF/persistence.xml b/jdoql_typesafe/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..e72f55c --- /dev/null +++ b/jdoql_typesafe/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,23 @@ + + + + + org.datanucleus.samples.jdo.query.Person + org.datanucleus.samples.jdo.query.Product + org.datanucleus.samples.jdo.query.Inventory + + + + + + + + + + + + + diff --git a/jdoql_typesafe/src/main/resources/log4j.properties b/jdoql_typesafe/src/main/resources/log4j.properties new file mode 100644 index 0000000..91e760b --- /dev/null +++ b/jdoql_typesafe/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + diff --git a/many_to_many/LICENSE.txt b/many_to_many/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/many_to_many/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/many_to_many/README.md b/many_to_many/README.md new file mode 100644 index 0000000..30bdae7 --- /dev/null +++ b/many_to_many/README.md @@ -0,0 +1,20 @@ +many_to_many +============ +The prerequisite is that you need the DataNucleus Maven2 plugin installed. +You can download this plugin from the DataNucleus downloads area. + +1. Set the database configuration in "src/main/resources/META-INF/persistence.xml" + +2. Make sure you have the JDBC driver jar specified in the "pom.xml" file + +3. Run the command: "mvn clean compile" + This builds everything, and enhances the classes + +4. Run the command: "mvn datanucleus:schema-create" + This creates the schema + +5. Run some persistence code (to be added) + +6. Run the command: "mvn datanucleus:schema-delete" + This deletes the schema + diff --git a/many_to_many/assembly.xml b/many_to_many/assembly.xml new file mode 100644 index 0000000..353c232 --- /dev/null +++ b/many_to_many/assembly.xml @@ -0,0 +1,28 @@ + + src + + zip + + + + + + README* + *.txt + *.xml + *.properties + + + assembly.xml + datanucleus.log + + + + src + + + + + diff --git a/many_to_many/pom.xml b/many_to_many/pom.xml new file mode 100644 index 0000000..18ad38c --- /dev/null +++ b/many_to_many/pom.xml @@ -0,0 +1,145 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-jdo-many_many + jar + 3.2 + DataNucleus AccessPlatform JDO Many-to-Many Relation Sample + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + [3.2.0, ) + + + org.datanucleus + datanucleus-api-jdo + [3.2.0, ) + + + org.datanucleus + datanucleus-rdbms + [3.2.0, ) + + + javax.jdo + jdo-api + [3.0, ) + + + + com.h2database + h2 + 1.3.168 + + + junit + junit + 4.9 + test + + + log4j + log4j + [1.2, 1.3) + + + + + + target/classes + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + *.ods + + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + MyTest + ${basedir}/src/main/resources/log4j.properties + false + + + + compile + + enhance + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.many_many.Main + + + log4j.configuration + file:${basedir}/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Customer.java b/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Customer.java new file mode 100644 index 0000000..4cad03d --- /dev/null +++ b/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Customer.java @@ -0,0 +1,59 @@ +/********************************************************************** +Copyright (c) 2006 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.many_many; + +import java.util.Collection; +import java.util.HashSet; + +public class Customer +{ + String name = null; + String description = null; + Collection suppliers = new HashSet(); + + public Customer(String name, String desc) + { + this.name = name; + this.description = desc; + } + + public void addSupplier(Supplier supplier) + { + suppliers.add(supplier); + } + + public void removeSupplier(Supplier supplier) + { + suppliers.remove(supplier); + } + + public Collection getSuppliers() + { + return suppliers; + } + + public int getNumberOfSuppliers() + { + return suppliers.size(); + } + + public String toString() + { + return "Customer : " + name + " [" + description + "] - " + suppliers.size() + " suppliers"; + } +} diff --git a/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Main.java b/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Main.java new file mode 100644 index 0000000..650557c --- /dev/null +++ b/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Main.java @@ -0,0 +1,161 @@ +/********************************************************************** +Copyright (c) 2006 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.many_many; + +import java.util.Collection; +import java.util.Iterator; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Transaction; + +public class Main +{ + public Main() + { + super(); + } + + public static void main(String[] args) + { + System.out.println("DataNucleus Samples : M-N Relation"); + System.out.println("==================================="); + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("datanucleus.properties"); + + // Persist some objects + System.out.println(">> Persisting some Customers and Suppliers"); + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + Object[] custIds = new Object[2]; + Object[] suppIds = new Object[3]; + try + { + tx.begin(); + Customer cust1 = new Customer("DFG Stores", "Small shop in London"); + Customer cust2 = new Customer("Kevins Cards", "Gift shop"); + Supplier supp1 = new Supplier("Stationery Direct", "123 The boulevard, Milton Keynes, UK"); + Supplier supp2 = new Supplier("Grocery Wholesale", "56 Jones Industrial Estate, London, UK"); + Supplier supp3 = new Supplier("Makro", "1 Parkville, Wembley, UK"); + + pm.makePersistent(cust1); + pm.makePersistent(cust2); + pm.makePersistent(supp1); + pm.makePersistent(supp2); + pm.makePersistent(supp3); + tx.commit(); + + custIds[0] = JDOHelper.getObjectId(cust1); + custIds[1] = JDOHelper.getObjectId(cust2); + suppIds[0] = JDOHelper.getObjectId(supp1); + suppIds[1] = JDOHelper.getObjectId(supp2); + suppIds[2] = JDOHelper.getObjectId(supp3); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + + // Establish the relationships + System.out.println(">> Adding relationships between Customers and Suppliers"); + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + + Customer cust1 = (Customer)pm.getObjectById(custIds[0]); + Customer cust2 = (Customer)pm.getObjectById(custIds[1]); + Supplier supp1 = (Supplier)pm.getObjectById(suppIds[0]); + Supplier supp2 = (Supplier)pm.getObjectById(suppIds[1]); + + // Establish the relation customer1 uses supplier2 + cust1.addSupplier(supp2); + supp2.addCustomer(cust1); + + // Establish the relation customer2 uses supplier1 + supp1.addCustomer(cust2); + cust2.addSupplier(supp1); + + tx.commit(); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(2); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + + System.out.println(">> Retrieving Customer/Supplier"); + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + + Customer cust1 = (Customer)pm.getObjectById(custIds[0]); + System.out.println(">> Retrieved customer : " + cust1); + Collection suppliers = cust1.getSuppliers(); + Iterator supplierIter = suppliers.iterator(); + while (supplierIter.hasNext()) + { + System.out.println(">> with Supplier : " + supplierIter.next()); + } + + Supplier supp2 = (Supplier)pm.getObjectById(suppIds[1]); + System.out.println(">> Retrieved supplier : " + supp2); + Collection customers = supp2.getCustomers(); + Iterator customerIter = customers.iterator(); + while (customerIter.hasNext()) + { + System.out.println(">> with Customers : " + customerIter.next()); + } + + tx.commit(); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(3); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + } +} diff --git a/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Supplier.java b/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Supplier.java new file mode 100644 index 0000000..6fed831 --- /dev/null +++ b/many_to_many/src/main/java/org/datanucleus/samples/jdo/many_many/Supplier.java @@ -0,0 +1,69 @@ +/********************************************************************** +Copyright (c) 2006 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.many_many; + +import java.util.Collection; +import java.util.HashSet; + +public class Supplier +{ + String name = null; + String address = null; + Collection customers = new HashSet(); + + public Supplier(String name,String address) + { + this.name = name; + this.address = address; + } + + public String getName() + { + return name; + } + + public String getAddress() + { + return address; + } + + public void addCustomer(Customer customer) + { + customers.add(customer); + } + + public void removeCustomer(Customer customer) + { + customers.remove(customer); + } + + public Collection getCustomers() + { + return customers; + } + + public int getNumberOfCustomers() + { + return customers.size(); + } + + public String toString() + { + return "Supplier : " + name + " [" + address + "] - " + customers.size() + " customers"; + } +} diff --git a/many_to_many/src/main/resources/META-INF/persistence.xml b/many_to_many/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..80fcbf3 --- /dev/null +++ b/many_to_many/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,22 @@ + + + + + org/datanucleus/samples/jdo/many_many/package.jdo + + + + + + + + + + + + + + diff --git a/many_to_many/src/main/resources/log4j.properties b/many_to_many/src/main/resources/log4j.properties new file mode 100644 index 0000000..91e760b --- /dev/null +++ b/many_to_many/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + diff --git a/many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package-h2.orm b/many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package-h2.orm new file mode 100644 index 0000000..0d43dd8 --- /dev/null +++ b/many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package-h2.orm @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package.jdo b/many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package.jdo new file mode 100644 index 0000000..bcf26d6 --- /dev/null +++ b/many_to_many/src/main/resources/org/datanucleus/samples/jdo/many_many/package.jdo @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/many_to_many_attributed/LICENSE.txt b/many_to_many_attributed/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/many_to_many_attributed/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/many_to_many_attributed/README.md b/many_to_many_attributed/README.md new file mode 100644 index 0000000..4a62564 --- /dev/null +++ b/many_to_many_attributed/README.md @@ -0,0 +1,20 @@ +many_to_many_attributed +======================= +The prerequisite is that you need the DataNucleus Maven2 plugin installed. +You can download this plugin from the DataNucleus downloads area. + +1. Set the database configuration in "src/main/resources/META-INF/persistence.xml" + +2. Make sure you have the JDBC driver jar specified in the "pom.xml" file + +3. Run the command: "mvn clean compile" + This builds everything, and enhances the classes + +4. Run the command: "mvn datanucleus:schema-create" + This creates the schema + +5. Run some persistence code. "mvn clean exec:java" + +6. Run the command: "mvn datanucleus:schema-delete" + This deletes the schema + diff --git a/many_to_many_attributed/pom.xml b/many_to_many_attributed/pom.xml new file mode 100644 index 0000000..878bf35 --- /dev/null +++ b/many_to_many_attributed/pom.xml @@ -0,0 +1,145 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-jdo-many_many_attributed + jar + 3.2 + DataNucleus AccessPlatform JDO Many-to-Many Attributed Relation Sample + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + [3.2.0, ) + + + org.datanucleus + datanucleus-api-jdo + [3.2.0, ) + + + org.datanucleus + datanucleus-rdbms + [3.2.0, ) + + + javax.jdo + jdo-api + [3.0, ) + + + + com.h2database + h2 + 1.3.168 + + + junit + junit + 4.9 + test + + + log4j + log4j + [1.2, 1.3) + + + + + + target/classes + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + *.ods + + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + MyTest + ${basedir}/src/main/resources/log4j.properties + false + + + + compile + + enhance + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.many_many_attributed.Main + + + log4j.configuration + file:${basedir}/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/BusinessRelation.java b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/BusinessRelation.java new file mode 100644 index 0000000..9d63b97 --- /dev/null +++ b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/BusinessRelation.java @@ -0,0 +1,100 @@ +/********************************************************************** +Copyright (c) 2006 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.many_many_attributed; + +import java.io.Serializable; +import java.util.StringTokenizer; + +import javax.jdo.identity.LongIdentity; + +public class BusinessRelation +{ + private Customer customer; + private Supplier supplier; + private String relationLevel; + private String meetingLocation; + + public BusinessRelation(Customer cust, Supplier supp, String level, String meeting) + { + this.customer = cust; + this.supplier = supp; + this.relationLevel = level; + this.meetingLocation = meeting; + } + + public Customer getCustomer() + { + return customer; + } + + public Supplier getSupplier() + { + return supplier; + } + + public String getRelationLevel() + { + return relationLevel; + } + + public String getMeetingLocation() + { + return meetingLocation; + } + + /** + * Primary-Key for BusinessRelation. + * Made up of Customer and Supplier. + */ + public static class PK implements Serializable + { + public LongIdentity customer; // Use same name as field above + public LongIdentity supplier; // Use same name as field above + + public PK() + { + } + + public PK(String s) + { + StringTokenizer st = new StringTokenizer(s, "::"); + this.customer = new LongIdentity(Customer.class, st.nextToken()); + this.supplier = new LongIdentity(Supplier.class, st.nextToken()); + } + + public String toString() + { + return (customer.toString() + "::" + supplier.toString()); + } + + public int hashCode() + { + return customer.hashCode() ^ supplier.hashCode(); + } + + public boolean equals(Object other) + { + if (other != null && (other instanceof PK)) + { + PK otherPK = (PK)other; + return this.customer.equals(otherPK.customer) && this.supplier.equals(otherPK.supplier); + } + return false; + } + } +} diff --git a/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Customer.java b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Customer.java new file mode 100644 index 0000000..ebeb30f --- /dev/null +++ b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Customer.java @@ -0,0 +1,58 @@ +/********************************************************************** +Copyright (c) 2006 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.many_many_attributed; + +import java.util.HashSet; +import java.util.Set; + +public class Customer +{ + long id; + String name = null; + Set supplierRelations = new HashSet(); + + public Customer(String name) + { + this.name = name; + } + + public void addRelation(BusinessRelation rel) + { + supplierRelations.add(rel); + } + + public void removeRelation(BusinessRelation rel) + { + supplierRelations.remove(rel); + } + + public Set getRelations() + { + return supplierRelations; + } + + public int getNumberOfRelations() + { + return supplierRelations.size(); + } + + public String toString() + { + return "Customer : " + name + " - " + supplierRelations.size() + " suppliers"; + } +} diff --git a/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Main.java b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Main.java new file mode 100644 index 0000000..d340a48 --- /dev/null +++ b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Main.java @@ -0,0 +1,122 @@ +/********************************************************************** +Copyright (c) 2006 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.many_many_attributed; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Transaction; + +public class Main +{ + public static void main(String[] args) + { + System.out.println("DataNucleus Samples : M-N Relation (attributed)"); + System.out.println("==============================================="); + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("datanucleus.properties"); + + Customer cust1 = null; + Customer cust2 = null; + Supplier supp1 = null; + Supplier supp2 = null; + Supplier supp3 = null; + + // Persist some objects + System.out.println(">> Persisting some Customers and Suppliers"); + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + try + { + tx.begin(); + + cust1 = new Customer("DFG Stores"); + cust2 = new Customer("Kevins Cards"); + supp1 = new Supplier("Stationery Direct"); + supp2 = new Supplier("Grocery Wholesale"); + supp3 = new Supplier("Makro"); + + pm.makePersistent(cust1); + pm.makePersistent(cust2); + pm.makePersistent(supp1); + pm.makePersistent(supp2); + pm.makePersistent(supp3); + + // We have javax.jdo.option.DetachAllOnCommit set, so all get detached at this point + tx.commit(); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(1); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + + // Establish the relationships + System.out.println(">> Adding relationships between Customers and Suppliers"); + + // Establish the relation customer1 uses supplier2 + BusinessRelation rel1 = new BusinessRelation(cust1, supp2, "Friendly", "Hilton Hotel, London"); + cust1.addRelation(rel1); + supp2.addRelation(rel1); + + // Establish the relation customer2 uses supplier1 + BusinessRelation rel2 = new BusinessRelation(cust2, supp1, "Frosty", "M61 motorway service station junction 23"); + cust2.addRelation(rel2); + supp1.addRelation(rel2); + + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + + // Reattach the changed objects + pm.makePersistent(rel1); + pm.makePersistent(rel2); + + // We have javax.jdo.option.DetachAllOnCommit set, so all get (re)detached at this point + tx.commit(); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(2); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + + // Print out the results + System.out.println(">> Customer1 has " + cust1.getNumberOfRelations() + " relations"); + System.out.println(">> Customer2 has " + cust2.getNumberOfRelations() + " relations"); + System.out.println(">> Supplier1 has " + supp1.getNumberOfRelations() + " relations"); + System.out.println(">> Supplier2 has " + supp2.getNumberOfRelations() + " relations"); + } +} diff --git a/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Supplier.java b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Supplier.java new file mode 100644 index 0000000..5cca006 --- /dev/null +++ b/many_to_many_attributed/src/main/java/org/datanucleus/samples/jdo/many_many_attributed/Supplier.java @@ -0,0 +1,63 @@ +/********************************************************************** +Copyright (c) 2006 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.many_many_attributed; + +import java.util.HashSet; +import java.util.Set; + +public class Supplier +{ + long id; + String name = null; + Set customerRelations = new HashSet(); + + public Supplier(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + public void addRelation(BusinessRelation rel) + { + customerRelations.add(rel); + } + + public void removeRelation(BusinessRelation rel) + { + customerRelations.remove(rel); + } + + public Set getRelations() + { + return customerRelations; + } + + public int getNumberOfRelations() + { + return customerRelations.size(); + } + + public String toString() + { + return "Supplier : " + name + " - " + customerRelations.size() + " customers"; + } +} diff --git a/many_to_many_attributed/src/main/resources/META-INF/persistence.xml b/many_to_many_attributed/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..74337e1 --- /dev/null +++ b/many_to_many_attributed/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,22 @@ + + + + + org/datanucleus/samples/jdo/many_many_attributed/package.jdo + + + + + + + + + + + + + + diff --git a/many_to_many_attributed/src/main/resources/log4j.properties b/many_to_many_attributed/src/main/resources/log4j.properties new file mode 100644 index 0000000..91e760b --- /dev/null +++ b/many_to_many_attributed/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + diff --git a/many_to_many_attributed/src/main/resources/org/datanucleus/samples/jdo/many_many_attributed/package.jdo b/many_to_many_attributed/src/main/resources/org/datanucleus/samples/jdo/many_many_attributed/package.jdo new file mode 100644 index 0000000..cb8763d --- /dev/null +++ b/many_to_many_attributed/src/main/resources/org/datanucleus/samples/jdo/many_many_attributed/package.jdo @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/one_to_many_fk_bidir/LICENSE.txt b/one_to_many_fk_bidir/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/one_to_many_fk_bidir/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/one_to_many_fk_bidir/README.md b/one_to_many_fk_bidir/README.md new file mode 100644 index 0000000..e2c481e --- /dev/null +++ b/one_to_many_fk_bidir/README.md @@ -0,0 +1,16 @@ +one_to_many_fk_bidir +==================== + +The prerequisite is that you need the DataNucleus Maven2 plugin installed. +You can download this plugin from the DataNucleus downloads area. + +1. Set the database configuration in the "src/main/resources/META-INF/persistence.xml" file. + +2. Make sure you have the JDBC driver jar specified in the "pom.xml" file + +3. Run the command: "mvn clean compile" + This builds everything, and enhances the classes + + + +(c) Copyright 2008-2013 DataNucleus diff --git a/one_to_many_fk_bidir/assembly.xml b/one_to_many_fk_bidir/assembly.xml new file mode 100644 index 0000000..353c232 --- /dev/null +++ b/one_to_many_fk_bidir/assembly.xml @@ -0,0 +1,28 @@ + + src + + zip + + + + + + README* + *.txt + *.xml + *.properties + + + assembly.xml + datanucleus.log + + + + src + + + + + diff --git a/one_to_many_fk_bidir/pom.xml b/one_to_many_fk_bidir/pom.xml new file mode 100644 index 0000000..e11bc0f --- /dev/null +++ b/one_to_many_fk_bidir/pom.xml @@ -0,0 +1,145 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-one-many-bidir-fk + jar + 3.2 + DataNucleus AccessPlatform JDO One-to-Many FK Relation Sample + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + [3.2.0, ) + + + org.datanucleus + datanucleus-api-jdo + [3.2.0, ) + + + org.datanucleus + datanucleus-rdbms + [3.2.0, ) + + + javax.jdo + jdo-api + [3.0, ) + + + + com.h2database + h2 + 1.3.168 + + + junit + junit + 4.9 + test + + + log4j + log4j + [1.2, 1.3) + + + + + + target/classes + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + *.ods + + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + MyTest + ${basedir}/src/main/resources/log4j.properties + false + + + + compile + + enhance + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.many_many_attributed.Main + + + log4j.configuration + file:${basedir}/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java b/one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java new file mode 100644 index 0000000..fd8c42e --- /dev/null +++ b/one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java @@ -0,0 +1,103 @@ +package org.datanucleus.samples.jdo.one_many_bidir; + +import java.io.Serializable; +import java.util.StringTokenizer; + +public class Card +{ + String suit = null; + String number = null; + Pack pack = null; + + public Card(String suit,String number) + { + this.suit = suit; + this.number = number; + } + + public String getSuit() + { + return suit; + } + + public String getNumber() + { + return number; + } + + public Pack getPack() + { + return pack; + } + + public void setPack(Pack pack) + { + this.pack = pack; + } + + public String toString() + { + return "The " + number + " of " + suit; + } + + // Primary Key, if using composite identity + public static class CardKey implements Serializable + { + public String suit; + public String number; + + /** + * Default constructor (mandatory for JDO). + **/ + public CardKey() + { + } + + /** + * String constructor (mandatory for JDO). + **/ + public CardKey(String str) + { + StringTokenizer toke = new StringTokenizer (str, "::"); + str = toke.nextToken (); + this.suit = str; + str = toke.nextToken (); + this.number = str; + } + + /** + * Implementation of equals method (JDO requirement). + **/ + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + if (!(obj instanceof CardKey)) + { + return false; + } + CardKey c=(CardKey)obj; + + return suit.equals(c.suit) && number.equals(c.number); + } + + /** + * Implementation of hashCode (JDO requirement) + **/ + public int hashCode () + { + return this.suit.hashCode() ^ this.number.hashCode(); + } + + /** + * Implementation of toString that outputs this object id's PK values. + * (JDO requirement). + **/ + public String toString () + { + return this.suit + "::" + this.number; + } + } +} diff --git a/one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java b/one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java new file mode 100644 index 0000000..bdd50e5 --- /dev/null +++ b/one_to_many_fk_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java @@ -0,0 +1,38 @@ +package org.datanucleus.samples.jdo.one_many_bidir; + +import java.util.Set; +import java.util.HashSet; + +public class Pack +{ + String name=null; + String description=null; + + Set cards = new HashSet(); + + public Pack(String name, String desc) + { + this.name = name; + this.description = desc; + } + + public void addCard(Card card) + { + cards.add(card); + } + + public void removeCard(Card card) + { + cards.remove(card); + } + + public Set getCards() + { + return cards; + } + + public int getNumberOfCards() + { + return cards.size(); + } +} diff --git a/one_to_many_fk_bidir/src/main/resources/META-INF/persistence.xml b/one_to_many_fk_bidir/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..893166d --- /dev/null +++ b/one_to_many_fk_bidir/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,22 @@ + + + + + org/datanucleus/samples/jdo/one_many_bidir/package.jdo + + + + + + + + + + + + + + diff --git a/one_to_many_fk_bidir/src/main/resources/log4j.properties b/one_to_many_fk_bidir/src/main/resources/log4j.properties new file mode 100644 index 0000000..91e760b --- /dev/null +++ b/one_to_many_fk_bidir/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + diff --git a/one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm b/one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm new file mode 100644 index 0000000..4740762 --- /dev/null +++ b/one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo b/one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo new file mode 100644 index 0000000..4730c4c --- /dev/null +++ b/one_to_many_fk_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/one_to_many_join_bidir/LICENSE.txt b/one_to_many_join_bidir/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/one_to_many_join_bidir/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/one_to_many_join_bidir/README.md b/one_to_many_join_bidir/README.md new file mode 100644 index 0000000..7107cee --- /dev/null +++ b/one_to_many_join_bidir/README.md @@ -0,0 +1,20 @@ +one_to_many_join_bidir +====================== +The prerequisite is that you need the DataNucleus Maven2 plugin installed. +You can download this plugin from the DataNucleus downloads area. + +1. Set the database configuration in "src/main/resources/META-INF/persistence.xml" + +2. Make sure you have the JDBC driver jar specified in the "pom.xml" file + +3. Run the command: "mvn clean compile" + This builds everything, and enhances the classes + +4. Run the command: "mvn datanucleus:schema-create" + This creates the schema + +[... run some persistence code ...] + +6. Run the command: "mvn datanucleus:schema-delete" + This deletes the schema + diff --git a/one_to_many_join_bidir/assembly.xml b/one_to_many_join_bidir/assembly.xml new file mode 100644 index 0000000..353c232 --- /dev/null +++ b/one_to_many_join_bidir/assembly.xml @@ -0,0 +1,28 @@ + + src + + zip + + + + + + README* + *.txt + *.xml + *.properties + + + assembly.xml + datanucleus.log + + + + src + + + + + diff --git a/one_to_many_join_bidir/pom.xml b/one_to_many_join_bidir/pom.xml new file mode 100644 index 0000000..7c07b13 --- /dev/null +++ b/one_to_many_join_bidir/pom.xml @@ -0,0 +1,145 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-one-many-bidir-join + jar + 3.2 + DataNucleus AccessPlatform JDO One-to-Many JoinTable Relation Sample + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + [3.2.0, ) + + + org.datanucleus + datanucleus-api-jdo + [3.2.0, ) + + + org.datanucleus + datanucleus-rdbms + [3.2.0, ) + + + javax.jdo + jdo-api + [3.0, ) + + + + com.h2database + h2 + 1.3.168 + + + junit + junit + 4.9 + test + + + log4j + log4j + [1.2, 1.3) + + + + + + target/classes + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + *.ods + + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + MyTest + ${basedir}/src/main/resources/log4j.properties + false + + + + compile + + enhance + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.many_many_attributed.Main + + + log4j.configuration + file:${basedir}/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java b/one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java new file mode 100644 index 0000000..f5475cc --- /dev/null +++ b/one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Card.java @@ -0,0 +1,103 @@ +package org.datanucleus.samples.jdo.one_many_bidir; + +import java.io.Serializable; +import java.util.StringTokenizer; + +public class Card +{ + String suit = null; + String number = null; + Pack pack = null; + + public Card(String suit,String number) + { + this.suit = suit; + this.number = number; + } + + public String getSuit() + { + return suit; + } + + public String getNumber() + { + return number; + } + + public Pack getPack() + { + return pack; + } + + public void setPack(Pack pack) + { + this.pack = pack; + } + + public String toString() + { + return "The " + number + " of " + suit; + } + + // Primary Key + public static class CardKey implements Serializable + { + public String suit; + public String number; + + /** + * Default constructor (mandatory for JDO). + **/ + public CardKey() + { + } + + /** + * String constructor (mandatory for JDO). + **/ + public CardKey(String str) + { + StringTokenizer toke = new StringTokenizer (str, "::"); + str = toke.nextToken (); + this.suit = str; + str = toke.nextToken (); + this.number = str; + } + + /** + * Implementation of equals method (JDO requirement). + **/ + public boolean equals(Object obj) + { + if (obj == this) + { + return true; + } + if (!(obj instanceof CardKey)) + { + return false; + } + CardKey c=(CardKey)obj; + + return suit.equals(c.suit) && number.equals(c.number); + } + + /** + * Implementation of hashCode (JDO requirement) + **/ + public int hashCode () + { + return this.suit.hashCode() ^ this.number.hashCode(); + } + + /** + * Implementation of toString that outputs this object id's PK values. + * (JDO requirement). + **/ + public String toString () + { + return this.suit + "::" + this.number; + } + } +} diff --git a/one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java b/one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java new file mode 100644 index 0000000..bdd50e5 --- /dev/null +++ b/one_to_many_join_bidir/src/main/java/org/datanucleus/samples/jdo/one_many_bidir/Pack.java @@ -0,0 +1,38 @@ +package org.datanucleus.samples.jdo.one_many_bidir; + +import java.util.Set; +import java.util.HashSet; + +public class Pack +{ + String name=null; + String description=null; + + Set cards = new HashSet(); + + public Pack(String name, String desc) + { + this.name = name; + this.description = desc; + } + + public void addCard(Card card) + { + cards.add(card); + } + + public void removeCard(Card card) + { + cards.remove(card); + } + + public Set getCards() + { + return cards; + } + + public int getNumberOfCards() + { + return cards.size(); + } +} diff --git a/one_to_many_join_bidir/src/main/resources/META-INF/persistence.xml b/one_to_many_join_bidir/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..893166d --- /dev/null +++ b/one_to_many_join_bidir/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,22 @@ + + + + + org/datanucleus/samples/jdo/one_many_bidir/package.jdo + + + + + + + + + + + + + + diff --git a/one_to_many_join_bidir/src/main/resources/log4j.properties b/one_to_many_join_bidir/src/main/resources/log4j.properties new file mode 100644 index 0000000..91e760b --- /dev/null +++ b/one_to_many_join_bidir/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + diff --git a/one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm b/one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm new file mode 100644 index 0000000..9516b40 --- /dev/null +++ b/one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package-h2.orm @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo b/one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo new file mode 100644 index 0000000..044cc7e --- /dev/null +++ b/one_to_many_join_bidir/src/main/resources/org/datanucleus/samples/jdo/one_many_bidir/package.jdo @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/one_to_one_embedded/LICENSE.txt b/one_to_one_embedded/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/one_to_one_embedded/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/one_to_one_embedded/README.md b/one_to_one_embedded/README.md new file mode 100644 index 0000000..4526192 --- /dev/null +++ b/one_to_one_embedded/README.md @@ -0,0 +1,22 @@ +one_to_one_embedded +=================== +The prerequisite is that you need the DataNucleus Maven2 plugin installed. +You can download this plugin from the DataNucleus downloads area. + +1. Set the database configuration in "src/main/resources/META-INF/persistence.xml" + +2. Make sure you have the JDBC driver jar specified in the "pom.xml" file + +3. Run the command: "mvn clean compile" + This builds everything, and enhances the classes + +4. Run the command: "mvn datanucleus:schema-create" + This creates the schema + +5. Run persistence code "mvn exec:java" + +6. Run the command: "mvn datanucleus:schema-delete" + This deletes the schema + + +Copyright (c) 2008-2013 DataNucleus diff --git a/one_to_one_embedded/assembly.xml b/one_to_one_embedded/assembly.xml new file mode 100644 index 0000000..353c232 --- /dev/null +++ b/one_to_one_embedded/assembly.xml @@ -0,0 +1,28 @@ + + src + + zip + + + + + + README* + *.txt + *.xml + *.properties + + + assembly.xml + datanucleus.log + + + + src + + + + + diff --git a/one_to_one_embedded/pom.xml b/one_to_one_embedded/pom.xml new file mode 100644 index 0000000..865f480 --- /dev/null +++ b/one_to_one_embedded/pom.xml @@ -0,0 +1,145 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-one-one-embedded + jar + 3.2 + DataNucleus AccessPlatform JDO One-to-One Embedded Relation Sample + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + [3.2.0, ) + + + org.datanucleus + datanucleus-api-jdo + [3.2.0, ) + + + org.datanucleus + datanucleus-rdbms + [3.2.0, ) + + + javax.jdo + jdo-api + [3.0, ) + + + + com.h2database + h2 + 1.3.168 + + + junit + junit + 4.9 + test + + + log4j + log4j + [1.2, 1.3) + + + + + + target/classes + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + *.ods + + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + MyTest + ${basedir}/src/main/resources/log4j.properties + false + + + + compile + + enhance + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.one_one_embedded.Main + + + log4j.configuration + file:${basedir}/src/main/resources/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Account.java b/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Account.java new file mode 100644 index 0000000..9e6edef --- /dev/null +++ b/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Account.java @@ -0,0 +1,72 @@ +/********************************************************************** +Copyright (c) 2011 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.one_one_embedded; + +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.DatastoreIdentity; +import javax.jdo.annotations.IdGeneratorStrategy; +import javax.jdo.annotations.Embedded; + +@PersistenceCapable +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY) +public class Account +{ + protected String firstName = null; + protected String lastName = null; + protected int level = 0; + + @Embedded + protected Login login = null; + + public Account(String first, String last, int level) + { + this.firstName = first; + this.lastName = last; + this.level = level; + } + + public String getFirstName() + { + return firstName; + } + + public String getLastName() + { + return lastName; + } + + public int getLevel() + { + return level; + } + + public void setLogin(Login login) + { + this.login = login; + } + + public Login getLogin() + { + return login; + } + + public String toString() + { + return "Account : " + firstName + " " + lastName + " [level=" + level + "]"; + } +} diff --git a/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Login.java b/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Login.java new file mode 100644 index 0000000..109ed80 --- /dev/null +++ b/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Login.java @@ -0,0 +1,56 @@ +/********************************************************************** +Copyright (c) 2011 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.one_one_embedded; + +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.PrimaryKey; + +@PersistenceCapable +public class Login +{ + @PrimaryKey + protected String login = null; + + protected String password = null; + + public Login(String login, String pwd) + { + this.login = login; + this.password = pwd; + } + + public String getLogin() + { + return login; + } + + public String getPassword() + { + return password; + } + + public void setPassword(String pwd) + { + this.password = pwd; + } + + public String toString() + { + return "Login : " + login; + } +} diff --git a/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Main.java b/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Main.java new file mode 100644 index 0000000..f566a4b --- /dev/null +++ b/one_to_one_embedded/src/main/java/org/datanucleus/samples/jdo/one_one_embedded/Main.java @@ -0,0 +1,93 @@ +/********************************************************************** +Copyright (c) 2011 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.one_one_embedded; + +import java.util.List; +import java.util.Iterator; + +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; +import javax.jdo.JDOHelper; + +public class Main +{ + public static void main(String args[]) + { + // Create a PersistenceManagerFactory for this datastore + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("MyTest"); + + System.out.println("DataNucleus AccessPlatform with JDO"); + System.out.println("==================================="); + + Object acctId = null; + + { + // Persistence of a Account and Login + PersistenceManager pm = pmf.getPersistenceManager(); + System.out.println("Persisting Account+Login"); + Account acct = new Account("John","Cameron", 3); + Login login = new Login("jcameron", "xxxx"); + acct.setLogin(login); + pm.makePersistent(acct); + acctId = pm.getObjectId(acct); + System.out.println("Account+Login have been persisted, with account-id=" + acctId); + + pm.close(); + } + System.out.println(""); + + { + // Perform some query operations + PersistenceManager pm = pmf.getPersistenceManager(); + + System.out.println("Executing Query for Accounts with level of 3 or above"); + Query q = pm.newQuery("SELECT FROM " + Account.class.getName() + + " WHERE level >= 3 ORDER BY lastName ASC"); + List c = (List)q.execute(); + Iterator iter = c.iterator(); + while (iter.hasNext()) + { + Account acct = iter.next(); + System.out.println("> " + acct); + + // Give an example of an update + Login login = acct.getLogin(); + login.setPassword("yyyy"); + } + + pm.close(); + } + System.out.println(""); + + { + // Clean out the database + PersistenceManager pm = pmf.getPersistenceManager(); + + System.out.println("Deleting all Accounts from persistence"); + Query q = pm.newQuery(Account.class); + long numberInstancesDeleted = q.deletePersistentAll(); + System.out.println("Deleted " + numberInstancesDeleted + " accounts"); + + pm.close(); + } + + System.out.println(""); + System.out.println("End of Tutorial"); + } +} diff --git a/one_to_one_embedded/src/main/resources/META-INF/persistence.xml b/one_to_one_embedded/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..445a310 --- /dev/null +++ b/one_to_one_embedded/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,23 @@ + + + + + org.datanucleus.samples.jdo.one_one_embedded.Account + org.datanucleus.samples.jdo.one_one_embedded.Login + + + + + + + + + + + + + + diff --git a/one_to_one_embedded/src/main/resources/log4j.properties b/one_to_one_embedded/src/main/resources/log4j.properties new file mode 100644 index 0000000..91e760b --- /dev/null +++ b/one_to_one_embedded/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + diff --git a/one_to_one_embedded/src/main/resources/org/datanucleus/samples/jdo/one_one_embedded/package-h2.orm b/one_to_one_embedded/src/main/resources/org/datanucleus/samples/jdo/one_one_embedded/package-h2.orm new file mode 100644 index 0000000..8e1c4ff --- /dev/null +++ b/one_to_one_embedded/src/main/resources/org/datanucleus/samples/jdo/one_one_embedded/package-h2.orm @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + diff --git a/spatial/LICENSE.txt b/spatial/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/spatial/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/spatial/README.md b/spatial/README.md new file mode 100644 index 0000000..8226144 --- /dev/null +++ b/spatial/README.md @@ -0,0 +1,23 @@ +spatial +======= +This requires the DataNucleus Maven2 plugin. You can download this plugin from the DataNucleus downloads area. + +1. Set the database configuration in the "src/main/resources/META-INF/persistence.xml" file. + +2. Make sure you have the JDBC driver jar specified in the "pom.xml" file + +3. Run the command: "mvn clean compile" + This builds everything, and enhances the classes + +4. Run the command: "mvn datanucleus:schema-create" + This creates the schema for this sample. + +5. Run the command: "mvn exec:java" + This runs the tutorial + +6. Run the command: "mvn datanucleus:schema-delete" + This deletes the schema for this sample. + + + +(c) Copyright 2008-2013 DataNucleus diff --git a/spatial/assembly.xml b/spatial/assembly.xml new file mode 100644 index 0000000..353c232 --- /dev/null +++ b/spatial/assembly.xml @@ -0,0 +1,28 @@ + + src + + zip + + + + + + README* + *.txt + *.xml + *.properties + + + assembly.xml + datanucleus.log + + + + src + + + + + diff --git a/spatial/pom.xml b/spatial/pom.xml new file mode 100644 index 0000000..2594856 --- /dev/null +++ b/spatial/pom.xml @@ -0,0 +1,180 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-jdo-spatial + jar + 3.2 + DataNucleus AccessPlatform JDO Spatial Sample + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + [3.2.0, ) + + + org.datanucleus + datanucleus-api-jdo + [3.2.0, ) + + + org.datanucleus + datanucleus-rdbms + [3.2.0, ) + + + org.datanucleus + datanucleus-spatial + [3.2.0, ) + + + javax.jdo + jdo-api + [3.0, ) + + + + mysql + mysql-connector-java + 5.0.5 + + + com.vividsolutions + jts + 1.12 + true + + + com.vividsolutions + jtsio + 1.12 + true + + + postgresql + postgresql + 9.1-901-1.jdbc4 + true + + + postgis + postgis-jdbc + 1.1.5 + true + + + postgis + postgis-jdbc-jts + 1.1.5 + true + + + junit + junit + 4.9 + test + + + log4j + log4j + [1.2, 1.3) + + + + + + target/classes + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + *.ods + + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + MyTest + ${basedir}/src/main/resources/log4j.properties + false + + + + compile + + enhance + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.spatial.Main + + + log4j.configuration + file:${basedir}/src/main/resources/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Main.java b/spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Main.java new file mode 100644 index 0000000..c12f7cd --- /dev/null +++ b/spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Main.java @@ -0,0 +1,95 @@ +package org.datanucleus.samples.jdo.spatial; + +import java.sql.SQLException; +import java.util.List; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.datanucleus.util.NucleusLogger; + +import org.postgis.Point; + +public class Main +{ + public static void main(String args[]) + throws SQLException + { + // Create a PersistenceManagerFactory for this datastore + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("MyTest"); + + System.out.println("DataNucleus JDO Spatial Sample"); + System.out.println("=============================="); + + // Persist several Position objects + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx=pm.currentTransaction(); + try + { + //create objects + tx.begin(); + + Position[] sps = new Position[3]; + Point[] points = new Point[3]; + points[0] = new Point("SRID=4326;POINT(5 0)"); + points[1] = new Point("SRID=4326;POINT(10 0)"); + points[2] = new Point("SRID=4326;POINT(20 0)"); + sps[0] = new Position("market",points[0]); + sps[1] = new Position("rent-a-car",points[1]); + sps[2] = new Position("pizza shop",points[2]); + Point homepoint = new Point("SRID=4326;POINT(0 0)"); + Position home = new Position("home",homepoint); + + System.out.println("Persisting spatial data..."); + System.out.println(home); + System.out.println(sps[0]); + System.out.println(sps[1]); + System.out.println(sps[2]); + System.out.println(""); + + pm.makePersistentAll(sps); + pm.makePersistent(home); + + tx.commit(); + + //query for the distance + tx.begin(); + + System.out.println("Retrieving position where X position is > 10 and Y position is 0 ... Found:"); + + // TODO Make this more elaborate, demonstrating more of the power of spatial method querying + Query query = pm.newQuery(Position.class, + "name != 'home' && (this.point.getX() > 10) && (this.point.getY() == 0)"); + List list = (List) query.execute(); + for( int i=0; i> Exception during tutorial", e); + System.err.println("Exception thrown during sample execution, consult the log for details : " + e.getMessage()); + return; + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + + System.out.println(""); + System.out.println("End of Sample"); + } +} diff --git a/spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Position.java b/spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Position.java new file mode 100644 index 0000000..9f201eb --- /dev/null +++ b/spatial/src/main/java/org/datanucleus/samples/jdo/spatial/Position.java @@ -0,0 +1,31 @@ +package org.datanucleus.samples.jdo.spatial; + +import org.postgis.Point; + +public class Position +{ + private String name; + + private Point point; + + public Position(String name, Point point) + { + this.name = name; + this.point = point; + } + + public String getName() + { + return name; + } + + public Point getPoint() + { + return point; + } + + public String toString() + { + return "[name] "+ name + " [point] "+point; + } +} diff --git a/spatial/src/main/resources/META-INF/persistence.xml b/spatial/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..155de50 --- /dev/null +++ b/spatial/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,21 @@ + + + + + org/datanucleus/samples/jdo/spatial/package.jdo + + + + + + + + + + + + + diff --git a/spatial/src/main/resources/log4j.properties b/spatial/src/main/resources/log4j.properties new file mode 100644 index 0000000..91e760b --- /dev/null +++ b/spatial/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + diff --git a/spatial/src/main/resources/org/datanucleus/samples/jdo/spatial/package.jdo b/spatial/src/main/resources/org/datanucleus/samples/jdo/spatial/package.jdo new file mode 100644 index 0000000..e53fe72 --- /dev/null +++ b/spatial/src/main/resources/org/datanucleus/samples/jdo/spatial/package.jdo @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/tutorial/LICENSE.txt b/tutorial/LICENSE.txt new file mode 100644 index 0000000..3a5fb38 --- /dev/null +++ b/tutorial/LICENSE.txt @@ -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: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (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 + + (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. + + 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 + + Copyright 2008-2013 DataNucleus + + 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/tutorial/README.md b/tutorial/README.md new file mode 100644 index 0000000..7b156af --- /dev/null +++ b/tutorial/README.md @@ -0,0 +1,40 @@ +tutorial +======== + +Simple demonstration of using JDO with DataNucleus. +You can run this with any supported datastore by simply editing the following +files + +* src/main/resources/META-INF/persistence.xml **[Edit the datastore details here]** +* pom.xml **[Edit the dependency jars for your datastore]** + +Maven Instructions +================== +1. Run the command *mvn clean compile*. This builds everything and enhances the + classes. + +2. Run the command *mvn datanucleus:schema-create*. This creates the schema for + the tutorial. + +3. Run the command *mvn exec:java*. This runs the tutorial. + +4. Run the command *mvn datanucleus:schema-delete*. This deletes the schema for + the tutorial + + +Ant instructions +================ +1. Create a directory **lib** and add the following jars to it : jdo-api.jar, + datanucleus-core.jar, datanucleus-api.jdo.jar, datanucleus-{store}.jar, +log4j.jar, {your-database-driver}.jar + +2. Run the command *ant clean compile enhance*. This builds everything and + enhances the classes + +3. Run the command *ant createschema*. This creates the schema for the + tutorial. + +4. Run the command *ant runtutorial*. This runs the tutorial. + +5. Run the command *ant deleteschema*. This deletes the schema for the + tutorial. diff --git a/tutorial/assembly.xml b/tutorial/assembly.xml new file mode 100644 index 0000000..a73dd99 --- /dev/null +++ b/tutorial/assembly.xml @@ -0,0 +1,29 @@ + + src + + zip + + + + + + README* + *.txt + *.xml + *.orm + *.properties + + + assembly.xml + datanucleus.log + + + + src + + + + + diff --git a/tutorial/build.xml b/tutorial/build.xml new file mode 100644 index 0000000..008773c --- /dev/null +++ b/tutorial/build.xml @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/log4j.properties b/tutorial/log4j.properties new file mode 100644 index 0000000..b4f8562 --- /dev/null +++ b/tutorial/log4j.properties @@ -0,0 +1,24 @@ +# LOG4J Configuration +# =================== + +# Basic logging goes to "datanucleus.log" +log4j.appender.A1=org.apache.log4j.FileAppender +log4j.appender.A1.File=datanucleus.log +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n +#log4j.appender.A1.Threshold=INFO + +# Categories +# Each category can be set to a "level", and to direct to an appender + +# Default to DEBUG level for all DataNucleus categories +log4j.logger.DataNucleus = DEBUG, A1 + +log4j.category.com.mchange.v2.c3p0=INFO, A1 +log4j.category.com.mchange.v2.resourcepool=INFO, A1 +log4j.category.org.logicalcobwebs.proxool=INFO,A1 + + +# Hbase libs logging +log4j.category.org.apache.hadoop=INFO,A1 +log4j.category.org.apache.zookeeper=INFO,A1 \ No newline at end of file diff --git a/tutorial/pom.xml b/tutorial/pom.xml new file mode 100644 index 0000000..4945e4b --- /dev/null +++ b/tutorial/pom.xml @@ -0,0 +1,267 @@ + + 4.0.0 + org.datanucleus + datanucleus-samples-jdo-tutorial + jar + 3.2 + DataNucleus AccessPlatform Tutorial for JDO + http://www.datanucleus.org + + + + DN_M2_Repo + DataNucleus Repository + http://www.datanucleus.org/downloads/maven2 + + false + + + + + + + DataNucleus_2 + http://www.datanucleus.org/downloads/maven2/ + + false + + + + + + + org.datanucleus + datanucleus-core + (3.1.99, ) + + + org.datanucleus + datanucleus-api-jdo + (3.1.99, ) + + + javax.jdo + jdo-api + [3.0, ) + + + log4j + log4j + [1.2, 1.3) + + + + + org.datanucleus + datanucleus-rdbms + (3.1.99, ) + + + com.h2database + h2 + 1.3.168 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${basedir}/src/main/resources + + **/*.xml + **/*.jdo + **/*.orm + **/*.properties + + + + + + + maven-clean-plugin + 2.4.1 + + + + ${basedir} + + *.log + tutorial.ods + tutorial.xls + testDB + + + + + + + + maven-compiler-plugin + 2.3.2 + + + + org.datanucleus + datanucleus-maven-plugin + 3.2.0-release + + JDO + Tutorial + ${basedir}/log4j.properties + false + + + + compile + + enhance + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.datanucleus.samples.jdo.tutorial.Main + + + log4j.configuration + file:${basedir}/log4j.properties + + + + + + maven-assembly-plugin + 2.2.1 + + + ${basedir}/assembly.xml + + + + + + diff --git a/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Book.java b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Book.java new file mode 100644 index 0000000..2e60c84 --- /dev/null +++ b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Book.java @@ -0,0 +1,76 @@ +/********************************************************************** +Copyright (c) 2003 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.tutorial; + +import javax.jdo.annotations.PersistenceCapable; + +/** + * Definition of a Book. Extends basic Product class. + */ +@PersistenceCapable +public class Book extends Product +{ + protected String author=null; + + protected String isbn=null; + + protected String publisher=null; + + public Book(String name, String description, double price, String author, String isbn, String publisher) + { + super(name,description,price); + this.author = author; + this.isbn = isbn; + this.publisher = publisher; + } + + public String getAuthor() + { + return author; + } + + public String getIsbn() + { + return isbn; + } + + public String getPublisher() + { + return publisher; + } + + public void setAuthor(String author) + { + this.author = author; + } + + public void setIsbn(String isbn) + { + this.isbn = isbn; + } + + public void setPublisher(String publisher) + { + this.publisher = publisher; + } + + public String toString() + { + return "Book : " + author + " - " + name; + } +} \ No newline at end of file diff --git a/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Inventory.java b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Inventory.java new file mode 100644 index 0000000..7bae4ff --- /dev/null +++ b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Inventory.java @@ -0,0 +1,56 @@ +/********************************************************************** +Copyright (c) 2011 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.tutorial; + +import java.util.HashSet; +import java.util.Set; + +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.PrimaryKey; + +/** + * Definition of an Inventory of products. + */ +@PersistenceCapable +public class Inventory +{ + @PrimaryKey + protected String name=null; + + protected Set products = new HashSet(); + + public Inventory(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + public Set getProducts() + { + return products; + } + + public String toString() + { + return "Inventory : " + name; + } +} \ No newline at end of file diff --git a/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Main.java b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Main.java new file mode 100644 index 0000000..778fa4e --- /dev/null +++ b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Main.java @@ -0,0 +1,176 @@ +/********************************************************************** +Copyright (c) 2003 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.tutorial; + +import java.util.Iterator; +import java.util.List; + +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Extent; +import javax.jdo.Query; +import javax.jdo.JDOHelper; +import javax.jdo.Transaction; + +/** + * Controlling application for the DataNucleus Tutorial using JDO. + * Relies on the user defining a file "datanucleus.properties" to be in the CLASSPATH + * and to include the JDO properties for the DataNucleus PersistenceManager. + */ +public class Main +{ + public static void main(String args[]) + { + // Create a PersistenceManagerFactory for this datastore + PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("Tutorial"); + + System.out.println("DataNucleus AccessPlatform with JDO"); + System.out.println("==================================="); + + // Persistence of a Product and a Book. + PersistenceManager pm = pmf.getPersistenceManager(); + Transaction tx=pm.currentTransaction(); + Object inventoryId = null; + try + { + tx.begin(); + System.out.println("Persisting Inventory of products"); + Inventory inv = new Inventory("My Inventory"); + Product product = new Product("Sony Discman","A standard discman from Sony",200.00); + Book book = new Book("Lord of the Rings by Tolkien","The classic story",49.99,"JRR Tolkien", "12345678", "MyBooks Factory"); + inv.getProducts().add(product); + inv.getProducts().add(book); + pm.makePersistent(inv); + + tx.commit(); + inventoryId = pm.getObjectId(inv); + System.out.println("Inventory, Product and Book have been persisted"); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + System.out.println(""); + + // Basic Extent of all Products + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + System.out.println("Retrieving Extent for Products"); + Extent e = pm.getExtent(Product.class, true); + Iterator iter = e.iterator(); + while (iter.hasNext()) + { + Object obj = iter.next(); + System.out.println("> " + obj); + } + tx.commit(); + } + catch (Exception e) + { + System.out.println("Exception thrown during retrieval of Extent : " + e.getMessage()); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + System.out.println(""); + + // Perform some query operations + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + System.out.println("Executing Query for Products with price below 150.00"); + Query q=pm.newQuery("SELECT FROM " + Product.class.getName() + + " WHERE price < 150.00 ORDER BY price ASC"); + List products = (List)q.execute(); + Iterator iter = products.iterator(); + while (iter.hasNext()) + { + Product p = iter.next(); + System.out.println("> " + p); + + // Give an example of an update + if (p instanceof Book) + { + Book b = (Book)p; + b.setDescription("This book has been reduced in price!"); + } + } + + tx.commit(); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + System.out.println(""); + + // Clean out the database + pm = pmf.getPersistenceManager(); + tx = pm.currentTransaction(); + try + { + tx.begin(); + + System.out.println("Retrieving Inventory using its id"); + Inventory inv = (Inventory)pm.getObjectById(inventoryId); + + System.out.println("Clearing out Inventory"); + inv.getProducts().clear(); + + System.out.println("Deleting Inventory"); + pm.deletePersistent(inv); + + System.out.println("Deleting all products from persistence"); + Query q = pm.newQuery(Product.class); + long numberInstancesDeleted = q.deletePersistentAll(); + System.out.println("Deleted " + numberInstancesDeleted + " products"); + + tx.commit(); + } + finally + { + if (tx.isActive()) + { + tx.rollback(); + } + pm.close(); + } + + System.out.println(""); + System.out.println("End of Tutorial"); + pmf.close(); + } +} diff --git a/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Product.java b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Product.java new file mode 100644 index 0000000..d4c3b27 --- /dev/null +++ b/tutorial/src/main/java/org/datanucleus/samples/jdo/tutorial/Product.java @@ -0,0 +1,88 @@ +/********************************************************************** +Copyright (c) 2003 Andy Jefferson and others. All rights reserved. +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. + +Contributors: + ... +**********************************************************************/ +package org.datanucleus.samples.jdo.tutorial; + +import javax.jdo.annotations.IdGeneratorStrategy; +import javax.jdo.annotations.PersistenceCapable; +import javax.jdo.annotations.Persistent; +import javax.jdo.annotations.PrimaryKey; + +/** + * Definition of a Product + * Represents a product, and contains the key aspects of the item. + */ +@PersistenceCapable +public class Product +{ + @PrimaryKey + @Persistent(valueStrategy=IdGeneratorStrategy.NATIVE) + protected long id; + + protected String name=null; + + protected String description=null; + + protected double price=0.0; + + public Product(String name, String description, double price) + { + this.name = name; + this.description = description; + this.price = price; + } + + public long getId() + { + return id; + } + + public String getName() + { + return name; + } + + public String getDescription() + { + return description; + } + + public double getPrice() + { + return price; + } + + public void setName(String name) + { + this.name = name; + } + + public void setDescription(String description) + { + this.description = description; + } + + public void setPrice(double price) + { + this.price = price; + } + + public String toString() + { + return "Product : " + id + " name=" + name + " [" + description + "]"; + } +} \ No newline at end of file diff --git a/tutorial/src/main/resources/META-INF/persistence.xml b/tutorial/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..f5dbe0e --- /dev/null +++ b/tutorial/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,55 @@ + + + + + + org.datanucleus.samples.jdo.tutorial.Inventory + org.datanucleus.samples.jdo.tutorial.Product + org.datanucleus.samples.jdo.tutorial.Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/hbase-site.xml b/tutorial/src/main/resources/hbase-site.xml new file mode 100644 index 0000000..f9f441f --- /dev/null +++ b/tutorial/src/main/resources/hbase-site.xml @@ -0,0 +1,10 @@ + + + + + hbase.zookeeper.quorum + localhost + The host and port that the HBase master runs at. + + + diff --git a/tutorial/src/main/resources/package-excel.orm b/tutorial/src/main/resources/package-excel.orm new file mode 100644 index 0000000..b61bee4 --- /dev/null +++ b/tutorial/src/main/resources/package-excel.orm @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/package-h2.orm b/tutorial/src/main/resources/package-h2.orm new file mode 100644 index 0000000..cc39a5f --- /dev/null +++ b/tutorial/src/main/resources/package-h2.orm @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/package-hbase.orm b/tutorial/src/main/resources/package-hbase.orm new file mode 100644 index 0000000..7af4230 --- /dev/null +++ b/tutorial/src/main/resources/package-hbase.orm @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/package-hsql.orm b/tutorial/src/main/resources/package-hsql.orm new file mode 100644 index 0000000..3f2f8cc --- /dev/null +++ b/tutorial/src/main/resources/package-hsql.orm @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/package-mongodb.orm b/tutorial/src/main/resources/package-mongodb.orm new file mode 100644 index 0000000..7af4230 --- /dev/null +++ b/tutorial/src/main/resources/package-mongodb.orm @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/package-mysql.orm b/tutorial/src/main/resources/package-mysql.orm new file mode 100644 index 0000000..cc39a5f --- /dev/null +++ b/tutorial/src/main/resources/package-mysql.orm @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/package-neo4j.orm b/tutorial/src/main/resources/package-neo4j.orm new file mode 100644 index 0000000..eb14d3d --- /dev/null +++ b/tutorial/src/main/resources/package-neo4j.orm @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tutorial/src/main/resources/package-odf.orm b/tutorial/src/main/resources/package-odf.orm new file mode 100644 index 0000000..b933cd8 --- /dev/null +++ b/tutorial/src/main/resources/package-odf.orm @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +