-
-
Save vitorenesduarte/164ded0bc52bf0e4418b to your computer and use it in GitHub Desktop.
pokemon embedded list
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
OrientGraphNoTx graphOne = new OrientGraphNoTx(URL, USER, USER); | |
try { | |
OSchema schema = graphOne.getRawGraph().getMetadata().getSchema(); | |
OClass pokemon = schema.createClass("Pokemon"); | |
pokemon.createProperty("name", OType.STRING); | |
OClass vClass = schema.getClass("V"); | |
OClass pokemonMaster = schema.createClass("PokemonMaster"); | |
pokemonMaster.setSuperClass(vClass); | |
pokemonMaster.createProperty("name", OType.STRING); | |
pokemonMaster.createProperty("age", OType.INTEGER); | |
pokemonMaster.createProperty("pokemons", OType.EMBEDDEDLIST, pokemon); | |
} finally { | |
graphOne.shutdown(); | |
} | |
String pmRID = ""; | |
OrientGraph graphTwo = new OrientGraph(URL, USER, USER); | |
try { | |
ODocument pokemon = new ODocument("Pokemon"); | |
pokemon.field("name", "Pikachu"); | |
OrientVertex v = graphTwo.addVertex("class:PokemonMaster", | |
"name", "Sacha", | |
"age", "42", | |
"pokemons", pokemon); | |
graphTwo.commit(); | |
pmRID = v.getIdentity().toString(); | |
} catch (Exception e) { | |
// ... | |
} finally { | |
graphTwo.shutdown(); | |
} | |
OrientGraph graphThree = new OrientGraph(URL, USER, USER); | |
try { | |
ODocument pokemon = new ODocument("Pokemon"); | |
pokemon.field("name", "Raichu"); | |
OrientVertex v = graphThree.getVertex(pmRID); | |
List<ODocument> pokemons = v.getProperty("pokemons"); | |
if (pokemons == null) { | |
pokemons = new ArrayList(); | |
} | |
pokemons.add(pokemon); | |
v.setProperty("pokemons", pokemons); | |
graphThree.commit(); | |
} catch (Exception e) { | |
// ... | |
} finally { | |
graphThree.shutdown(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment