Search in sources :

Example 6 with FailToSyncEntryException

use of net.viperfish.journal.framework.errors.FailToSyncEntryException in project vsDiaryWriter by shilongdai.

the class FileEntryDatabase method flush.

/**
 * flush the data into the file in JSON format
 */
public synchronized void flush() {
    JsonGenerator generator = new JsonGenerator();
    try {
        String toWrite = generator.toJson(struct);
        file.write(toWrite, StandardCharsets.UTF_16);
    } catch (IOException e) {
        FailToSyncEntryException e1 = new FailToSyncEntryException("Cannot flush entries to file at:" + file.getFile() + " message:" + e.getMessage());
        e1.initCause(e);
        throw new RuntimeException(e1);
    }
}
Also used : FailToSyncEntryException(net.viperfish.journal.framework.errors.FailToSyncEntryException) JsonGenerator(net.viperfish.framework.serialization.JsonGenerator) IOException(java.io.IOException)

Example 7 with FailToSyncEntryException

use of net.viperfish.journal.framework.errors.FailToSyncEntryException in project vsDiaryWriter by shilongdai.

the class HibernateEntryDatabase method addEntry.

@Override
public Journal addEntry(Journal j) throws FailToSyncEntryException {
    Transaction tr = this.getSession().beginTransaction();
    try {
        this.getSession().persist(j);
        this.getSession().flush();
        return j;
    } catch (RuntimeException e) {
        tr.rollback();
        FailToSyncEntryException f = new FailToSyncEntryException("Cannot persist entry to database:" + e.getMessage() + " entry:" + j);
        f.initCause(e);
        throw f;
    } finally {
        tr.commit();
    }
}
Also used : Transaction(org.hibernate.Transaction) FailToSyncEntryException(net.viperfish.journal.framework.errors.FailToSyncEntryException)

Example 8 with FailToSyncEntryException

use of net.viperfish.journal.framework.errors.FailToSyncEntryException in project vsDiaryWriter by shilongdai.

the class EditEntryOperation method execute.

@Override
public void execute() {
    Journal e = db().getEntry(id);
    edit(e);
    try {
        db().updateEntry(id, e);
    } catch (FailToSyncEntryException e1) {
        OperationErrorException fail = new OperationErrorException("Cannot update journal " + id + " in the database:" + e1.getMessage());
        fail.initCause(e1);
        throw fail;
    }
    indexer().delete(id);
    indexer().add(e);
}
Also used : FailToSyncEntryException(net.viperfish.journal.framework.errors.FailToSyncEntryException) Journal(net.viperfish.journal.framework.Journal) OperationErrorException(net.viperfish.journal.framework.errors.OperationErrorException)

Aggregations

FailToSyncEntryException (net.viperfish.journal.framework.errors.FailToSyncEntryException)8 IOException (java.io.IOException)3 Journal (net.viperfish.journal.framework.Journal)3 Transaction (org.hibernate.Transaction)3 JsonGenerator (net.viperfish.framework.serialization.JsonGenerator)2 OperationErrorException (net.viperfish.journal.framework.errors.OperationErrorException)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 FailToStoreCredentialException (net.viperfish.journal.framework.errors.FailToStoreCredentialException)1