Example usage for org.hibernate NonUniqueResultException NonUniqueResultException

List of usage examples for org.hibernate NonUniqueResultException NonUniqueResultException

Introduction

In this page you can find the example usage for org.hibernate NonUniqueResultException NonUniqueResultException.

Prototype

public NonUniqueResultException(int resultCount) 

Source Link

Document

Constructs a NonUniqueResultException.

Usage

From source file:com.algoTrader.entity.security.EquityIndexDaoBase.java

/**
 * {@inheritDoc}//from  w  ww . ja v  a2  s.c o  m
 */
@Override
public EquityIndex searchUniqueIsin(final String isin) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("isin", isin, SearchParameter.EQUAL_COMPARATOR) });

    final Set<EquityIndex> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:com.algoTrader.entity.security.ForexDaoBase.java

/**
 * {@inheritDoc}/*from  w w  w. jav  a2 s.c  om*/
 */
@Override
public Forex searchUniqueIsin(final String isin) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("isin", isin, SearchParameter.EQUAL_COMPARATOR) });

    final Set<Forex> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:com.algoTrader.entity.security.FutureDaoBase.java

/**
 * {@inheritDoc}/*www .ja v a 2 s .  co m*/
 */
@Override
public Future searchUniqueIsin(final String isin) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("isin", isin, SearchParameter.EQUAL_COMPARATOR) });

    final Set<Future> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:com.algoTrader.entity.security.IntrestRateDaoBase.java

/**
 * {@inheritDoc}//w ww . j a v a 2 s . c  o m
 */
@Override
public IntrestRate searchUniqueIsin(final String isin) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("isin", isin, SearchParameter.EQUAL_COMPARATOR) });

    final Set<IntrestRate> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:com.algoTrader.entity.security.SecurityDaoBase.java

/**
 * {@inheritDoc}//from  w  w w.ja v  a2  s  .c  o m
 */
@Override
public Security searchUniqueIsin(final String isin) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("isin", isin, SearchParameter.EQUAL_COMPARATOR) });

    final Set<Security> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:com.algoTrader.entity.security.StockDaoBase.java

/**
 * {@inheritDoc}/* w  w w. j  a  v  a2 s. c o m*/
 */
@Override
public Stock searchUniqueIsin(final String isin) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("isin", isin, SearchParameter.EQUAL_COMPARATOR) });

    final Set<Stock> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:com.algoTrader.entity.security.StockOptionDaoBase.java

/**
 * {@inheritDoc}/*from w  ww . j av a2s. co m*/
 */
@Override
public StockOption searchUniqueIsin(final String isin) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("isin", isin, SearchParameter.EQUAL_COMPARATOR) });

    final Set<StockOption> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:com.algoTrader.entity.StrategyDaoBase.java

/**
 * {@inheritDoc}//from   w w  w .  j  ava  2s . co  m
 */
@Override
public Strategy searchUniqueName(final String name) {
    final Search search = new Search(
            new SearchParameter[] { new SearchParameter("name", name, SearchParameter.EQUAL_COMPARATOR) });

    final Set<Strategy> searchResult = this.search(search);
    switch (searchResult.size()) {
    case 0:
        return null;
    case 1:
        return searchResult.iterator().next();
    default:
        throw new NonUniqueResultException(searchResult.size());
    }
}

From source file:de.escidoc.core.common.persistence.hibernate.AbstractHibernateDao.java

License:Open Source License

/**
 * Asserts the provided {@link List} contains one Object and returns it. If the list is empty, {@code null} is
 * returned. If the list contains more than one object, a {@link NonUniqueResultException} is thrown.
 *
 * @param results The {@link List} to be asserted.
 * @return Returns the single Object contained in the list or {@code null}.
 */// w  ww  .java2 s.c  om
protected Object getUniqueResult(final List<Object> results) {

    final int resultSize = results.size();
    if (resultSize == 1) {
        return results.get(0);
    } else if (resultSize > 1) {
        throw new NonUniqueResultException(resultSize);
    } else {
        return null;
    }
}

From source file:mockit.emulation.hibernate3.QueryEmul.java

License:Open Source License

public Object uniqueResult() {
    List<?> result = list();
    int resultCount = result.size();

    if (resultCount == 1) {
        return result.get(0);
    } else if (resultCount == 0) {
        return null;
    } else {/* w w w .ja v  a2  s .  co m*/
        throw new NonUniqueResultException(resultCount);
    }
}