Search in sources :

Example 1 with SchemaUpdateException

use of nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaUpdateException in project timbuctoo by HuygensING.

the class BdbSchemaStore method finish.

@Override
public void finish() {
    LOG.info("Finished processing entities");
    importStatus.setStatus("Finished processing entities");
    // Step 3: Add type information to inverse predicates
    for (Map.Entry<String, Type> typeEntry : types.entrySet()) {
        Type type = typeEntry.getValue();
        String typeName = typeEntry.getKey();
        for (Predicate predicate : type.getPredicates()) {
            predicate.finish();
            if (predicate.getDirection() == Direction.IN) {
                continue;
            }
            for (String referenceType : predicate.getReferenceTypes().keySet()) {
                try {
                    types.get(referenceType).getPredicate(predicate.getName(), // There must be an inverse for each outward predicate
                    Direction.IN).incReferenceType(type.getName(), 1);
                } catch (Exception e) {
                    String cause = "Referenced type " + referenceType + " not found";
                    try {
                        if (types.containsKey(referenceType)) {
                            cause = "type does not have the inverse predicate " + predicate.getName();
                            if (types.get(referenceType).getPredicate(predicate.getName(), Direction.IN) != null) {
                                cause = "Something failed during addreferencetype(" + typeName + ")";
                            }
                        }
                        LOG.error("Error during inverse generation (ignored): " + cause, e);
                        importStatus.addError("Error during inverse generation (ignored): " + cause, e);
                    } catch (Exception e2) {
                        LOG.error("Error during inverse generation " + cause, e);
                        importStatus.addError("Error during inverse generation " + cause, e);
                        LOG.error("Error during recovery generation ", e2);
                        importStatus.addError("Error during recovery generation ", e2);
                    }
                }
            }
        }
    }
    try {
        try {
            String serializedValue = objectMapper.writeValueAsString(types);
            dataStore.setValue(serializedValue);
            dataStore.commit();
            stableTypes = readTypes(serializedValue);
        } catch (IOException | DatabaseWriteException e) {
            throw new SchemaUpdateException(e);
        }
    } catch (SchemaUpdateException e) {
        e.printStackTrace();
    }
}
Also used : Type(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type) ChangeType(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType) DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException) IOException(java.io.IOException) SchemaUpdateException(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaUpdateException) HashMap(java.util.HashMap) Map(java.util.Map) DatabaseWriteException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException) IOException(java.io.IOException) SchemaUpdateException(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaUpdateException) Predicate(nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DatabaseWriteException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.DatabaseWriteException)1 ChangeType (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.ChangeType)1 SchemaUpdateException (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaUpdateException)1 Predicate (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Predicate)1 Type (nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.dto.Type)1