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

net.sf.ahtutils.db.ejb.AhtDbEjbUpdater Maven / Gradle / Ivy

package net.sf.ahtutils.db.ejb;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import net.sf.ahtutils.controller.interfaces.UtilsFacade;
import net.sf.ahtutils.exception.ejb.UtilsContraintViolationException;
import net.sf.ahtutils.exception.ejb.UtilsIntegrityException;
import net.sf.ahtutils.model.interfaces.crud.EjbRemoveable;
import net.sf.ahtutils.model.interfaces.with.EjbWithCode;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AhtDbEjbUpdater
{
	final static Logger logger = LoggerFactory.getLogger(AhtDbEjbUpdater.class);
	
	final Class codeClass;
	
	private Map ejbInDb;

	public AhtDbEjbUpdater(final Class codeClass)
    {
        this.codeClass = codeClass;
        ejbInDb = new Hashtable();
    } 
	
	public static  AhtDbEjbUpdater createFactory(final Class codeClass)
	{
		return new AhtDbEjbUpdater(codeClass);
	}
	
	public void dbEjbs(List list)
	{
		for(C c : list){ejbInDb.put(c.getCode(), c);}
	}
	
	public void actualAdd(String code)
	{
		if(ejbInDb.containsKey(code))
		{
			ejbInDb.remove(code);
		}
	}
	
	public List getEjbForRemove()
	{
		List result = new ArrayList();
		for(String key : ejbInDb.keySet())
		{
			result.add(ejbInDb.get(key));
		}
		return result;
	}
	
	public void remove(UtilsFacade fUtils)
	{
		if(getEjbForRemove().size()>0)
		{
			logger.info("Removing "+getEjbForRemove().size()+" from "+codeClass.getSimpleName());
			for(C pc : getEjbForRemove())
			{
				if(pc instanceof EjbRemoveable)
				{
					try {fUtils.rm((EjbRemoveable)pc);}
					catch (UtilsIntegrityException e) {e.printStackTrace();}
				}
				else
				{
					logger.warn(pc.getClass().getSimpleName()+" does not implement "+EjbRemoveable.class.getSimpleName());
				}
			}
		}	
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy