001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.jdbc.core.simple;
018:
019: import java.util.Map;
020:
021: import org.springframework.jdbc.core.namedparam.SqlParameterSource;
022: import org.springframework.jdbc.support.KeyHolder;
023:
024: /**
025: * Interface specifying the API for a Simple JDBC Insert implemented by {@link SimpleJdbcInsert}.
026: * This interface is not often used directly, but provides the
027: * option to enhance testability, as it can easily be mocked or stubbed.
028: *
029: * @author Thomas Risberg
030: * @since 2.5
031: */
032: public interface SimpleJdbcInsertOperations {
033:
034: /**
035: * Specify the table name to be used for the insert.
036: * @param tableName the name of the stored table
037: * @return the instance of this SimpleJdbcInsert
038: */
039: SimpleJdbcInsertOperations withTableName(String tableName);
040:
041: /**
042: * Specify the shema name, if any, to be used for the insert.
043: * @param schemaName the name of the schema
044: * @return the instance of this SimpleJdbcInsert
045: */
046: SimpleJdbcInsertOperations withSchemaName(String schemaName);
047:
048: /**
049: * Specify the catalog name, if any, to be used for the insert.
050: * @param catalogName the name of the catalog
051: * @return the instance of this SimpleJdbcInsert
052: */
053: SimpleJdbcInsertOperations withCatalogName(String catalogName);
054:
055: /**
056: * Specify the column names that the insert statement should be limited to use.
057: * @param columnNames one or more column names
058: * @return the instance of this SimpleJdbcInsert
059: */
060: SimpleJdbcInsertOperations usingColumns(String... columnNames);
061:
062: /**
063: * Specify the name sof any columns that have auto generated keys.
064: * @param columnNames one or more column names
065: * @return the instance of this SimpleJdbcInsert
066: */
067: SimpleJdbcInsertOperations usingGeneratedKeyColumns(
068: String... columnNames);
069:
070: /**
071: * Execute the insert using the values passed in.
072: * @param args Map containing column names and corresponding value
073: * @return the number of rows affected as returned by the JDBC driver
074: */
075: int execute(Map<String, Object> args);
076:
077: /**
078: * Execute the insert using the values passed in.
079: * @param parameterSource SqlParameterSource containing values to use for insert
080: * @return the number of rows affected as returned by the JDBC driver
081: */
082: int execute(SqlParameterSource parameterSource);
083:
084: /**
085: * Execute the insert using the values passed in and return the generated key. This requires that
086: * the name of the columns with auto generated keys have been specified. This method will always
087: * return a key or throw an exception if a key was not returned.
088: * @param args Map containing column names and corresponding value
089: * @return the generated key value
090: */
091: Number executeAndReturnKey(Map<String, Object> args);
092:
093: /**
094: * Execute the insert using the values passed in and return the generated key. This requires that
095: * the name of the columns with auto generated keys have been specified. This method will always
096: * return a key or throw an exception if a key was not returned.
097: * @param parameterSource SqlParameterSource containing values to use for insert
098: * @return the generated key value.
099: */
100: Number executeAndReturnKey(SqlParameterSource parameterSource);
101:
102: /**
103: * Execute the insert using the values passed in and return the generated keys. This requires that
104: * the name of the columns with auto generated keys have been specified. This method will always return
105: * a KeyHolder but the caller must verify that it actually contains the generated keys.
106: * @param args Map containing column names and corresponding value
107: * @return the KeyHolder containing all generated keys
108: */
109: KeyHolder executeAndReturnKeyHolder(Map<String, Object> args);
110:
111: /**
112: * Execute the insert using the values passed in and return the generated keys. This requires that
113: * the name of the columns with auto generated keys have been specified. This method will always return
114: * a KeyHolder but the caller must verify that it actually contains the generated keys.
115: * @param parameterSource SqlParameterSource containing values to use for insert
116: * @return the KeyHolder containing all generated keys
117: */
118: KeyHolder executeAndReturnKeyHolder(
119: SqlParameterSource parameterSource);
120:
121: /**
122: * Execute a batch insert using the batch of values passed in.
123: * @param batch an array of Maps containing a batch of column names and corresponding value
124: * @return the array of number of rows affected as returned by the JDBC driver
125: */
126: int[] executeBatch(Map<String, Object>[] batch);
127:
128: /**
129: * Execute a batch insert using the batch of values passed in.
130: * @param batch an array of SqlParameterSource containing values for the batch
131: * @return the array of number of rows affected as returned by the JDBC driver
132: */
133: int[] executeBatch(SqlParameterSource[] batch);
134:
135: }
|