Skip to content

Commit 8fdc57e

Browse files
author
Thomas Risberg
committed
added a concrete GenericStoredProcedure class to make it possible to configure using application context (SPR-3987)
1 parent a0139ab commit 8fdc57e

File tree

6 files changed

+355
-92
lines changed

6 files changed

+355
-92
lines changed

org.springframework.jdbc/jdbc.iml

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<module relativePaths="true" type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" inherit-compiler-output="true">
4-
<exclude-output />
5-
<content url="file://$MODULE_DIR$">
6-
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
7-
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
8-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
10-
<excludeFolder url="file://$MODULE_DIR$/target" />
11-
</content>
12-
<orderEntry type="sourceFolder" forTests="false" />
13-
<orderEntry type="inheritedJdk" />
14-
<orderEntry type="module-library">
15-
<library>
16-
<CLASSES>
17-
<root url="jar://$IVY_CACHE$/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-1.1.1.jar!/" />
18-
</CLASSES>
19-
<JAVADOC />
20-
<SOURCES>
21-
<root url="jar://$IVY_CACHE$/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-sources-1.1.1.jar!/" />
22-
</SOURCES>
23-
</library>
24-
</orderEntry>
25-
<orderEntry type="module" module-name="aop" />
26-
<orderEntry type="module" module-name="beans" />
27-
<orderEntry type="module" module-name="context" />
28-
<orderEntry type="module" module-name="core" />
29-
<orderEntry type="module" module-name="transaction" />
30-
<orderEntry type="module-library">
31-
<library>
32-
<CLASSES>
33-
<root url="jar://$IVY_CACHE$/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-1.1.0.jar!/" />
34-
</CLASSES>
35-
<JAVADOC />
36-
<SOURCES>
37-
<root url="jar://$IVY_CACHE$/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-sources-1.1.0.jar!/" />
38-
</SOURCES>
39-
</library>
40-
</orderEntry>
41-
<orderEntry type="module-library">
42-
<library>
43-
<CLASSES>
44-
<root url="jar://$IVY_CACHE$/com.mchange.c3p0/com.springsource.com.mchange.v2.c3p0/0.9.1.2/com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar!/" />
45-
</CLASSES>
46-
<JAVADOC />
47-
<SOURCES>
48-
<root url="jar://$IVY_CACHE$/com.mchange.c3p0/com.springsource.com.mchange.v2.c3p0/0.9.1.2/com.springsource.com.mchange.v2.c3p0-sources-0.9.1.2.jar!/" />
49-
</SOURCES>
50-
</library>
51-
</orderEntry>
52-
<orderEntry type="module-library">
53-
<library>
54-
<CLASSES>
55-
<root url="jar://$IVY_CACHE$/com.experlog.xapool/com.springsource.org.enhydra.jdbc/1.5.0/com.springsource.org.enhydra.jdbc-1.5.0.jar!/" />
56-
</CLASSES>
57-
<JAVADOC />
58-
<SOURCES>
59-
<root url="jar://$IVY_CACHE$/com.experlog.xapool/com.springsource.org.enhydra.jdbc/1.5.0/com.springsource.org.enhydra.jdbc-sources-1.5.0.jar!/" />
60-
</SOURCES>
61-
</library>
62-
</orderEntry>
63-
<orderEntry type="module-library">
64-
<library>
65-
<CLASSES>
66-
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-4.5.0.jar!/" />
67-
</CLASSES>
68-
<JAVADOC />
69-
<SOURCES>
70-
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-sources-4.5.0.jar!/" />
71-
</SOURCES>
72-
</library>
73-
</orderEntry>
74-
<orderEntry type="module-library">
75-
<library>
76-
<CLASSES>
77-
<root url="jar://$IVY_CACHE$/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar!/" />
78-
</CLASSES>
79-
<JAVADOC />
80-
<SOURCES>
81-
<root url="jar://$IVY_CACHE$/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar!/" />
82-
</SOURCES>
83-
</library>
84-
</orderEntry>
85-
</component>
86-
<component name="copyright">
87-
<Base>
88-
<setting name="state" value="2" />
89-
</Base>
90-
</component>
91-
</module>
92-
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module relativePaths="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
10+
<excludeFolder url="file://$MODULE_DIR$/target" />
11+
</content>
12+
<orderEntry type="sourceFolder" forTests="false" />
13+
<orderEntry type="inheritedJdk" />
14+
<orderEntry type="module-library">
15+
<library>
16+
<CLASSES>
17+
<root url="jar://$IVY_CACHE$/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-1.1.1.jar!/" />
18+
</CLASSES>
19+
<JAVADOC />
20+
<SOURCES>
21+
<root url="jar://$IVY_CACHE$/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-sources-1.1.1.jar!/" />
22+
</SOURCES>
23+
</library>
24+
</orderEntry>
25+
<orderEntry type="module" module-name="aop" />
26+
<orderEntry type="module" module-name="beans" />
27+
<orderEntry type="module" module-name="context" />
28+
<orderEntry type="module" module-name="core" />
29+
<orderEntry type="module" module-name="transaction" />
30+
<orderEntry type="module-library">
31+
<library>
32+
<CLASSES>
33+
<root url="jar://$IVY_CACHE$/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-1.1.0.jar!/" />
34+
</CLASSES>
35+
<JAVADOC />
36+
<SOURCES>
37+
<root url="jar://$IVY_CACHE$/javax.transaction/com.springsource.javax.transaction/1.1.0/com.springsource.javax.transaction-sources-1.1.0.jar!/" />
38+
</SOURCES>
39+
</library>
40+
</orderEntry>
41+
<orderEntry type="module-library">
42+
<library>
43+
<CLASSES>
44+
<root url="jar://$IVY_CACHE$/com.mchange.c3p0/com.springsource.com.mchange.v2.c3p0/0.9.1.2/com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar!/" />
45+
</CLASSES>
46+
<JAVADOC />
47+
<SOURCES>
48+
<root url="jar://$IVY_CACHE$/com.mchange.c3p0/com.springsource.com.mchange.v2.c3p0/0.9.1.2/com.springsource.com.mchange.v2.c3p0-sources-0.9.1.2.jar!/" />
49+
</SOURCES>
50+
</library>
51+
</orderEntry>
52+
<orderEntry type="module-library">
53+
<library>
54+
<CLASSES>
55+
<root url="jar://$IVY_CACHE$/com.experlog.xapool/com.springsource.org.enhydra.jdbc/1.5.0/com.springsource.org.enhydra.jdbc-1.5.0.jar!/" />
56+
</CLASSES>
57+
<JAVADOC />
58+
<SOURCES>
59+
<root url="jar://$IVY_CACHE$/com.experlog.xapool/com.springsource.org.enhydra.jdbc/1.5.0/com.springsource.org.enhydra.jdbc-sources-1.5.0.jar!/" />
60+
</SOURCES>
61+
</library>
62+
</orderEntry>
63+
<orderEntry type="module-library">
64+
<library>
65+
<CLASSES>
66+
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-4.5.0.jar!/" />
67+
</CLASSES>
68+
<JAVADOC />
69+
<SOURCES>
70+
<root url="jar://$IVY_CACHE$/org.junit/com.springsource.org.junit/4.5.0/com.springsource.org.junit-sources-4.5.0.jar!/" />
71+
</SOURCES>
72+
</library>
73+
</orderEntry>
74+
<orderEntry type="module-library">
75+
<library>
76+
<CLASSES>
77+
<root url="jar://$IVY_CACHE$/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-2.3.0.jar!/" />
78+
</CLASSES>
79+
<JAVADOC />
80+
<SOURCES>
81+
<root url="jar://$IVY_CACHE$/org.easymock/com.springsource.org.easymock/2.3.0/com.springsource.org.easymock-sources-2.3.0.jar!/" />
82+
</SOURCES>
83+
</library>
84+
</orderEntry>
85+
</component>
86+
<component name="copyright">
87+
<Base>
88+
<setting name="state" value="2" />
89+
</Base>
90+
</component>
91+
</module>
92+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2002-2009 the original author or authors.
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+
17+
package org.springframework.jdbc.object;
18+
19+
import java.sql.ResultSet;
20+
import java.sql.SQLException;
21+
import java.util.Map;
22+
23+
import org.springframework.jdbc.core.RowMapper;
24+
import org.springframework.util.Assert;
25+
import org.springframework.dao.InvalidDataAccessApiUsageException;
26+
27+
public class GenericSqlQuery extends SqlQuery {
28+
29+
Class rowMapperClass;
30+
31+
RowMapper rowMapper;
32+
33+
public void setRowMapperClass(Class rowMapperClass)
34+
throws IllegalAccessException, InstantiationException {
35+
this.rowMapperClass = rowMapperClass;
36+
if (!RowMapper.class.isAssignableFrom(rowMapperClass))
37+
throw new IllegalStateException("The specified class '" +
38+
rowMapperClass.getName() + " is not a sub class of " +
39+
"'org.springframework.jdbc.core.RowMapper'");
40+
}
41+
42+
public void afterPropertiesSet() {
43+
super.afterPropertiesSet();
44+
Assert.notNull(rowMapperClass, "The 'rowMapperClass' property is required");
45+
}
46+
47+
protected RowMapper newRowMapper(Object[] parameters, Map context) {
48+
try {
49+
return (RowMapper) rowMapperClass.newInstance();
50+
}
51+
catch (InstantiationException e) {
52+
throw new InvalidDataAccessApiUsageException("Unable to instantiate RowMapper", e);
53+
}
54+
catch (IllegalAccessException e) {
55+
throw new InvalidDataAccessApiUsageException("Unable to instantiate RowMapper", e);
56+
}
57+
}
58+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2002-2009 the original author or authors.
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+
17+
package org.springframework.jdbc.object;
18+
19+
/**
20+
* Concrete implementation making it possible to define the RDBMS stored procedures
21+
* in an application context without writing a custom Java implementation class.
22+
* <p>
23+
* This implementation does not provide a typed method for invocation so executions
24+
* must use one of the generic {@link StoredProcedure#execute(java.util.Map)} or
25+
* {@link StoredProcedure#execute(org.springframework.jdbc.core.ParameterMapper)} methods.
26+
*
27+
* @author Thomas Risberg
28+
* @see org.springframework.jdbc.object.StoredProcedure
29+
*/
30+
public class GenericStoredProcedure extends StoredProcedure {
31+
32+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.springframework.jdbc.datasource;
2+
3+
import java.sql.Connection;
4+
import java.sql.SQLException;
5+
import javax.sql.DataSource;
6+
7+
public class TestDataSourceWrapper extends AbstractDataSource {
8+
9+
private DataSource target;
10+
11+
public void setTarget(DataSource target) {
12+
this.target = target;
13+
}
14+
15+
public Connection getConnection() throws SQLException {
16+
return target.getConnection();
17+
}
18+
19+
public Connection getConnection(String username, String password) throws SQLException {
20+
return target.getConnection(username, password);
21+
}
22+
23+
}

0 commit comments

Comments
 (0)