private boolean deleteReferenceInSystemKeyspace(Keyspace keyspace){ try (EmbeddedGraknTx<?> tx = systemKeyspaceSession.transaction(GraknTxType.WRITE)) { AttributeType<String> keyspaceName = tx.getSchemaConcept(KEYSPACE_RESOURCE); Attribute<String> attribute = keyspaceName.attribute(keyspace.getValue()); if(attribute == null) return false; Thing thing = attribute.owner(); if(thing != null) thing.delete(); attribute.delete(); existingKeyspaces.remove(keyspace); tx.commit(); } return true; }
/** * Logs a new {@link Keyspace} to the {@link KeyspaceStore}. * * @param keyspace The new {@link Keyspace} we have just created */ @Override public void addKeyspace(Keyspace keyspace){ if(containsKeyspace(keyspace)) return; try (EmbeddedGraknTx<?> tx = systemKeyspaceSession.transaction(GraknTxType.WRITE)) { AttributeType<String> keyspaceName = tx.getSchemaConcept(KEYSPACE_RESOURCE); if (keyspaceName == null) { throw GraknBackendException.initializationException(keyspace); } Attribute<String> attribute = keyspaceName.create(keyspace.getValue()); if (attribute.owner() == null) { tx.<EntityType>getSchemaConcept(KEYSPACE_ENTITY).create().has(attribute); } tx.commit(); // add to cache existingKeyspaces.add(keyspace); } catch (InvalidKBException e) { throw new RuntimeException("Could not add keyspace [" + keyspace + "] to system graph", e); } }
public Pattern pattern(Attribute concept) { Var owner = Graql.var().asUserDefined(); VarPattern resourceVar = Graql.var().asUserDefined().val(concept.value()); return owner .has(concept.type().label(),resourceVar) .id(concept.owner().id()); } }