本文整理汇总了Java中org.springframework.dao.InvalidDataAccessApiUsageException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidDataAccessApiUsageException类的具体用法?Java InvalidDataAccessApiUsageException怎么用?Java InvalidDataAccessApiUsageException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvalidDataAccessApiUsageException类属于org.springframework.dao包,在下文中一共展示了InvalidDataAccessApiUsageException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateNamedParameters
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Validate the named parameters passed to an execute method based on declared parameters.
* Subclasses should invoke this method before every {@code executeQuery()} or
* {@code update()} method.
* @param parameters parameter Map supplied. May be {@code null}.
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
*/
protected void validateNamedParameters(Map<String, ?> parameters) throws InvalidDataAccessApiUsageException {
checkCompiled();
Map<String, ?> paramsToUse = (parameters != null ? parameters : Collections.<String, Object> emptyMap());
int declaredInParameters = 0;
for (SqlParameter param : this.declaredParameters) {
if (param.isInputValueProvided()) {
if (!supportsLobParameters() &&
(param.getSqlType() == Types.BLOB || param.getSqlType() == Types.CLOB)) {
throw new InvalidDataAccessApiUsageException(
"BLOB or CLOB parameters are not allowed for this kind of operation");
}
if (param.getName() != null && !paramsToUse.containsKey(param.getName())) {
throw new InvalidDataAccessApiUsageException("The parameter named '" + param.getName() +
"' was not among the parameters supplied: " + paramsToUse.keySet());
}
declaredInParameters++;
}
}
validateParameterCount(paramsToUse.size(), declaredInParameters);
}
示例2: testParametersSetWithList
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
public void testParametersSetWithList() {
TestRdbmsOperation operation = new TestRdbmsOperation();
DataSource ds = new DriverManagerDataSource();
operation.setDataSource(ds);
operation.setSql("select * from mytable where one = ? and two = ?");
List l = new ArrayList();
l.add(new SqlParameter("one", Types.NUMERIC));
l.add(new SqlParameter("two", Types.VARCHAR));
operation.setParameters(new SqlParameter[] {
new SqlParameter("one", Types.NUMERIC),
new SqlParameter("two", Types.NUMERIC)});
operation.afterPropertiesSet();
try {
operation.validateParameters(new Object[] {new Integer(1), new String("2")});
assertEquals(2, operation.getDeclaredParameters().size());
// OK
}
catch (InvalidDataAccessApiUsageException idaauex) {
fail("Should have validated with parameters set using List: " + idaauex.getMessage());
}
}
示例3: getKey
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
@Override
public Number getKey() throws InvalidDataAccessApiUsageException, DataRetrievalFailureException {
if (this.keyList.size() == 0) {
return null;
}
if (this.keyList.size() > 1 || this.keyList.get(0).size() > 1) {
throw new InvalidDataAccessApiUsageException(
"The getKey method should only be used when a single key is returned. " +
"The current key entry contains multiple keys: " + this.keyList);
}
Iterator<Object> keyIter = this.keyList.get(0).values().iterator();
if (keyIter.hasNext()) {
Object key = keyIter.next();
if (!(key instanceof Number)) {
throw new DataRetrievalFailureException(
"The generated key is not of a supported numeric type. " +
"Unable to cast [" + (key != null ? key.getClass().getName() : null) +
"] to [" + Number.class.getName() + "]");
}
return (Number) key;
}
else {
throw new DataRetrievalFailureException("Unable to retrieve the generated key. " +
"Check that the table has an identity column enabled.");
}
}
示例4: compile
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Compile this query.
* Ignores subsequent attempts to compile.
* @throws InvalidDataAccessApiUsageException if the object hasn't
* been correctly initialized, for example if no DataSource has been provided
*/
public final void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getSql() == null) {
throw new InvalidDataAccessApiUsageException("Property 'sql' is required");
}
try {
this.jdbcTemplate.afterPropertiesSet();
}
catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("RdbmsOperation with SQL [" + getSql() + "] compiled");
}
}
}
示例5: validateParameters
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Validate the parameters passed to an execute method based on declared parameters.
* Subclasses should invoke this method before every {@code executeQuery()}
* or {@code update()} method.
* @param parameters parameters supplied (may be {@code null})
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
*/
protected void validateParameters(Object[] parameters) throws InvalidDataAccessApiUsageException {
checkCompiled();
int declaredInParameters = 0;
for (SqlParameter param : this.declaredParameters) {
if (param.isInputValueProvided()) {
if (!supportsLobParameters() &&
(param.getSqlType() == Types.BLOB || param.getSqlType() == Types.CLOB)) {
throw new InvalidDataAccessApiUsageException(
"BLOB or CLOB parameters are not allowed for this kind of operation");
}
declaredInParameters++;
}
}
validateParameterCount((parameters != null ? parameters.length : 0), declaredInParameters);
}
示例6: PreparedStatementCreatorImpl
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
public PreparedStatementCreatorImpl(String actualSql, List<?> parameters) {
this.actualSql = actualSql;
Assert.notNull(parameters, "Parameters List must not be null");
this.parameters = parameters;
if (this.parameters.size() != declaredParameters.size()) {
// account for named parameters being used multiple times
Set<String> names = new HashSet<String>();
for (int i = 0; i < parameters.size(); i++) {
Object param = parameters.get(i);
if (param instanceof SqlParameterValue) {
names.add(((SqlParameterValue) param).getName());
}
else {
names.add("Parameter #" + i);
}
}
if (names.size() != declaredParameters.size()) {
throw new InvalidDataAccessApiUsageException(
"SQL [" + sql + "]: given " + names.size() +
" parameters but expected " + declaredParameters.size());
}
}
}
示例7: compile
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Compile this JdbcInsert using provided parameters and meta data plus other settings.
* This finalizes the configuration for this object and subsequent attempts to compile are
* ignored. This will be implicitly called the first time an un-compiled insert is executed.
* @throws InvalidDataAccessApiUsageException if the object hasn't been correctly initialized,
* for example if no DataSource has been provided
*/
public synchronized final void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getTableName() == null) {
throw new InvalidDataAccessApiUsageException("Table name is required");
}
try {
this.jdbcTemplate.afterPropertiesSet();
}
catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("JdbcInsert for table [" + getTableName() + "] compiled");
}
}
}
示例8: prepareStatementForGeneratedKeys
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Create the PreparedStatement to be used for insert that have generated keys
*
* @param con the connection used
* @return PreparedStatement to use
* @throws SQLException
*/
private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throws SQLException {
if (getGeneratedKeyNames().length < 1) {
throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specificed. " +
"Using the generated keys features requires specifying the name(s) of the generated column(s)");
}
PreparedStatement ps;
if (this.tableMetaDataContext.isGeneratedKeysColumnNameArraySupported()) {
if (logger.isDebugEnabled()) {
logger.debug("Using generated keys support with array of column names.");
}
ps = con.prepareStatement(getInsertString(), getGeneratedKeyNames());
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Using generated keys support with Statement.RETURN_GENERATED_KEYS.");
}
ps = con.prepareStatement(getInsertString(), Statement.RETURN_GENERATED_KEYS);
}
return ps;
}
示例9: addDeclaredParameter
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Add a declared parameter to the list of parameters for the call.
* Only parameters declared as {@code SqlParameter} and {@code SqlInOutParameter}
* will be used to provide input values. This is different from the {@code StoredProcedure} class
* which for backwards compatibility reasons allows input values to be provided for parameters declared
* as {@code SqlOutParameter}.
* @param parameter the {@link SqlParameter} to add
*/
public void addDeclaredParameter(SqlParameter parameter) {
Assert.notNull(parameter, "The supplied parameter must not be null");
if (!StringUtils.hasText(parameter.getName())) {
throw new InvalidDataAccessApiUsageException(
"You must specify a parameter name when declaring parameters for \"" + getProcedureName() + "\"");
}
this.declaredParameters.add(parameter);
if (logger.isDebugEnabled()) {
logger.debug("Added declared parameter for [" + getProcedureName() + "]: " + parameter.getName());
}
}
示例10: compile
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Compile this JdbcCall using provided parameters and meta data plus other settings. This
* finalizes the configuration for this object and subsequent attempts to compile are ignored.
* This will be implicitly called the first time an un-compiled call is executed.
* @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't
* been correctly initialized, for example if no DataSource has been provided
*/
public synchronized final void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getProcedureName() == null) {
throw new InvalidDataAccessApiUsageException("Procedure or Function name is required");
}
try {
this.jdbcTemplate.afterPropertiesSet();
}
catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("SqlCall for " + (isFunction() ? "function" : "procedure") + " [" + getProcedureName() + "] compiled");
}
}
}
示例11: init
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
@Override
public void init(DataSource dataSource) throws Exception {
Assert.notNull(dataSource);
Assert.hasLength(selectClause, "selectClause must be specified");
Assert.hasLength(fromClause, "fromClause must be specified");
Assert.notEmpty(sortKeys, "sortKey must be specified");
StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(selectClause);
sql.append(" FROM ").append(fromClause);
if (whereClause != null) {
sql.append(" WHERE ").append(whereClause);
}
List<String> namedParameters = new ArrayList<String>();
parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql.toString(), namedParameters);
if (namedParameters.size() > 0) {
if (parameterCount != namedParameters.size()) {
throw new InvalidDataAccessApiUsageException(
"You can't use both named parameters and classic \"?\" placeholders: " + sql);
}
usingNamedParameters = true;
}
}
示例12: fromInequalityVariant
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
private Predicate<?> fromInequalityVariant(Type type, boolean ignoreCase, Iterator<Comparable<?>> iterator) {
if (ignoreCase && type != Type.SIMPLE_PROPERTY) {
throw new InvalidDataAccessApiUsageException(String.format("Ignore case not supported for '%s'", type));
}
switch (type) {
case GREATER_THAN:
return GreaterLessPredicate.gr(iterator.next());
case GREATER_THAN_EQUAL:
return GreaterLessPredicate.ge(iterator.next());
case LESS_THAN:
return GreaterLessPredicate.ls(iterator.next());
case LESS_THAN_EQUAL:
return GreaterLessPredicate.le(iterator.next());
default:
throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
}
}
示例13: doExecute
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
@Override
protected Object doExecute(final AbstractEbeanQuery ebeanQuery, Object[] values) {
if (!SurroundingTransactionDetectorMethodInterceptor.INSTANCE.isSurroundingTransactionActive()) {
throw new InvalidDataAccessApiUsageException(NO_SURROUNDING_TRANSACTION);
}
Object createQuery = ebeanQuery.createQuery(values);
if (createQuery instanceof Query) {
Query ormQuery = (Query) createQuery;
QueryIterator<Object> iter = ormQuery.findIterate();
return StreamUtils.createStreamFromIterator(iter);
} else if (createQuery instanceof SqlQuery) {
throw new InvalidEbeanQueryMethodException("query must be Query");
} else {
throw new InvalidEbeanQueryMethodException("query must be Query or SqlQuery");
}
}
示例14: prepareStatementForGeneratedKeys
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Create a PreparedStatement to be used for an insert operation with generated keys.
* @param con the Connection to use
* @return the PreparedStatement
*/
private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throws SQLException {
if (getGeneratedKeyNames().length < 1) {
throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specified. " +
"Using the generated keys features requires specifying the name(s) of the generated column(s).");
}
PreparedStatement ps;
if (this.tableMetaDataContext.isGeneratedKeysColumnNameArraySupported()) {
if (logger.isDebugEnabled()) {
logger.debug("Using generated keys support with array of column names.");
}
ps = con.prepareStatement(getInsertString(), getGeneratedKeyNames());
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Using generated keys support with Statement.RETURN_GENERATED_KEYS.");
}
ps = con.prepareStatement(getInsertString(), Statement.RETURN_GENERATED_KEYS);
}
return ps;
}
示例15: compile
import org.springframework.dao.InvalidDataAccessApiUsageException; //导入依赖的package包/类
/**
* Compile this JdbcCall using provided parameters and meta data plus other settings.
* <p>This finalizes the configuration for this object and subsequent attempts to compile are
* ignored. This will be implicitly called the first time an un-compiled call is executed.
* @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't
* been correctly initialized, for example if no DataSource has been provided
*/
public synchronized final void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getProcedureName() == null) {
throw new InvalidDataAccessApiUsageException("Procedure or Function name is required");
}
try {
this.jdbcTemplate.afterPropertiesSet();
}
catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("SqlCall for " + (isFunction() ? "function" : "procedure") +
" [" + getProcedureName() + "] compiled");
}
}
}