Search in sources :

Example 1 with NotFoundSolarThingDatabaseException

use of me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException in project solarthing by wildmountainfarms.

the class SimpleQueryHandler method queryMeta.

public MetaDatabase queryMeta() {
    final VersionedPacket<RootMetaPacket> metadata;
    synchronized (this) {
        final VersionedPacket<RootMetaPacket> currentCache = metadataCache;
        final Long lastMetadataCacheNanos = this.lastMetadataCacheNanos;
        if (lastMetadataCacheNanos != null && System.nanoTime() - lastMetadataCacheNanos < METADATA_CACHE_VALID.toNanos()) {
            requireNonNull(currentCache);
            metadata = currentCache;
        } else {
            UpdateToken updateToken = currentCache == null ? null : currentCache.getUpdateToken();
            final VersionedPacket<RootMetaPacket> newMetadata;
            try {
                newMetadata = database.queryMetadata(updateToken);
            } catch (NotFoundSolarThingDatabaseException e) {
                // If we have not defined metadata, then we return an "empty" instance
                return EmptyMetaDatabase.getInstance();
            } catch (SolarThingDatabaseException e) {
                throw new DatabaseException("Could not query meta", e);
            }
            this.lastMetadataCacheNanos = System.nanoTime();
            if (newMetadata == null) {
                requireNonNull(currentCache);
                metadata = currentCache;
            } else {
                metadataCache = newMetadata;
                metadata = newMetadata;
            }
        }
    }
    return new DefaultMetaDatabase(metadata.getPacket());
}
Also used : NotFoundSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException) RootMetaPacket(me.retrodaredevil.solarthing.type.closed.meta.RootMetaPacket) DefaultMetaDatabase(me.retrodaredevil.solarthing.type.closed.meta.DefaultMetaDatabase) DatabaseException(me.retrodaredevil.solarthing.rest.exceptions.DatabaseException) NotFoundSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException) UpdateToken(me.retrodaredevil.solarthing.database.UpdateToken) NotFoundSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)

Example 2 with NotFoundSolarThingDatabaseException

use of me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException in project solarthing by wildmountainfarms.

the class CouchDbAlterDatabase method delete.

@Override
public void delete(String documentId, UpdateToken updateToken) throws SolarThingDatabaseException {
    RevisionUpdateToken revisionUpdateToken = CouchDbSolarThingDatabase.checkUpdateToken(updateToken);
    String revision = revisionUpdateToken.getRevision();
    try {
        database.deleteDocument(documentId, revision);
    } catch (CouchDbUnauthorizedException e) {
        throw new UnauthorizedSolarThingDatabaseException(e);
    } catch (CouchDbUpdateConflictException e) {
        throw new UpdateConflictSolarThingDatabaseException("Update conflict on delete. Must not be latest revision. documentId: " + documentId + " revision: " + revision, e);
    } catch (CouchDbNotFoundException e) {
        throw new NotFoundSolarThingDatabaseException("(Not found) Could not delete documentId: " + documentId + " revision: " + revision, e);
    } catch (CouchDbException e) {
        throw new SolarThingDatabaseException("Could not delete documentId: " + documentId + " revision: " + revision, e);
    }
}
Also used : CouchDbUnauthorizedException(me.retrodaredevil.couchdbjava.exception.CouchDbUnauthorizedException) CouchDbException(me.retrodaredevil.couchdbjava.exception.CouchDbException) CouchDbNotFoundException(me.retrodaredevil.couchdbjava.exception.CouchDbNotFoundException) UpdateConflictSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.UpdateConflictSolarThingDatabaseException) UnauthorizedSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.UnauthorizedSolarThingDatabaseException) NotFoundSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException) CouchDbUpdateConflictException(me.retrodaredevil.couchdbjava.exception.CouchDbUpdateConflictException) NotFoundSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException) UnauthorizedSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.UnauthorizedSolarThingDatabaseException) UpdateConflictSolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.UpdateConflictSolarThingDatabaseException) SolarThingDatabaseException(me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)

Aggregations

NotFoundSolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.NotFoundSolarThingDatabaseException)2 SolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.SolarThingDatabaseException)2 CouchDbException (me.retrodaredevil.couchdbjava.exception.CouchDbException)1 CouchDbNotFoundException (me.retrodaredevil.couchdbjava.exception.CouchDbNotFoundException)1 CouchDbUnauthorizedException (me.retrodaredevil.couchdbjava.exception.CouchDbUnauthorizedException)1 CouchDbUpdateConflictException (me.retrodaredevil.couchdbjava.exception.CouchDbUpdateConflictException)1 UpdateToken (me.retrodaredevil.solarthing.database.UpdateToken)1 UnauthorizedSolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.UnauthorizedSolarThingDatabaseException)1 UpdateConflictSolarThingDatabaseException (me.retrodaredevil.solarthing.database.exception.UpdateConflictSolarThingDatabaseException)1 DatabaseException (me.retrodaredevil.solarthing.rest.exceptions.DatabaseException)1 DefaultMetaDatabase (me.retrodaredevil.solarthing.type.closed.meta.DefaultMetaDatabase)1 RootMetaPacket (me.retrodaredevil.solarthing.type.closed.meta.RootMetaPacket)1