Created
February 24, 2016 21:25
-
-
Save Leward/e88ab28857a523c20821 to your computer and use it in GitHub Desktop.
OGM Test
This file contains hidden or 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
public class Main { | |
public static void main(String[] args) { | |
Configuration config = new Configuration(); | |
config | |
.driverConfiguration() | |
.setDriverClassName(HttpDriver.class.getName()) | |
.setURI("http://localhost:7474"); | |
SessionFactory sessionFactory = new SessionFactory(config, "fr.zenika.zenapp.ogm.domain"); | |
Session session = sessionFactory.openSession(); | |
String cypher = "MATCH (u:User) WHERE id(u) = {0} WITH u " + | |
"OPTIONAL MATCH p = (u)-[:MANAGE]-() " + | |
"RETURN p "; | |
Map<String, Object> params = new HashMap<>(); | |
params.put("0", 70841); | |
Iterable<User> results = session.query(User.class, cypher, params); | |
for(User result : results) { | |
System.out.println(result.getEmail()); | |
} | |
} | |
} |
This file contains hidden or 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
[email protected] (Let's say its ID is 70841) | |
[email protected] |
This file contains hidden or 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
CREATE (u1:User { email: '[email protected]' })-[:MANAGE]->(u2:User { email: '[email protected]' }) |
This file contains hidden or 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
public class User extends DomainComponent { | |
private String firstName; | |
private String lastName; | |
private String email; | |
@Relationship(type = "MANAGE", direction = Relationship.INCOMING) | |
private User manager; | |
public String getFirstName() { | |
return firstName; | |
} | |
public void setFirstName(String firstName) { | |
this.firstName = firstName; | |
} | |
public String getLastName() { | |
return lastName; | |
} | |
public void setLastName(String lastName) { | |
this.lastName = lastName; | |
} | |
public String getEmail() { | |
return email; | |
} | |
public void setEmail(String email) { | |
this.email = email; | |
} | |
public User getManager() { | |
return manager; | |
} | |
@Relationship(type = "MANAGE", direction = Relationship.INCOMING) | |
public void setManager(User manager) { | |
this.manager = manager; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment