ForexGroupRepositoryImpl.java

package com.tradecloud.repository.impl;

import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.tradecloud.domain.model.ForexGroup;
import com.tradecloud.repository.ForexGroupRepository;
import com.tradecloud.repository.base.impl.RepositoryBaseImpl;

@Repository(value = "forexGroupRepository")
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public class ForexGroupRepositoryImpl extends RepositoryBaseImpl<ForexGroup, Object> implements ForexGroupRepository {

    private static Logger log = Logger.getLogger(ForexGroupRepositoryImpl.class);
    private static final String COLUMN_NAME = "name";

    private static final String QUERY_FIND_BY_NAME = "from ForexGroup as fg where fg.name = :name";

    @Transactional(readOnly = true)
    @Override
    public ForexGroup findByName(String name) {
        log.debug("In find by Name. Searching for ForexGroup with Name:" + name);
        @SuppressWarnings("unchecked")
        List<ForexGroup> list = (List<ForexGroup>) findByNamedParam(QUERY_FIND_BY_NAME, COLUMN_NAME, name);
        log.debug("Found " + list.size() + " ForexGroups.");

        return list.isEmpty() ? null : list.iterator().next();
    }
}