org.apache.commons.collections4.set.ListOrderedSet Java Examples
The following examples show how to use
org.apache.commons.collections4.set.ListOrderedSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActionGet.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private void referenceGroup(Business business, Wo wo) throws Exception { EntityManager em = business.entityManagerContainer().get(Group.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Group> cq = cb.createQuery(Group.class); Root<Group> root = cq.from(Group.class); Predicate p = cb.isMember(wo.getId(), root.get(Group_.personList)); List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList(); ListOrderedSet<Group> set = new ListOrderedSet<>(); os.stream().forEach(o -> { set.add(o); try { set.addAll(business.group().listSupNestedObject(o)); } catch (Exception e) { e.printStackTrace(); } }); List<WoGroup> wos = WoGroup.copier.copy(set.asList()); wos = business.group().sort(wos); wo.setWoGroupList(wos); }
Example #2
Source File: VertexLabel.java From sqlg with MIT License | 6 votes |
static VertexLabel createPartitionedVertexLabel( SqlgGraph sqlgGraph, Schema schema, String label, Map<String, PropertyType> columns, ListOrderedSet<String> identifiers, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(!schema.isSqlgSchema(), "createVertexLabel may not be called for \"%s\"", SQLG_SCHEMA); Preconditions.checkArgument(partitionType != PartitionType.NONE, "PartitionType must be RANGE or LIST. Found NONE."); Preconditions.checkArgument(!StringUtils.isEmpty(partitionExpression), "partitionExpression may not be null or empty when creating a partitioned vertex label."); Preconditions.checkArgument(!identifiers.isEmpty(), "Partitioned label must have at least one identifier."); VertexLabel vertexLabel = new VertexLabel(schema, label, columns, identifiers, partitionType, partitionExpression); vertexLabel.createPartitionedVertexLabelOnDb(columns, identifiers); TopologyManager.addVertexLabel(sqlgGraph, schema.getName(), label, columns, identifiers, partitionType, partitionExpression); vertexLabel.committed = false; return vertexLabel; }
Example #3
Source File: TestColumnRefactor.java From sqlg with MIT License | 6 votes |
@Test public void testMapUserSuppliedPK() { VertexLabel vertexLabel = this.sqlgGraph.getTopology().getPublicSchema() .ensureVertexLabelExist( "Person", new HashMap<String, PropertyType>() {{ put("uid", PropertyType.varChar(100)); put("name1", PropertyType.STRING); put("name2", PropertyType.STRING); put("name3", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("uid")) ); Map<String, Object> map = new HashMap<>(); map.put("uid", UUID.randomUUID().toString()); map.put("name1", "p1"); map.put("name2", "p2"); map.put("name3", "p3"); Vertex v1 = this.sqlgGraph.addVertex("Person", map); this.sqlgGraph.tx().commit(); Vertex v2 = this.sqlgGraph.traversal().V().has(T.label, "Person").next(); Assert.assertEquals(v1, v2); Assert.assertEquals("p1", v2.property("name1").value()); Assert.assertEquals("p2", v2.property("name2").value()); Assert.assertEquals("p3", v2.property("name3").value()); }
Example #4
Source File: AbstractLabel.java From sqlg with MIT License | 6 votes |
/** * Only called for a new partitioned vertex/edge label being added. * * @param label The vertex or edge's label. * @param properties The element's properties. * @param identifiers The element's identifiers. * @param partitionType The partition type. i.e. RANGE or LIST. * @param partitionExpression The sql fragment to express the partition column or expression. */ AbstractLabel(SqlgGraph sqlgGraph, String label, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(partitionType == PartitionType.RANGE || partitionType == PartitionType.LIST, "Only RANGE and LIST partitions are supported. Found %s", partitionType.name()); Preconditions.checkArgument(!partitionExpression.isEmpty(), "partitionExpression may not be an empty string."); Preconditions.checkArgument(!identifiers.isEmpty(), "Partitioned labels must have at least one identifier."); this.sqlgGraph = sqlgGraph; this.label = label; for (Map.Entry<String, PropertyType> propertyEntry : properties.entrySet()) { PropertyColumn property = new PropertyColumn(this, propertyEntry.getKey(), propertyEntry.getValue()); property.setCommitted(false); this.uncommittedProperties.put(propertyEntry.getKey(), property); } this.uncommittedIdentifiers.addAll(identifiers); this.partitionType = partitionType; this.partitionExpression = partitionExpression; }
Example #5
Source File: VertexLabel.java From sqlg with MIT License | 6 votes |
/** * Called via {@link Schema#ensureEdgeLabelExist(String, VertexLabel, VertexLabel, Map)} * This is called when the {@link EdgeLabel} does not exist and needs to be created. * * @param edgeLabelName The edge's label. * @param inVertexLabel The edge's in vertex. * @param properties The edge's properties. * @param identifiers The edge's user defined identifiers. * @return The new EdgeLabel. */ EdgeLabel addEdgeLabel( String edgeLabelName, VertexLabel inVertexLabel, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers) { EdgeLabel edgeLabel = EdgeLabel.createEdgeLabel(edgeLabelName, this, inVertexLabel, properties, identifiers); if (this.schema.isSqlgSchema()) { this.outEdgeLabels.put(this.schema.getName() + "." + edgeLabel.getLabel(), edgeLabel); inVertexLabel.inEdgeLabels.put(this.schema.getName() + "." + edgeLabel.getLabel(), edgeLabel); } else { this.uncommittedOutEdgeLabels.put(this.schema.getName() + "." + edgeLabel.getLabel(), edgeLabel); inVertexLabel.uncommittedInEdgeLabels.put(this.schema.getName() + "." + edgeLabel.getLabel(), edgeLabel); } return edgeLabel; }
Example #6
Source File: TestMultipleIDQuery.java From sqlg with MIT License | 6 votes |
@Test public void testMultipleIDs() { Schema aSchema = this.sqlgGraph.getTopology().ensureSchemaExist("A"); aSchema.ensureVertexLabelExist( "A", new HashMap<String, PropertyType>(){{ put("uid", PropertyType.varChar(100)); put("country", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid", "country"))); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); int count = 2; List<Vertex> ids = new ArrayList<>(); for (int i = 0; i < count; i++) { Vertex v = this.sqlgGraph.addVertex(T.label, "A.A", "uid", UUID.randomUUID().toString(), "country", "SA"); ids.add(v); } this.sqlgGraph.tx().commit(); List<Vertex> vertices = this.sqlgGraph.traversal().V(ids.toArray()).toList(); Assert.assertEquals(count, vertices.size()); }
Example #7
Source File: TestMultipleIDQuery.java From sqlg with MIT License | 6 votes |
@Test(expected = RuntimeException.class) public void testIdAsPrimaryKeyIsUnique() { Schema aSchema = this.sqlgGraph.getTopology().ensureSchemaExist("A"); aSchema.ensureVertexLabelExist( "A", new HashMap<String, PropertyType>(){{ put("uid", PropertyType.STRING); put("country", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid", "country"))); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().normalBatchModeOn(); List<Vertex> ids = new ArrayList<>(); int count = 5; for (int i = 0; i < count; i++) { Vertex v = this.sqlgGraph.addVertex(T.label, "A.A", "uid", "aaa", "country", "SA"); ids.add(v); } this.sqlgGraph.tx().commit(); }
Example #8
Source File: TestUserSuppliedPKBulkMode.java From sqlg with MIT License | 6 votes |
@Test public void testVertexBatchStreamMode() { Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsStreamingBatchMode()); this.sqlgGraph.getTopology().ensureVertexLabelExist( "A", new HashMap<String, PropertyType>() {{ put("name1", PropertyType.STRING); put("name2", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Arrays.asList("name1", "name2")) ); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().streamingBatchModeOn(); for (int i = 0; i < 100; i++) { this.sqlgGraph.streamVertex(T.label, "A", "name1", "a" + i, "name2", "a" + i); } this.sqlgGraph.tx().commit(); Assert.assertEquals(100, this.sqlgGraph.traversal().V().hasLabel("A").toList().size()); }
Example #9
Source File: GroupFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public List<String> listSupNestedWithPerson(String id) throws Exception { ListOrderedSet<String> set = new ListOrderedSet<>(); List<String> list = new ArrayList<>(); for (String o : this.listSupDirectWithPerson(id)) { if (!set.contains(o)) { list.add(o); } } if (!list.isEmpty()) { set.addAll(list); for (String str : list) { this.supNested(str, set); } } return set.asList(); }
Example #10
Source File: TestRecordId.java From sqlg with MIT License | 6 votes |
@Test public void testRecordIdFromElementUserSuppliedPK_With2Ids() { this.sqlgGraph.getTopology().getPublicSchema() .ensureVertexLabelExist( "A", new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2"))); String uid1 = UUID.randomUUID().toString(); String uid2 = UUID.randomUUID().toString(); this.sqlgGraph.addVertex(T.label, "A", "uid1", uid1, "uid2", uid2); this.sqlgGraph.tx().commit(); RecordId recordId = RecordId.from(this.sqlgGraph, this.sqlgGraph.getTopology().getPublicSchema().getName() + ".A" + RecordId.RECORD_ID_DELIMITER + "[" + uid1 + ", " + uid2 + "]"); Assert.assertEquals( SchemaTable.of(this.sqlgGraph.getTopology().getPublicSchema().getName(), "A"), recordId.getSchemaTable() ); Assert.assertEquals(2, recordId.getIdentifiers().size()); Assert.assertEquals(uid1, recordId.getIdentifiers().get(0)); Assert.assertEquals(uid2, recordId.getIdentifiers().get(1)); }
Example #11
Source File: GroupFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public List<String> listSupNestedWithPerson(String id) throws Exception { ListOrderedSet<String> set = new ListOrderedSet<>(); List<String> list = new ArrayList<>(); for (String o : this.listSupDirectWithPerson(id)) { if (!set.contains(o)) { list.add(o); } } if (!list.isEmpty()) { set.addAll(list); for (String str : list) { this.supNested(str, set); } } return set.asList(); }
Example #12
Source File: TestDeletedVertex.java From sqlg with MIT License | 6 votes |
@Test public void testDeletedVertexUserSuppliedPK() { this.sqlgGraph.getTopology().getPublicSchema() .ensureVertexLabelExist( "Person", new HashMap<String, PropertyType>() {{ put("name", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("name")) ); Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "marko"); Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "pieter"); this.sqlgGraph.tx().commit(); this.sqlgGraph.tx().close(); v1.remove(); this.sqlgGraph.tx().commit(); Assert.assertFalse(this.sqlgGraph.traversal().V(v1.id()).hasNext()); Assert.assertTrue(this.sqlgGraph.traversal().V(v2.id()).hasNext()); }
Example #13
Source File: TestRecordId.java From sqlg with MIT License | 6 votes |
@Test public void testRecordIdFromElementUserSuppliedPK() { this.sqlgGraph.getTopology().getPublicSchema() .ensureVertexLabelExist( "A", new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("uid1"))); String uid1 = UUID.randomUUID().toString(); this.sqlgGraph.addVertex(T.label, "A", "uid1", uid1); this.sqlgGraph.tx().commit(); RecordId recordId = RecordId.from(this.sqlgGraph, this.sqlgGraph.getTopology().getPublicSchema().getName() + ".A" + RecordId.RECORD_ID_DELIMITER + "[" + uid1 + "]"); Assert.assertEquals( SchemaTable.of(this.sqlgGraph.getTopology().getPublicSchema().getName(), "A"), recordId.getSchemaTable() ); Assert.assertEquals(1, recordId.getIdentifiers().size()); Assert.assertEquals(uid1, recordId.getIdentifiers().get(0)); }
Example #14
Source File: ListTools.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public static <T> List<T> addWithProperty(Object obj, String propertyName, boolean ignoreNull, T... ts) throws Exception { List<T> list = new ArrayList<>(); ListOrderedSet<T> set = new ListOrderedSet<T>(); Object o = PropertyUtils.getProperty(obj, propertyName); if (null != o) { set.addAll((List<T>) o); } for (T t : ts) { if (null == t && ignoreNull) { continue; } if (!set.contains(t)) { set.add(t); list.add(t); } } PropertyUtils.setProperty(obj, propertyName, set.asList()); return list; }
Example #15
Source File: EdgeLabel.java From sqlg with MIT License | 6 votes |
private EdgeLabel( boolean forSqlgSchema, String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties, ListOrderedSet<String> identifiers) { super(outVertexLabel.getSchema().getSqlgGraph(), edgeLabelName, properties, identifiers); if (forSqlgSchema) { this.outVertexLabels.add(outVertexLabel); this.inVertexLabels.add(inVertexLabel); } else { this.uncommittedOutVertexLabels.add(outVertexLabel); this.uncommittedInVertexLabels.add(inVertexLabel); } // this is a topology edge label, the columns exist if (forSqlgSchema) { for (PropertyColumn pc : this.uncommittedProperties.values()) { pc.setCommitted(true); this.properties.put(pc.getName(), pc); } this.uncommittedProperties.clear(); } this.topology = outVertexLabel.getSchema().getTopology(); }
Example #16
Source File: ListTools.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public static <T> List<T> subtractWithProperty(Object obj, String propertyName, T... ts) throws Exception { List<T> list = new ArrayList<>(); ListOrderedSet<T> set = new ListOrderedSet<T>(); Object o = PropertyUtils.getProperty(obj, propertyName); if (null != o) { set.addAll((List<T>) o); } for (T t : ts) { if (set.contains(t)) { set.remove(t); list.add(t); } } PropertyUtils.setProperty(obj, propertyName, set.asList()); return list; }
Example #17
Source File: ListTools.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public static <T> List<T> subtractWithProperty(Object obj, String propertyName, List<T> ts) throws Exception { List<T> list = new ArrayList<>(); ListOrderedSet<T> set = new ListOrderedSet<T>(); Object o = PropertyUtils.getProperty(obj, propertyName); if (null != o) { set.addAll((List<T>) o); } if (null != ts) { for (T t : ts) { if (set.contains(t)) { set.remove(t); list.add(t); } } } PropertyUtils.setProperty(obj, propertyName, set.asList()); return list; }
Example #18
Source File: Schema.java From sqlg with MIT License | 6 votes |
public VertexLabel ensureVertexLabelExist(final String label, final Map<String, PropertyType> columns, ListOrderedSet<String> identifiers) { Objects.requireNonNull(label, "Given table must not be null"); Preconditions.checkArgument(!label.startsWith(VERTEX_PREFIX), "label may not be prefixed with \"%s\"", VERTEX_PREFIX); for (String identifier : identifiers) { Preconditions.checkState(columns.containsKey(identifier), "The identifiers must be in the specified columns. \"%s\" not found", identifier); } Optional<VertexLabel> vertexLabelOptional = this.getVertexLabel(label); if (!vertexLabelOptional.isPresent()) { this.topology.lock(); vertexLabelOptional = this.getVertexLabel(label); //noinspection OptionalIsPresent if (!vertexLabelOptional.isPresent()) { return this.createVertexLabel(label, columns, identifiers); } else { return vertexLabelOptional.get(); } } else { VertexLabel vertexLabel = vertexLabelOptional.get(); //check if all the columns are there. vertexLabel.ensurePropertiesExist(columns); return vertexLabel; } }
Example #19
Source File: Schema.java From sqlg with MIT License | 5 votes |
public EdgeLabel ensureEdgeLabelExist( final String edgeLabelName, final VertexLabel outVertexLabel, final VertexLabel inVertexLabel, Map<String, PropertyType> columns) { return ensureEdgeLabelExist(edgeLabelName, outVertexLabel, inVertexLabel, columns, new ListOrderedSet<>()); }
Example #20
Source File: EdgeLabel.java From sqlg with MIT License | 5 votes |
static EdgeLabel createEdgeLabel( String edgeLabelName, VertexLabel outVertexLabel, VertexLabel inVertexLabel, Map<String, PropertyType> properties) { return createEdgeLabel(edgeLabelName, outVertexLabel, inVertexLabel, properties, new ListOrderedSet<>()); }
Example #21
Source File: TestIoEdge.java From sqlg with MIT License | 5 votes |
@Test public void shouldReadWriteEdgeUserSuppliedPK() throws Exception { VertexLabel personVertexLabel = this.sqlgGraph.getTopology().getPublicSchema(). ensureVertexLabelExist( "person", new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); personVertexLabel.ensureEdgeLabelExist( "friend", personVertexLabel, new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); put("weight", PropertyType.DOUBLE); put("acl", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); final Vertex v1 = this.sqlgGraph.addVertex(T.label, "person", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); final Vertex v2 = this.sqlgGraph.addVertex(T.label, "person", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); final Edge e = v1.addEdge("friend", v2, "weight", 0.5d, "acl", "rw", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); assertEdge(v1, v2, e, true); }
Example #22
Source File: TestSimpleVertexEdgeGremlin.java From sqlg with MIT License | 5 votes |
@Test public void testGetEdgeById() { VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist( this.sqlgGraph.getSqlDialect().getPublicSchema(), "A", new HashMap<String, PropertyType>() {{ put("name", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("name")) ); VertexLabel bVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist( this.sqlgGraph.getSqlDialect().getPublicSchema(), "B", new HashMap<String, PropertyType>() {{ put("name", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("name")) ); aVertexLabel.ensureEdgeLabelExist( "ab", bVertexLabel, new HashMap<String, PropertyType>() {{ put("name", PropertyType.varChar(100)); put("country", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("name")) ); Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "A1"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "A1"); Edge e = a1.addEdge("ab", b1, "name", "halo", "country", "earth"); this.sqlgGraph.tx().commit(); Vertex otherV = this.sqlgGraph.traversal().V(a1.id()).next(); Assert.assertEquals(a1, otherV); Edge other = this.sqlgGraph.traversal().E(e.id()).next(); Assert.assertEquals(e, other); }
Example #23
Source File: TestPartitioning.java From sqlg with MIT License | 5 votes |
@Test public void testReloadVertexLabelWithPartitions() { Schema publicSchema = this.sqlgGraph.getTopology().getPublicSchema(); VertexLabel a = publicSchema.ensurePartitionedVertexLabelExist( "A", new LinkedHashMap<String, PropertyType>() {{ put("int1", PropertyType.INTEGER); put("int2", PropertyType.INTEGER); put("int3", PropertyType.INTEGER); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("int1")), PartitionType.RANGE, "int1,int2"); a.ensureRangePartitionExists("part1", "1,1", "5,5"); a.ensureRangePartitionExists("part2", "5,5", "10,10"); this.sqlgGraph.tx().commit(); //Delete the topology dropSqlgSchema(this.sqlgGraph); this.sqlgGraph.tx().commit(); this.sqlgGraph.close(); try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { a = sqlgGraph1.getTopology().getPublicSchema().getVertexLabel("A").get(); Assert.assertEquals("int1,int2", a.getPartitionExpression()); Assert.assertEquals(PartitionType.RANGE, a.getPartitionType()); Optional<Partition> part1 = a.getPartition("part1"); Assert.assertTrue(part1.isPresent()); Assert.assertNull(part1.get().getPartitionExpression()); Assert.assertEquals("1, 1", part1.get().getFrom()); Assert.assertEquals("5, 5", part1.get().getTo()); Optional<Partition> part2 = a.getPartition("part2"); Assert.assertTrue(part2.isPresent()); Assert.assertNull(part2.get().getPartitionExpression()); Assert.assertEquals("5, 5", part2.get().getFrom()); Assert.assertEquals("10, 10", part2.get().getTo()); } }
Example #24
Source File: TestPartitioning.java From sqlg with MIT License | 5 votes |
@Test public void testPartitionedEdgesList() { VertexLabel person = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("Person"); VertexLabel address = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("Address"); EdgeLabel livedAt = person.ensurePartitionedEdgeLabelExist( "liveAt", address, new LinkedHashMap<String, PropertyType>() {{ put("date", PropertyType.LOCALDATE); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("date")), PartitionType.LIST, "date"); Partition p1 = livedAt.ensureListPartitionExists("livedAt1", "'2016-07-01'"); Partition p2 = livedAt.ensureListPartitionExists("livedAt2", "'2016-07-02'"); Partition p3 = livedAt.ensureListPartitionExists("livedAt2", "'2016-07-03'"); Partition p4 = livedAt.ensureListPartitionExists("livedAt2", "'2016-07-04'"); this.sqlgGraph.tx().commit(); Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person"); Vertex a1 = this.sqlgGraph.addVertex(T.label, "Address"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "Address"); person1.addEdge("liveAt", a1, "date", LocalDate.of(2016, 7, 1)); person1.addEdge("liveAt", a2, "date", LocalDate.of(2016, 7, 2)); this.sqlgGraph.tx().commit(); Assert.assertEquals(2, this.sqlgGraph.traversal().E().hasLabel("liveAt").count().next(), 0); Assert.assertEquals(1, this.sqlgGraph.traversal().E().hasLabel("liveAt").has("date", LocalDate.of(2016, 7, 1)).count().next(), 0); try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { Assert.assertEquals(2, this.sqlgGraph.traversal().E().hasLabel("liveAt").count().next(), 0); Assert.assertEquals(1, this.sqlgGraph.traversal().E().hasLabel("liveAt").has("date", LocalDate.of(2016, 7, 1)).count().next(), 0); Assert.assertEquals(2, sqlgGraph1.topology().V().hasLabel(Topology.SQLG_SCHEMA + "." + Topology.SQLG_SCHEMA_PARTITION).count().next(), 0); } catch (Exception e) { Assert.fail(e.getMessage()); } }
Example #25
Source File: TestDeletedVertex.java From sqlg with MIT License | 5 votes |
@Test public void testRemoveInVertexRemovesEdgesUserSuppliedPK() { VertexLabel personVertexLabel = this.sqlgGraph.getTopology().getPublicSchema() .ensureVertexLabelExist( "Person", new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); put("name", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); VertexLabel dogVertexLabel = this.sqlgGraph.getTopology().getPublicSchema() .ensureVertexLabelExist( "Dog", new HashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); put("name", PropertyType.STRING); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); personVertexLabel.ensureEdgeLabelExist( "friend", dogVertexLabel, new HashMap<String, PropertyType>() {{ put("uid", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("uid")) ); Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString(), "name", "marko"); Vertex dog = this.sqlgGraph.addVertex(T.label, "Dog", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString(), "name", "snowy"); person.addEdge("friend", dog, "uid", UUID.randomUUID().toString()); this.sqlgGraph.tx().commit(); dog.remove(); Assert.assertEquals(0, this.sqlgGraph.traversal().E().toList().size()); }
Example #26
Source File: TestDropStep.java From sqlg with MIT License | 5 votes |
@Test public void testUserSuppliedDrop() { this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist( "A", new LinkedHashMap<String, PropertyType>() {{ put("name", PropertyType.STRING); put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); this.sqlgGraph.tx().commit(); String uid1 = UUID.randomUUID().toString(); String uid2 = UUID.randomUUID().toString(); this.sqlgGraph.addVertex(T.label, "A", "uid1", uid1, "uid2", uid2, "name", "a1"); this.sqlgGraph.addVertex(T.label, "A", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString(), "name", "a2"); this.sqlgGraph.addVertex(T.label, "A", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString(), "name", "a3"); this.sqlgGraph.tx().commit(); Assert.assertEquals(3, this.sqlgGraph.traversal().V().hasLabel("A").count().next(), 0); SchemaTable schemaTable = SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A"); this.sqlgGraph.traversal().V().hasLabel("A") .hasId(RecordId.from(sqlgGraph, schemaTable.getSchema() + "." + schemaTable.getTable() + RecordId.RECORD_ID_DELIMITER + "[" + uid1 + "," + uid2 + "]")) .drop().iterate(); Assert.assertEquals(2, this.sqlgGraph.traversal().V().hasLabel("A").count().next(), 0); this.sqlgGraph.addVertex(T.label, "A", "uid1", uid1, "uid2", uid2, "name", "a1"); this.sqlgGraph.tx().commit(); Assert.assertEquals(3, this.sqlgGraph.traversal().V().hasLabel("A").count().next(), 0); this.sqlgGraph.traversal().V().hasLabel("A") .has("name", "a1") .drop().iterate(); Assert.assertEquals(2, this.sqlgGraph.traversal().V().hasLabel("A").count().next(), 0); }
Example #27
Source File: TestPartitioning.java From sqlg with MIT License | 5 votes |
@Test public void testReloadVertexLabelWithNoPartitions() { Schema publicSchema = this.sqlgGraph.getTopology().getPublicSchema(); publicSchema.ensurePartitionedVertexLabelExist( "A", new LinkedHashMap<String, PropertyType>() {{ put("int1", PropertyType.INTEGER); put("int2", PropertyType.INTEGER); put("int3", PropertyType.INTEGER); }}, ListOrderedSet.listOrderedSet(Collections.singletonList("int1")), PartitionType.RANGE, "int1,int2"); this.sqlgGraph.tx().commit(); //Delete the topology dropSqlgSchema(this.sqlgGraph); this.sqlgGraph.tx().commit(); this.sqlgGraph.close(); try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) { VertexLabel a = sqlgGraph1.getTopology().getPublicSchema().getVertexLabel("A").get(); Assert.assertEquals("int1,int2", a.getPartitionExpression()); Assert.assertEquals(PartitionType.RANGE, a.getPartitionType()); } }
Example #28
Source File: TestDropStepBarrier.java From sqlg with MIT License | 5 votes |
@Test public void dropPropertyuserSuppliedIds() { final AtomicBoolean triggered = new AtomicBoolean(false); final MutationListener listener = new AbstractMutationListener() { @Override public void vertexPropertyRemoved(final VertexProperty element) { triggered.set(true); } }; final EventStrategy.Builder builder = EventStrategy.build().addListener(listener); final EventStrategy eventStrategy = builder.create(); VertexLabel aVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist( "A", new LinkedHashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); put("uid3", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); VertexLabel bVertexLabel = this.sqlgGraph.getTopology().ensureVertexLabelExist( "B", new LinkedHashMap<String, PropertyType>() {{ put("uid1", PropertyType.varChar(100)); put("uid2", PropertyType.varChar(100)); put("uid3", PropertyType.varChar(100)); }}, ListOrderedSet.listOrderedSet(Arrays.asList("uid1", "uid2")) ); this.sqlgGraph.tx().commit(); Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "uid1", UUID.randomUUID().toString(), "uid2", UUID.randomUUID().toString()); this.sqlgGraph.tx().commit(); this.sqlgGraph.traversal().withStrategies(eventStrategy).V().properties("name").drop().iterate(); this.sqlgGraph.tx().commit(); Assert.assertTrue(triggered.get()); Assert.assertFalse(this.sqlgGraph.traversal().V().hasLabel("A").has("name").hasNext()); }
Example #29
Source File: AbstractLabel.java From sqlg with MIT License | 5 votes |
public ListOrderedSet<String> getIdentifiers() { ListOrderedSet<String> result = ListOrderedSet.listOrderedSet(this.identifiers); if (this.getSchema().getTopology().isSqlWriteLockHeldByCurrentThread()) { result.addAll(this.uncommittedIdentifiers); } return result; }
Example #30
Source File: Schema.java From sqlg with MIT License | 5 votes |
private VertexLabel createPartitionedVertexLabel( String vertexLabelName, Map<String, PropertyType> columns, ListOrderedSet<String> identifers, PartitionType partitionType, String partitionExpression) { Preconditions.checkState(!this.isSqlgSchema(), "createVertexLabel may not be called for \"%s\"", SQLG_SCHEMA); Preconditions.checkArgument(!vertexLabelName.startsWith(VERTEX_PREFIX), "vertex label may not start with " + VERTEX_PREFIX); this.sqlgGraph.getSqlDialect().validateTableName(vertexLabelName); for (String columnName : columns.keySet()) { this.sqlgGraph.getSqlDialect().validateColumnName(columnName); } this.uncommittedRemovedVertexLabels.remove(this.name + "." + VERTEX_PREFIX + vertexLabelName); VertexLabel vertexLabel = VertexLabel.createPartitionedVertexLabel( this.sqlgGraph, this, vertexLabelName, columns, identifers, partitionType, partitionExpression ); this.uncommittedVertexLabels.put(this.name + "." + VERTEX_PREFIX + vertexLabelName, vertexLabel); this.getTopology().fire(vertexLabel, "", TopologyChangeAction.CREATE); return vertexLabel; }