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);
}
}
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();
}
}
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);
}
Aggregations