Example usage for org.springframework.dao InvalidDataAccessResourceUsageException InvalidDataAccessResourceUsageException

List of usage examples for org.springframework.dao InvalidDataAccessResourceUsageException InvalidDataAccessResourceUsageException

Introduction

In this page you can find the example usage for org.springframework.dao InvalidDataAccessResourceUsageException InvalidDataAccessResourceUsageException.

Prototype

public InvalidDataAccessResourceUsageException(String msg) 

Source Link

Document

Constructor for InvalidDataAccessResourceUsageException.

Usage

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

/**
 * {@inheritDoc}/*  w  w  w.j  av a 2  s.  co  m*/
 */
@Override
@SuppressWarnings("unchecked")
public Object findByNameFetched(final int transform, final String queryString, final String name) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        queryObject.setParameter("name", name);
        Set results = new LinkedHashSet(queryObject.list());
        Object result = null;
        if (results.size() > 1) {
            throw new InvalidDataAccessResourceUsageException(
                    "More than one instance of 'com.algoTrader.entity.Strategy"
                            + "' was found when executing query --> '" + queryString + "'");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (transform != TRANSFORM_NONE) {
            result = transformEntity(transform, (Strategy) result);
        }
        return result;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:com.turbospaces.spaces.AbstractJSpace.java

private Object[] fetch0(final TransactionModificationContext modificationContext, final Object entry,
        final int timeout, final int maxResults, final int modifiers) {
    Preconditions.checkNotNull(entry);//  www . ja  v a 2s  . co  m
    Preconditions.checkArgument(maxResults >= 1, NON_POSITIVE_MAX_RESULTS);
    Preconditions.checkArgument(timeout >= 0, NEGATIVE_TIMEOUT);

    SpaceStore heapBuffer;
    CacheStoreEntryWrapper cacheStoreEntryWrapper;
    Object template;

    if (entry instanceof CacheStoreEntryWrapper) {
        cacheStoreEntryWrapper = (CacheStoreEntryWrapper) entry;
        heapBuffer = offHeapBuffers
                .get(cacheStoreEntryWrapper.getPersistentEntity().getOriginalPersistentEntity().getType());
        template = cacheStoreEntryWrapper.getBean();
    } else {
        heapBuffer = offHeapBuffers.get(entry.getClass());
        cacheStoreEntryWrapper = CacheStoreEntryWrapper.writeValueOf(configuration.boFor(entry.getClass()),
                entry);
        template = entry;
    }

    boolean isTakeOnly = SpaceModifiers.isTakeOnly(modifiers);
    boolean isReadOnly = SpaceModifiers.isReadOnly(modifiers);
    boolean isEvictOnly = SpaceModifiers.isEvictOnly(modifiers);
    boolean isExclusiveRead = SpaceModifiers.isExclusiveRead(modifiers);
    boolean isMatchById = SpaceModifiers.isMatchById(modifiers);
    boolean isReturnAsBytes = SpaceModifiers.isReturnAsBytes(modifiers);

    if (isTakeOnly && isReadOnly)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and readOnly modifiers at the same time",
                template));

    if (isTakeOnly && isEvictOnly)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and evictOnly modifiers at the same time",
                template));

    if (isTakeOnly && isExclusiveRead)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and exclusiveReadLock modifiers at the same time",
                template));

    if (isReadOnly && isEvictOnly)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and evictOnly modifiers at the same time",
                template));

    if (isEvictOnly && isExclusiveRead)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with evictOnly and exclusiveReadLock modifiers at the same time",
                template));

    if (isMatchById && cacheStoreEntryWrapper.getId() == null)
        throw new InvalidDataAccessApiUsageException(String.format(
                "Illegal attempt to perform matching by ID when id is not provided. Template = %s", template));

    if (logger.isDebugEnabled())
        logger.debug(
                "onFetch: template={}, id={}, version={}, routing={}, timeout={}, maxResults={}, transaction={}",
                new Object[] { cacheStoreEntryWrapper.getBean(), cacheStoreEntryWrapper.getId(),
                        cacheStoreEntryWrapper.getOptimisticLockVersion(), cacheStoreEntryWrapper.getRouting(),
                        timeout, maxResults, modificationContext.getTransactionId() });

    // fetch
    ByteBuffer[] c = heapBuffer.fetch(cacheStoreEntryWrapper, modificationContext, timeout, maxResults,
            modifiers);
    if (c != null)
        if (!isReturnAsBytes) {
            int size = c.length;
            Class type = cacheStoreEntryWrapper.getPersistentEntity().getOriginalPersistentEntity().getType();

            Object[] result = new Object[size];
            Map<EntryKeyLockQuard, WriteTakeEntry> takes = modificationContext.getTakes();
            for (int i = 0; i < size; i++) {
                SerializationEntry sEntry = configuration.getKryo().deserialize(c[i], type);
                Object[] propertyValues = sEntry.getPropertyValues();
                Object id = propertyValues[BO.getIdIndex()];

                if (!takes.isEmpty())
                    for (Entry<EntryKeyLockQuard, WriteTakeEntry> next : takes.entrySet())
                        if (ObjectUtils.nullSafeEquals(next.getKey().getKey(), id)) {
                            next.getValue().setObj(sEntry.getObject());
                            next.getValue().setPropertyValues(propertyValues);
                        }

                result[i] = sEntry.getObject();
            }
            return result;
        }
    return c;
}

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

