use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class FileEntryDatabase method removeEntry.
@Override
public Journal removeEntry(Long id) {
Journal j = new Journal(struct.getData().get(id));
struct.getData().remove(id);
return j;
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class JavaSerializationEntryDatabase method removeEntry.
@Override
public Journal removeEntry(Long id) {
Journal j = new Journal(data.get(id));
data.remove(id);
return j;
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class HibernateEntryDatabase method removeEntry.
@Override
public Journal removeEntry(Long id) throws FailToSyncEntryException {
Transaction tr = this.getSession().beginTransaction();
try {
Journal deleted = getEntry(id);
this.getSession().delete(getEntry(id));
return deleted;
} catch (RuntimeException e) {
tr.rollback();
FailToSyncEntryException f = new FailToSyncEntryException("Cannot delete entry from database:" + e.getMessage() + " id:" + id);
throw f;
} finally {
tr.commit();
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class ExportJournalOperation method execute.
@Override
public void execute() {
// get all entries
List<Journal> allJournals = db().getAll();
Journal[] toExport = allJournals.toArray(new Journal[0]);
// set the id to null to reassign id when importing
for (Journal i : toExport) {
i.setId(null);
}
// serialize to JSON and write
try {
String result = generator.toJson(toExport);
outputTarget.write(result, StandardCharsets.UTF_16);
} catch (IOException e) {
FailToExportEntriesException f = new FailToExportEntriesException("Cannot export entries to:" + outputTarget + " message:" + e.getMessage());
f.initCause(e);
throw new RuntimeException(f);
}
}
use of net.viperfish.journal.framework.Journal in project vsDiaryWriter by shilongdai.
the class GetAllOperation method execute.
@Override
public void execute() {
List<Journal> all = new LinkedList<>();
List<JournalPointer> results = new LinkedList<>();
try {
all = db().getAll();
for (Journal i : all) {
results.add(new JournalPointer(i));
}
Collections.sort(results);
} finally {
setResult(results);
}
}
Aggregations