package com.jasamedika.medifirst2000.logging.hibernate.async;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;

import org.hibernate.type.Type;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;


/**
 * 
 * @author Syamsu
 */

@Component
public class LoggingSystemAsynchronous {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(LoggingSystemAsynchronous.class);

	@Autowired
	DataSource dataSource;

	@Autowired
	HttpServletRequest request;

	Map<String, Holder> commit = new HashMap<String, Holder>();

	Object entity;

	private static class Holder {
		String userName;
		String superVisor;

		String host;

		String noRecP;
		String detilCrud;
		String jSonObject;
		String method;
		String object;
		int kdHistoryLogin;
		
		Date crudIn = new Date();
		
		Object entity;
		Serializable id;
		Object[] currentState;
		Object[] previousState;
		String[] propertyNames;
		Type[] types;
		Object[] state;
	}

	final Object o = new Object();
	
	public void saveSignOutLog(String userName, int IdPegawai) {
		
		JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);

		asynchMethodtoLogSign(0, 0, userName, IdPegawai, jdbcTemplateObject, false);
	}

	/// SignIn Log

	public void saveSignInLog(int modulaplikasiId, int ruanganId, String userName, int idPegawai) {
		String currentPrincipalName = "";
		if (userName == null) {
			Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
			if (authentication == null || (authentication instanceof AnonymousAuthenticationToken)) {
				return;
			}

			currentPrincipalName = authentication.getName();
			if ("anonymousUser".equals(currentPrincipalName)) {
				return;
			}
		} else {
			currentPrincipalName = userName;
		}

		JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);

		asynchMethodtoLogSign(modulaplikasiId, ruanganId, currentPrincipalName, idPegawai, jdbcTemplateObject, true);
	}

	@Async
	public void asynchMethodtoLogSign(int modulaplikasiId, int ruanganId, String UserName, int idPegawai, JdbcTemplate jdbcTemplateObject, boolean signin) {

		String SQL = "INSERT INTO HistoryLoginModulAplikasi_S "
				+ "(id, KdProfile, StatusEnabled, KodeExternal, NamaExternal, " + "NoRec, ReportDisplay,  "
				+ "KdHistoryLogin, Kduser, IdPegawai, " 
				+ "ObjectModulAplikasiFK, NamaHost, ObjectRuanganUserFK, "
				+ "tglLogin, tglLogout) " 
				+ "VALUES "
				+ "(nextval('historyloginmodulaplikasi_m_id_seq'), ?, true, ?,  ?, " 
				+ "?, ?, "
				+ "nextval('historyloginmodulaplikasi_m_id_seq'), ?, ?, " 
				+ "?, ?, ?, " 
				+ "?, ?)";

		String uuid = UUID.randomUUID().toString().replaceAll("-", "");

		String host = request.getRemoteHost();
//		String KdRuangan = request.getHeader(Constants.HttpHeader.KD_RUANGAN) == null ? "0"
//				: request.getHeader(Constants.HttpHeader.KD_RUANGAN);

		try {
			jdbcTemplateObject
					.update("INSERT INTO modulaplikasi_s (id, kdprofile, statusenabled, norec, kdmodulaplikasi, modulaplikasi) "
							+ "VALUES (0, 0, true, '0000', '0', 'Belum Pilih Modul')");
			
			jdbcTemplateObject.update("UPDATE modulaplikasi_s SET kdprofile = 0 WHERE id = 0");
		} catch (Throwable t) {
		}
		
		try{
			jdbcTemplateObject.update("UPDATE modulaplikasi_s SET kdprofile = 0 WHERE id = 0");
		}catch(Throwable t){
			
		}

		try {
			jdbcTemplateObject
					.update("INSERT INTO modulaplikasi_m (id, kdprofile, statusenabled, norec, kdmodulaplikasi, modulaplikasi) "
							+ "VALUES (0, 0, true, '0000', '0', 'Belum Pilih Modul')");
		} catch (Throwable t) {
		}
		
		try{
			jdbcTemplateObject.update("UPDATE modulaplikasi_m SET kdprofile = 0 WHERE id = 0");
		}catch(Throwable t){
			
		}

		try {

			jdbcTemplateObject
					.update("INSERT INTO ruangan_m (id, kdprofile, statusenabled, norec, kdruangan, namaruangan, qruangan) "
							+ "VALUES (0, 0, true, '0000', '0', 'Belum Pilih Ruangan', 0)");
		} catch (Throwable t) {
		}
		
		try{
			jdbcTemplateObject.update("UPDATE ruangan_m SET kdprofile = 0 WHERE id = 0");
		}catch(Throwable t){
			
		}

		try {
			jdbcTemplateObject.update(SQL, 0, "0", "", uuid, "", UserName, idPegawai, modulaplikasiId, host,
					ruanganId, (signin)?new Date():null, (signin)?null:new Date());
		} catch (Throwable t) {
		}

		// nextval('historyloginmodulaplikasi_m_id_seq')
	}

	/// SignIn Log

	/// Operation Log //

	public void pushData(Object entity, Serializable id, Object[] currentState, Object[] previousState,
			String[] propertyNames, Type[] types) {

		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null || (authentication instanceof AnonymousAuthenticationToken)) {
			return;
		}

		String currentPrincipalName = authentication.getName();
		if ("anonymousUser".equals(currentPrincipalName)) {
			return;
		}

		synchronized (o) {
			this.entity = entity;

			Holder h = new Holder();
			h.userName = currentPrincipalName;

			h.entity = entity;
			h.id = id;
			h.currentState = currentState;
			h.previousState = previousState;
			h.propertyNames = propertyNames;
			h.types = types;

			commit.put(h.entity.getClass().getName() + "." + currentPrincipalName, h);
		}
	}

	public void insertData(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {

		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null || (authentication instanceof AnonymousAuthenticationToken)) {
			return;
		}

		String currentPrincipalName = authentication.getName();
		if ("anonymousUser".equals(currentPrincipalName)) {
			return;
		}

		synchronized (o) {
			this.entity = entity;

			Holder h = new Holder();
			h.userName = currentPrincipalName;

			h.entity = entity;
			h.id = id;
			h.state = state;
			h.propertyNames = propertyNames;
			h.types = types;
			h.previousState = new Object[state.length];
			h.currentState = state;

			commit.put(h.entity.getClass().getName() + "." + currentPrincipalName, h);

		}
	}
	

	public void deleteData(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null || (authentication instanceof AnonymousAuthenticationToken)) {
			return;
		}

		String currentPrincipalName = authentication.getName();
		if ("anonymousUser".equals(currentPrincipalName)) {
			return;
		}
		
		synchronized (o) {
			this.entity = entity;

			Holder h = new Holder();
			h.userName = currentPrincipalName;

			h.entity = entity;
			h.id = id;
			h.state = state;
			h.propertyNames = propertyNames;
			h.types = types;
			h.previousState = state;
			h.currentState = new Object[state.length];

			commit.put(h.entity.getClass().getName() + "." + currentPrincipalName, h);

		}
		
	}

	public void saveOperationLog(String sql) {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null || (authentication instanceof AnonymousAuthenticationToken)) {
			return;
		}

		String currentPrincipalName = authentication.getName();
		if ("anonymousUser".equals(currentPrincipalName)) {
			return;
		}

		JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);

		asynchMethodtoCreatedLog(sql, currentPrincipalName, jdbcTemplateObject, request);
	}
	
	private void putStringToJSONObject(JSONObject jObject, String key, String value){
		try{
			jObject.put(key, value);
		}catch(Exception e){
			
		}
	}
	
	private void putIntToJSONObject(JSONObject jObject, String key, int value){
		try{
			jObject.put(key, value);
		}catch(Exception e){
			
		}
	}
	
	private void putJSONArrayToJSONObject(JSONObject jObject, String key, JSONArray value){
		try{
			jObject.put(key, value);
		}catch(Exception e){
			
		}
	}
	
	private void putJSONObjectToJSONArray(JSONArray jArray, JSONObject value){
		try{
			jArray.put(value);
		}catch(Exception e){
			
		}
	}

	@Async
	public void asynchMethodtoCreatedLog(String sql, String UserName, JdbcTemplate jdbcTemplateObject,
			HttpServletRequest request) {

		if (entity != null) {
			Holder h = commit.get(entity.getClass().getName() + "." + UserName);
			destroy();
			if (h != null) {
				String method = "X";
				String object = "";

				StringBuilder infoBuilder = new StringBuilder();
				StringBuilder jSonObject = new StringBuilder();
				
				JSONObject jObject = new JSONObject();
				

				jSonObject.append("{\n");

				String host = request.getRemoteHost();
				
				
				String infoOperasi = "Pengambilan";

				if (sql.toUpperCase().contains("INSERT ")) {
					method = "I";
					infoBuilder.append("INSERT METOD").append("\n");
					jSonObject.append("'m':'I',\n");
					putStringToJSONObject(jObject, "m", "I");
					infoOperasi = "Penambahan data";
				} else if (sql.toUpperCase().contains("UPDATE ")) {
					method = "U";
					infoBuilder.append("UPDATE METOD").append("\n");
					jSonObject.append("'m':'U',\n");
					putStringToJSONObject(jObject, "m", "U");
					infoOperasi = "Perubahan data";
				} else if (sql.toUpperCase().contains("DELETE ")) {
					method = "D";
					infoBuilder.append("DELETE METOD").append("\n");
					jSonObject.append("'m':'D',\n");
					putStringToJSONObject(jObject, "m", "D");
					infoOperasi = "Penghapusan data";
				}

				// String AlamatUrlForm =
				// request.getHeader(Constants.HttpHeader.URL_FORM) == null ? ""
				// : request.getHeader(Constants.HttpHeader.URL_FORM);
				// String KdRuangan =
				// request.getHeader(Constants.HttpHeader.KD_RUANGAN) == null ?
				// "0" : request.getHeader(Constants.HttpHeader.KD_RUANGAN);

				Boolean isSupervising = (request.getHeader(Constants.HttpHeader.SUPERVISING) != null)
						&& ("true".equals(request.getHeader(Constants.HttpHeader.SUPERVISING))) ? true : false;

				String SQL = "SELECT id FROM HistoryLoginModulAplikasi_S WHERE Kduser = ? AND TglLogin IS NOT NULL ORDER BY id DESC, TglLogin DESC LIMIT 1";
				int kdHistoryLogin = 1;

				if (isSupervising) {
					try {
						String Username = request.getHeader(Constants.HttpHeader.KD_USER) == null ? ""
								: request.getHeader(Constants.HttpHeader.KD_USER);
						kdHistoryLogin = jdbcTemplateObject.queryForObject(SQL, new Object[] { Username },
								Integer.class);

						
						infoBuilder.append(infoOperasi + " oleh '" + Username + "'").append("\n");
						infoBuilder.append("Supervisor " + UserName).append("\n");

						jSonObject.append("'user':'" + Username + "',\n");
						jSonObject.append("'supervisor':'" + UserName + "',\n");
						
						putStringToJSONObject(jObject, "user", Username);
						putStringToJSONObject(jObject, "supervisor", UserName);

					} catch (Throwable t) {

					}
				} else {
					try {

						kdHistoryLogin = jdbcTemplateObject.queryForObject(SQL, new Object[] { UserName },
								Integer.class);
						infoBuilder.append(infoOperasi + " oleh '" + UserName + "'").append("\n");
						jSonObject.append("'user':'" + UserName + "',\n");
						jSonObject.append("'supervisor':'-',\n");
						
						putStringToJSONObject(jObject, "user", UserName);

					} catch (Throwable t) {

					}
				}

				Table table = h.entity.getClass().getAnnotation(Table.class);

				if ("ActivityPegawai".equals(h.entity.getClass().getSimpleName())) {
					return;
				}

				String className = h.entity.getClass().getName();
				object = className;

				infoBuilder.append("Di class '" + className);
				infoBuilder.append("' atau entity '" + h.entity.getClass().getSimpleName());
				infoBuilder.append("' pada table '" + table.name() + "'.").append("\n");
				infoBuilder.append("Yang berubah : ").append("\n");

				jSonObject.append("'class':'" + className + "', \n");
				jSonObject.append("'entity':'" + h.entity.getClass().getSimpleName() + "', \n");
				jSonObject.append("'table':'" + table.name() + "', \n");
				
				putStringToJSONObject(jObject, "class", className);
				putStringToJSONObject(jObject, "entity", h.entity.getClass().getSimpleName());
				putStringToJSONObject(jObject, "table", table.name());

				String noRecP = "";
				int idP = 0;
				JSONArray jArray = new JSONArray();
				
				jSonObject.append("'property' : [");
				
				putJSONArrayToJSONObject(jObject,"property", jArray);

				for (int i = 0; i < h.propertyNames.length; i++) {

					if ("norec".equalsIgnoreCase(h.propertyNames[i].trim())) {
						if (h.previousState[i] != null) {
							noRecP = String.valueOf(h.previousState[i]);
						} else if (h.currentState[i] != null) {
							noRecP = String.valueOf(h.currentState[i]);
						} else {
							noRecP = "null";
						}
					}

					if ("id".equalsIgnoreCase(h.propertyNames[i].trim())) {
						if (h.previousState[i] != null) {
							idP = (Integer) h.previousState[i];
						} else if (h.currentState[i] != null) {
							idP = (Integer) h.currentState[i];
						} else {
							idP = 0;
						}
					}

					if (h.previousState.length > i && h.currentState.length > i) {
						String columName = "";
						Class<? extends Object> cl = h.entity.getClass();
						for (;;) {
							try {
								Field field = cl.getDeclaredField(h.propertyNames[i]);
								Column column = field.getAnnotation(Column.class);
								columName = column.name();
								break;
							} catch (Throwable t) {
								cl = cl.getSuperclass();
								if (cl == null) {
									break;
								}
							}
						}
						JSONObject pObject = new JSONObject();
						boolean addObject = false;
						switch (whoIsNull(h.previousState[i], h.currentState[i])) {
							case 0:
								addObject = showNotAllNull(pObject, infoBuilder, jSonObject, columName, h.propertyNames[i], h.previousState[i], h.currentState[i]);
								break;
							case 1:
								addObject = showCurNotNull(pObject, infoBuilder, jSonObject, columName, h.propertyNames[i], h.currentState[i]);
								break;
							case 2:
								addObject = showPrevNotNull(pObject, infoBuilder, jSonObject, columName, h.propertyNames[i], h.previousState[i]);
								break;
						}
						
						if (addObject){
							putJSONObjectToJSONArray(jArray, pObject);
						}
					}
				}
				jSonObject.append("{}],\n");
				jSonObject.append("'id' : '").append(idP).append("',\n");
				
				putIntToJSONObject(jObject, "id", idP);
				
				jSonObject.append("'noRecP' : '").append(noRecP).append("'");
				putStringToJSONObject(jObject, "noRecP", noRecP);

				infoBuilder.append("Dengan id : " + idP + " dan noRecP : " + noRecP);
				infoBuilder.append(" dari host : " + host + ".").append("\n");

				jSonObject.append("\n}\n");
								

				h.host = host;
				h.detilCrud = infoBuilder.toString();
				h.noRecP = noRecP;
				h.jSonObject = jObject.toString();
				h.method = method;
				h.object = object;
				h.kdHistoryLogin = kdHistoryLogin;

				commit.put(className, h);
			}
		}
	}

	public void save(Iterator entities) {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null || (authentication instanceof AnonymousAuthenticationToken)) {
			return;
		}

		String currentPrincipalName = authentication.getName();
		if ("anonymousUser".equals(currentPrincipalName)) {
			return;
		}

		JdbcTemplate jdbcTemplateObject = new JdbcTemplate(dataSource);
		AsynchMethodSave(entities, jdbcTemplateObject, currentPrincipalName);
	}

	@Async
	public void AsynchMethodSave(Iterator entities, JdbcTemplate jdbcTemplateObject, String currentPrincipalName) {
		while (entities.hasNext()) {
			String keyName = entities.next().getClass().getName() + "." + currentPrincipalName;
			Holder h = commit.get(keyName);

			if (h != null) {
				
//				LOGGER.info("\n" + h.detilCrud);
//				LOGGER.info("\n" + h.jSonObject);
				
				addLogData(jdbcTemplateObject, h.noRecP, h.jSonObject, h.method, h.object, h.kdHistoryLogin, h.crudIn);
				commit.put(keyName, null);
			}

		}
	}

	public void addLogData(JdbcTemplate jdbcTemplateObject, String NoRecP, String jSonObject, String method,
			String object, int kdHistoryLogin, Date crudIn) {
		String SQL = "INSERT INTO HistoryLoginUser_S " + "(id, KdProfile, StatusEnabled, KodeExternal, NamaExternal, "
				+ "NoRec, ReportDisplay, " + "DetailDataCrud,  " + "ObjectHistoryLoginFK, IsCrud, NamaObjekCrud, "
				+ "NoRecord, TglCrudIn, TglCrudOut) " + "VALUES "
				+ "( nextval('historyloginuser_m_id_seq'), ?, true, ?, ?," + "?, ?, " + "?, " + "?, ?, ?, "
				+ "?, ?, ?)";

		String uuid = UUID.randomUUID().toString().replaceAll("-", "");

		try {
			jdbcTemplateObject.update(SQL, 0, "0", "", uuid, "",
					jSonObject.replaceAll("\n", "").replaceAll("\t", ""), kdHistoryLogin, method,
					object, NoRecP, crudIn, new Date());
		} catch (Throwable t) {
//			try{
//				LOGGER.warn("operasi 'LogData' gagal di log karena " + t.getMessage());
//			}catch(Exception e){
//				
//			}
		}
	}

	////// private method

	private void destroy() {
		synchronized (o) {
			this.entity = null;
		}
	}

	private boolean showObj(JSONObject pObject, StringBuilder infoBuilder, StringBuilder jSonObject, String columName, String property,
			Object prev, Object curr) {

		jSonObject.append("{\n");
		jSonObject.append("\t'name' : '" + property + "', \n");
		jSonObject.append("\t'column' : '" + columName + "', \n");
		jSonObject.append("\t'oldData' : '" + prev + "', \n");
		jSonObject.append("\t'newData' : '" + curr + "', \n");
		jSonObject.append("},\n");
		
		putStringToJSONObject(pObject, "name", property);
		putStringToJSONObject(pObject, "column", columName);
		putStringToJSONObject(pObject, "oldData", String.valueOf(prev));
		putStringToJSONObject(pObject, "newData", String.valueOf(curr));

		infoBuilder.append(property + " : Sebelumnya " + prev + " menjadi " + curr).append("\n");
		
		return true;
	}

	private boolean showDate(JSONObject pObject, StringBuilder infoBuilder, StringBuilder jSonObject, String columName, String property,
			Date prev, Date curr) {

		if (prev.compareTo(curr) != 0) {
			infoBuilder.append(property + " : Sebelumnya " + prev + " menjadi " + curr).append("\n");

			jSonObject.append("{\n");
			jSonObject.append("\t'name' : '" + property + "', \n");
			jSonObject.append("\t'column' : '" + columName + "', \n");
			jSonObject.append("\t'oldData' : '" + prev + "', \n");
			jSonObject.append("\t'newData' : '" + curr + "', \n");
			jSonObject.append("},\n");
			
			putStringToJSONObject(pObject, "name", property);
			putStringToJSONObject(pObject, "column", columName);
			putStringToJSONObject(pObject, "oldData", String.valueOf(prev));
			putStringToJSONObject(pObject, "newData", String.valueOf(curr));
			
			return true;
		}
		
		return false;
	}

	private int whoIsNull(Object o1, Object o2) {

		if (o1 == null && o2 == null) {
			return 3;
		} else if (o1 == null) {
			return 1;
		} else if (o2 == null) {
			return 2;
		} else {
			return 0;
		}

	}

	private boolean showPrevNotNull(JSONObject pObject, StringBuilder infoBuilder, StringBuilder jSonObject, String columName, String property,
			Object prev) {
		if (!property.endsWith("Id")) {
			jSonObject.append("{\n");
			jSonObject.append("\t'name' : '" + property + "', \n");
			jSonObject.append("\t'column' : '" + columName + "', \n");
			jSonObject.append("\t'oldData' : '" + prev + "', \n");
			jSonObject.append("\t'newData' : 'null', \n");
			jSonObject.append("},\n");
			
			putStringToJSONObject(pObject, "name", property);
			putStringToJSONObject(pObject, "column", columName);
			putStringToJSONObject(pObject, "oldData", String.valueOf(prev));
			putStringToJSONObject(pObject, "newData", "null");
			
			infoBuilder.append("Property : " + property + ", column name : " + columName + ", Sebelumnya " + prev
					+ "  menjadi null ").append("\n");
			
			return true;
		}
		
		return false;
	}

	private boolean showCurNotNull(JSONObject pObject, StringBuilder infoBuilder, StringBuilder jSonObject, String columName, String property,
			Object curr) {
		jSonObject.append("{\n");
		jSonObject.append("\t'name' : '" + property + "', \n");
		jSonObject.append("\t'column' : '" + columName + "', \n");
		jSonObject.append("\t'oldData' : 'null', \n");
		jSonObject.append("\t'newData' : '" + curr + "', \n");
		jSonObject.append("},\n");
		
		putStringToJSONObject(pObject, "name", property);
		putStringToJSONObject(pObject, "column", columName);
		putStringToJSONObject(pObject, "oldData", "null");
		putStringToJSONObject(pObject, "newData", String.valueOf(curr));
		
		infoBuilder.append("Property : " + property + ", column name " + columName + ", Sebelumnya null menjadi " + curr)
				.append("\n");
		
		return true;
	}

	private boolean showNotAllNull(JSONObject pObject, StringBuilder infoBuilder, StringBuilder jSonObject, String columName, String property,
			Object prev, Object curr) {

		if (prev instanceof String || curr instanceof Character) {
			if (!(String.valueOf(prev)).equals(String.valueOf(curr))) {
				jSonObject.append("{\n");
				jSonObject.append("\t'name' : '" + property + "', \n");
				jSonObject.append("\t'column' : '" + columName + "', \n");
				jSonObject.append("\t'oldData' : '" + prev + "', \n");
				jSonObject.append("\t'newData' : '" + curr + "', \n");
				jSonObject.append("},\n");
				
				putStringToJSONObject(pObject, "name", property);
				putStringToJSONObject(pObject, "column", columName);
				putStringToJSONObject(pObject, "oldData", String.valueOf(prev));
				putStringToJSONObject(pObject, "newData", String.valueOf(curr));

				infoBuilder.append("Property : " + property + ", column name " + columName + ", Sebelumnya " + prev
						+ " menjadi " + curr).append("\n");
				
				return true;
			}
		} else {
			if (prev instanceof Byte || curr instanceof Byte) {
				if (Byte.compare((byte) prev, (byte) curr) != 0) {
					return showObj(pObject, infoBuilder, jSonObject, columName, property, prev, curr);
				}
			} else if (prev instanceof Short || curr instanceof Short) {
				if (Short.compare((short) prev, (short) curr) != 0) {
					return showObj(pObject, infoBuilder, jSonObject, columName, property, prev, curr);
				}
			} else if (prev instanceof Integer || curr instanceof Integer) {
				if (Integer.compare((int) prev, (int) curr) != 0) {
					return showObj(pObject, infoBuilder, jSonObject, columName, property, prev, curr);
				}
			} else if (prev instanceof Long || curr instanceof Long) {
				if (Long.compare((long) prev, (long) curr) != 0) {
					return showObj(pObject, infoBuilder, jSonObject, columName, property, prev, curr);
				}
			} else if (prev instanceof Float || curr instanceof Float) {
				if (Float.compare((float) prev, (float) curr) != 0) {
					return showObj(pObject, infoBuilder, jSonObject, columName, property, prev, curr);
				}
			} else if (prev instanceof Double || curr instanceof Double) {
				if (Double.compare((double) prev, (double) curr) != 0) {
					return showObj(pObject, infoBuilder, jSonObject, columName, property, prev, curr);
				}
			} else if (prev instanceof Date || curr instanceof Date) {
				return showDate(pObject, infoBuilder, jSonObject, columName, property, (Date) prev, (Date) curr);
			}

		}
		
		return false;
	}

}