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

com.ivanceras.db.api.DAO_Operator Maven / Gradle / Ivy

There is a newer version: 0.1.2
Show newest version
package com.ivanceras.db.api;

import java.util.Map;
import java.util.Map.Entry;

import com.ivanceras.db.shared.DAO;

public class DAO_Operator {
	
	public static  T cast(T instance, String modelName, DAO dao) 	{
		if(dao == null){
			return null;
		}
		copyProperties(instance, dao);
		ColumnPair pair = dao.getRenamedColumns(modelName);//This is the name of the model to cast the dao to
		
		if(pair != null){
			ColumnPair[] pairs = pair.getPairs();
			for(ColumnPair p : pairs){
				if(dao.getProperties().containsKey(p.getColumn2())){
					String key = p.getColumn1();
					Object value = dao.get_Value(p.getColumn2());
					instance.set_Value(key, value);
				}
			}
		}
		instance.setRenamedColumns(dao.getRenamedColumns());
		return instance;
	}

	public static  T[] cast(T[] instanceArr, String modelName, DAO[] daoList){
		if(daoList == null || instanceArr == null){
			return null;
		}
		for(int i = 0; i < daoList.length; i++)	{
			instanceArr[i] = cast(instanceArr[i], modelName, daoList[i]);
		}
		return instanceArr;
	}
	
	
	private static  void copyProperties(T instance, DAO dao){
		
		Map properties = dao.getProperties();
		for(Entry entry : properties.entrySet()){
			String key = entry.getKey();
			Object value = entry.getValue();
			((DAO) instance).set_Value(key, value);
		}
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy