FECRequestDealLinkRepositoryImpl.java
package com.tradecloud.repository.impl;
import com.tradecloud.domain.configuration.TreasuryConfig;
import com.tradecloud.domain.model.FECRequestDealLink;
import com.tradecloud.domain.model.deal.Deal;
import com.tradecloud.domain.model.fecrequest.FECRequest;
import com.tradecloud.repository.ConfigPropertyRepository;
import com.tradecloud.repository.FECRequestDealLinkRepository;
import com.tradecloud.repository.base.impl.RepositoryBaseImpl;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Repository(value = "fecRequestDealLinkRepository")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class FECRequestDealLinkRepositoryImpl extends RepositoryBaseImpl<FECRequestDealLink, Object> implements FECRequestDealLinkRepository {
private static Logger log = Logger.getLogger(FECRequestDealLinkRepositoryImpl.class);
@Autowired
ConfigPropertyRepository configPropertyRepository;
@Override
public void store(FECRequestDealLink fecDealLink) {
saveOrUpdate(fecDealLink);
flush();
}
@Override
public List<FECRequestDealLink> findAllByDeal(Deal deal, boolean requireFECAuthorization) {
if (requireFECAuthorization && deal.getId() != null) {
return (List<FECRequestDealLink>)
findByNamedParam("from FECRequestDealLink where deal_id = :dealId", "dealId", deal.getId());
} else {
// log.error("?? Should not be here");
return new ArrayList<FECRequestDealLink>();
}
}
@Override
public List<FECRequestDealLink> findAll() {
/*
* if (TreasuryConfig.requireFECAuthorization()) { return getSession().createQuery("from FECRequestDealLink").list(); } else { return new
* ArrayList<FECRequestDealLink>(); }
*/
return getSessionCustom().createQuery("from FECRequestDealLink").list();
}
@Override
public List<FECRequestDealLink> findAllByFECRequest(FECRequest fecRequest) {
if (Boolean.valueOf(configPropertyRepository.getProperty(TreasuryConfig.REQUIRE_FEC_AUTH_PROPERTY))) {
return (List<FECRequestDealLink>)
findByNamedParam("from FECRequestDealLink where fecrequest_id = :fecRequestID", "fecRequestID",fecRequest.getId());
} else {
//log.error("?? Should not be here");
return new ArrayList<FECRequestDealLink>();
}
}
@Override
public void delete(FECRequestDealLink fecRequestDealLink) {
super.delete(fecRequestDealLink);
}
@Override
public void deleteAllLInks(List<FECRequestDealLink> fecRequestDealLinks) {
getSessionCustom().createQuery("delete from FECRequestDealLink f where f in (:links)")
.setParameterList("links", fecRequestDealLinks).executeUpdate();
}
@Override
public void deleteAllLInks(FECRequest fecRequest) {
getSessionCustom().createQuery("delete from FECRequestDealLink f where f.fecRequest.id =:fecRequest")
.setParameter("fecRequest", fecRequest.getId()).executeUpdate();
}
@Override
public void deleteAllByDeal(Deal deal) {
getSessionCustom().createQuery("delete from FECRequestDealLink where deal_id = :dealId").setParameter("dealId", deal.getId()).executeUpdate();
}
@Override
public List<FECRequestDealLink> findAllByDeal(Deal deal) {
if (Boolean.valueOf(configPropertyRepository.getProperty(TreasuryConfig.REQUIRE_FEC_AUTH_PROPERTY))) {
return findAllByDeal(deal, true);
} else {
// log.error("?? Should not be here");
return new ArrayList<FECRequestDealLink>();
}
}
@Override
public List<FECRequestDealLink> findAllByDealIdIn(List<Long> dealIds) {
String hql =
"select fdl from FECRequestDealLink fdl where deal.id in (:dealIds)";
Query query = getSessionCustom().createQuery(hql).setParameterList("dealIds", dealIds);
return query.list();
}
}