package at.gv.egovernment.moa.id.process.spring.test; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import javax.sql.DataSource; import at.gv.egovernment.moa.id.auth.exception.AuthenticationException; import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; import at.gv.egovernment.moa.id.storage.ITransactionStorage; import at.gv.egovernment.moa.logging.Logger; /** * Dummy DataSource implementation for convenience in test cases where a * database connection will never actually be acquired. * * @see DataSource * @author Chris Beams */ public class DummyTransactionStorage implements ITransactionStorage { public class DummyDBEntry{ public DummyDBEntry(String key, Object value){ this.obj =value; this.key = key; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public Object getObj() { return obj; } public void setObj(Object obj) { this.obj = obj; } private String key; private Object obj; } private ArrayList ds = new ArrayList(); @Override public boolean containsKey(String key) { // TODO Auto-generated method stub Iterator it = ds.iterator(); while(it.hasNext()){ DummyDBEntry t = it.next(); if(t.getKey().equals(key)) return true; } return false; } @Override public void put(String key, Object value, int timeout_ms) throws MOADatabaseException { // TODO Auto-generated method stub this.remove(key); this.ds.add(new DummyDBEntry(key, value)); } @Override public Object get(String key) throws MOADatabaseException { // TODO Auto-generated method stub Iterator it = ds.iterator(); while(it.hasNext()){ DummyDBEntry t = it.next(); if(t.getKey().equals(key)) return t; } return null; } @Override public T get(String key, Class clazz) throws MOADatabaseException { DummyDBEntry o = (DummyDBEntry) get(key); if(o == null) return null; try { @SuppressWarnings("unchecked") T test = (T) (clazz.cast(o.getObj())); return test; } catch (Exception e) { Logger.warn("Sessioninformation Cast-Exception by using Artifact=" + key); throw new MOADatabaseException("Sessioninformation Cast-Exception"); } } @Override public T get(String key, Class clazz, long dataTimeOut) throws MOADatabaseException, AuthenticationException { // TODO Auto-generated method stub return get(key,clazz); } @Override public void changeKey(String oldKey, String newKey, Object value) throws MOADatabaseException { this.remove(oldKey); this.put(newKey, value, -1); } @Override public void remove(String key) { Iterator it = ds.iterator(); while(it.hasNext()){ DummyDBEntry t = it.next(); if(t.getKey().equals(key)){ this.ds.remove(t); return; } } } @Override public List clean(Date now, long dataTimeOut) { // TODO Auto-generated method stub return null; } @Override public Object getAssertionStore(String key) throws MOADatabaseException { // TODO Auto-generated method stub return null; } @Override public void putAssertionStore(Object element) throws MOADatabaseException { // TODO Auto-generated method stub } }