/**
 * {@inheritDoc}//from  w  ww.j  a va  2 s  . c o m
 */
@Override
@SuppressWarnings("unchecked")
public Object findBySymbol(final int transform, final String queryString, final String symbol) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        queryObject.setParameter("symbol", symbol);
        Set results = new LinkedHashSet(queryObject.list());
        Object result = null;
        if (results.size() > 1) {
            throw new InvalidDataAccessResourceUsageException(
                    "More than one instance of 'com.algoTrader.entity.security.Security"
                            + "' was found when executing query --> '" + queryString + "'");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (transform != TRANSFORM_NONE) {
            result = transformEntity(transform, (Security) result);
        }
        return result;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:org.solq.dht.db.redis.service.JedisConnectionFactory.java

@Override
public RedisSentinelConnection getSentinelConnection() {

    if (!isRedisSentinelAware()) {
        throw new InvalidDataAccessResourceUsageException("No Sentinels configured");
    }/* w w  w.  j  ava2  s. c o  m*/

    return new JedisSentinelConnection(getActiveSentinel());
}

From source file:org.solq.dht.db.redis.service.JedisConnectionFactory.java

private Jedis getActiveSentinel() {

    Assert.notNull(this.sentinelConfig);
    for (RedisNode node : this.sentinelConfig.getSentinels()) {
        Jedis jedis = new Jedis(node.getHost(), node.getPort());
        if (jedis.ping().equalsIgnoreCase("pong")) {
            return jedis;
        }/*from  w w w.  j av  a 2s. c o  m*/
    }

    throw new InvalidDataAccessResourceUsageException("no sentinel found");
}

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

/**
 * {@inheritDoc}/* w w  w.java  2s .c  om*/
 */
@Override
@SuppressWarnings("unchecked")
public Object findByIdFetched(final int transform, final String queryString, final int id) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        queryObject.setParameter("id", new Integer(id));
        Set results = new LinkedHashSet(queryObject.list());
        Object result = null;
        if (results.size() > 1) {
            throw new InvalidDataAccessResourceUsageException(
                    "More than one instance of 'com.algoTrader.entity.Position"
                            + "' was found when executing query --> '" + queryString + "'");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (transform != TRANSFORM_NONE) {
            result = transformEntity(transform, (Position) result);
        }
        return result;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

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

/**
 * {@inheritDoc}/*from   ww  w.  j  a v  a 2s . c om*/
 */
@Override
@SuppressWarnings("unchecked")
public Object findBySecurityAndStrategy(final int transform, final String queryString, final int securityId,
        final String strategyName) {
    try {
        Query queryObject = super.getSession(false).createQuery(queryString);
        queryObject.setCacheable(true);
        queryObject.setParameter("securityId", new Integer(securityId));
        queryObject.setParameter("strategyName", strategyName);
        Set results = new LinkedHashSet(queryObject.list());
        Object result = null;
        if (results.size() > 1) {
            throw new InvalidDataAccessResourceUsageException(
                    "More than one instance of 'com.algoTrader.entity.Position"
                            + "' was found when executing query --> '" + queryString + "'");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
        if (transform != TRANSFORM_NONE) {
            result = transformEntity(transform, (Position) result);
        }
        return result;
    } catch (HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}

From source file:org.grails.datastore.mapping.redis.query.RedisQuery.java

private PersistentProperty getAndValidateProperty(RedisEntityPersister entityPersister, String property) {
    final PersistentEntity entity = entityPersister.getPersistentEntity();
    PersistentProperty prop = entity.getPropertyByName(property);
    if (prop == null) {
        throw new InvalidDataAccessResourceUsageException("Cannot execute between query on property ["
                + property + "] of class [" + entity + "]. Property does not exist.");
    }/*w ww.j av a  2  s. co  m*/
    return prop;
}

From source file:org.grails.datastore.mapping.redis.query.RedisQuery.java

private void assertIndexed(String property, PersistentProperty prop) {
    if (prop == null) {
        throw new InvalidDataAccessResourceUsageException("Cannot execute query. Entity [" + getEntity()
                + "] does not declare a property named [" + property + "]");
    }//from  w  w w. j a v  a  2  s  .  c o  m
    if (!isIndexed(prop)) {
        throw new InvalidDataAccessResourceUsageException("Cannot query class [" + getEntity()
                + "] on property [" + prop + "]. The property is not indexed!");
    }
}

From source file:org.grails.datastore.mapping.mongo.query.MongoQuery.java

@SuppressWarnings("hiding")
@Override/*from   www .j  a  v  a  2  s .c  o  m*/
protected List executeQuery(final PersistentEntity entity, final Junction criteria) {
    final MongoTemplate template = mongoSession.getMongoTemplate(entity);

    return template.execute(new DbCallback<List>() {
        @SuppressWarnings("unchecked")
        public List doInDB(DB db) throws MongoException, DataAccessException {

            final DBCollection collection = db.getCollection(mongoEntityPersister.getCollectionName(entity));
            if (uniqueResult) {
                final DBObject dbObject;
                if (criteria.isEmpty()) {
                    if (entity.isRoot()) {
                        dbObject = collection.findOne();
                    } else {
                        dbObject = collection.findOne(new BasicDBObject(MongoEntityPersister.MONGO_CLASS_FIELD,
                                entity.getDiscriminator()));
                    }
                } else {
                    dbObject = collection.findOne(getMongoQuery());
                }
                return wrapObjectResultInList(createObjectFromDBObject(dbObject));
            }

            DBCursor cursor = null;
            DBObject query = createQueryObject(entity);

            final List<Projection> projectionList = projections().getProjectionList();
            if (projectionList.isEmpty()) {
                cursor = executeQuery(entity, criteria, collection, query);
                return (List) new MongoResultList(cursor, mongoEntityPersister).clone();
            }

            List projectedResults = new ArrayList();
            for (Projection projection : projectionList) {
                if (projection instanceof CountProjection) {
                    // For some reason the below doesn't return the expected result whilst executing the query and returning the cursor does
                    //projectedResults.add(collection.getCount(query));
                    if (cursor == null)
                        cursor = executeQuery(entity, criteria, collection, query);
                    projectedResults.add(cursor.size());
                } else if (projection instanceof MinProjection) {
                    if (cursor == null)
                        cursor = executeQuery(entity, criteria, collection, query);
                    MinProjection mp = (MinProjection) projection;

                    MongoResultList results = new MongoResultList(cursor, mongoEntityPersister);
                    projectedResults.add(manualProjections.min((Collection) results.clone(),
                            getPropertyName(entity, mp.getPropertyName())));
                } else if (projection instanceof MaxProjection) {
                    if (cursor == null)
                        cursor = executeQuery(entity, criteria, collection, query);
                    MaxProjection mp = (MaxProjection) projection;

                    MongoResultList results = new MongoResultList(cursor, mongoEntityPersister);
                    projectedResults.add(manualProjections.max((Collection) results.clone(),
                            getPropertyName(entity, mp.getPropertyName())));
                } else if (projection instanceof CountDistinctProjection) {
                    if (cursor == null)
                        cursor = executeQuery(entity, criteria, collection, query);
                    CountDistinctProjection mp = (CountDistinctProjection) projection;

                    MongoResultList results = new MongoResultList(cursor, mongoEntityPersister);
                    projectedResults.add(manualProjections.countDistinct((Collection) results.clone(),
                            getPropertyName(entity, mp.getPropertyName())));

                } else if ((projection instanceof PropertyProjection) || (projection instanceof IdProjection)) {
                    final PersistentProperty persistentProperty;
                    final String propertyName;
                    if (projection instanceof IdProjection) {
                        persistentProperty = entity.getIdentity();
                        propertyName = MongoEntityPersister.MONGO_ID_FIELD;
                    } else {
                        PropertyProjection pp = (PropertyProjection) projection;
                        persistentProperty = entity.getPropertyByName(pp.getPropertyName());
                        propertyName = getPropertyName(entity, persistentProperty.getName());
                    }
                    if (persistentProperty != null) {
                        populateMongoQuery(entity, query, criteria);

                        List propertyResults = null;
                        if (max > -1) {
                            // if there is a limit then we have to do a manual projection since the MongoDB driver doesn't support limits and distinct together
                            cursor = executeQueryAndApplyPagination(collection, query);
                            propertyResults = manualProjections
                                    .property(new MongoResultList(cursor, mongoEntityPersister), propertyName);
                        } else {

                            propertyResults = collection.distinct(propertyName, query);
                        }

                        if (persistentProperty instanceof ToOne) {
                            Association a = (Association) persistentProperty;
                            propertyResults = session.retrieveAll(a.getAssociatedEntity().getJavaClass(),
                                    propertyResults);
                        }

                        if (projectedResults.size() == 0 && projectionList.size() == 1) {
                            return propertyResults;
                        }
                        projectedResults.add(propertyResults);
                    } else {
                        throw new InvalidDataAccessResourceUsageException(
                                "Cannot use [" + projection.getClass().getSimpleName()
                                        + "] projection on non-existent property: " + propertyName);
                    }
                }
            }

            return projectedResults;
        }

        protected DBCursor executeQuery(final PersistentEntity entity, final Junction criteria,
                final DBCollection collection, DBObject query) {
            final DBCursor cursor;
            if (criteria.isEmpty()) {
                cursor = executeQueryAndApplyPagination(collection, query);
            } else {
                populateMongoQuery(entity, query, criteria);
                cursor = executeQueryAndApplyPagination(collection, query);
            }

            if (queryArguments != null) {
                if (queryArguments.containsKey(HINT_ARGUMENT)) {
                    Object hint = queryArguments.get(HINT_ARGUMENT);
                    if (hint instanceof Map) {
                        cursor.hint(new BasicDBObject((Map) hint));
                    } else if (hint != null) {
                        cursor.hint(hint.toString());
                    }

                }
            }
            return cursor;
        }

        protected DBCursor executeQueryAndApplyPagination(final DBCollection collection, DBObject query) {
            final DBCursor cursor;
            cursor = collection.find(query);
            if (offset > 0) {
                cursor.skip(offset);
            }
            if (max > -1) {
                cursor.limit(max);
            }

            if (!orderBy.isEmpty()) {
                DBObject orderObject = new BasicDBObject();
                for (Order order : orderBy) {
                    String property = order.getProperty();
                    property = getPropertyName(entity, property);
                    orderObject.put(property, order.getDirection() == Order.Direction.DESC ? -1 : 1);
                }
                cursor.sort(orderObject);
            }

            return cursor;
        }
    });
}