use of org.umlg.sqlg.structure.topology.Schema in project sqlg by pietermartin.
the class SchemaTableTree method hasOnlyOneInOutEdgeLabel.
private boolean hasOnlyOneInOutEdgeLabel(SchemaTable schemaTable) {
Optional<Schema> schemaOptional = sqlgGraph.getTopology().getSchema(schemaTable.getSchema());
Preconditions.checkState(schemaOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.getSchema());
Schema schema = schemaOptional.get();
boolean result = true;
if (schemaTable.isVertexTable()) {
// Need to delete any in/out edges.
Optional<VertexLabel> vertexLabelOptional = schema.getVertexLabel(schemaTable.withOutPrefix().getTable());
Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.withOutPrefix().getTable());
VertexLabel vertexLabel = vertexLabelOptional.get();
Collection<EdgeLabel> outEdgeLabels = vertexLabel.getOutEdgeLabels().values();
for (EdgeLabel edgeLabel : outEdgeLabels) {
result = edgeLabel.getOutVertexLabels().size() == 1;
if (!result) {
break;
}
}
if (result) {
Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values();
for (EdgeLabel edgeLabel : inEdgeLabels) {
result = edgeLabel.getInVertexLabels().size() == 1;
if (!result) {
break;
}
}
}
}
return result;
}
use of org.umlg.sqlg.structure.topology.Schema in project sqlg by pietermartin.
the class TestMultipleThreadMultipleJvm method testMultiThreadedSchemaCreation.
@Test
public void testMultiThreadedSchemaCreation() throws Exception {
// number graphs, pretending its a separate jvm
int NUMBER_OF_GRAPHS = 5;
int NUMBER_OF_SCHEMAS = 100;
// Pre-create all the graphs
List<SqlgGraph> graphs = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_GRAPHS; i++) {
graphs.add(SqlgGraph.open(configuration));
}
logger.info(String.format("Done firing up %d graphs", NUMBER_OF_GRAPHS));
ExecutorService poolPerGraph = Executors.newFixedThreadPool(NUMBER_OF_GRAPHS);
CompletionService<SqlgGraph> poolPerGraphsExecutorCompletionService = new ExecutorCompletionService<>(poolPerGraph);
try {
List<Future<SqlgGraph>> results = new ArrayList<>();
for (final SqlgGraph sqlgGraphAsync : graphs) {
results.add(poolPerGraphsExecutorCompletionService.submit(() -> {
for (int i = 0; i < NUMBER_OF_SCHEMAS; i++) {
// noinspection Duplicates
try {
sqlgGraphAsync.getTopology().ensureSchemaExist("schema_" + i);
final Random random = new Random();
if (random.nextBoolean()) {
sqlgGraphAsync.tx().commit();
} else {
sqlgGraphAsync.tx().rollback();
}
} catch (Exception e) {
sqlgGraphAsync.tx().rollback();
throw new RuntimeException(e);
}
}
return sqlgGraphAsync;
}));
}
poolPerGraph.shutdown();
for (Future<SqlgGraph> result : results) {
result.get(100, TimeUnit.SECONDS);
}
Thread.sleep(1000);
for (SqlgGraph graph : graphs) {
assertEquals(this.sqlgGraph.getTopology(), graph.getTopology());
for (Schema schema : graph.getTopology().getSchemas()) {
assertTrue(schema.isCommitted());
}
}
} finally {
for (SqlgGraph graph : graphs) {
graph.close();
}
}
}
use of org.umlg.sqlg.structure.topology.Schema in project sqlg by pietermartin.
the class TestBatchGlobalUniqueIndexes method testGlobalUniqueIndexOnVertexNormalBatchMode.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testGlobalUniqueIndexOnVertexNormalBatchMode() throws InterruptedException {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsBatchMode());
Map<String, PropertyType> properties = new HashMap<>();
properties.put("namec", PropertyType.STRING);
properties.put("namea", PropertyType.STRING);
properties.put("nameb", PropertyType.STRING);
this.sqlgGraph.getTopology().ensureVertexLabelExist("A", properties);
@SuppressWarnings("OptionalGetWithoutIsPresent") Collection<PropertyColumn> propertyColumns = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("A").get().getProperties().values();
this.sqlgGraph.getTopology().ensureGlobalUniqueIndexExist(new HashSet<>(propertyColumns));
this.sqlgGraph.tx().commit();
Schema globalUniqueIndexSchema = this.sqlgGraph.getTopology().getGlobalUniqueIndexSchema();
Optional<GlobalUniqueIndex> globalUniqueIndexOptional = globalUniqueIndexSchema.getGlobalUniqueIndex("A_namea_A_nameb_A_namec");
Assert.assertTrue(globalUniqueIndexOptional.isPresent());
Optional<PropertyColumn> nameaPropertyColumnOptional = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("A").get().getProperty("namea");
Assert.assertTrue(nameaPropertyColumnOptional.isPresent());
@SuppressWarnings("OptionalGetWithoutIsPresent") Set<GlobalUniqueIndex> globalUniqueIndices = nameaPropertyColumnOptional.get().getGlobalUniqueIndices();
Assert.assertEquals(1, globalUniqueIndices.size());
GlobalUniqueIndex globalUniqueIndex = globalUniqueIndices.iterator().next();
Assert.assertEquals("A_namea_A_nameb_A_namec", globalUniqueIndex.getName());
this.sqlgGraph.tx().normalBatchModeOn();
Vertex a = this.sqlgGraph.addVertex(T.label, "A", "namea", "a");
this.sqlgGraph.tx().commit();
try {
this.sqlgGraph.tx().normalBatchModeOn();
this.sqlgGraph.addVertex(T.label, "A", "namea", "a");
this.sqlgGraph.tx().commit();
Assert.fail("GlobalUniqueIndex should prevent this from executing");
} catch (Exception e) {
// swallow
}
this.sqlgGraph.tx().rollback();
this.sqlgGraph.tx().normalBatchModeOn();
this.sqlgGraph.addVertex(T.label, "A", "namea", "aa");
this.sqlgGraph.tx().commit();
testGlobalUniqueIndexOnVertexNormalBatchMode_assert(this.sqlgGraph, globalUniqueIndex, a);
if (this.sqlgGraph1 != null) {
Thread.sleep(1000);
testGlobalUniqueIndexOnVertexNormalBatchMode_assert(this.sqlgGraph1, globalUniqueIndex, a);
}
}
use of org.umlg.sqlg.structure.topology.Schema in project sqlg by pietermartin.
the class TestTopologyDeleteSpecific method testSchemaDelete.
/**
* this failed with a NPE because we lost the table definition we're working on
*
* @throws Exception
*/
@Test
public void testSchemaDelete() throws Exception {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsDistribution());
String schema = "willDelete";
Vertex v1 = sqlgGraph.addVertex(T.label, schema + ".t1", "name", "n1", "hello", "world");
sqlgGraph.tx().commit();
Configuration c = getConfigurationClone();
c.setProperty(SqlgGraph.DISTRIBUTED, true);
sqlgGraph = SqlgGraph.open(c);
sqlgGraph.getTopology().getSchema(schema).ifPresent((Schema s) -> s.remove(false));
sqlgGraph.tx().commit();
v1 = sqlgGraph.addVertex(T.label, schema + ".t1", "name", "n1");
Vertex v2 = sqlgGraph.addVertex(T.label, schema + ".t2", "name", "n2");
Edge e1 = v1.addEdge("e1", v2);
sqlgGraph.tx().commit();
sqlgGraph.tx().normalBatchModeOn();
v1.property("hello", "world");
// this line was failing
e1.property("hello", "world");
sqlgGraph.tx().commit();
assertEquals("world", e1.value("hello"));
}
use of org.umlg.sqlg.structure.topology.Schema in project sqlg by pietermartin.
the class TestSchemaEagerCreation method testAddEdgeLabelViaOutVertexLabel.
@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
public void testAddEdgeLabelViaOutVertexLabel() {
VertexLabel a = this.sqlgGraph.getTopology().ensureSchemaExist("A").ensureVertexLabelExist("A");
Optional<Schema> schemaOptional = this.sqlgGraph.getTopology().getSchema("A");
assertTrue(schemaOptional.isPresent());
VertexLabel b = schemaOptional.get().ensureVertexLabelExist("B");
a.ensureEdgeLabelExist("ab", b);
this.sqlgGraph.tx().commit();
Optional<EdgeLabel> edgeLabel = this.sqlgGraph.getTopology().getSchema("A").get().getEdgeLabel("ab");
assertTrue(edgeLabel.isPresent());
assertEquals("ab", edgeLabel.get().getLabel());
}
Aggregations