// Path: src/main/java/com/github/marcelothebuilder/webpedidos/util/report/EmissorRelatorio.java
// public interface EmissorRelatorio {
// 
// 	void setConnection(Connection connection);
// 
// 	void emitir() throws IOException, JRException;
// 
// 	boolean isRelatorioGerado();
// 
// }
// 
// Path: src/main/java/com/github/marcelothebuilder/webpedidos/util/report/EmissorRelatorioWork.java
// public class EmissorRelatorioWork implements Work {
// 	private EmissorRelatorio emissor;
// 
// 	public EmissorRelatorioWork(EmissorRelatorio emissor) {
// 		this.emissor = emissor;
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.hibernate.jdbc.Work#execute(java.sql.Connection)
// 	 */
// 	@Override
// 	public void execute(Connection connection) throws SQLException {
// 		emissor.setConnection(connection);
// 		try {
// 			emissor.emitir();
// 		} catch (IOException | JRException e) {
// 			throw new SQLException(e);
// 		}
// 	}
// }
// 
// Path: src/main/java/com/github/marcelothebuilder/webpedidos/util/report/ExecutorRelatorio.java
// public interface ExecutorRelatorio {
// 
// 	void emite();
// 
// 	void setEmissor(EmissorRelatorio emissor);
// 
// }


import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import com.github.marcelothebuilder.webpedidos.util.report.EmissorRelatorio;
import com.github.marcelothebuilder.webpedidos.util.report.EmissorRelatorioWork;
import com.github.marcelothebuilder.webpedidos.util.report.ExecutorRelatorio;
/**
 * 
 */
package com.github.marcelothebuilder.webpedidos.util.report.impl;




/**
 * @author Marcelo Paixao Resende
 *
 */
@RequestScoped
public final class ExecutorRelatorioHibernate implements ExecutorRelatorio {
	
	private @Inject EntityManager manager;
	private EmissorRelatorio emissor;
	
	public ExecutorRelatorioHibernate() {
		
	}
	
	public ExecutorRelatorioHibernate(EmissorRelatorio emissor) {
		this.emissor = emissor;
	}

	/* (non-Javadoc)
	 * @see com.github.marcelothebuilder.webpedidos.util.report.ExecutorRelatorio#emite()
	 */
	@Override
	public void emite() {
		// we CAN'T close the resource, as it's managed by Hibernate
		@SuppressWarnings("resource")
		Session session = manager.unwrap(Session.class);
// Path: src/main/java/com/github/marcelothebuilder/webpedidos/util/report/EmissorRelatorio.java
// public interface EmissorRelatorio {
// 
// 	void setConnection(Connection connection);
// 
// 	void emitir() throws IOException, JRException;
// 
// 	boolean isRelatorioGerado();
// 
// }
// 
// Path: src/main/java/com/github/marcelothebuilder/webpedidos/util/report/EmissorRelatorioWork.java
// public class EmissorRelatorioWork implements Work {
// 	private EmissorRelatorio emissor;
// 
// 	public EmissorRelatorioWork(EmissorRelatorio emissor) {
// 		this.emissor = emissor;
// 	}
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.hibernate.jdbc.Work#execute(java.sql.Connection)
// 	 */
// 	@Override
// 	public void execute(Connection connection) throws SQLException {
// 		emissor.setConnection(connection);
// 		try {
// 			emissor.emitir();
// 		} catch (IOException | JRException e) {
// 			throw new SQLException(e);
// 		}
// 	}
// }
// 
// Path: src/main/java/com/github/marcelothebuilder/webpedidos/util/report/ExecutorRelatorio.java
// public interface ExecutorRelatorio {
// 
// 	void emite();
// 
// 	void setEmissor(EmissorRelatorio emissor);
// 
// }


// Path: src/main/java/com/github/marcelothebuilder/webpedidos/util/report/impl/ExecutorRelatorioHibernate.java
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import org.hibernate.Session;
import org.hibernate.jdbc.Work;
import com.github.marcelothebuilder.webpedidos.util.report.EmissorRelatorio;
import com.github.marcelothebuilder.webpedidos.util.report.EmissorRelatorioWork;
import com.github.marcelothebuilder.webpedidos.util.report.ExecutorRelatorio;

/**
 * 
 */
package com.github.marcelothebuilder.webpedidos.util.report.impl;




/**
 * @author Marcelo Paixao Resende
 *
 */
@RequestScoped
public final class ExecutorRelatorioHibernate implements ExecutorRelatorio {
	
	private @Inject EntityManager manager;
	private EmissorRelatorio emissor;
	
	public ExecutorRelatorioHibernate() {
		
	}
	
	public ExecutorRelatorioHibernate(EmissorRelatorio emissor) {
		this.emissor = emissor;
	}

	/* (non-Javadoc)
	 * @see com.github.marcelothebuilder.webpedidos.util.report.ExecutorRelatorio#emite()
	 */
	@Override
	public void emite() {
		// we CAN'T close the resource, as it's managed by Hibernate
		@SuppressWarnings("resource")
		Session session = manager.unwrap(Session.class);
		Work work = new EmissorRelatorioWork(this.emissor);