kode-kommentar
Er der nogen som vil være mig behjælpelig med kommentar af denne kode, det er specilt dette med mapper jeg gerne vil have noget svar påprivate HashMap mappers;
private PersistensFacade() throws SQLException, ClassNotFoundException
{
createHashMap();
}
private void createHashMap() throws SQLException, ClassNotFoundException
{
mappers = new HashMap();
IMapper mapper;
mapper = new OrdreMapper();
mappers.put(Class.forName("dk.jes1.domain.Ordre"), mapper);
mapper = new VareOrdreMapper();
mappers.put(Class.forName("dk.jes1.domain.VareOrdre"), mapper);
mapper = new VareMapper();
mappers.put(Class.forName("dk.jes1.domain.Vare"), mapper);
}
public static PersistensFacade getInstance()
{
try
{
if (instance == null)
{
instance = new PersistensFacade();
}
return instance;
}
catch(Exception e){return null;}
}
public boolean insert(int oId, Object obj, boolean delAfTransaction)
{
try
{
IMapper mapper = (IMapper)mappers.get(obj.getClass());
mapper.put(oId, obj, delAfTransaction);
return true; // returner true hvis insert er udført korrekt
}
catch(Exception e){return false;} // returner false hvis insert ikke er udført korrekt
}
public Object select(int oId, Object obj, boolean delAfTransaction)
{
try
{
IMapper mapper = (IMapper)mappers.get(obj.getClass());
return mapper.get(oId, delAfTransaction);
}
catch(Exception e){return null;}
}
public Object selectAll(Object obj)
{
try
{
IMapper mapper = (IMapper)mappers.get(obj.getClass());
return mapper.getAll();
}
catch(Exception e){return null;}
}
public Object selectAllWhere(String searchValue, Object obj, boolean delAfTransaction)
{
try
{
IMapper mapper = (IMapper)mappers.get(obj.getClass());
return mapper.getAllWhere(searchValue, delAfTransaction);
}
catch(Exception e){return null;}
}