Skip to content

Commit

Permalink
refactor: finish the graph lab
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasnogueira committed Oct 5, 2023
1 parent b85ef72 commit e65012f
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 195 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*/
package expert.os.labs.persistence.persistence;

import jakarta.nosql.Column;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*/
package expert.os.labs.persistence.persistence;


import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.jnosql.mapping.graph.EntityTree;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*/
package expert.os.labs.persistence.persistence;

import jakarta.enterprise.inject.se.SeContainer;
import jakarta.enterprise.inject.se.SeContainerInitializer;
import org.eclipse.jnosql.mapping.graph.EntityTree;

import java.util.List;

public class AppAnimal {

public static void main(String[] args) {
try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {

AnimalService service = container.select(AnimalService.class).get();

// Create and establish "eats" relationships between animals
Animal grass = service.animal("grass");
Animal grasshopper = service.animal("grasshopper");
Animal frog = service.animal("frog");
Animal snake = service.animal("snake");
Animal eagle = service.animal("eagle");

// Use the service method eats() to define which animal can eat another one based on the chain food
service.eats(eagle, snake);
service.eats(snake, frog);
service.eats(frog, grasshopper);
service.eats(grasshopper, grass);

// Retrieve and printout the list of animals that eats twice
List<Animal> animalEatsTwice = service.eatsTwice();
System.out.println("The animals that eat twice: " + animalEatsTwice);

// Retrieve and printout the list of animals that eats grass
List<Animal> animalEatGrass = service.untilGrass();
System.out.println("The animals that eat until grass: " + animalEatGrass);

// Retrieve the entity tree and print it out
EntityTree entityTree = service.entityTree();
System.out.println("At the top of the entity tree: " + entityTree.getLeaf().toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*
* You may elect to redistribute this code under either of these licenses.
*/

package expert.os.labs.persistence.persistence;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*/
package expert.os.labs.persistence.persistence;


import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.jnosql.mapping.graph.GraphTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*/
package expert.os.labs.persistence.persistence;

import java.util.function.Supplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*
* You may elect to redistribute this code under either of these licenses.
*/

package expert.os.labs.persistence.persistence;

import jakarta.nosql.Column;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*/
package expert.os.labs.persistence.persistence;

import jakarta.enterprise.context.ApplicationScoped;
Expand Down
2 changes: 1 addition & 1 deletion docs/extra-labs/graph-lab-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Try to, first implement, and later, see the solution!
### :material-play-box-multiple-outline: Steps

1. Create a class called `AppMarketing` in the `expert.os.labs.persistence` package
2. Add all the fields and methods from the code below to the class
2. Add the necessary below code to the class

```java
import jakarta.enterprise.inject.se.SeContainer;
Expand Down
Loading

0 comments on commit e65012f

Please sign in to comment.