package org.jerrymouse.database.hadoop.jpa;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.Query;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;

public class HadoopEntityManager implements EntityManager {
	HBaseAdmin hBaseAdmin;
	HBaseConfiguration hBaseConfiguration;

	public HadoopEntityManager(HBaseAdmin hBaseAdmin,
			HBaseConfiguration hBaseConfiguration) {
		this.hBaseAdmin = hBaseAdmin;
		this.hBaseConfiguration = hBaseConfiguration;
	}

	public void clear() {

	}

	public void close() {

	}

	public boolean contains(Object entity) {
		throw new UnsupportedOperationException();
	}

	public Query createNamedQuery(String name) {
		throw new UnsupportedOperationException();
	}

	public Query createNativeQuery(String sqlString) {
		throw new UnsupportedOperationException();
	}

	public Query createNativeQuery(String sqlString, Class resultClass) {
		throw new UnsupportedOperationException();

	}

	public Query createNativeQuery(String sqlString, String resultSetMapping) {
		throw new UnsupportedOperationException();
	}

	public Query createQuery(String qlString) {
		return new HadoopQuery(new HadoopTable(hBaseAdmin,hBaseConfiguration), qlString);
	}

	public <T> T find(Class<T> entityClass, Object primaryKey) {
		HadoopEntity bean = new HadoopEntity(entityClass, new HadoopTable(hBaseAdmin,hBaseConfiguration));
		bean.find(primaryKey);
		return (T) bean.getObject();
	}

	public void flush() {
		throw new UnsupportedOperationException();
	}

	public Object getDelegate() {
		throw new UnsupportedOperationException();

	}

	public FlushModeType getFlushMode() {
		throw new UnsupportedOperationException();
	}

	public <T> T getReference(Class<T> entityClass, Object primaryKey) {
		throw new UnsupportedOperationException();
	}

	public EntityTransaction getTransaction() {
		return new HadoopEntityTransaction();
	}

	public boolean isOpen() {
		throw new UnsupportedOperationException();
	}

	public void joinTransaction() {
		throw new UnsupportedOperationException();
	}

	public void lock(Object entity, LockModeType lockMode) {
		throw new UnsupportedOperationException();
	}

	public <T> T merge(T entity) {
		throw new UnsupportedOperationException();
	}

	public void persist(Object entity) {
		HadoopEntity bean = new HadoopEntity(entity, new HadoopTable(hBaseAdmin,hBaseConfiguration));
		bean.put();
	}

	public void refresh(Object entity) {
		throw new UnsupportedOperationException();
	}

	public void remove(Object entity) {
		HadoopEntity bean = new HadoopEntity(entity, new HadoopTable(hBaseAdmin,hBaseConfiguration));
		bean.remove();
	}

	public void setFlushMode(FlushModeType flushMode) {
		throw new UnsupportedOperationException();
	}


}
