se.emilsjolander.sprinkles.Transaction Java Examples

The following examples show how to use se.emilsjolander.sprinkles.Transaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UploadService.java    From flickr-uploader with GNU General Public License v2.0 6 votes vote down vote up
public static void enqueueRetry(Iterable<Media> medias) {
	int nbQueued = 0;
	Transaction t = new Transaction();
	try {
		for (Media media : medias) {
			if (!media.isQueued() && media.getTimestampRetry() < Long.MAX_VALUE) {
				nbQueued++;
				media.setStatus(STATUS.QUEUED, t);
			}
		}
		t.setSuccessful(true);
	} finally {
		t.finish();
	}
	if (nbQueued > 0) {
		checkQueue();
	}
	wake(nbQueued > 0);
}
 
Example #2
Source File: UploadService.java    From flickr-uploader with GNU General Public License v2.0 6 votes vote down vote up
public static void dequeue(Collection<Media> medias) {
	int nbDequeued = 0;
	Transaction t = new Transaction();
	try {
		for (final Media media : medias) {
			if (media.isQueued()) {
				LOG.debug("dequeueing " + media);
				media.setStatus(STATUS.PAUSED, t);
				nbDequeued++;
				if (media.equals(mediaCurrentlyUploading)) {
					REST.kill(media);
				}
			}
		}
		t.setSuccessful(true);
	} finally {
		t.finish();
	}
	if (nbDequeued > 0) {
		checkQueue();
		for (UploadProgressListener uploadProgressListener : uploadProgressListeners) {
			uploadProgressListener.onDequeued(nbDequeued);
		}
	}
	wake();
}
 
Example #3
Source File: SprinklesTest.java    From Storm with Apache License 2.0 5 votes vote down vote up
@Override
protected void insert(List<SprinklesObject> list) {
    final Transaction transaction = new Transaction();
    for (SprinklesObject object: list) {
        object.save(transaction);
    }
    transaction.setSuccessful(true);
    transaction.finish();
}
 
Example #4
Source File: SprinklesTest.java    From Storm with Apache License 2.0 5 votes vote down vote up
@Override
protected void deleteAll() {

    // no exceptions are thrown, catch it yourself
    // throws IndexOutOfBoundsException if passed db version is not starts with 0
    // java.lang.IllegalStateException: Couldn't read row 5470, col 5 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

    final Transaction dt = new Transaction();
    for (SprinklesObject sprinklesObject : Query.all(SprinklesObject.class).get()) {
        sprinklesObject.delete(dt);
    }

    dt.setSuccessful(true);
    dt.finish();
}
 
Example #5
Source File: Media.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public void save2(Transaction t) {
	FlickrUploaderActivity.updateStatic(this);
	if (t == null) {
		save();
	} else {
		save(t);
	}
}
 
Example #6
Source File: Media.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public void setStatus(int status, Transaction t) {
	if (this.status != status) {
		this.status = status;
		if (status == STATUS.QUEUED) {
			setRetries(0);
			setTimestampQueued(System.currentTimeMillis());
		} else if (status == STATUS.UPLOADED) {
			setTimestampUploaded(System.currentTimeMillis());
		}
		if (t != null) {
			save2(t);
		}
	}
}
 
Example #7
Source File: UploadService.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static int enqueue(boolean auto, Collection<Media> medias, String photoSetTitle) {
	int nbQueued = 0;
	int nbAlreadyQueued = 0;
	int nbAlreadyUploaded = 0;
	Transaction t = new Transaction();
	try {
		for (Media media : medias) {
			if (media.isQueued()) {
				nbAlreadyQueued++;
			} else if (media.isUploaded()) {
				nbAlreadyUploaded++;
			} else if (auto && media.getRetries() > 3) {
				LOG.debug("not auto enqueueing file with too many retries : " + media);
			} else {
				nbQueued++;
				LOG.debug("enqueueing " + media);
				media.setFlickrSetTitle(photoSetTitle);
				media.setStatus(STATUS.QUEUED, t);
			}
		}
		t.setSuccessful(true);
	} finally {
		t.finish();
	}
	if (nbQueued > 0) {
		checkQueue();
	}
	for (UploadProgressListener uploadProgressListener : uploadProgressListeners) {
		uploadProgressListener.onQueued(nbQueued, nbAlreadyUploaded, nbAlreadyQueued);
	}
	wake(nbQueued > 0);
	return nbQueued;
}
 
Example #8
Source File: UploadService.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static void clear(final int status, final Callback<Void> callback) {
	if (status == STATUS.FAILED || status == STATUS.QUEUED) {
		BackgroundExecutor.execute(new Runnable() {
			@Override
			public void run() {
				int nbModified = 0;
				List<Media> medias = Utils.loadMedia(false);
				Transaction t = new Transaction();
				try {
					for (final Media media : medias) {
						if (media.getStatus() == status) {
							if (media.isQueued() && media.equals(mediaCurrentlyUploading)) {
								REST.kill(media);
							}
							media.setStatus(STATUS.PAUSED, t);
							nbModified++;
						}
					}
					t.setSuccessful(true);
				} finally {
					t.finish();
				}
				if (nbModified > 0) {
					checkQueue();
				}
				if (callback != null)
					callback.onResult(null);
			}
		});
	} else {
		LOG.error("status " + status + " is not supported");
	}
}