-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change example to use Starwars entity schema
fixed #3
- Loading branch information
Showing
7 changed files
with
254 additions
and
35 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...example/src/main/java/com/introproventures/graphql/jpa/query/example/model/Character.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2017 IntroPro Ventures Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.introproventures.graphql.jpa.query.example.model; | ||
|
||
import java.util.Set; | ||
|
||
import javax.persistence.ElementCollection; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.JoinTable; | ||
import javax.persistence.ManyToMany; | ||
import javax.persistence.OrderBy; | ||
|
||
import com.introproventures.graphql.jpa.query.annotation.GraphQLDescription; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@GraphQLDescription("Abstract representation of an entity in the Star Wars Universe") | ||
@Getter | ||
@Setter | ||
@ToString | ||
@EqualsAndHashCode(exclude={"appearsIn","friends"}) // Fixes NPE in Hibernate when initializing loaded collections #1 | ||
public abstract class Character { | ||
|
||
@Id | ||
@GraphQLDescription("Primary Key for the Character Class") | ||
String id; | ||
|
||
@GraphQLDescription("Name of the character") | ||
String name; | ||
|
||
@GraphQLDescription("Who are the known friends to this character") | ||
@ManyToMany | ||
@JoinTable(name="character_friends", | ||
joinColumns=@JoinColumn(name="source_id", referencedColumnName="id"), | ||
inverseJoinColumns=@JoinColumn(name="friend_id", referencedColumnName="id")) | ||
Set<Character> friends; | ||
|
||
@GraphQLDescription("What Star Wars episodes does this character appear in") | ||
@ElementCollection(targetClass = Episode.class) | ||
@Enumerated(EnumType.ORDINAL) | ||
@OrderBy | ||
Set<Episode> appearsIn; | ||
|
||
Character() {} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...-example/src/main/java/com/introproventures/graphql/jpa/query/example/model/CodeList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2017 IntroPro Ventures Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.introproventures.graphql.jpa.query.example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
|
||
import com.introproventures.graphql.jpa.query.annotation.GraphQLDescription; | ||
|
||
import lombok.Data; | ||
|
||
@Entity | ||
@GraphQLDescription("Database driven enumeration") | ||
@Data | ||
public class CodeList { | ||
|
||
@Id | ||
@GraphQLDescription("Primary Key for the Code List Class") | ||
Long id; | ||
|
||
String type; | ||
String code; | ||
Integer sequence; | ||
boolean active; | ||
String description; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "parent_id") | ||
CodeList parent; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,104 @@ | ||
-- Books | ||
insert into author (id, name) values (1, 'Leo Tolstoy'); | ||
insert into book (id, title, author_id, genre) values (2, 'War and Peace', 1, 'NOVEL'); | ||
insert into book (id, title, author_id, genre) values (3, 'Anna Karenina', 1, 'NOVEL'); | ||
insert into author (id, name) values (4, 'Anton Chekhov'); | ||
insert into book (id, title, author_id, genre) values (5, 'The Cherry Orchard', 4, 'PLAY'); | ||
insert into book (id, title, author_id, genre) values (6, 'The Seagull', 4, 'PLAY'); | ||
insert into book (id, title, author_id, genre) values (7, 'Three Sisters', 4, 'PLAY'); | ||
-- Insert Code Lists | ||
insert into code_list (id, type, code, description, sequence, active, parent_id) values | ||
(0, 'org.crygier.graphql.model.starwars.Gender', 'Male', 'Male', 1, true, null), | ||
(1, 'org.crygier.graphql.model.starwars.Gender', 'Female', 'Female', 2, true, null); | ||
|
||
-- Insert Droids | ||
insert into character (id, name, primary_function, dtype) values | ||
('2000', 'C-3PO', 'Protocol', 'Droid'), | ||
('2001', 'R2-D2', 'Astromech', 'Droid'); | ||
|
||
-- Insert Humans | ||
insert into character (id, name, home_planet, favorite_droid_id, dtype, gender_code_id) values | ||
('1000', 'Luke Skywalker', 'Tatooine', '2000', 'Human', 0), | ||
('1001', 'Darth Vader', 'Tatooine', '2001', 'Human', 0), | ||
('1002', 'Han Solo', NULL, NULL, 'Human', 0), | ||
('1003', 'Leia Organa', 'Alderaan', NULL, 'Human', 1), | ||
('1004', 'Wilhuff Tarkin', NULL, NULL, 'Human', 0); | ||
|
||
-- Luke's friends | ||
insert into character_friends (source_id, friend_id) values | ||
('1000', '1002'), | ||
('1000', '1003'), | ||
('1000', '2000'), | ||
('1000', '2001'); | ||
|
||
-- Luke Appears in | ||
insert into character_appears_in (character_id, appears_in) values | ||
('1000', 3), | ||
('1000', 4), | ||
('1000', 5), | ||
('1000', 6); | ||
|
||
-- Vader's friends | ||
insert into character_friends (source_id, friend_id) values | ||
('1001', '1004'); | ||
|
||
-- Vader Appears in | ||
insert into character_appears_in (character_id, appears_in) values | ||
('1001', 3), | ||
('1001', 4), | ||
('1001', 5); | ||
|
||
-- Solo's friends | ||
insert into character_friends (source_id, friend_id) values | ||
('1002', '1000'), | ||
('1002', '1003'), | ||
('1002', '2001'); | ||
|
||
-- Solo Appears in | ||
insert into character_appears_in (character_id, appears_in) values | ||
('1002', 3), | ||
('1002', 4), | ||
('1002', 5), | ||
('1002', 6); | ||
|
||
-- Leia's friends | ||
insert into character_friends (source_id, friend_id) values | ||
('1003', '1000'), | ||
('1003', '1002'), | ||
('1003', '2000'), | ||
('1003', '2001'); | ||
|
||
-- Leia Appears in | ||
insert into character_appears_in (character_id, appears_in) values | ||
('1003', 3), | ||
('1003', 4), | ||
('1003', 5), | ||
('1003', 6); | ||
|
||
-- Wilhuff's friends | ||
insert into character_friends (source_id, friend_id) values | ||
('1004', '1001'); | ||
|
||
-- Wilhuff Appears in | ||
insert into character_appears_in (character_id, appears_in) values | ||
('1004', 3); | ||
|
||
-- C3PO's friends | ||
insert into character_friends (source_id, friend_id) values | ||
('2000', '1000'), | ||
('2000', '1002'), | ||
('2000', '1003'), | ||
('2000', '2001'); | ||
|
||
-- C3PO Appears in | ||
insert into character_appears_in (character_id, appears_in) values | ||
('2000', 3), | ||
('2000', 4), | ||
('2000', 5), | ||
('2000', 6); | ||
|
||
-- R2's friends | ||
insert into character_friends (source_id, friend_id) values | ||
('2001', '1000'), | ||
('2001', '1002'), | ||
('2001', '1003'); | ||
|
||
-- R2 Appears in | ||
insert into character_appears_in (character_id, appears_in) values | ||
('2001', 3), | ||
('2001', 4), | ||
('2001', 5), | ||
('2001', 6); | ||
|