All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.yawp.repository.FutureObject Maven / Gradle / Ivy

There is a newer version: 2.08alpha
Show newest version
package io.yawp.repository;

import io.yawp.repository.hooks.RepositoryHooks;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class FutureObject {

	private Repository r;

	private Future> futureIdRef;

	private T object;

	private boolean enableHooks;

	public FutureObject(Repository r, Future> futureIdRef, T object) {
		this.r = r;
		this.futureIdRef = futureIdRef;
		this.object = object;
	}

	public void setEnableHooks(boolean enableHooks) {
		this.enableHooks = enableHooks;
	}

	public T get() {
		try {
			setObjectId();

			if (enableHooks) {
				RepositoryHooks.afterSave(r, object);
			}

			return object;

		} catch (InterruptedException | ExecutionException e) {
			throw new RuntimeException(e);
		}
	}

	private void setObjectId() throws InterruptedException, ExecutionException {
		ObjectHolder objectHolder = new ObjectHolder(object);
		objectHolder.setId(futureIdRef.get());
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy