EntityManager em;
em = EMF.get().createEntityManager();
Long id_max = (Long)em.createQuery("select max(rr.id) from RosieRecords rr where rr.used =0").getSingleResult(); // this will give you the current record's id
Long id_min = (Long)em.createQuery("select min(rr.id) from RosieRecords rr where rr.used =0").getSingleResult(); // this will give you the current record's id
em.close();
RosieRecordsService rrs = new RosieRecordsService();
GcsFilename filename = new GcsFilename(BUCKETNAME, "RosieConversion_" + (new Date()).toString());
GcsFileOptions options = new GcsFileOptions.Builder().mimeType("text/html").acl("public-read").build();
//.addUserMetadata("myfield1", "my field value").build();
GcsOutputChannel writeChannel;
try {
writeChannel = gcsService.createOrReplace(filename, options);
// You can write to the channel using the standard Java methods.
// Here we use a PrintWriter:
PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8"));
for (Long id_count = id_min; id_count <= id_max; id_count++) {
//write record value as a new line in Google Cloud Storage object
rr = rrs.getRosieRecords(Long.valueOf(id_count));
if (rr.getUsed() != 1) {
log.info("writing out rosie record id: " + id_count);
out.print(rr.getValue());
out.flush();
rrs.setRosieRecordsUsed(id_count);
}
}
log.info("Done writing...");
writeChannel.close();
} catch (IOException e) {