Source Code Cross Referenced for Deity.java in  » Database-ORM » openjpa » relations » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » openjpa » relations 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.    
018:         */
019:        package relations;
020:
021:        import java.io.Serializable;
022:        import java.util.HashSet;
023:        import java.util.Set;
024:
025:        import javax.persistence.Basic;
026:        import javax.persistence.CascadeType;
027:        import javax.persistence.Entity;
028:        import javax.persistence.Enumerated;
029:        import javax.persistence.EnumType;
030:        import javax.persistence.Id;
031:        import javax.persistence.NamedQuery;
032:        import javax.persistence.NamedQueries;
033:        import javax.persistence.OneToMany;
034:        import javax.persistence.OneToOne;
035:
036:        /** 
037:         * An entity that contains relations corresponding to family tree relations.
038:         * This entity demonstrates the following JPA features:
039:         *
040:         * 1. Enum fields (gender)
041:         * 2. @OneToOne relations
042:         * 3. @OneToMany relations
043:         * 4. Named queries
044:         */
045:        @Entity
046:        @NamedQueries({@NamedQuery(name="siblings",query="select distinct sibling1 " + "from Deity sibling1, Deity sibling2 where " + "sibling1.father = sibling2.father "+ "and sibling1.mother = sibling2.mother "+ "and sibling2 = ?1 and sibling1 <> ?1"),@NamedQuery(name="half-siblings",query="select distinct sibling1 " + "from Deity sibling1, Deity sibling2 where " + "((sibling1.father = sibling2.father "+ "and sibling1.mother <> sibling2.mother) "+ "or (sibling1.father <> sibling2.father "+ "and sibling1.mother = sibling2.mother)) "+ "and sibling2 = ?1 and sibling1 <> ?1"),@NamedQuery(name="cousins",query="select distinct cousin1 " + "from Deity cousin1, Deity cousin2 where " + "("+ "cousin1.father.father = cousin2.father.father "+ "or cousin1.father.mother = cousin2.father.mother "+ "or cousin1.mother.father = cousin2.mother.father "+ "or cousin1.mother.mother = cousin2.mother.mother) "+ "and (cousin1.father <> cousin2.father) "+ "and (cousin1.mother <> cousin2.mother) "+ "and cousin2 = ?1 and cousin1 <> ?1")})
047:        public class Deity implements  Serializable {
048:            // the Id is the name, which is generally a bad idea, but we are
049:            // confident that diety names will be unique
050:            @Id
051:            private String name;
052:
053:            @Basic
054:            @Enumerated(EnumType.STRING)
055:            private Gender gender;
056:
057:            @OneToOne(cascade=CascadeType.ALL)
058:            private Deity mother;
059:
060:            @OneToOne(cascade=CascadeType.ALL)
061:            private Deity father;
062:
063:            @OneToMany(cascade=CascadeType.ALL)
064:            private Set<Deity> children;
065:
066:            public static enum Gender {
067:                MALE, FEMALE
068:            }
069:
070:            public Deity(String name, Gender gender) {
071:                this .name = name;
072:                this .gender = gender;
073:            }
074:
075:            //////////////////////////
076:            // Business methods follow
077:            //////////////////////////
078:
079:            /** 
080:             * She's having a baby... 
081:             *  
082:             * @param  childName  the baby name
083:             * @return the new child
084:             *
085:             * @throws IllegalArgumentException if the person is not a woman, or
086:             *                                  if the person is unmarried (illegitimate
087:             *                                  children are not yet supported)
088:             */
089:            public Deity giveBirth(String childName, Deity childFather,
090:                    Gender gender) {
091:                if (this .gender != Gender.FEMALE)
092:                    throw new IllegalArgumentException(
093:                            "Only women can have children!");
094:
095:                if (childName == null)
096:                    throw new IllegalArgumentException("No child name!");
097:
098:                // create the child
099:                Deity child = new Deity(childName, gender);
100:
101:                // set the parents in the children...
102:                child.mother = this ;
103:
104:                // add the child to this member's children
105:                if (children == null)
106:                    children = new HashSet<Deity>();
107:                children.add(child);
108:
109:                if (childFather != null) {
110:                    child.father = childFather;
111:                    if (childFather.children == null)
112:                        childFather.children = new HashSet<Deity>();
113:                    childFather.children.add(child);
114:                }
115:
116:                return child;
117:            }
118:
119:            ////////////////////////////////////
120:            // Property accessor methods follow
121:            ////////////////////////////////////
122:
123:            public void setName(String name) {
124:                this .name = name;
125:            }
126:
127:            public String getName() {
128:                return this .name;
129:            }
130:
131:            public void setGender(Gender gender) {
132:                this .gender = gender;
133:            }
134:
135:            public Gender getGender() {
136:                return this .gender;
137:            }
138:
139:            public void setMother(Deity mother) {
140:                this .mother = mother;
141:            }
142:
143:            public Deity getMother() {
144:                return this .mother;
145:            }
146:
147:            public void setFather(Deity father) {
148:                this .father = father;
149:            }
150:
151:            public Deity getFather() {
152:                return this .father;
153:            }
154:
155:            public void setChildren(Set<Deity> children) {
156:                this .children = children;
157:            }
158:
159:            public Set<Deity> getChildren() {
160:                return this.children;
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.