Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package data.services; import data.dao.FreeValueRangeDao; import data.entity.FreeValueRange; import data.services.parent.PrimService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import support.StringAdapter; /** * * @author bezdatiuzer */ @Service @Transactional @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) public class FreeValueRangeService extends PrimService { @Autowired private FreeValueRangeDao freeValueRangeDao; public FreeValueRange getParam(Object uid, Object valMin, Object valMax, Object amin, Object amax) { FreeValueRange fvr = new FreeValueRange(); fvr.setUid(StringAdapter.getString(uid)); fvr.setAmax(Long.valueOf(getZeroInNullAndTrim(amax))); fvr.setAmin(Long.valueOf(getZeroInNullAndTrim(amin))); fvr.setValueMax(Long.valueOf(getZeroInNullAndTrim(valMax))); fvr.setValueMin(Long.valueOf(getZeroInNullAndTrim(valMin))); //validate(vr); return fvr; } public void create(FreeValueRange fvr) { FreeValueRange supvr = new FreeValueRange(); supvr.setUid(fvr.getUid()); supvr.setEvent(fvr.getEvent()); String arr = ""; for (FreeValueRange ovr : freeValueRangeDao.findByEventUid(supvr)) { arr += ovr.getUid() + "; " + ovr.getEvent().getId() + " - " + ovr.getEvent().getName(); freeValueRangeDao.delete(ovr); } fvr.setAmax(Long.valueOf(getZeroInNullAndTrim(fvr.getAmax()))); fvr.setAmin(Long.valueOf(getZeroInNullAndTrim(fvr.getAmin()))); fvr.setValueMax(Long.valueOf(getZeroInNullAndTrim(fvr.getValueMax()))); fvr.setValueMin(Long.valueOf(getZeroInNullAndTrim(fvr.getValueMin()))); if (validate(fvr)) { freeValueRangeDao.save(fvr); //addError(fvr.getUid()); } } public void delete(Long fvrId) { freeValueRangeDao.delete(freeValueRangeDao.find(fvrId)); } private static String getZeroInNullAndTrim(Object obj) { if (StringAdapter.getString(obj).trim().equals("")) { return "0"; } else { return StringAdapter.getString(obj).trim(); } } }