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

org.liveSense.api.sql.AnnotationHelper Maven / Gradle / Ivy

The newest version!
package org.liveSense.api.sql;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.liveSense.core.BaseAnnotationHelper;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.beanutils.BeanUtilsBean;

public class AnnotationHelper extends BaseAnnotationHelper {
	
    public static Map getObjectAsMap(Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    	return getObjectAsMap(bean, (List)null);
    }

    public static Map getObjectAsMap(Object bean, String[] fieldList) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    	List list =  new ArrayList(Arrays.asList(fieldList));
    	return getObjectAsMap(bean, list);
    }    
	
    public static Map getObjectAsMap(Object bean, List fieldList) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    	Map ret = new HashMap();
    	
    	List fields = getAllFields(bean.getClass());
  	
    	for (Field fld : fields) {
    		if ((fieldList ==  null) || (fieldList.size() == 0) || (fieldList.indexOf(fld.getName()) != -1)) {
	    		Annotation[] annotations = fld.getAnnotations();
	    		for (int i=0; i getObjectAsMap2(Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
    	return getObjectAsMap2(bean, (List)null);
    }

    public static Map getObjectAsMap2(Object bean, String[] fieldList) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
    	List list =  new ArrayList(Arrays.asList(fieldList));
    	return getObjectAsMap2(bean, list);
    }    
	
    public static Map getObjectAsMap2(Object bean, List fieldList) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
    	Map ret = new HashMap();
    	
    	List fields = getAllFields(bean.getClass());
  	
    	for (Field fld : fields) {
    		if ((fieldList ==  null) || (fieldList.size() == 0) || (fieldList.indexOf(fld.getName()) != -1)) {
	    		Annotation[] annotations = fld.getAnnotations();
	    		for (int i=0; i getClassColumnNames(Class clazz) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    	return getClassColumnNames(clazz,(List)null);
    }
    
    public static Set getClassColumnNames(Class clazz, String[] fieldList) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    	List list = new ArrayList(Arrays.asList(fieldList));
    	return getClassColumnNames(clazz, list);
    }
    
    public static Set getClassColumnNames(Class clazz, List fieldList) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    	Set ret = new HashSet();
    	ret.addAll(getClassColumnNames(clazz, fieldList, false));
    	return ret;
    }

    public static ArrayList getClassColumnNames(Class clazz, List fieldList, boolean keepFieldOrder) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    	ArrayList ret = new ArrayList();
    
    	String[] retArray = null;
    	if (keepFieldOrder) {
    		retArray = new String[fieldList.size()];    		
    	}
    	List fields = getAllFields(clazz);
  	
    	for (Field fld : fields) {
    		if ((fieldList ==  null) || (fieldList.size() == 0) || (fieldList.indexOf(fld.getName()) != -1)) {
    			Annotation[] annotations = fld.getAnnotations();
    			for (int i=0; i clazz) {
    	List fields = getAllFields(clazz);
    	for (Field fld : fields) {
    		Annotation[] annotations = fld.getAnnotations();
    		Column clm = null;
    		boolean idField = false;
    		for (int i=0; i getAnnotationMap(Class clazz, List fieldList, boolean includeIdColumn) {
    	
    	Map ret = new HashMap();
    	
    	List fields = getAllFields(clazz);
  	
    	for (Field fld : fields) {
    		if ((fieldList ==  null) || (fieldList.size() == 0) || (fieldList.indexOf(fld.getName()) != -1)) {
    			Annotation[] annotations = fld.getAnnotations();
    			for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy