Skip to content

Commit 76d381b

Browse files
committed
Corrected line endings from CRLF to LF.
1 parent c5060a0 commit 76d381b

File tree

9 files changed

+780
-780
lines changed

9 files changed

+780
-780
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
1-
/*
2-
* Copyright 2009-2013 The MyBatis Team
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.apache.ibatis.executor.keygen;
17-
18-
import java.sql.Statement;
19-
import java.util.List;
20-
21-
import org.apache.ibatis.executor.Executor;
22-
import org.apache.ibatis.executor.ExecutorException;
23-
import org.apache.ibatis.mapping.MappedStatement;
24-
import org.apache.ibatis.reflection.MetaObject;
25-
import org.apache.ibatis.session.Configuration;
26-
import org.apache.ibatis.session.ExecutorType;
27-
import org.apache.ibatis.session.RowBounds;
28-
29-
public class SelectKeyGenerator implements KeyGenerator {
30-
31-
public static final String SELECT_KEY_SUFFIX = "!selectKey";
32-
private boolean executeBefore;
33-
private MappedStatement keyStatement;
34-
35-
public SelectKeyGenerator(MappedStatement keyStatement, boolean executeBefore) {
36-
this.executeBefore = executeBefore;
37-
this.keyStatement = keyStatement;
38-
}
39-
40-
public void processBefore(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
41-
if (executeBefore) {
42-
processGeneratedKeys(executor, ms, parameter);
43-
}
44-
}
45-
46-
public void processAfter(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
47-
if (!executeBefore) {
48-
processGeneratedKeys(executor, ms, parameter);
49-
}
50-
}
51-
52-
private void processGeneratedKeys(Executor executor, MappedStatement ms, Object parameter) {
53-
try {
54-
if (parameter != null && keyStatement != null && keyStatement.getKeyProperties() != null) {
55-
String keyProperty = keyStatement.getKeyProperties()[0]; // just one key property is supported
56-
final Configuration configuration = ms.getConfiguration();
57-
final MetaObject metaParam = configuration.newMetaObject(parameter);
58-
if (keyProperty != null && metaParam.hasSetter(keyProperty)) {
59-
// Do not close keyExecutor.
60-
// The transaction will be closed by parent executor.
61-
Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
62-
List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
63-
if (values.size() == 0) {
64-
throw new ExecutorException("SelectKey returned no data.");
65-
} else if (values.size() > 1) {
66-
throw new ExecutorException("SelectKey returned more than one value.");
67-
} else {
68-
metaParam.setValue(keyProperty, values.get(0));
69-
}
70-
}
71-
}
72-
} catch (ExecutorException e) {
73-
throw e;
74-
} catch (Exception e) {
75-
throw new ExecutorException("Error selecting key or setting result to parameter object. Cause: " + e, e);
76-
}
77-
}
78-
79-
}
1+
/*
2+
* Copyright 2009-2013 The MyBatis Team
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.executor.keygen;
17+
18+
import java.sql.Statement;
19+
import java.util.List;
20+
21+
import org.apache.ibatis.executor.Executor;
22+
import org.apache.ibatis.executor.ExecutorException;
23+
import org.apache.ibatis.mapping.MappedStatement;
24+
import org.apache.ibatis.reflection.MetaObject;
25+
import org.apache.ibatis.session.Configuration;
26+
import org.apache.ibatis.session.ExecutorType;
27+
import org.apache.ibatis.session.RowBounds;
28+
29+
public class SelectKeyGenerator implements KeyGenerator {
30+
31+
public static final String SELECT_KEY_SUFFIX = "!selectKey";
32+
private boolean executeBefore;
33+
private MappedStatement keyStatement;
34+
35+
public SelectKeyGenerator(MappedStatement keyStatement, boolean executeBefore) {
36+
this.executeBefore = executeBefore;
37+
this.keyStatement = keyStatement;
38+
}
39+
40+
public void processBefore(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
41+
if (executeBefore) {
42+
processGeneratedKeys(executor, ms, parameter);
43+
}
44+
}
45+
46+
public void processAfter(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
47+
if (!executeBefore) {
48+
processGeneratedKeys(executor, ms, parameter);
49+
}
50+
}
51+
52+
private void processGeneratedKeys(Executor executor, MappedStatement ms, Object parameter) {
53+
try {
54+
if (parameter != null && keyStatement != null && keyStatement.getKeyProperties() != null) {
55+
String keyProperty = keyStatement.getKeyProperties()[0]; // just one key property is supported
56+
final Configuration configuration = ms.getConfiguration();
57+
final MetaObject metaParam = configuration.newMetaObject(parameter);
58+
if (keyProperty != null && metaParam.hasSetter(keyProperty)) {
59+
// Do not close keyExecutor.
60+
// The transaction will be closed by parent executor.
61+
Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
62+
List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
63+
if (values.size() == 0) {
64+
throw new ExecutorException("SelectKey returned no data.");
65+
} else if (values.size() > 1) {
66+
throw new ExecutorException("SelectKey returned more than one value.");
67+
} else {
68+
metaParam.setValue(keyProperty, values.get(0));
69+
}
70+
}
71+
}
72+
} catch (ExecutorException e) {
73+
throw e;
74+
} catch (Exception e) {
75+
throw new ExecutorException("Error selecting key or setting result to parameter object. Cause: " + e, e);
76+
}
77+
}
78+
79+
}
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,105 @@
1-
/*
2-
* Copyright 2009-2012 The MyBatis Team
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.apache.ibatis.executor.statement;
17-
18-
import java.sql.CallableStatement;
19-
import java.sql.Connection;
20-
import java.sql.ResultSet;
21-
import java.sql.SQLException;
22-
import java.sql.Statement;
23-
import java.util.List;
24-
25-
import org.apache.ibatis.executor.Executor;
26-
import org.apache.ibatis.executor.ExecutorException;
27-
import org.apache.ibatis.executor.keygen.KeyGenerator;
28-
import org.apache.ibatis.mapping.BoundSql;
29-
import org.apache.ibatis.mapping.MappedStatement;
30-
import org.apache.ibatis.mapping.ParameterMapping;
31-
import org.apache.ibatis.mapping.ParameterMode;
32-
import org.apache.ibatis.session.ResultHandler;
33-
import org.apache.ibatis.session.RowBounds;
34-
import org.apache.ibatis.type.JdbcType;
35-
36-
public class CallableStatementHandler extends BaseStatementHandler {
37-
38-
public CallableStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
39-
super(executor, mappedStatement, parameter, rowBounds, resultHandler, boundSql);
40-
}
41-
42-
public int update(Statement statement)
43-
throws SQLException {
44-
CallableStatement cs = (CallableStatement) statement;
45-
cs.execute();
46-
int rows = cs.getUpdateCount();
47-
Object parameterObject = boundSql.getParameterObject();
48-
KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
49-
keyGenerator.processAfter(executor, mappedStatement, cs, parameterObject);
50-
resultSetHandler.handleOutputParameters(cs);
51-
return rows;
52-
}
53-
54-
public void batch(Statement statement)
55-
throws SQLException {
56-
CallableStatement cs = (CallableStatement) statement;
57-
cs.addBatch();
58-
}
59-
60-
public <E> List<E> query(Statement statement, ResultHandler resultHandler)
61-
throws SQLException {
62-
CallableStatement cs = (CallableStatement) statement;
63-
cs.execute();
64-
List<E> resultList = resultSetHandler.<E>handleResultSets(cs);
65-
resultSetHandler.handleOutputParameters(cs);
66-
return resultList;
67-
}
68-
69-
protected Statement instantiateStatement(Connection connection) throws SQLException {
70-
String sql = boundSql.getSql();
71-
if (mappedStatement.getResultSetType() != null) {
72-
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
73-
} else {
74-
return connection.prepareCall(sql);
75-
}
76-
}
77-
78-
public void parameterize(Statement statement) throws SQLException {
79-
registerOutputParameters((CallableStatement) statement);
80-
parameterHandler.setParameters((CallableStatement) statement);
81-
}
82-
83-
private void registerOutputParameters(CallableStatement cs) throws SQLException {
84-
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
85-
for (int i = 0, n = parameterMappings.size(); i < n; i++) {
86-
ParameterMapping parameterMapping = parameterMappings.get(i);
87-
if (parameterMapping.getMode() == ParameterMode.OUT || parameterMapping.getMode() == ParameterMode.INOUT) {
88-
if (null == parameterMapping.getJdbcType()) {
89-
throw new ExecutorException("The JDBC Type must be specified for output parameter. Parameter: " + parameterMapping.getProperty());
90-
} else {
91-
if (parameterMapping.getNumericScale() != null && (parameterMapping.getJdbcType() == JdbcType.NUMERIC || parameterMapping.getJdbcType() == JdbcType.DECIMAL)) {
92-
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE, parameterMapping.getNumericScale());
93-
} else {
94-
if (parameterMapping.getJdbcTypeName() == null) {
95-
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE);
96-
} else {
97-
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE, parameterMapping.getJdbcTypeName());
98-
}
99-
}
100-
}
101-
}
102-
}
103-
}
104-
105-
}
1+
/*
2+
* Copyright 2009-2012 The MyBatis Team
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.executor.statement;
17+
18+
import java.sql.CallableStatement;
19+
import java.sql.Connection;
20+
import java.sql.ResultSet;
21+
import java.sql.SQLException;
22+
import java.sql.Statement;
23+
import java.util.List;
24+
25+
import org.apache.ibatis.executor.Executor;
26+
import org.apache.ibatis.executor.ExecutorException;
27+
import org.apache.ibatis.executor.keygen.KeyGenerator;
28+
import org.apache.ibatis.mapping.BoundSql;
29+
import org.apache.ibatis.mapping.MappedStatement;
30+
import org.apache.ibatis.mapping.ParameterMapping;
31+
import org.apache.ibatis.mapping.ParameterMode;
32+
import org.apache.ibatis.session.ResultHandler;
33+
import org.apache.ibatis.session.RowBounds;
34+
import org.apache.ibatis.type.JdbcType;
35+
36+
public class CallableStatementHandler extends BaseStatementHandler {
37+
38+
public CallableStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
39+
super(executor, mappedStatement, parameter, rowBounds, resultHandler, boundSql);
40+
}
41+
42+
public int update(Statement statement)
43+
throws SQLException {
44+
CallableStatement cs = (CallableStatement) statement;
45+
cs.execute();
46+
int rows = cs.getUpdateCount();
47+
Object parameterObject = boundSql.getParameterObject();
48+
KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
49+
keyGenerator.processAfter(executor, mappedStatement, cs, parameterObject);
50+
resultSetHandler.handleOutputParameters(cs);
51+
return rows;
52+
}
53+
54+
public void batch(Statement statement)
55+
throws SQLException {
56+
CallableStatement cs = (CallableStatement) statement;
57+
cs.addBatch();
58+
}
59+
60+
public <E> List<E> query(Statement statement, ResultHandler resultHandler)
61+
throws SQLException {
62+
CallableStatement cs = (CallableStatement) statement;
63+
cs.execute();
64+
List<E> resultList = resultSetHandler.<E>handleResultSets(cs);
65+
resultSetHandler.handleOutputParameters(cs);
66+
return resultList;
67+
}
68+
69+
protected Statement instantiateStatement(Connection connection) throws SQLException {
70+
String sql = boundSql.getSql();
71+
if (mappedStatement.getResultSetType() != null) {
72+
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
73+
} else {
74+
return connection.prepareCall(sql);
75+
}
76+
}
77+
78+
public void parameterize(Statement statement) throws SQLException {
79+
registerOutputParameters((CallableStatement) statement);
80+
parameterHandler.setParameters((CallableStatement) statement);
81+
}
82+
83+
private void registerOutputParameters(CallableStatement cs) throws SQLException {
84+
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
85+
for (int i = 0, n = parameterMappings.size(); i < n; i++) {
86+
ParameterMapping parameterMapping = parameterMappings.get(i);
87+
if (parameterMapping.getMode() == ParameterMode.OUT || parameterMapping.getMode() == ParameterMode.INOUT) {
88+
if (null == parameterMapping.getJdbcType()) {
89+
throw new ExecutorException("The JDBC Type must be specified for output parameter. Parameter: " + parameterMapping.getProperty());
90+
} else {
91+
if (parameterMapping.getNumericScale() != null && (parameterMapping.getJdbcType() == JdbcType.NUMERIC || parameterMapping.getJdbcType() == JdbcType.DECIMAL)) {
92+
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE, parameterMapping.getNumericScale());
93+
} else {
94+
if (parameterMapping.getJdbcTypeName() == null) {
95+
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE);
96+
} else {
97+
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE, parameterMapping.getJdbcTypeName());
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
104+
105+
}

0 commit comments

Comments
 (0)