Example usage for org.springframework.dao InvalidDataAccessApiUsageException InvalidDataAccessApiUsageException

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

Introduction

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

Prototype

public InvalidDataAccessApiUsageException(String msg) 

Source Link

Document

Constructor for InvalidDataAccessApiUsageException.

Usage

From source file:com.frank.search.solr.core.query.result.DelegatingCursor.java

@Override
public DelegatingCursor<T> open() {

    if (!isReady()) {
        throw new InvalidDataAccessApiUsageException("Cursor already " + state + ". Cannot (re)open it.");
    }/*from   ww w .j a  va 2s  .  c om*/

    this.state = State.OPEN;
    doOpen(this.getCursorMark());
    return this;
}

From source file:com.gzj.tulip.jade.statement.JdbcStatement.java

public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters,
        Querier querier) {// ww  w.  j  a  v  a2 s.  c om
    this.metaData = statementMetaData;
    AfterInvocation afterInvocationAnnotation = metaData.getMethod().getAnnotation(AfterInvocation.class);
    if (afterInvocationAnnotation != null) {
        try {
            this.afterInvocationCallback = afterInvocationAnnotation.value().newInstance();
        } catch (InstantiationException e) {
            throw new IllegalArgumentException(e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(e);
        }
    } else {
        this.afterInvocationCallback = nullAfterInvocationCallback;
    }
    this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters;
    this.querier = querier;
    this.sqlType = sqlType;
    if (sqlType == SQLType.WRITE) {
        Method method = statementMetaData.getMethod();
        Class<?>[] types = method.getParameterTypes();
        Class<?> returnType = statementMetaData.getReturnType();
        if (returnType.isPrimitive()) {
            returnType = ClassUtils.primitiveToWrapper(returnType);
        }

        //change by guozijian 2016-2-09-29
        //?SQL???
        //???updateinsert???
        SQL sqlAnnotation = method.getAnnotation(SQL.class);
        if (types.length > 0 && List.class.isAssignableFrom(types[0]) && (sqlAnnotation == null // @SQL
                || StringUtils.isBlank(sqlAnnotation.value()))) // SQL
        {
            //TODO ?List?????
            //if (types.length > 0 && List.class.isAssignableFrom(types[0])) {
            this.batchUpdate = true;
            if (metaData.getMethod().getAnnotation(ReturnGeneratedKeys.class) != null) {
                // ????@ReturnGeneratedKeys
                throw new InvalidDataAccessApiUsageException(
                        "batch update method cannot return generated keys: " + method);
            }
            if (returnType != void.class && returnType != int[].class //
                    && returnType != Integer.class && returnType != Boolean.class) {
                throw new InvalidDataAccessApiUsageException(
                        "error return type, only support type of {void,boolean,int,int[]}: " + method);
            }
        } else {
            this.batchUpdate = false;
            if (metaData.getMethod().getAnnotation(ReturnGeneratedKeys.class) != null) {
                metaData.getReturnGeneratedKeys().checkMethodReturnType(metaData.getReturnType(), metaData);
            } else if (returnType != void.class && returnType != Boolean.class && returnType != Integer.class) {
                throw new InvalidDataAccessApiUsageException(
                        "error return type, only support type of {void,boolean,int}:" + method);
            }
        }
    } else {
        this.batchUpdate = false;
    }
    this.logPrefix = "\n @method:" + this.metaData;
}

From source file:nivance.jpa.cassandra.prepare.core.CassandraSessionFactoryBean.java

@Override
public void afterPropertiesSet() {
    if (converter == null) {
        throw new IllegalArgumentException("converter is required");
    }/*  w  ww.j  a v  a 2 s.com*/
    super.afterPropertiesSet();

    //      mappingContext = converter.getMappingContext();
    schemaOperations = new DefaultSchemaOperations(session, keyspace, converter);
    schemaCqlOperations = new DefaultSchemaCqlOperations(session, keyspace);

    if (StringUtils.hasText(keyspace)) {
        if (!CollectionUtils.isEmpty(tables)) {
            for (TableAttributes tableAttributes : tables) {
                String entityClassName = tableAttributes.getEntityClass();
                Class<?> entityClass = loadClass(entityClassName);
                String useTableName = tableAttributes.getTableName() != null ? tableAttributes.getTableName()
                        : this.getTableName(entityClass);
                if (keyspaceCreated) {
                    createNewTable(useTableName, entityClass);
                } else if (keyspaceAttributes.isUpdate()) {
                    TableMetadata table = schemaCqlOperations.getTableMetadata(useTableName);
                    if (table == null) {
                        createNewTable(useTableName, entityClass);
                    } else {
                        Optional<UpdateOperation> alter = schemaOperations.alterTable(useTableName, entityClass,
                                true);
                        if (alter.isPresent()) {
                            alter.get().execute();
                        }
                        schemaOperations.alterIndexes(useTableName, entityClass).execute();
                    }
                } else if (keyspaceAttributes.isValidate()) {
                    TableMetadata table = schemaCqlOperations.getTableMetadata(useTableName);
                    if (table == null) {
                        throw new InvalidDataAccessApiUsageException(
                                "not found table " + useTableName + " for entity " + entityClassName);
                    }

                    String query = schemaOperations.validateTable(useTableName, entityClass);

                    if (query != null) {
                        throw new InvalidDataAccessApiUsageException("invalid table " + useTableName
                                + " for entity " + entityClassName + ". modify it by " + query);
                    }

                    List<String> queryList = schemaOperations.validateIndexes(useTableName, entityClass);

                    if (!queryList.isEmpty()) {
                        throw new InvalidDataAccessApiUsageException("invalid indexes in table " + useTableName
                                + " for entity " + entityClassName + ". modify it by " + queryList);
                    }
                }
            }
        }
    }
}

From source file:com.joyveb.dbpimpl.cass.prepare.core.CassandraSessionFactoryBean.java

@Override
public void afterPropertiesSet() {
    if (converter == null) {
        throw new IllegalArgumentException("converter is required");
    }//from   ww w.  j  a v a2 s .  c  o  m
    super.afterPropertiesSet();

    mappingContext = converter.getMappingContext();
    schemaOperations = new DefaultSchemaOperations(session, keyspace, converter);
    schemaCqlOperations = new DefaultSchemaCqlOperations(session, keyspace);

    if (StringUtils.hasText(keyspace)) {
        if (!CollectionUtils.isEmpty(tables)) {
            for (TableAttributes tableAttributes : tables) {
                String entityClassName = tableAttributes.getEntityClass();
                Class<?> entityClass = loadClass(entityClassName);
                String useTableName = tableAttributes.getTableName() != null ? tableAttributes.getTableName()
                        : this.getTableName(entityClass);
                if (keyspaceCreated) {
                    createNewTable(useTableName, entityClass);
                } else if (keyspaceAttributes.isUpdate()) {
                    TableMetadata table = schemaCqlOperations.getTableMetadata(useTableName);
                    if (table == null) {
                        createNewTable(useTableName, entityClass);
                    } else {
                        Optional<UpdateOperation> alter = schemaOperations.alterTable(useTableName, entityClass,
                                true);
                        if (alter.isPresent()) {
                            alter.get().execute();
                        }
                        schemaOperations.alterIndexes(useTableName, entityClass).execute();
                    }
                } else if (keyspaceAttributes.isValidate()) {
                    TableMetadata table = schemaCqlOperations.getTableMetadata(useTableName);
                    if (table == null) {
                        throw new InvalidDataAccessApiUsageException(
                                "not found table " + useTableName + " for entity " + entityClassName);
                    }

                    String query = schemaOperations.validateTable(useTableName, entityClass);

                    if (query != null) {
                        throw new InvalidDataAccessApiUsageException("invalid table " + useTableName
                                + " for entity " + entityClassName + ". modify it by " + query);
                    }

                    List<String> queryList = schemaOperations.validateIndexes(useTableName, entityClass);

                    if (!queryList.isEmpty()) {
                        throw new InvalidDataAccessApiUsageException("invalid indexes in table " + useTableName
                                + " for entity " + entityClassName + ". modify it by " + queryList);
                    }
                }
            }
        }
    }
}

From source file:com.joyveb.dbpimpl.cass.prepare.mapping.BasicCassandraPersistentProperty.java

/**
 * Returns the data type information if exists.
 * //  w  ww .ja  va2s . com
 * @return
 */
public DataType getDataType() {
    Qualify annotation = findAnnotation(Qualify.class);
    if (annotation != null && annotation.type() != null) {
        return qualifyAnnotatedType(annotation);
    }
    if (isMap()) {
        List<TypeInformation<?>> args = getTypeInformation().getTypeArguments();
        ensureTypeArguments(args.size(), 2);
        return DataType.map(autodetectPrimitiveType(args.get(0).getType()),
                autodetectPrimitiveType(args.get(1).getType()));
    }
    if (isCollectionLike()) {
        List<TypeInformation<?>> args = getTypeInformation().getTypeArguments();
        ensureTypeArguments(args.size(), 1);
        if (Set.class.isAssignableFrom(getType())) {
            return DataType.set(autodetectPrimitiveType(args.get(0).getType()));
        } else if (List.class.isAssignableFrom(getType())) {
            return DataType.list(autodetectPrimitiveType(args.get(0).getType()));
        }
    }
    DataType dataType = CassandraSimpleTypes.autodetectPrimitive(this.getType());
    if (dataType == null) {
        throw new InvalidDataAccessApiUsageException(
                "only primitive types and Set,List,Map collections are allowed, unknown type for property '"
                        + this.getName() + "' type is '" + this.getType() + "' in the entity "
                        + this.getOwner().getName());
    }
    return dataType;
}

From source file:com.joyveb.dbpimpl.cass.prepare.core.SessionFactoryBean.java

@Override
public void afterPropertiesSet() {

    if (cluster == null) {
        throw new IllegalArgumentException("cluster is required");
    }/*from  w w w  .jav a  2 s.  c  o m*/
    Session session = null;
    try {
        session = cluster.connect();
    } catch (RuntimeException ex) {
        RuntimeException resolved = translateExceptionIfPossible(ex);
        throw resolved == null ? ex : resolved;
    }
    if (StringUtils.hasText(keyspace)) {
        //         CqlTemplate cqlTemplate = new CqlTemplate(session, keyspace);
        adminOps = new DefaultAdminCqlOperations(session);

        KeyspaceMetadata keyspaceMetadata = adminOps.getKeyspaceMetadata(keyspace);
        boolean keyspaceExists = keyspaceMetadata != null;
        keyspaceCreated = false;

        if (keyspaceExists) {
            log.info("keyspace exists " + keyspaceMetadata.asCQLQuery());
        }
        if (keyspaceAttributes == null) {
            keyspaceAttributes = new KeyspaceAttributes();
        }
        // drop the old schema if needed
        if (keyspaceExists && (keyspaceAttributes.isCreate() || keyspaceAttributes.isCreateDrop())) {
            log.info("Drop keyspace " + keyspace + " on afterPropertiesSet");
            adminOps.dropKeyspace(keyspace).execute();
            keyspaceExists = false;
        }
        // create the new schema if needed
        if (!keyspaceExists && (keyspaceAttributes.isCreate() || keyspaceAttributes.isCreateDrop()
                || keyspaceAttributes.isUpdate())) {
            log.info("Create keyspace " + keyspace + " on afterPropertiesSet");
            adminOps.createKeyspace(keyspace, createKeyspaceOptions()).execute();
            keyspaceCreated = true;
        }
        // update schema if needed
        if (keyspaceAttributes.isUpdate() && !keyspaceCreated) {
            if (compareKeyspaceAttributes(keyspaceAttributes, keyspaceMetadata) != null) {
                log.info("Update keyspace " + keyspace + " on afterPropertiesSet");
                adminOps.alterKeyspace(keyspace, createKeyspaceOptions()).execute();
            }
        }
        // validate schema if needed
        if (keyspaceAttributes.isValidate()) {
            if (!keyspaceExists) {
                throw new InvalidDataAccessApiUsageException(
                        "keyspace '" + keyspace + "' not found in the Cassandra");
            }
            String errorField = compareKeyspaceAttributes(keyspaceAttributes, keyspaceMetadata);
            if (errorField != null) {
                throw new InvalidDataAccessApiUsageException(
                        errorField + " attribute is not much in the keyspace '" + keyspace + "'");
            }
        }
        adminOps.useKeyspace(keyspace).execute();
    }
    // initialize property
    this.session = session;
}

From source file:com.frank.search.solr.repository.query.AbstractSolrQuery.java

@Override
public Object execute(Object[] parameters) {
    SolrParameterAccessor accessor = new SolrParametersParameterAccessor(solrQueryMethod, parameters);

    Query query = createQuery(accessor);
    decorateWithFilterQuery(query, accessor);
    setDefaultQueryOperatorIfDefined(query);
    setAllowedQueryExeutionTime(query);//  ww w  . j  a  va 2 s . co m
    setDefTypeIfDefined(query);
    setRequestHandlerIfDefined(query);

    if (solrQueryMethod.hasStatsDefinition()) {
        query.setStatsOptions(extractStatsOptions(solrQueryMethod, accessor));
    }

    if (isCountQuery() && isDeleteQuery()) {
        throw new InvalidDataAccessApiUsageException("Cannot execute 'delete' and 'count' at the same time.");
    }

    if (isCountQuery()) {
        return new CountExecution().execute(query);
    }
    if (isDeleteQuery()) {
        return new DeleteExecution().execute(query);
    }

    if (solrQueryMethod.isPageQuery() || solrQueryMethod.isSliceQuery()) {
        if (solrQueryMethod.isFacetQuery() && solrQueryMethod.isHighlightQuery()) {
            throw new InvalidDataAccessApiUsageException("Facet and Highlight cannot be combined.");
        }
        if (solrQueryMethod.isFacetQuery()) {
            FacetQuery facetQuery = SimpleFacetQuery.fromQuery(query, new SimpleFacetQuery());
            facetQuery.setFacetOptions(extractFacetOptions(solrQueryMethod, accessor));
            return new FacetPageExecution(accessor.getPageable()).execute(facetQuery);
        }
        if (solrQueryMethod.isHighlightQuery()) {
            HighlightQuery highlightQuery = SimpleHighlightQuery.fromQuery(query, new SimpleHighlightQuery());
            highlightQuery.setHighlightOptions(extractHighlightOptions(solrQueryMethod, accessor));
            return new HighlightPageExecution(accessor.getPageable()).execute(highlightQuery);
        }
        return new PagedExecution(accessor.getPageable()).execute(query);
    } else if (solrQueryMethod.isCollectionQuery()) {
        return new CollectionExecution(accessor.getPageable()).execute(query);
    }

    return new SingleEntityExecution().execute(query);
}

From source file:com.frank.search.solr.repository.support.SimpleSolrRepository.java

@Override
public <S extends T> Iterable<S> save(Iterable<S> entities) {
    Assert.notNull(entities, "Cannot insert 'null' as a List.");

    if (!(entities instanceof Collection<?>)) {
        throw new InvalidDataAccessApiUsageException("Entities have to be inside a collection");
    }/*from   ww w  .j  a  va  2 s .  co m*/

    registerTransactionSynchronisationIfSynchronisationActive();
    this.solrOperations.saveBeans((Collection<? extends T>) entities);
    commitIfTransactionSynchronisationIsInactive();
    return entities;
}

From source file:nivance.jpa.cassandra.prepare.core.CassandraSessionFactoryBean.java

public String getTableName(Class<?> entityClass) {
    if (entityClass == null) {
        throw new InvalidDataAccessApiUsageException(
                "No class parameter provided, entity table name can't be determined!");
    }/* w w w.  j  av  a 2  s  .  com*/
    Table table = entityClass.getAnnotation(Table.class);
    if (table == null) {
        throw new InvalidDataAccessApiUsageException("Tablename is null:: " + entityClass.getName());
    }

    //      CassandraPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
    //      if (entity == null) {
    //         throw new InvalidDataAccessApiUsageException("No Persitent Entity information found for the class "
    //               + entityClass.getName());
    //      }
    return table.name();
}

From source file:com.duowan.common.spring.jdbc.BeanPropertyRowMapper.java

/**
 * Set the class that each row should be mapped to.
 *//* www  .j  a v  a 2  s  . co m*/
public void setMappedClass(Class<T> mappedClass) {
    if (this.mappedClass == null) {
        initialize(mappedClass);
    } else {
        if (!this.mappedClass.equals(mappedClass)) {
            throw new InvalidDataAccessApiUsageException("The mapped class can not be reassigned to map to "
                    + mappedClass + " since it is already providing mapping for " + this.mappedClass);
        }
    }
}