├── .circleci
└── config.yml
├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE.txt
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── j256
│ │ └── ormlite
│ │ └── jdbc
│ │ ├── BaseJdbcConnectionSource.java
│ │ ├── DataSourceConnectionSource.java
│ │ ├── JdbcCompiledStatement.java
│ │ ├── JdbcConnectionSource.java
│ │ ├── JdbcDatabaseConnection.java
│ │ ├── JdbcDatabaseResults.java
│ │ ├── JdbcPooledConnectionSource.java
│ │ ├── JdbcSingleConnectionSource.java
│ │ ├── TypeValMapper.java
│ │ ├── db
│ │ ├── DatabaseTypeUtils.java
│ │ ├── Db2DatabaseType.java
│ │ ├── DerbyClientServerDatabaseType.java
│ │ ├── DerbyEmbeddedDatabaseType.java
│ │ ├── GenericOdbcDatabaseType.java
│ │ ├── H2DatabaseType.java
│ │ ├── HsqldbDatabaseType.java
│ │ ├── MariaDbDatabaseType.java
│ │ ├── MysqlDatabaseType.java
│ │ ├── NetezzaDatabaseType.java
│ │ ├── OracleDatabaseType.java
│ │ ├── PostgresDatabaseType.java
│ │ ├── SqlServerDatabaseType.java
│ │ ├── SqlServerJtdsDatabaseType.java
│ │ └── SqliteDatabaseType.java
│ │ └── spring
│ │ ├── DaoFactory.java
│ │ └── TableCreator.java
├── javadoc
│ ├── com
│ │ └── j256
│ │ │ └── ormlite
│ │ │ ├── db
│ │ │ └── package.html
│ │ │ ├── jdbc
│ │ │ └── package.html
│ │ │ └── spring
│ │ │ └── package.html
│ └── overview.html
└── resources
│ └── com
│ └── j256
│ └── ormlite
│ └── jdbc
│ ├── LICENSE.txt
│ └── README.txt
└── test
├── java
└── com
│ └── j256
│ └── ormlite
│ └── jdbc
│ ├── BaseJdbcTest.java
│ ├── DataSourceConnectionSourceTest.java
│ ├── JdbcCompiledStatementTest.java
│ ├── JdbcConnectionSourceTest.java
│ ├── JdbcDatabaseConnectionTest.java
│ ├── JdbcDatabaseResultsTest.java
│ ├── JdbcPooledConnectionSourceTest.java
│ ├── JdbcRawResultsImplTest.java
│ ├── JdbcSingleConnectionSourceTest.java
│ ├── dao
│ ├── BulkJdbcDaoTest.java
│ ├── DoubleDbOpenTest.java
│ └── JdbcBaseDaoImplTest.java
│ ├── db
│ ├── BaseJdbcDatabaseTypeTest.java
│ ├── DatabaseTypeUtilsTest.java
│ ├── Db2DatabaseTypeTest.java
│ ├── DerbyClientServerDatabaseTypeTest.java
│ ├── DerbyEmbeddedDatabaseTypeTest.java
│ ├── H2DatabaseTypeTest.java
│ ├── HsqldbDatabaseTypeTest.java
│ ├── MariaDbDatabaseTypeTest.java
│ ├── MysqlDatabaseTypeTest.java
│ ├── OracleDatabaseTypeTest.java
│ ├── PostgresDatabaseTypeTest.java
│ ├── SqlServerDatabaseTypeTest.java
│ ├── SqlServerJtdsDatabaseConnectTypeTest.java
│ └── SqliteDatabaseTypeTest.java
│ ├── examples
│ ├── datapersister
│ │ ├── DataPersisterMain.java
│ │ ├── DateTimePersister.java
│ │ ├── MyDatePersister.java
│ │ ├── README.txt
│ │ └── User.java
│ ├── fieldConfig
│ │ ├── Account.java
│ │ ├── Delivery.java
│ │ ├── FieldConfigMain.java
│ │ └── README.txt
│ ├── foreign
│ │ ├── Account.java
│ │ ├── ForeignMain.java
│ │ ├── Order.java
│ │ └── README.txt
│ ├── foreignCollection
│ │ ├── Account.java
│ │ ├── ForeignCollectionMain.java
│ │ ├── Order.java
│ │ └── README.txt
│ ├── manytomany
│ │ ├── ManyToManyMain.java
│ │ ├── Post.java
│ │ ├── README.txt
│ │ ├── User.java
│ │ └── UserPost.java
│ └── simple
│ │ ├── Account.java
│ │ ├── README.txt
│ │ └── SimpleMain.java
│ ├── misc
│ └── JdbcTransactionManagerTest.java
│ ├── spring
│ ├── DaoFactoryTest.java
│ └── TableCreatorTest.java
│ └── stmt
│ └── JdbcQueryBuilderTest.java
└── resources
├── log4j.properties
└── ormliteLocalLog.properties
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | # config file for circleci
2 | version: 2
3 | jobs:
4 | build:
5 | docker:
6 | - image: circleci/openjdk:8-jdk-browsers
7 | steps:
8 | - checkout
9 | - restore_cache:
10 | key: j256-ormlite-jdbc-{{ checksum "pom.xml" }}
11 | - run:
12 | name: Get maven project dependencies
13 | command: mvn -P testing -U -DskipTests clean install dependency:resolve-plugins dependency:go-offline
14 | # save the project dependencies
15 | - save_cache:
16 | paths:
17 | - ~/.m2
18 | key: j256-ormlite-jdbc-{{ checksum "pom.xml" }}
19 | - run:
20 | name: mvn package
21 | # we need this profile to file the ormlite-core test release
22 | command: mvn -P testing package
23 | # uploads the test metadata from the `target/surefire-reports` directory so that it can show up in the CircleCI dashboard.
24 | - store_test_results:
25 | path: target/surefire-reports
26 | - run:
27 | name: Generate coverage report using jacoco
28 | command: mvn jacoco:report
29 | - run:
30 | name: Upload coverage report to CodeCov
31 | command: bash <(curl -s https://codecov.io/bash)
32 | - run:
33 | name: Test checks publishing to github
34 | command: mvn -X test-check-publisher:publish
35 | when: always
36 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: j256
4 | patreon: j256
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /target
3 | /.settings
4 | /.classpath
5 | /.project
6 | .idea
7 | *.iml
8 | /dependency-reduced-pom.xml
9 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | ISC License (https://opensource.org/licenses/ISC)
2 |
3 | Copyright 2021, Gray Watson
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ORMLite JDBC
2 | ============
3 |
4 | This package provides the JDBC specific functionality. The released jars for this include the
5 | [ormlite-core (https://github.com/j256/ormlite-core) package as well. Android users should download the
6 | [ormlite-android](https://github.com/j256/ormlite-android) package instead of this JDBC one.
7 |
8 | * For more background on ORMLite, see the [ormlite-core repo](https://github.com/j256/ormlite-core).
9 | * For more information, visit the [ORMLite home page](http://ormlite.com/).
10 | * Online documentation can be found off the home page. Here's the [getting started information](http://ormlite.com/docs/getting-started).
11 | Here are the [Javadocs for the code](http://ormlite.com/javadoc/ormlite-jdbc/).
12 | * Browse the code on the [git repository](https://github.com/j256/ormlite-jdbc). [](https://circleci.com/gh/j256/ormlite-jdbc) [](https://codecov.io/github/j256/ormlite-jdbc/)
13 | * Maven packages are published via [](https://maven-badges.herokuapp.com/maven-central/com.j256.ormlite/ormlite-jdbc/) [](https://javadoc.io/doc/com.j256.ormlite/ormlite-jdbc)
14 |
15 | Enjoy, Gray Watson
16 |
17 | # Maven Configuration
18 |
19 | Maven packages are published via [](https://maven-badges.herokuapp.com/maven-central/com.j256.ormlite/ormlite-jdbc/) which includes the [ormlite-core](https://github.com/j256/ormlite-core) classes.
20 |
21 | For JDBC usage:
22 |
23 | ``` xml
24 |
25 | com.j256.ormlite
26 | ormlite-jdbc
27 | 6.0
28 |
29 | ```
30 |
31 | # ChangeLog Release Notes
32 |
33 | The ChangeLog file comes from the ormlite-core repository. See the
34 | [ChangeLog.txt file](https://github.com/j256/ormlite-core/blob/master/src/main/javadoc/doc-files/changelog.txt).
35 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/BaseJdbcConnectionSource.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import java.sql.DriverManager;
4 | import java.sql.SQLException;
5 |
6 | import com.j256.ormlite.db.DatabaseType;
7 | import com.j256.ormlite.jdbc.db.DatabaseTypeUtils;
8 | import com.j256.ormlite.logger.Logger;
9 | import com.j256.ormlite.logger.LoggerFactory;
10 | import com.j256.ormlite.misc.IOUtils;
11 | import com.j256.ormlite.support.BaseConnectionSource;
12 | import com.j256.ormlite.support.ConnectionSource;
13 | import com.j256.ormlite.support.DatabaseConnection;
14 | import com.j256.ormlite.support.DatabaseConnectionProxyFactory;
15 |
16 | /**
17 | * Base class that defines some of the common JDBC connection source functionality.
18 | *
19 | * @author graywatson
20 | */
21 | public abstract class BaseJdbcConnectionSource extends BaseConnectionSource implements ConnectionSource {
22 |
23 | protected static Logger logger = LoggerFactory.getLogger(BaseJdbcConnectionSource.class);
24 |
25 | protected String url;
26 | protected DatabaseConnection connection;
27 | protected DatabaseType databaseType;
28 | protected boolean initialized = false;
29 | private static DatabaseConnectionProxyFactory connectionProxyFactory;
30 |
31 | /**
32 | * Constructor for Spring type wiring if you are using the set methods. If you are using Spring then your should
33 | * use: init-method="initialize"
34 | */
35 | public BaseJdbcConnectionSource() {
36 | // for spring type wiring
37 | }
38 |
39 | /**
40 | * Create a data source for a particular database URL.
41 | *
42 | * @param url
43 | * The database URL which should start jdbc:...
44 | * @throws SQLException
45 | * If the driver associated with the database driver is not found in the classpath.
46 | */
47 | public BaseJdbcConnectionSource(String url) throws SQLException {
48 | this(url, null, true);
49 | }
50 |
51 | /**
52 | * Create a data source for a particular database URL. The databaseType is usually determined from the databaseUrl
53 | * so most users should call {@link #BaseJdbcConnectionSource(String)} instead. If, however, you need to force the
54 | * class to use a specific DatabaseType then this constructor should be used.
55 | *
56 | * @param url
57 | * The database URL which should start jdbc:...
58 | * @param databaseType
59 | * Database to associate with this connection source.
60 | * @throws SQLException
61 | * If the driver associated with the database driver is not found in the classpath.
62 | */
63 | public BaseJdbcConnectionSource(String url, DatabaseType databaseType) throws SQLException {
64 | this(url, databaseType, true);
65 | }
66 |
67 | /**
68 | * Set initialize to false if you don't want to initialize. This is used by subclasses.
69 | */
70 | protected BaseJdbcConnectionSource(String url, DatabaseType databaseType, boolean initialize) throws SQLException {
71 | this.url = url;
72 | this.databaseType = databaseType;
73 | if (initialize) {
74 | initialize();
75 | }
76 | }
77 |
78 | /**
79 | * Make a connection to the database.
80 | *
81 | * @param logger
82 | * This is here so we can use the right logger associated with the sub-class.
83 | */
84 | protected abstract DatabaseConnection makeConnection(Logger logger) throws SQLException;
85 |
86 | /**
87 | * Initialize the class after the setters have been called. If you are using the no-arg constructor and Spring type
88 | * wiring, this should be called after all of the set methods.
89 | *
90 | * @throws SQLException
91 | * If the driver associated with the database URL is not found in the classpath.
92 | */
93 | public void initialize() throws SQLException {
94 | if (initialized) {
95 | return;
96 | }
97 | if (url == null) {
98 | throw new SQLException("url was never set on " + getClass().getSimpleName());
99 | }
100 | if (databaseType == null) {
101 | databaseType = DatabaseTypeUtils.createDatabaseType(url);
102 | }
103 | databaseType.loadDriver();
104 | databaseType.setDriver(DriverManager.getDriver(url));
105 | initialized = true;
106 | }
107 |
108 | @Override
109 | public void close() throws Exception {
110 | if (!initialized) {
111 | throw new SQLException(getClass().getSimpleName() + " was not initialized properly");
112 | }
113 | if (connection != null) {
114 | connection.close();
115 | logger.debug("closed connection #{}", connection.hashCode());
116 | connection = null;
117 | }
118 | }
119 |
120 | @Override
121 | public void closeQuietly() {
122 | IOUtils.closeQuietly(this);
123 | }
124 |
125 | public String getUrl() {
126 | return url;
127 | }
128 |
129 | public void setUrl(String url) {
130 | this.url = url;
131 | }
132 |
133 | @Override
134 | public DatabaseConnection getReadOnlyConnection(String tableName) throws SQLException {
135 | if (!initialized) {
136 | throw new SQLException(getClass().getSimpleName() + " was not initialized properly");
137 | }
138 | return getReadWriteConnection(tableName);
139 | }
140 |
141 | @Override
142 | public DatabaseConnection getReadWriteConnection(String tableName) throws SQLException {
143 | if (!initialized) {
144 | throw new SQLException(getClass().getSimpleName() + " was not initialized properly");
145 | }
146 | if (connection != null) {
147 | if (connection.isClosed()) {
148 | throw new SQLException("Connection has already been closed");
149 | } else {
150 | return connection;
151 | }
152 | }
153 | connection = makeConnection(logger);
154 | if (connectionProxyFactory != null) {
155 | connection = connectionProxyFactory.createProxy(connection);
156 | }
157 | return connection;
158 | }
159 |
160 | @Override
161 | public void releaseConnection(DatabaseConnection connection) throws SQLException {
162 | if (!initialized) {
163 | throw new SQLException(getClass().getSimpleName() + " was not initialized properly");
164 | }
165 | // noop right now
166 | }
167 |
168 | @Override
169 | @SuppressWarnings("unused")
170 | public boolean saveSpecialConnection(DatabaseConnection connection) throws SQLException {
171 | // noop since this is a single connection source
172 | return true;
173 | }
174 |
175 | @Override
176 | public void clearSpecialConnection(DatabaseConnection connection) {
177 | // noop since this is a single connection source
178 | }
179 |
180 | @Override
181 | public DatabaseType getDatabaseType() {
182 | if (!initialized) {
183 | throw new IllegalStateException(getClass().getSimpleName() + " was not initialized properly");
184 | }
185 | return databaseType;
186 | }
187 |
188 | @Override
189 | public boolean isOpen(String tableName) {
190 | return connection != null;
191 | }
192 |
193 | @Override
194 | public boolean isSingleConnection(String tableName) {
195 | return true;
196 | }
197 |
198 | // not required
199 | public void setDatabaseType(DatabaseType databaseType) {
200 | this.databaseType = databaseType;
201 | }
202 |
203 | /**
204 | * Set to enable connection proxying. Set to null to disable.
205 | */
206 | public static void setDatabaseConnectionProxyFactory(DatabaseConnectionProxyFactory connectionProxyFactory) {
207 | BaseJdbcConnectionSource.connectionProxyFactory = connectionProxyFactory;
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/JdbcCompiledStatement.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import java.sql.PreparedStatement;
4 | import java.sql.ResultSetMetaData;
5 | import java.sql.SQLException;
6 |
7 | import com.j256.ormlite.dao.ObjectCache;
8 | import com.j256.ormlite.field.SqlType;
9 | import com.j256.ormlite.misc.IOUtils;
10 | import com.j256.ormlite.stmt.StatementBuilder.StatementType;
11 | import com.j256.ormlite.support.CompiledStatement;
12 | import com.j256.ormlite.support.DatabaseResults;
13 |
14 | /**
15 | * Wrapper around a {@link PreparedStatement} object which we delegate to.
16 | *
17 | * @author graywatson
18 | */
19 | public class JdbcCompiledStatement implements CompiledStatement {
20 |
21 | private final PreparedStatement preparedStatement;
22 | private final String statement;
23 | private final StatementType type;
24 | private final boolean cacheStore;
25 | private ResultSetMetaData metaData = null;
26 |
27 | public JdbcCompiledStatement(PreparedStatement preparedStatement, String statement, StatementType type,
28 | boolean cacheStore) {
29 | this.preparedStatement = preparedStatement;
30 | this.statement = statement;
31 | this.type = type;
32 | this.cacheStore = cacheStore;
33 | }
34 |
35 | @Override
36 | public int getColumnCount() throws SQLException {
37 | if (metaData == null) {
38 | metaData = preparedStatement.getMetaData();
39 | }
40 | return metaData.getColumnCount();
41 | }
42 |
43 | @Override
44 | public String getColumnName(int column) throws SQLException {
45 | if (metaData == null) {
46 | metaData = preparedStatement.getMetaData();
47 | }
48 | return metaData.getColumnName(column + 1);
49 | }
50 |
51 | @Override
52 | public int runUpdate() throws SQLException {
53 | // this can be a UPDATE, DELETE, or ... just not a SELECT
54 | if (!type.isOkForUpdate()) {
55 | throw new IllegalArgumentException("Cannot call update on a " + type + " statement");
56 | }
57 | return preparedStatement.executeUpdate();
58 | }
59 |
60 | @Override
61 | public DatabaseResults runQuery(ObjectCache objectCache) throws SQLException {
62 | if (!type.isOkForQuery()) {
63 | throw new IllegalArgumentException("Cannot call query on a " + type + " statement");
64 | }
65 | return new JdbcDatabaseResults(preparedStatement, preparedStatement.executeQuery(), objectCache, cacheStore);
66 | }
67 |
68 | @Override
69 | public int runExecute() throws SQLException {
70 | if (!type.isOkForExecute()) {
71 | throw new IllegalArgumentException("Cannot call execute on a " + type + " statement");
72 | }
73 | preparedStatement.execute();
74 | return preparedStatement.getUpdateCount();
75 | }
76 |
77 | @Override
78 | public void close() throws SQLException {
79 | try {
80 | preparedStatement.close();
81 | } catch (SQLException e) {
82 | throw new SQLException("could not close prepared statement", e);
83 | }
84 | }
85 |
86 | @Override
87 | public void closeQuietly() {
88 | IOUtils.closeQuietly(this);
89 | }
90 |
91 | @Override
92 | public void cancel() throws SQLException {
93 | preparedStatement.cancel();
94 | }
95 |
96 | @Override
97 | public void setObject(int parameterIndex, Object obj, SqlType sqlType) throws SQLException {
98 | if (obj == null) {
99 | preparedStatement.setNull(parameterIndex + 1, TypeValMapper.getTypeValForSqlType(sqlType));
100 | } else {
101 | preparedStatement.setObject(parameterIndex + 1, obj, TypeValMapper.getTypeValForSqlType(sqlType));
102 | }
103 | }
104 |
105 | @Override
106 | public void setMaxRows(int max) throws SQLException {
107 | preparedStatement.setMaxRows(max);
108 | }
109 |
110 | @Override
111 | public void setQueryTimeout(long millis) throws SQLException {
112 | preparedStatement.setQueryTimeout(Long.valueOf(millis).intValue() / 1000);
113 | }
114 |
115 | @Override
116 | public String getStatement() {
117 | return statement;
118 | }
119 |
120 | @Override
121 | public String toString() {
122 | return statement;
123 | }
124 |
125 | /**
126 | * Called by {@link JdbcDatabaseResults#next()} to get more results into the existing ResultSet.
127 | */
128 | boolean getMoreResults() throws SQLException {
129 | return preparedStatement.getMoreResults();
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/JdbcConnectionSource.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import java.sql.DriverManager;
4 | import java.sql.SQLException;
5 | import java.util.Properties;
6 |
7 | import com.j256.ormlite.db.DatabaseType;
8 | import com.j256.ormlite.logger.Logger;
9 | import com.j256.ormlite.support.ConnectionSource;
10 | import com.j256.ormlite.support.DatabaseConnection;
11 |
12 | /**
13 | * Implementation of the ConnectionSource interface that supports what is needed by ORMLite. This is not thread-safe nor
14 | * synchronized and under the covers uses a single database connection. For other dataSources, see the
15 | * {@link DataSourceConnectionSource} class.
16 | *
17 | *
18 | * NOTE: If you are using the Spring type wiring in Java, {@link #initialize} should be called after all of the
19 | * set methods. In Spring XML, init-method="initialize" should be used.
20 | *
21 | *
22 | * @author graywatson
23 | */
24 | public class JdbcConnectionSource extends BaseJdbcConnectionSource implements ConnectionSource {
25 |
26 | private String username;
27 | private String password;
28 | private Integer loginTimeoutSecs;
29 | private Properties additionalProperties;
30 |
31 | /**
32 | * Constructor for Spring type wiring if you are using the set methods. If you are using Spring then your should
33 | * use: init-method="initialize"
34 | */
35 | public JdbcConnectionSource() {
36 | // for spring type wiring
37 | }
38 |
39 | /**
40 | * Create a data source for a particular database URL.
41 | *
42 | * @param url
43 | * The database URL which should start jdbc:...
44 | * @throws SQLException
45 | * If the driver associated with the database driver is not found in the classpath.
46 | */
47 | public JdbcConnectionSource(String url) throws SQLException {
48 | this(url, null, null, null);
49 | }
50 |
51 | /**
52 | * Create a data source for a particular database URL. The databaseType is usually determined from the databaseUrl
53 | * so most users should call {@link #JdbcConnectionSource(String)} instead. If, however, you need to force the class
54 | * to use a specific DatabaseType then this constructor should be used.
55 | *
56 | * @param url
57 | * The database URL which should start jdbc:...
58 | * @param databaseType
59 | * Database to associate with this connection source.
60 | * @throws SQLException
61 | * If the driver associated with the database driver is not found in the classpath.
62 | */
63 | public JdbcConnectionSource(String url, DatabaseType databaseType) throws SQLException {
64 | this(url, null, null, databaseType);
65 | }
66 |
67 | /**
68 | * Create a data source for a particular database URL with username and password permissions.
69 | *
70 | * @param url
71 | * The database URL which should start jdbc:...
72 | * @param username
73 | * Username for permissions on the database.
74 | * @param password
75 | * Password for permissions on the database.
76 | * @throws SQLException
77 | * If the driver associated with the database driver is not found in the classpath.
78 | */
79 | public JdbcConnectionSource(String url, String username, String password) throws SQLException {
80 | this(url, username, password, null);
81 | }
82 |
83 | /**
84 | * Create a data source for a particular database URL with username and password permissions. The databaseType is
85 | * usually determined from the databaseUrl so most users should call
86 | * {@link #JdbcConnectionSource(String, String, String)} instead. If, however, you need to force the class to use a
87 | * specific DatabaseType then this constructor should be used.
88 | *
89 | * @param url
90 | * The database URL which should start jdbc:...
91 | * @param username
92 | * Username for permissions on the database.
93 | * @param password
94 | * Password for permissions on the database.
95 | * @param databaseType
96 | * Database to associate with this connection source.
97 | * @throws SQLException
98 | * If the driver associated with the database driver is not found in the classpath.
99 | */
100 | public JdbcConnectionSource(String url, String username, String password, DatabaseType databaseType)
101 | throws SQLException {
102 | super(url, databaseType, false);
103 | this.username = username;
104 | this.password = password;
105 | initialize();
106 | }
107 |
108 | // not required
109 | public void setUsername(String username) {
110 | this.username = username;
111 | }
112 |
113 | // not required
114 | public void setPassword(String password) {
115 | this.password = password;
116 | }
117 |
118 | /**
119 | * Set additional properties to pass to DriverManager#getConnection method.
120 | */
121 | public void setAdditionalProperties(Properties props) {
122 | this.additionalProperties = props;
123 | }
124 |
125 | /**
126 | * Set the connection timeout number of seconds.
127 | *
128 | * NOTE: this is very database dependent and certain database drivers may not obey it. I recommend using a real
129 | * database connection pool if you need strict controls over this.
130 | */
131 | public void setLoginTimeoutSecs(Integer loginTimeoutSecs) {
132 | this.loginTimeoutSecs = loginTimeoutSecs;
133 | }
134 |
135 | @Override
136 | protected DatabaseConnection makeConnection(Logger logger) throws SQLException {
137 | Properties properties = new Properties();
138 | if (username != null) {
139 | properties.setProperty("user", username);
140 | }
141 | if (password != null) {
142 | properties.setProperty("password", password);
143 | }
144 | if (loginTimeoutSecs != null) {
145 | DriverManager.setLoginTimeout(loginTimeoutSecs);
146 | }
147 | if (additionalProperties != null) {
148 | properties.putAll(additionalProperties);
149 | }
150 | DatabaseConnection connection = new JdbcDatabaseConnection(DriverManager.getConnection(url, properties));
151 | // by default auto-commit is set to true
152 | connection.setAutoCommit(true);
153 | logger.debug("opened connection to {} got #{}", url, connection.hashCode());
154 | return connection;
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/JdbcDatabaseResults.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import java.io.InputStream;
4 | import java.math.BigDecimal;
5 | import java.sql.Blob;
6 | import java.sql.PreparedStatement;
7 | import java.sql.ResultSet;
8 | import java.sql.ResultSetMetaData;
9 | import java.sql.SQLException;
10 | import java.sql.Timestamp;
11 |
12 | import com.j256.ormlite.dao.ObjectCache;
13 | import com.j256.ormlite.misc.IOUtils;
14 | import com.j256.ormlite.support.DatabaseResults;
15 |
16 | /**
17 | * Wrapper around a {@link ResultSet} object which we delegate to.
18 | *
19 | * @author graywatson
20 | */
21 | public class JdbcDatabaseResults implements DatabaseResults {
22 |
23 | private final PreparedStatement preparedStmt;
24 | private final ResultSet resultSet;
25 | private final ResultSetMetaData metaData;
26 | private final ObjectCache objectCache;
27 | private final boolean cacheStore;
28 | private boolean first = true;
29 |
30 | public JdbcDatabaseResults(PreparedStatement preparedStmt, ResultSet resultSet, ObjectCache objectCache,
31 | boolean cacheStore) throws SQLException {
32 | this.preparedStmt = preparedStmt;
33 | this.resultSet = resultSet;
34 | this.metaData = resultSet.getMetaData();
35 | this.objectCache = objectCache;
36 | this.cacheStore = cacheStore;
37 | }
38 |
39 | @Override
40 | public int getColumnCount() throws SQLException {
41 | return metaData.getColumnCount();
42 | }
43 |
44 | @Override
45 | public String[] getColumnNames() throws SQLException {
46 | int colN = metaData.getColumnCount();
47 | String[] columnNames = new String[colN];
48 | for (int colC = 0; colC < colN; colC++) {
49 | columnNames[colC] = metaData.getColumnLabel(colC + 1);
50 | }
51 | return columnNames;
52 | }
53 |
54 | @Override
55 | public boolean first() throws SQLException {
56 | if (first) {
57 | /*
58 | * We have to do this because some databases do not like us calling first() if we are only moving forward
59 | * through the results. We do this here because Android has no such issues.
60 | */
61 | first = false;
62 | return next();
63 | } else {
64 | return resultSet.first();
65 | }
66 | }
67 |
68 | @Override
69 | public boolean next() throws SQLException {
70 | // NOTE: we should not auto-close here, even if there are no more results
71 | if (resultSet.next()) {
72 | return true;
73 | } else if (!preparedStmt.getMoreResults()) {
74 | return false;
75 | } else {
76 | return resultSet.next();
77 | }
78 | }
79 |
80 | @Override
81 | public boolean last() throws SQLException {
82 | return resultSet.last();
83 | }
84 |
85 | @Override
86 | public boolean previous() throws SQLException {
87 | return resultSet.previous();
88 | }
89 |
90 | @Override
91 | public boolean moveRelative(int offset) throws SQLException {
92 | return resultSet.relative(offset);
93 | }
94 |
95 | @Override
96 | public boolean moveAbsolute(int position) throws SQLException {
97 | return resultSet.absolute(position);
98 | }
99 |
100 | @Override
101 | public int findColumn(String columnName) throws SQLException {
102 | return resultSet.findColumn(columnName) - 1;
103 | }
104 |
105 | @Override
106 | public InputStream getBlobStream(int columnIndex) throws SQLException {
107 | Blob blob = resultSet.getBlob(columnIndex + 1);
108 | if (blob == null) {
109 | return null;
110 | } else {
111 | return blob.getBinaryStream();
112 | }
113 | }
114 |
115 | @Override
116 | public boolean getBoolean(int columnIndex) throws SQLException {
117 | return resultSet.getBoolean(columnIndex + 1);
118 | }
119 |
120 | @Override
121 | public char getChar(int columnIndex) throws SQLException {
122 | String string = resultSet.getString(columnIndex + 1);
123 | if (string == null || string.length() == 0) {
124 | return 0;
125 | } else if (string.length() == 1) {
126 | return string.charAt(0);
127 | } else {
128 | throw new SQLException("More than 1 character stored in database column: " + columnIndex);
129 | }
130 | }
131 |
132 | @Override
133 | public byte getByte(int columnIndex) throws SQLException {
134 | return resultSet.getByte(columnIndex + 1);
135 | }
136 |
137 | @Override
138 | public byte[] getBytes(int columnIndex) throws SQLException {
139 | return resultSet.getBytes(columnIndex + 1);
140 | }
141 |
142 | @Override
143 | public double getDouble(int columnIndex) throws SQLException {
144 | return resultSet.getDouble(columnIndex + 1);
145 | }
146 |
147 | @Override
148 | public float getFloat(int columnIndex) throws SQLException {
149 | return resultSet.getFloat(columnIndex + 1);
150 | }
151 |
152 | @Override
153 | public int getInt(int columnIndex) throws SQLException {
154 | return resultSet.getInt(columnIndex + 1);
155 | }
156 |
157 | @Override
158 | public long getLong(int columnIndex) throws SQLException {
159 | return resultSet.getLong(columnIndex + 1);
160 | }
161 |
162 | @Override
163 | public short getShort(int columnIndex) throws SQLException {
164 | return resultSet.getShort(columnIndex + 1);
165 | }
166 |
167 | @Override
168 | public String getString(int columnIndex) throws SQLException {
169 | return resultSet.getString(columnIndex + 1);
170 | }
171 |
172 | @Override
173 | public Timestamp getTimestamp(int columnIndex) throws SQLException {
174 | return resultSet.getTimestamp(columnIndex + 1);
175 | }
176 |
177 | @Override
178 | public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
179 | return resultSet.getBigDecimal(columnIndex + 1);
180 | }
181 |
182 | @Override
183 | public Object getObject(int columnIndex) throws SQLException {
184 | return resultSet.getObject(columnIndex + 1);
185 | }
186 |
187 | @Override
188 | public boolean wasNull(int columnIndex) throws SQLException {
189 | return resultSet.wasNull();
190 | }
191 |
192 | @Override
193 | public ObjectCache getObjectCacheForRetrieve() {
194 | return objectCache;
195 | }
196 |
197 | @Override
198 | public ObjectCache getObjectCacheForStore() {
199 | if (cacheStore) {
200 | return objectCache;
201 | } else {
202 | return null;
203 | }
204 | }
205 |
206 | @Override
207 | public void close() throws Exception {
208 | try {
209 | resultSet.close();
210 | } catch (SQLException e) {
211 | throw new SQLException("could not close result set", e);
212 | }
213 | }
214 |
215 | @Override
216 | public void closeQuietly() {
217 | IOUtils.closeQuietly(this);
218 | }
219 |
220 | /**
221 | * Returns the underlying JDBC ResultSet object.
222 | */
223 | public ResultSet getResultSet() {
224 | return resultSet;
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/JdbcSingleConnectionSource.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import java.sql.Connection;
4 | import java.sql.SQLException;
5 |
6 | import com.j256.ormlite.db.DatabaseType;
7 | import com.j256.ormlite.logger.Logger;
8 | import com.j256.ormlite.support.ConnectionSource;
9 | import com.j256.ormlite.support.DatabaseConnection;
10 |
11 | /**
12 | * A connection source that uses an existing open database connection. This is not thread-safe nor synchronized. For
13 | * other dataSources, see the {@link DataSourceConnectionSource} class.
14 | *
15 | *
16 | * NOTE: If you are using the Spring type wiring in Java, {@link #initialize} should be called after all of the
17 | * set methods. In Spring XML, init-method="initialize" should be used.
18 | *
19 | *
20 | * @author graywatson
21 | */
22 | public class JdbcSingleConnectionSource extends BaseJdbcConnectionSource implements ConnectionSource {
23 |
24 | private Connection sqlConnection;
25 |
26 | /**
27 | * Constructor for Spring type wiring if you are using the set methods. If you are using Spring then your should
28 | * use: init-method="initialize"
29 | */
30 | public JdbcSingleConnectionSource() {
31 | // for spring type wiring
32 | }
33 |
34 | /**
35 | * Create a data source for a particular database URL.
36 | *
37 | * @param url
38 | * The database URL which should start jdbc:...
39 | * @param sqlConnection
40 | * Already open database connection that we will use.
41 | * @throws SQLException
42 | * If the driver associated with the database driver is not found in the classpath.
43 | */
44 | public JdbcSingleConnectionSource(String url, Connection sqlConnection) throws SQLException {
45 | this(url, null, sqlConnection);
46 | }
47 |
48 | /**
49 | * Create a data source for a particular database URL. The databaseType is usually determined from the databaseUrl
50 | * so most users should call {@link #JdbcSingleConnectionSource(String, Connection)} instead. If, however, you need
51 | * to force the class to use a specific DatabaseType then this constructor should be used.
52 | *
53 | * @param url
54 | * The database URL which should start jdbc:...
55 | * @param databaseType
56 | * Database to associate with this connection source.
57 | * @param sqlConnection
58 | * Already open database connection that we will use.
59 | * @throws SQLException
60 | * If the driver associated with the database driver is not found in the classpath.
61 | */
62 | public JdbcSingleConnectionSource(String url, DatabaseType databaseType, Connection sqlConnection)
63 | throws SQLException {
64 | super(url, databaseType, false);
65 | this.sqlConnection = sqlConnection;
66 | initialize();
67 | }
68 |
69 | @Override
70 | public void close() {
71 | // no-op because we don't want to close the connection
72 | }
73 |
74 | @Override
75 | public void closeQuietly() {
76 | // no-op because we don't want to close the connection
77 | }
78 |
79 | // required
80 | public void setSqlConnection(Connection sqlConnection) {
81 | this.sqlConnection = sqlConnection;
82 | }
83 |
84 | @Override
85 | protected DatabaseConnection makeConnection(Logger logger) {
86 | return new JdbcDatabaseConnection(sqlConnection);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/TypeValMapper.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import java.sql.SQLException;
4 | import java.sql.Types;
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | import com.j256.ormlite.field.SqlType;
9 |
10 | /**
11 | * Map from {@link SqlType} to the constants in the {@link Types} class.
12 | *
13 | * @author graywatson
14 | */
15 | public class TypeValMapper {
16 |
17 | private static final Map typeToValMap = new HashMap();
18 |
19 | static {
20 | for (SqlType sqlType : SqlType.values()) {
21 | int[] values;
22 | switch (sqlType) {
23 | case STRING:
24 | values = new int[] { Types.VARCHAR };
25 | break;
26 | case LONG_STRING:
27 | values = new int[] { Types.LONGVARCHAR };
28 | break;
29 | case DATE:
30 | values = new int[] { Types.TIMESTAMP };
31 | break;
32 | case BOOLEAN:
33 | values = new int[] { Types.BOOLEAN };
34 | break;
35 | case CHAR:
36 | values = new int[] { Types.CHAR };
37 | break;
38 | case BYTE:
39 | values = new int[] { Types.TINYINT };
40 | break;
41 | case BYTE_ARRAY:
42 | values = new int[] { Types.VARBINARY };
43 | break;
44 | case SHORT:
45 | values = new int[] { Types.SMALLINT };
46 | break;
47 | case INTEGER:
48 | values = new int[] { Types.INTEGER };
49 | break;
50 | case LONG:
51 | values = new int[] { Types.BIGINT };
52 | break;
53 | case FLOAT:
54 | values = new int[] { Types.FLOAT };
55 | break;
56 | case DOUBLE:
57 | values = new int[] { Types.DOUBLE };
58 | break;
59 | case SERIALIZABLE:
60 | values = new int[] { Types.VARBINARY };
61 | break;
62 | case BLOB:
63 | // the following do not need to be handled except in specific situations
64 | values = new int[] { Types.BLOB };
65 | break;
66 | case BIG_DECIMAL:
67 | values = new int[] { Types.DECIMAL, Types.NUMERIC };
68 | break;
69 | case UUID:
70 | values = new int[] { Types.OTHER };
71 | break;
72 | case OTHER:
73 | values = new int[] { Types.OTHER };
74 | break;
75 | case UNKNOWN:
76 | values = new int[] {};
77 | break;
78 | default:
79 | throw new IllegalArgumentException("No JDBC mapping for unknown SqlType " + sqlType);
80 | }
81 | typeToValMap.put(sqlType, values);
82 | }
83 | }
84 |
85 | /**
86 | * Returns the primary type value associated with the SqlType argument.
87 | */
88 | public static int getTypeValForSqlType(SqlType sqlType) throws SQLException {
89 | int[] typeVals = typeToValMap.get(sqlType);
90 | if (typeVals == null) {
91 | throw new SQLException("SqlType is unknown to type val mapping: " + sqlType);
92 | }
93 | if (typeVals.length == 0) {
94 | throw new SQLException("SqlType does not have any JDBC type value mapping: " + sqlType);
95 | } else {
96 | return typeVals[0];
97 | }
98 | }
99 |
100 | /**
101 | * Returns the SqlType value associated with the typeVal argument. Can be slow-er.
102 | */
103 | public static SqlType getSqlTypeForTypeVal(int typeVal) {
104 | // iterate through to save on the extra HashMap since only for errors
105 | for (Map.Entry entry : typeToValMap.entrySet()) {
106 | for (int val : entry.getValue()) {
107 | if (val == typeVal) {
108 | return entry.getKey();
109 | }
110 | }
111 | }
112 | return SqlType.UNKNOWN;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/DatabaseTypeUtils.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.j256.ormlite.db.DatabaseType;
7 |
8 | /**
9 | * Utility class which helps with managing database specific classes.
10 | *
11 | * @author graywatson
12 | */
13 | public class DatabaseTypeUtils {
14 |
15 | private static List databaseTypes = new ArrayList();
16 |
17 | static {
18 | // new drivers need to be added here
19 | databaseTypes.add(new Db2DatabaseType());
20 | databaseTypes.add(new DerbyClientServerDatabaseType());
21 | databaseTypes.add(new DerbyEmbeddedDatabaseType());
22 | databaseTypes.add(new GenericOdbcDatabaseType());
23 | databaseTypes.add(new H2DatabaseType());
24 | databaseTypes.add(new HsqldbDatabaseType());
25 | databaseTypes.add(new MysqlDatabaseType());
26 | databaseTypes.add(new MariaDbDatabaseType());
27 | databaseTypes.add(new NetezzaDatabaseType());
28 | databaseTypes.add(new OracleDatabaseType());
29 | databaseTypes.add(new PostgresDatabaseType());
30 | databaseTypes.add(new SqliteDatabaseType());
31 | databaseTypes.add(new SqlServerDatabaseType());
32 | databaseTypes.add(new SqlServerJtdsDatabaseType());
33 | }
34 |
35 | /**
36 | * For static methods only.
37 | */
38 | private DatabaseTypeUtils() {
39 | }
40 |
41 | /**
42 | * Creates and returns a {@link DatabaseType} for the database URL.
43 | *
44 | * @throws IllegalArgumentException
45 | * if the url format is not recognized, the database type is unknown, or the class could not be
46 | * constructed.
47 | */
48 | public static DatabaseType createDatabaseType(String databaseUrl) {
49 | String dbTypePart = extractDbType(databaseUrl);
50 | for (DatabaseType databaseType : databaseTypes) {
51 | if (databaseType.isDatabaseUrlThisType(databaseUrl, dbTypePart)) {
52 | return databaseType;
53 | }
54 | }
55 | throw new IllegalArgumentException("Unknown database-type url part '" + dbTypePart + "' in: " + databaseUrl);
56 | }
57 |
58 | private static String extractDbType(String databaseUrl) {
59 | if (!databaseUrl.startsWith("jdbc:")) {
60 | throw new IllegalArgumentException("Database URL was expected to start with jdbc: but was " + databaseUrl);
61 | }
62 | String[] urlParts = databaseUrl.split(":");
63 | if (urlParts.length < 2) {
64 | throw new IllegalArgumentException(
65 | "Database URL was expected to be in the form: jdbc:db-type:... but was " + databaseUrl);
66 | }
67 | return urlParts[1];
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/Db2DatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.List;
4 |
5 | import com.j256.ormlite.db.BaseDatabaseType;
6 | import com.j256.ormlite.field.FieldType;
7 |
8 | /**
9 | * IBM DB2 database type information used to create the tables, etc..
10 | *
11 | *
12 | * WARNING: I have not tested this unfortunately because of a lack of access to a DB2 instance. Love to get 1-2
13 | * hours of access to an database to test/tweak this. Undoubtably is it wrong. Please contact us if you'd like to help
14 | * with this class.
15 | *
16 | *
17 | * @author graywatson
18 | */
19 | public class Db2DatabaseType extends BaseDatabaseType {
20 |
21 | private final static String DATABASE_URL_PORTION = "db2";
22 | private final static String DATABASE_NAME = "DB2";
23 | private final static String NEWER_DRIVER_CLASS_NAME = "com.ibm.db2.jcc.DB2Driver";
24 | private final static String OLDER_DRIVER_CLASS_NAME = "COM.ibm.db2.jdbc.app.DB2Driver";
25 |
26 | @Override
27 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
28 | return DATABASE_URL_PORTION.equals(dbTypePart);
29 | }
30 |
31 | @Override
32 | protected String[] getDriverClassNames() {
33 | return new String[] { NEWER_DRIVER_CLASS_NAME, OLDER_DRIVER_CLASS_NAME };
34 | }
35 |
36 | @Override
37 | public String getDatabaseName() {
38 | return DATABASE_NAME;
39 | }
40 |
41 | @Override
42 | protected void appendBooleanType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
43 | sb.append("SMALLINT");
44 | }
45 |
46 | @Override
47 | protected void appendByteType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
48 | sb.append("SMALLINT");
49 | }
50 |
51 | @Override
52 | protected void appendByteArrayType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
53 | sb.append("VARCHAR [] FOR BIT DATA");
54 | }
55 |
56 | @Override
57 | protected void appendSerializableType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
58 | sb.append("VARCHAR [] FOR BIT DATA");
59 | }
60 |
61 | @Override
62 | protected void configureGeneratedId(String tableName, StringBuilder sb, FieldType fieldType,
63 | List statementsBefore, List statementsAfter, List additionalArgs,
64 | List queriesAfter) {
65 | sb.append("GENERATED ALWAYS AS IDENTITY ");
66 | configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
67 | }
68 |
69 | @Override
70 | public void appendEscapedEntityName(StringBuilder sb, String name) {
71 | sb.append('\"').append(name).append('\"');
72 | }
73 |
74 | @Override
75 | public boolean isOffsetSqlSupported() {
76 | // there is no easy way to do this in this database type
77 | return false;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/DerbyClientServerDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | /**
4 | * Derby database type information used to create the tables, etc.. This is for client connections to a remote Derby
5 | * server. For embedded databases, you should use {@link DerbyEmbeddedDatabaseType}.
6 | *
7 | * @author graywatson
8 | */
9 | public class DerbyClientServerDatabaseType extends DerbyEmbeddedDatabaseType {
10 |
11 | private final static String DRIVER_CLASS_NAME = "org.apache.derby.jdbc.ClientDriver";
12 | private final static String DATABASE_NAME = "Derby Client/Server";
13 |
14 | @Override
15 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
16 | if (!DATABASE_URL_PORTION.equals(dbTypePart)) {
17 | return false;
18 | }
19 | // jdbc:derby://localhost:1527/MyDbTest;create=true';
20 | String[] parts = url.split(":");
21 | return (parts.length >= 3 && parts[2].startsWith("//"));
22 | }
23 |
24 | @Override
25 | protected String[] getDriverClassNames() {
26 | return new String[] { DRIVER_CLASS_NAME };
27 | }
28 |
29 | @Override
30 | public String getDatabaseName() {
31 | return DATABASE_NAME;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/GenericOdbcDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import com.j256.ormlite.db.BaseDatabaseType;
4 |
5 | /**
6 | * Generic JdbcOdbcBridge database type information used to create the tables, etc..
7 | *
8 | *
9 | * NOTE: This is the initial take on this database type. We hope to get access to an external database for
10 | * testing. Please contact us if you'd like to help with this class.
11 | *
12 | *
13 | * @author Dale Asberry
14 | */
15 | public class GenericOdbcDatabaseType extends BaseDatabaseType {
16 |
17 | private final static String DATABASE_URL_PORTION = "odbc";
18 | private final static String DRIVER_CLASS_NAME = "sun.jdbc.odbc.JdbcOdbcDriver";
19 | private final static String DATABASE_NAME = "ODBC";
20 |
21 | @Override
22 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
23 | return DATABASE_URL_PORTION.equals(dbTypePart);
24 | }
25 |
26 | @Override
27 | protected String[] getDriverClassNames() {
28 | return new String[] { DRIVER_CLASS_NAME };
29 | }
30 |
31 | @Override
32 | public String getDatabaseName() {
33 | return DATABASE_NAME;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/H2DatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.List;
4 |
5 | import com.j256.ormlite.db.BaseDatabaseType;
6 | import com.j256.ormlite.field.FieldType;
7 |
8 | /**
9 | * H2 database type information used to create the tables, etc..
10 | *
11 | * NOTE: if this is updated, the ormlite-core/src/test one should be as well.
12 | *
13 | * @author graywatson
14 | */
15 | public class H2DatabaseType extends BaseDatabaseType {
16 |
17 | private final static String DATABASE_URL_PORTION = "h2";
18 | private final static String DRIVER_CLASS_NAME = "org.h2.Driver";
19 | private final static String DATABASE_NAME = "H2";
20 |
21 | @Override
22 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
23 | return DATABASE_URL_PORTION.equals(dbTypePart);
24 | }
25 |
26 | @Override
27 | protected String[] getDriverClassNames() {
28 | return new String[] { DRIVER_CLASS_NAME };
29 | }
30 |
31 | @Override
32 | public String getDatabaseName() {
33 | return DATABASE_NAME;
34 | }
35 |
36 | @Override
37 | protected void configureGeneratedId(String tableName, StringBuilder sb, FieldType fieldType,
38 | List statementsBefore, List statementsAfter, List additionalArgs,
39 | List queriesAfter) {
40 | sb.append("AUTO_INCREMENT ");
41 | configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
42 | }
43 |
44 | @Override
45 | public void appendLimitValue(StringBuilder sb, long limit, Long offset) {
46 | sb.append("LIMIT ");
47 | if (offset != null) {
48 | sb.append(offset).append(',');
49 | }
50 | sb.append(limit).append(' ');
51 | }
52 |
53 | @Override
54 | public boolean isOffsetLimitArgument() {
55 | return true;
56 | }
57 |
58 | @Override
59 | public void appendOffsetValue(StringBuilder sb, long offset) {
60 | throw new IllegalStateException("Offset is part of the LIMIT in database type " + getClass());
61 | }
62 |
63 | @Override
64 | public boolean isTruncateSupported() {
65 | return true;
66 | }
67 |
68 | @Override
69 | public boolean isCreateIfNotExistsSupported() {
70 | return true;
71 | }
72 |
73 | @Override
74 | public boolean isLimitUpdateAtEndSupported() {
75 | return true;
76 | }
77 |
78 | @Override
79 | public boolean isLimitDeleteAtEndSupported() {
80 | return true;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/HsqldbDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.List;
4 |
5 | import com.j256.ormlite.db.BaseDatabaseType;
6 | import com.j256.ormlite.field.FieldType;
7 | import com.j256.ormlite.field.SqlType;
8 |
9 | /**
10 | * HyberSQL database type information used to create the tables, etc..
11 | *
12 | * @author graywatson
13 | */
14 | public class HsqldbDatabaseType extends BaseDatabaseType {
15 |
16 | private final static String DATABASE_URL_PORTION = "hsqldb";
17 | private final static String DRIVER_CLASS_NAME = "org.hsqldb.jdbcDriver";
18 | private final static String DATABASE_NAME = "HSQLdb";
19 |
20 | @Override
21 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
22 | return DATABASE_URL_PORTION.equals(dbTypePart);
23 | }
24 |
25 | @Override
26 | protected String[] getDriverClassNames() {
27 | return new String[] { DRIVER_CLASS_NAME };
28 | }
29 |
30 | @Override
31 | public String getDatabaseName() {
32 | return DATABASE_NAME;
33 | }
34 |
35 | @Override
36 | protected void appendLongStringType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
37 | sb.append("LONGVARCHAR");
38 | }
39 |
40 | @Override
41 | protected void appendBooleanType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
42 | sb.append("BIT");
43 | }
44 |
45 | @Override
46 | protected void appendByteArrayType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
47 | // was: "BINARY"
48 | if (fieldWidth == 0) {
49 | sb.append("VARBINARY(255)");
50 | } else {
51 | sb.append("VARBINARY(").append(fieldWidth).append(')');
52 | }
53 | }
54 |
55 | @Override
56 | protected void appendSerializableType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
57 | appendByteArrayType(sb, fieldType, fieldWidth);
58 | }
59 |
60 | @Override
61 | protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List statementsBefore,
62 | List additionalArgs, List queriesAfter) {
63 | // needs to match dropColumnArg()
64 | StringBuilder seqSb = new StringBuilder(128);
65 | seqSb.append("CREATE SEQUENCE ");
66 | appendEscapedEntityName(seqSb, fieldType.getGeneratedIdSequence());
67 | if (fieldType.getSqlType() == SqlType.LONG) {
68 | seqSb.append(" AS BIGINT");
69 | } else {
70 | // integer is the default
71 | }
72 | // with hsqldb (as opposed to all else) the sequences start at 0, grumble
73 | seqSb.append(" START WITH 1");
74 | statementsBefore.add(seqSb.toString());
75 | sb.append("GENERATED BY DEFAULT AS IDENTITY ");
76 | configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
77 | }
78 |
79 | @Override
80 | public void appendEscapedEntityName(StringBuilder sb, String name) {
81 | sb.append('\"').append(name).append('\"');
82 | }
83 |
84 | @Override
85 | public void dropColumnArg(FieldType fieldType, List statementsBefore, List statementsAfter) {
86 | if (fieldType.isGeneratedIdSequence()) {
87 | StringBuilder sb = new StringBuilder(64);
88 | sb.append("DROP SEQUENCE ");
89 | appendEscapedEntityName(sb, fieldType.getGeneratedIdSequence());
90 | statementsAfter.add(sb.toString());
91 | }
92 | }
93 |
94 | @Override
95 | public boolean isIdSequenceNeeded() {
96 | return true;
97 | }
98 |
99 | @Override
100 | public boolean isSelectSequenceBeforeInsert() {
101 | return true;
102 | }
103 |
104 | @Override
105 | public boolean isVarcharFieldWidthSupported() {
106 | /**
107 | * In version 2.X, VARCHAR(width) is required. In 1.8.X or before, it is not supported. Wonderful.
108 | */
109 | if (driver != null && driver.getMajorVersion() >= 2) {
110 | return true;
111 | } else {
112 | return false;
113 | }
114 | }
115 |
116 | @Override
117 | public boolean isLimitAfterSelect() {
118 | return true;
119 | }
120 |
121 | @Override
122 | public void appendLimitValue(StringBuilder sb, long limit, Long offset) {
123 | // the 0 is the offset, could also use TOP X
124 | sb.append("LIMIT ");
125 | if (offset == null) {
126 | sb.append("0 ");
127 | } else {
128 | sb.append(offset).append(' ');
129 | }
130 | sb.append(limit).append(' ');
131 | }
132 |
133 | @Override
134 | public boolean isOffsetLimitArgument() {
135 | return true;
136 | }
137 |
138 | @Override
139 | public void appendOffsetValue(StringBuilder sb, long offset) {
140 | throw new IllegalStateException("Offset is part of the LIMIT in database type " + getClass());
141 | }
142 |
143 | @Override
144 | public void appendSelectNextValFromSequence(StringBuilder sb, String sequenceName) {
145 | sb.append("CALL NEXT VALUE FOR ");
146 | appendEscapedEntityName(sb, sequenceName);
147 | }
148 |
149 | @Override
150 | public boolean isEntityNamesMustBeUpCase() {
151 | return true;
152 | }
153 |
154 | @Override
155 | public String getPingStatement() {
156 | return "SELECT COUNT(*) FROM INFORMATION_SCHEMA.SYSTEM_TABLES";
157 | }
158 |
159 | @Override
160 | public boolean isCreateIfNotExistsSupported() {
161 | // support for EXISTS subquery was added in 2.3.x, thanks to @lukewhitt
162 | return (driver != null && driver.getMajorVersion() >= 2 && driver.getMinorVersion() >= 3);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/MariaDbDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import com.j256.ormlite.field.DataPersister;
4 | import com.j256.ormlite.field.FieldConverter;
5 | import com.j256.ormlite.field.FieldType;
6 | import com.j256.ormlite.field.SqlType;
7 | import com.j256.ormlite.field.converter.CharacterCompatFieldConverter;
8 |
9 | /**
10 | * MariaDB database type information used to create the tables, etc.. It is an extension of MySQL.
11 | *
12 | * @author kratorius
13 | */
14 | public class MariaDbDatabaseType extends MysqlDatabaseType {
15 |
16 | private final static String DATABASE_URL_PORTION = "mariadb";
17 | private final static String DRIVER_CLASS_NAME = "org.mariadb.jdbc.Driver";
18 | private final static String DATABASE_NAME = "MariaDB";
19 |
20 | @Override
21 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
22 | return DATABASE_URL_PORTION.equals(dbTypePart);
23 | }
24 |
25 | @Override
26 | protected String[] getDriverClassNames() {
27 | return new String[] { DRIVER_CLASS_NAME };
28 | }
29 |
30 | @Override
31 | public String getDatabaseName() {
32 | return DATABASE_NAME;
33 | }
34 |
35 | @Override
36 | protected void appendByteArrayType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
37 | super.appendByteArrayType(sb, fieldType, fieldWidth);
38 | }
39 |
40 | @Override
41 | protected void appendLongStringType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
42 | super.appendLongStringType(sb, fieldType, fieldWidth);
43 | }
44 |
45 | @Override
46 | public FieldConverter getFieldConverter(DataPersister dataPersister, FieldType fieldType) {
47 | if (dataPersister.getSqlType() == SqlType.CHAR) {
48 | return new CharacterCompatFieldConverter(dataPersister);
49 | } else {
50 | return super.getFieldConverter(dataPersister, fieldType);
51 | }
52 | }
53 |
54 | @Override
55 | public boolean isCreateIndexIfNotExistsSupported() {
56 | return true;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/MysqlDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.List;
4 |
5 | import com.j256.ormlite.db.BaseDatabaseType;
6 | import com.j256.ormlite.field.FieldType;
7 |
8 | /**
9 | * MySQL database type information used to create the tables, etc..
10 | *
11 | *
12 | * NOTE: By default the tables are created with the ENGINE=InnoDB suffix (see
13 | * {@link #DEFAULT_CREATE_TABLE_SUFFIX}. Use {@link #setCreateTableSuffix} to change that to "" to use the default
14 | * MyISAM storage engine, to choose another engine, or set other settings. For more information about engines, see the
15 | * 'SHOW ENGINES;' results from the MySQL command line tool.
16 | *
17 | *
18 | * @author graywatson
19 | */
20 | public class MysqlDatabaseType extends BaseDatabaseType {
21 |
22 | private final static String DATABASE_URL_PORTION = "mysql";
23 | private final static String DRIVER_CLASS_NAME_OLD = "com.mysql.jdbc.Driver";
24 | private final static String DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
25 | private final static String DATABASE_NAME = "MySQL";
26 |
27 | /**
28 | * Default suffix to the CREATE TABLE statement. Change with the {@link #setCreateTableSuffix} method.
29 | */
30 | public final static String DEFAULT_CREATE_TABLE_SUFFIX = "ENGINE=InnoDB";
31 |
32 | private String createTableSuffix = DEFAULT_CREATE_TABLE_SUFFIX;
33 |
34 | @Override
35 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
36 | return DATABASE_URL_PORTION.equals(dbTypePart);
37 | }
38 |
39 | @Override
40 | protected String[] getDriverClassNames() {
41 | return new String[] { DRIVER_CLASS_NAME, DRIVER_CLASS_NAME_OLD };
42 | }
43 |
44 | @Override
45 | public String getDatabaseName() {
46 | return DATABASE_NAME;
47 | }
48 |
49 | /**
50 | * Set the string that is appended to the end of a CREATE TABLE statement.
51 | */
52 | public void setCreateTableSuffix(String createTableSuffix) {
53 | this.createTableSuffix = createTableSuffix;
54 | }
55 |
56 | @Override
57 | protected void appendDateType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
58 | /**
59 | * TIMESTAMP in MySQL does some funky stuff with the last-modification time. Values are 'not null' by default
60 | * with an automatic default of CURRENT_TIMESTAMP. Strange design decision.
61 | */
62 | sb.append("DATETIME");
63 | }
64 |
65 | @Override
66 | protected void appendBooleanType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
67 | sb.append("TINYINT(1)");
68 | }
69 |
70 | @Override
71 | protected void configureGeneratedId(String tableName, StringBuilder sb, FieldType fieldType,
72 | List statementsBefore, List statementsAfter, List additionalArgs,
73 | List queriesAfter) {
74 | sb.append("AUTO_INCREMENT ");
75 | configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
76 | }
77 |
78 | @Override
79 | public void appendCreateTableSuffix(StringBuilder sb) {
80 | sb.append(createTableSuffix);
81 | sb.append(' ');
82 | }
83 |
84 | @Override
85 | public boolean isTruncateSupported() {
86 | return true;
87 | }
88 |
89 | @Override
90 | public boolean isCreateIfNotExistsSupported() {
91 | return true;
92 | }
93 |
94 | @Override
95 | public boolean isCreateIndexIfNotExistsSupported() {
96 | return false;
97 | }
98 |
99 | @Override
100 | public boolean isLimitUpdateAtEndSupported() {
101 | return true;
102 | }
103 |
104 | @Override
105 | public boolean isLimitDeleteAtEndSupported() {
106 | return super.isLimitDeleteAtEndSupported();
107 | }
108 |
109 | @Override
110 | protected void appendByteArrayType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
111 | super.appendByteArrayType(sb, fieldType, fieldWidth);
112 | }
113 |
114 | @Override
115 | protected void appendLongStringType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
116 | super.appendLongStringType(sb, fieldType, fieldWidth);
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/NetezzaDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.List;
4 |
5 | import com.j256.ormlite.db.BaseDatabaseType;
6 | import com.j256.ormlite.field.FieldType;
7 |
8 | /**
9 | * Netezza database type information used to create the tables, etc..
10 | *
11 | *
12 | * NOTE: This is the initial take on this database type. We hope to get access to an external database for
13 | * testing. Please contact us if you'd like to help with this class.
14 | *
15 | *
16 | * @author Richard Kooijman
17 | */
18 | public class NetezzaDatabaseType extends BaseDatabaseType {
19 |
20 | private final static String DATABASE_URL_PORTION = "netezza";
21 | private final static String DRIVER_CLASS_NAME = "org.netezza.Driver";
22 | private final static String DATABASE_NAME = "Netezza";
23 |
24 | @Override
25 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
26 | return DATABASE_URL_PORTION.equals(dbTypePart);
27 | }
28 |
29 | @Override
30 | protected String[] getDriverClassNames() {
31 | return new String[] { DRIVER_CLASS_NAME };
32 | }
33 |
34 | @Override
35 | public String getDatabaseName() {
36 | return DATABASE_NAME;
37 | }
38 |
39 | @Override
40 | protected void appendByteType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
41 | sb.append("BYTEINT");
42 | }
43 |
44 | @Override
45 | protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List statementsBefore,
46 | List additionalArgs, List queriesAfter) {
47 | String sequenceName = fieldType.getGeneratedIdSequence();
48 | // needs to match dropColumnArg()
49 | StringBuilder seqSb = new StringBuilder(64);
50 | seqSb.append("CREATE SEQUENCE ");
51 | // when it is created, it needs to be escaped specially
52 | appendEscapedEntityName(seqSb, sequenceName);
53 | statementsBefore.add(seqSb.toString());
54 |
55 | configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
56 | }
57 |
58 | @Override
59 | public void dropColumnArg(FieldType fieldType, List statementsBefore, List statementsAfter) {
60 | if (fieldType.isGeneratedIdSequence()) {
61 | StringBuilder sb = new StringBuilder(64);
62 | sb.append("DROP SEQUENCE ");
63 | appendEscapedEntityName(sb, fieldType.getGeneratedIdSequence());
64 | statementsAfter.add(sb.toString());
65 | }
66 | }
67 |
68 | @Override
69 | public void appendEscapedEntityName(StringBuilder sb, String name) {
70 | sb.append('\"').append(name).append('\"');
71 | }
72 |
73 | @Override
74 | public boolean isIdSequenceNeeded() {
75 | return true;
76 | }
77 |
78 | @Override
79 | public void appendSelectNextValFromSequence(StringBuilder sb, String sequenceName) {
80 | sb.append("SELECT NEXT VALUE FOR ");
81 | // this is word and not entity unfortunately
82 | appendEscapedWord(sb, sequenceName);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/OracleDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.List;
4 |
5 | import com.j256.ormlite.db.BaseDatabaseType;
6 | import com.j256.ormlite.field.DataPersister;
7 | import com.j256.ormlite.field.DataType;
8 | import com.j256.ormlite.field.FieldConverter;
9 | import com.j256.ormlite.field.FieldType;
10 | import com.j256.ormlite.field.converter.CharacterCompatFieldConverter;
11 |
12 | /**
13 | * Oracle database type information used to create the tables, etc..
14 | *
15 | *
16 | * WARNING: I have not tested this unfortunately because of a lack of access to a Oracle instance. Love to get
17 | * 1-2 hours of access to an database to test/tweak this. Undoubtably is it wrong. Please contact Please contact us if
18 | * you'd like to help with this class.
19 | *
20 | *
21 | * @author graywatson
22 | */
23 | public class OracleDatabaseType extends BaseDatabaseType {
24 |
25 | private final static String DATABASE_URL_PORTION = "oracle";
26 | private final static String DRIVER_CLASS_NAME = "oracle.jdbc.driver.OracleDriver";
27 | private final static String DATABASE_NAME = "Oracle";
28 | private static final String BOOLEAN_INTEGER_FORMAT = "integer";
29 |
30 | @Override
31 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
32 | return DATABASE_URL_PORTION.equals(dbTypePart);
33 | }
34 |
35 | @Override
36 | protected String[] getDriverClassNames() {
37 | return new String[] { DRIVER_CLASS_NAME };
38 | }
39 |
40 | @Override
41 | public String getDatabaseName() {
42 | return DATABASE_NAME;
43 | }
44 |
45 | @Override
46 | protected void appendStringType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
47 | sb.append("VARCHAR2(").append(fieldWidth).append(')');
48 | }
49 |
50 | @Override
51 | protected void appendLongStringType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
52 | sb.append("LONG");
53 | }
54 |
55 | @Override
56 | protected void appendByteType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
57 | sb.append("SMALLINT");
58 | }
59 |
60 | @Override
61 | protected void appendLongType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
62 | sb.append("NUMERIC");
63 | }
64 |
65 | @Override
66 | protected void appendByteArrayType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
67 | sb.append("LONG RAW");
68 | }
69 |
70 | @Override
71 | protected void appendSerializableType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
72 | sb.append("LONG RAW");
73 | }
74 |
75 | @Override
76 | protected void appendBigDecimalNumericType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
77 | // from stew
78 | sb.append("NUMBER(*," + fieldWidth + ")");
79 | }
80 |
81 | @Override
82 | protected void appendBooleanType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
83 | if (BOOLEAN_INTEGER_FORMAT.equalsIgnoreCase(fieldType.getFormat())) {
84 | sb.append("INTEGER");
85 | } else {
86 | sb.append("CHAR(1)");
87 | }
88 | }
89 |
90 | @Override
91 | public FieldConverter getFieldConverter(DataPersister dataPersister, FieldType fieldType) {
92 | switch (dataPersister.getSqlType()) {
93 | case BOOLEAN:
94 | /*
95 | * Booleans in Oracle are stored as the character '1' or '0'. You can change the characters by
96 | * specifying a format string. It must be a string with 2 characters. The first character is the value
97 | * for TRUE, the second is FALSE. See {@link BooleanCharType}.
98 | *
99 | * You can also specify the format as "integer" to use an integer column type and the value 1 (really
100 | * non-0) for true and 0 for false. See {@link BooleanIntegerType}.
101 | */
102 | if (BOOLEAN_INTEGER_FORMAT.equalsIgnoreCase(fieldType.getFormat())) {
103 | return DataType.BOOLEAN_INTEGER.getDataPersister();
104 | } else {
105 | return new CharacterCompatFieldConverter(DataType.BOOLEAN_CHAR.getDataPersister());
106 | }
107 | case CHAR:
108 | return new CharacterCompatFieldConverter(dataPersister);
109 | default:
110 | return super.getFieldConverter(dataPersister, fieldType);
111 | }
112 | }
113 |
114 | @Override
115 | protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List statementsBefore,
116 | List additionalArgs, List queriesAfter) {
117 | String seqName = fieldType.getGeneratedIdSequence();
118 | // needs to match dropColumnArg()
119 | StringBuilder seqSb = new StringBuilder(64);
120 | seqSb.append("CREATE SEQUENCE ");
121 | // when it is created, it needs to be escaped specially
122 | appendEscapedEntityName(seqSb, seqName);
123 | statementsBefore.add(seqSb.toString());
124 |
125 | configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
126 | }
127 |
128 | @Override
129 | protected void configureId(StringBuilder sb, FieldType fieldType, List statementsBefore,
130 | List additionalArgs, List queriesAfter) {
131 | // no PRIMARY KEY per stew
132 | }
133 |
134 | @Override
135 | public void dropColumnArg(FieldType fieldType, List statementsBefore, List statementsAfter) {
136 | if (fieldType.isGeneratedIdSequence()) {
137 | StringBuilder sb = new StringBuilder(64);
138 | sb.append("DROP SEQUENCE ");
139 | appendEscapedEntityName(sb, fieldType.getGeneratedIdSequence());
140 | statementsAfter.add(sb.toString());
141 | }
142 | }
143 |
144 | @Override
145 | public void appendEscapedEntityName(StringBuilder sb, String name) {
146 | sb.append('\"').append(name).append('\"');
147 | }
148 |
149 | @Override
150 | public boolean isIdSequenceNeeded() {
151 | return true;
152 | }
153 |
154 | @Override
155 | public void appendSelectNextValFromSequence(StringBuilder sb, String sequenceName) {
156 | sb.append("SELECT ");
157 | // this may not work -- may need to have no escape
158 | appendEscapedEntityName(sb, sequenceName);
159 | // dual is some sort of special internal table I think
160 | sb.append(".nextval FROM dual");
161 | }
162 |
163 | @Override
164 | public String getPingStatement() {
165 | return "SELECT 1 FROM DUAL";
166 | }
167 |
168 | @Override
169 | public boolean isOffsetSqlSupported() {
170 | // there is no easy way to do this in this database type
171 | return false;
172 | }
173 |
174 | @Override
175 | public boolean isBatchUseTransaction() {
176 | // from stew
177 | return true;
178 | }
179 |
180 | @Override
181 | public boolean isSelectSequenceBeforeInsert() {
182 | // from stew
183 | return true;
184 | }
185 |
186 | @Override
187 | public boolean isEntityNamesMustBeUpCase() {
188 | // from stew
189 | return true;
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/PostgresDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | import java.util.List;
4 |
5 | import com.j256.ormlite.db.BaseDatabaseType;
6 | import com.j256.ormlite.field.FieldType;
7 |
8 | /**
9 | * Postgres database type information used to create the tables, etc..
10 | *
11 | * @author graywatson
12 | */
13 | public class PostgresDatabaseType extends BaseDatabaseType {
14 |
15 | private final static String DATABASE_URL_PORTION = "postgresql";
16 | private final static String DRIVER_CLASS_NAME = "org.postgresql.Driver";
17 | private final static String DATABASE_NAME = "Postgres";
18 |
19 | @Override
20 | public boolean isDatabaseUrlThisType(String url, String dbTypePart) {
21 | return DATABASE_URL_PORTION.equals(dbTypePart);
22 | }
23 |
24 | @Override
25 | protected String[] getDriverClassNames() {
26 | return new String[] { DRIVER_CLASS_NAME };
27 | }
28 |
29 | @Override
30 | public String getDatabaseName() {
31 | return DATABASE_NAME;
32 | }
33 |
34 | @Override
35 | protected void appendUuidNativeType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
36 | sb.append("UUID");
37 | }
38 |
39 | @Override
40 | protected void appendByteType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
41 | sb.append("SMALLINT");
42 | }
43 |
44 | @Override
45 | protected void appendByteArrayType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
46 | sb.append("BYTEA");
47 | }
48 |
49 | @Override
50 | protected void appendSerializableType(StringBuilder sb, FieldType fieldType, int fieldWidth) {
51 | sb.append("BYTEA");
52 | }
53 |
54 | @Override
55 | protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List statementsBefore,
56 | List additionalArgs, List queriesAfter) {
57 | String sequenceName = fieldType.getGeneratedIdSequence();
58 | // needs to match dropColumnArg()
59 | StringBuilder seqSb = new StringBuilder(64);
60 | seqSb.append("CREATE SEQUENCE ");
61 | // when it is created, it needs to be escaped specially
62 | appendEscapedEntityName(seqSb, sequenceName);
63 | statementsBefore.add(seqSb.toString());
64 |
65 | sb.append("DEFAULT NEXTVAL(");
66 | // postgres needed this special escaping for NEXTVAL('"sequence-name"')
67 | sb.append('\'').append('\"').append(sequenceName).append('\"').append('\'');
68 | sb.append(") ");
69 | // could also be the type serial for auto-generated sequences
70 | // 8.2 also have the returning insert statement
71 |
72 | configureId(sb, fieldType, statementsBefore, additionalArgs, queriesAfter);
73 | }
74 |
75 | @Override
76 | public void dropColumnArg(FieldType fieldType, List statementsBefore, List statementsAfter) {
77 | if (fieldType.isGeneratedIdSequence()) {
78 | StringBuilder sb = new StringBuilder(64);
79 | sb.append("DROP SEQUENCE ");
80 | appendEscapedEntityName(sb, fieldType.getGeneratedIdSequence());
81 | statementsAfter.add(sb.toString());
82 | }
83 | }
84 |
85 | @Override
86 | public void appendEscapedEntityName(StringBuilder sb, String name) {
87 | // this handles table names like schema.table which have to be quoted like "schema"."table"
88 | boolean first = true;
89 | for (String namePart : name.split("\\.")) {
90 | if (first) {
91 | first = false;
92 | } else {
93 | sb.append('.');
94 | }
95 | sb.append('\"').append(namePart).append('\"');
96 | }
97 | }
98 |
99 | @Override
100 | public boolean isIdSequenceNeeded() {
101 | return true;
102 | }
103 |
104 | @Override
105 | public boolean isSelectSequenceBeforeInsert() {
106 | return true;
107 | }
108 |
109 | @Override
110 | public void appendSelectNextValFromSequence(StringBuilder sb, String sequenceName) {
111 | sb.append("SELECT NEXTVAL(");
112 | // this is word and not entity unfortunately
113 | appendEscapedWord(sb, sequenceName);
114 | sb.append(')');
115 | }
116 |
117 | @Override
118 | public boolean isTruncateSupported() {
119 | return true;
120 | }
121 |
122 | @Override
123 | public boolean isCreateIfNotExistsSupported() {
124 | int major = driver.getMajorVersion();
125 | if (major > 9 || (major == 9 && driver.getMinorVersion() >= 1)) {
126 | return true;
127 | } else {
128 | return super.isCreateIfNotExistsSupported();
129 | }
130 | }
131 |
132 | @Override
133 | public boolean isSequenceNamesMustBeLowerCase() {
134 | return true;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/db/SqlServerJtdsDatabaseType.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.db;
2 |
3 | /**
4 | * Microsoft SQL server database type information connected through the JTDS JDBC driver.
5 | *
6 | *
7 | * NOTE: Currently with 1.2.4 version of the jTDS package, I'm seeing problems with Java 1.5 because jTDS is
8 | * using a java.sql 1.6 class.
9 | *
10 | *
11 | *
12 | * See JTDS home page for more information. To use this driver, you need to
13 | * specify the database URL as something like the following. See the URL for more information.
14 | *
25 | *
26 | * @author graywatson
27 | */
28 | public class DaoFactory {
29 |
30 | /**
31 | * Create and return a Dao based on the arguments.
32 | */
33 | public static Dao createDao(ConnectionSource connectionSource, Class clazz) throws SQLException {
34 | return DaoManager.createDao(connectionSource, clazz);
35 | }
36 |
37 | /**
38 | * Create and return a Dao based on the arguments.
39 | */
40 | public static Dao createDao(ConnectionSource connectionSource, DatabaseTableConfig tableConfig)
41 | throws SQLException {
42 | return DaoManager.createDao(connectionSource, tableConfig);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/j256/ormlite/jdbc/spring/TableCreator.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc.spring;
2 |
3 | import java.sql.SQLException;
4 | import java.util.HashSet;
5 | import java.util.List;
6 | import java.util.Set;
7 |
8 | import com.j256.ormlite.dao.BaseDaoImpl;
9 | import com.j256.ormlite.dao.Dao;
10 | import com.j256.ormlite.support.ConnectionSource;
11 | import com.j256.ormlite.table.DatabaseTableConfig;
12 | import com.j256.ormlite.table.TableUtils;
13 |
14 | /**
15 | * Spring bean that auto-creates any tables that it finds DAOs for if the property name in
16 | * TableCreator.AUTO_CREATE_TABLES property has been set to true. It will also auto-drop any tables that were
17 | * auto-created if the property name in TableCreator.AUTO_DROP_TABLES property has been set to true.
18 | *
19 | *
20 | * NOTE: If you are using the Spring type wiring in Java, {@link #initialize} should be called after all of the
21 | * set methods. In Spring XML, init-method="initialize" should be used.
22 | *
23 | *
24 | *
25 | * Here is an example of spring wiring.
26 | *
9 | This package provides the JDBC support for a lightweight Object Relational Mapping between Java classes and
11 | SQL databases. See the ORMLite home page for more
12 | information.
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/main/resources/com/j256/ormlite/jdbc/LICENSE.txt:
--------------------------------------------------------------------------------
1 | ISC License (https://opensource.org/licenses/ISC)
2 |
3 | Copyright 2010 to 2020, Gray Watson
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 |
--------------------------------------------------------------------------------
/src/main/resources/com/j256/ormlite/jdbc/README.txt:
--------------------------------------------------------------------------------
1 | This package provides the JDBC specific functionality. You will also need to download the
2 | ormlite-core package as well. Android users should download the ormlite-android package instead of
3 | this JDBC one.
4 |
5 | For more information, see the online documentation on the home page:
6 |
7 | http://ormlite.com/
8 |
9 | Sources can be found online via Github:
10 |
11 | https://github.com/j256/ormlite-jdbc
12 |
13 | Enjoy,
14 | Gray Watson
15 |
--------------------------------------------------------------------------------
/src/test/java/com/j256/ormlite/jdbc/BaseJdbcTest.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.net.InetAddress;
6 | import java.net.UnknownHostException;
7 | import java.sql.SQLException;
8 | import java.util.HashSet;
9 | import java.util.Set;
10 |
11 | import org.junit.jupiter.api.AfterEach;
12 | import org.junit.jupiter.api.BeforeEach;
13 |
14 | import com.j256.ormlite.dao.BaseDaoImpl;
15 | import com.j256.ormlite.dao.Dao;
16 | import com.j256.ormlite.dao.DaoManager;
17 | import com.j256.ormlite.db.DatabaseType;
18 | import com.j256.ormlite.table.DatabaseTableConfig;
19 | import com.j256.ormlite.table.TableUtils;
20 |
21 | public abstract class BaseJdbcTest {
22 |
23 | private static final String DATASOURCE_ERROR = "Property 'dataSource' is required";
24 |
25 | protected static final String DEFAULT_DATABASE_URL = "jdbc:h2:mem:ormlite";
26 |
27 | protected String databaseHost = null;
28 | protected String databaseUrl = DEFAULT_DATABASE_URL;
29 | protected String userName = null;
30 | protected String password = null;
31 |
32 | protected JdbcConnectionSource connectionSource = null;
33 | protected boolean isConnectionExpected = false;
34 | protected DatabaseType databaseType = null;
35 |
36 | private Set> dropClassSet = new HashSet>();
37 | private Set> dropTableConfigSet = new HashSet>();
38 |
39 | @BeforeEach
40 | public void before() throws Exception {
41 | DaoManager.clearCache();
42 | if (connectionSource != null) {
43 | return;
44 | }
45 | // do this for everyone
46 | System.setProperty("derby.stream.error.file", "target/derby.log");
47 | setDatabaseParams();
48 | doOpenConnectionSource();
49 | }
50 |
51 | protected void openConnectionSource() throws Exception {
52 | if (connectionSource == null) {
53 | doOpenConnectionSource();
54 | }
55 | }
56 |
57 | /**
58 | * Set the database parameters for this db type.
59 | *
60 | * @throws SQLException
61 | * For sub classes
62 | */
63 | protected void setDatabaseParams() throws SQLException {
64 | // noop here -- designed to be overridden
65 | }
66 |
67 | @AfterEach
68 | public void after() throws Exception {
69 | if (connectionSource != null) {
70 | for (Class> clazz : dropClassSet) {
71 | dropTable(clazz, true);
72 | }
73 | dropClassSet.clear();
74 | for (DatabaseTableConfig> tableConfig : dropTableConfigSet) {
75 | dropTable(tableConfig, true);
76 | }
77 | dropTableConfigSet.clear();
78 | }
79 | closeConnectionSource();
80 | DaoManager.clearCache();
81 | }
82 |
83 | /**
84 | * Return if this test was expecting to be able to load the driver class
85 | */
86 | protected boolean isDriverClassExpected() {
87 | return true;
88 | }
89 |
90 | /**
91 | * Return if this test was expecting to be able to connect to the database
92 | */
93 | protected boolean isConnectionExpected() throws IOException {
94 | try {
95 | if (databaseHost == null) {
96 | return true;
97 | } else {
98 | return InetAddress.getByName(databaseHost).isReachable(500);
99 | }
100 | } catch (UnknownHostException e) {
101 | return false;
102 | }
103 | }
104 |
105 | protected void closeConnectionSource() throws Exception {
106 | if (connectionSource != null) {
107 | connectionSource.close();
108 | connectionSource = null;
109 | }
110 | }
111 |
112 | protected Dao createDao(Class clazz, boolean createTable) throws Exception {
113 | if (connectionSource == null) {
114 | throw new SQLException(DATASOURCE_ERROR);
115 | }
116 | @SuppressWarnings("unchecked")
117 | BaseDaoImpl dao = (BaseDaoImpl) DaoManager.createDao(connectionSource, clazz);
118 | return configDao(dao, createTable);
119 | }
120 |
121 | protected Dao createDao(DatabaseTableConfig tableConfig, boolean createTable) throws Exception {
122 | if (connectionSource == null) {
123 | throw new SQLException(DATASOURCE_ERROR);
124 | }
125 | @SuppressWarnings("unchecked")
126 | BaseDaoImpl dao = (BaseDaoImpl) DaoManager.createDao(connectionSource, tableConfig);
127 | return configDao(dao, createTable);
128 | }
129 |
130 | protected void createTable(Class clazz, boolean dropAtEnd) throws Exception {
131 | try {
132 | // first we drop it in case it existed before
133 | dropTable(clazz, true);
134 | } catch (SQLException ignored) {
135 | // ignore any errors about missing tables
136 | }
137 | TableUtils.createTable(connectionSource, clazz);
138 | if (dropAtEnd) {
139 | dropClassSet.add(clazz);
140 | }
141 | }
142 |
143 | protected void createTable(DatabaseTableConfig tableConfig, boolean dropAtEnd) throws Exception {
144 | try {
145 | // first we drop it in case it existed before
146 | dropTable(tableConfig, true);
147 | } catch (SQLException ignored) {
148 | // ignore any errors about missing tables
149 | }
150 | TableUtils.createTable(connectionSource, tableConfig);
151 | if (dropAtEnd) {
152 | dropTableConfigSet.add(tableConfig);
153 | }
154 | }
155 |
156 | protected void dropTable(Class clazz, boolean ignoreErrors) throws Exception {
157 | // drop the table and ignore any errors along the way
158 | TableUtils.dropTable(connectionSource, clazz, ignoreErrors);
159 | }
160 |
161 | protected void dropTable(DatabaseTableConfig tableConfig, boolean ignoreErrors) throws Exception {
162 | // drop the table and ignore any errors along the way
163 | TableUtils.dropTable(connectionSource, tableConfig, ignoreErrors);
164 | }
165 |
166 | protected static void removeDirectory(String path) {
167 | File file = new File(path);
168 | if (file.isDirectory()) {
169 | removeDirectory(file);
170 | } else {
171 | file.delete();
172 | }
173 | }
174 |
175 | protected static void removeDirectory(File dir) {
176 | for (File file : dir.listFiles()) {
177 | if (file.isDirectory()) {
178 | removeDirectory(file);
179 | } else {
180 | file.delete();
181 | }
182 | }
183 | dir.delete();
184 | }
185 |
186 | private void doOpenConnectionSource() throws Exception {
187 | if (connectionSource == null) {
188 | isConnectionExpected = isConnectionExpected();
189 | if (isConnectionExpected) {
190 | connectionSource = new JdbcConnectionSource(databaseUrl, userName, password);
191 | }
192 | }
193 | if (databaseType == null) {
194 | if (connectionSource != null) {
195 | databaseType = connectionSource.getDatabaseType();
196 | }
197 | } else {
198 | if (connectionSource != null) {
199 | connectionSource.setDatabaseType(databaseType);
200 | }
201 | }
202 | }
203 |
204 | private Dao configDao(BaseDaoImpl dao, boolean createTable) throws Exception {
205 | if (connectionSource == null) {
206 | throw new SQLException(DATASOURCE_ERROR);
207 | }
208 | dao.setConnectionSource(connectionSource);
209 | if (createTable) {
210 | DatabaseTableConfig tableConfig = dao.getTableConfig();
211 | if (tableConfig == null) {
212 | tableConfig = DatabaseTableConfig.fromClass(databaseType, dao.getDataClass());
213 | }
214 | createTable(tableConfig, true);
215 | }
216 | dao.initialize();
217 | return dao;
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/src/test/java/com/j256/ormlite/jdbc/JdbcCompiledStatementTest.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import static org.easymock.EasyMock.createMock;
4 | import static org.easymock.EasyMock.expect;
5 | import static org.easymock.EasyMock.replay;
6 | import static org.easymock.EasyMock.verify;
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 | import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
9 |
10 | import java.sql.PreparedStatement;
11 | import java.sql.ResultSetMetaData;
12 |
13 | import org.easymock.EasyMock;
14 | import org.junit.jupiter.api.Test;
15 |
16 | import com.j256.ormlite.BaseCoreTest;
17 | import com.j256.ormlite.field.SqlType;
18 | import com.j256.ormlite.stmt.StatementBuilder.StatementType;
19 |
20 | public class JdbcCompiledStatementTest extends BaseCoreTest {
21 |
22 | @Test
23 | public void testGetColumnName() throws Exception {
24 | PreparedStatement preparedStatement = createMock(PreparedStatement.class);
25 | ResultSetMetaData metadata = createMock(ResultSetMetaData.class);
26 | expect(metadata.getColumnName(1)).andReturn("TEST_COLUMN1");
27 | expect(preparedStatement.getMetaData()).andReturn(metadata);
28 | preparedStatement.close();
29 | replay(metadata, preparedStatement);
30 | String statement = "statement";
31 | JdbcCompiledStatement stmt =
32 | new JdbcCompiledStatement(preparedStatement, statement, StatementType.SELECT, false);
33 | assertEquals(statement, stmt.getStatement());
34 | assertEquals(statement, stmt.toString());
35 | assertEquals("TEST_COLUMN1", stmt.getColumnName(0));
36 | stmt.close();
37 | verify(preparedStatement, metadata);
38 | }
39 |
40 | @Test
41 | public void testGetMoreResults() throws Exception {
42 | PreparedStatement preparedStatement = createMock(PreparedStatement.class);
43 | expect(preparedStatement.getMoreResults()).andReturn(Boolean.TRUE);
44 | preparedStatement.close();
45 | replay(preparedStatement);
46 | JdbcCompiledStatement stmt =
47 | new JdbcCompiledStatement(preparedStatement, "statement", StatementType.SELECT, false);
48 | stmt.getMoreResults();
49 | stmt.close();
50 | verify(preparedStatement);
51 | }
52 |
53 | @Test
54 | public void testSetNull() throws Exception {
55 | PreparedStatement preparedStatement = createMock(PreparedStatement.class);
56 | preparedStatement.setNull(1, TypeValMapper.getTypeValForSqlType(SqlType.STRING));
57 | EasyMock.expectLastCall();
58 | preparedStatement.close();
59 | replay(preparedStatement);
60 | JdbcCompiledStatement stmt =
61 | new JdbcCompiledStatement(preparedStatement, "statement", StatementType.SELECT, false);
62 | stmt.setObject(0, null, SqlType.STRING);
63 | stmt.close();
64 | verify(preparedStatement);
65 | }
66 |
67 | @Test
68 | public void testExecuteUpdateWithSelectType() {
69 | PreparedStatement preparedStatement = createMock(PreparedStatement.class);
70 | JdbcCompiledStatement stmt =
71 | new JdbcCompiledStatement(preparedStatement, "statement", StatementType.SELECT, false);
72 | assertThrowsExactly(IllegalArgumentException.class, () -> {
73 | stmt.runUpdate();
74 | stmt.close();
75 | });
76 | }
77 |
78 | @Test
79 | public void testExecuteQueryWithNonSelectType() {
80 | PreparedStatement preparedStatement = createMock(PreparedStatement.class);
81 | JdbcCompiledStatement stmt =
82 | new JdbcCompiledStatement(preparedStatement, "statement", StatementType.EXECUTE, false);
83 | assertThrowsExactly(IllegalArgumentException.class, () -> {
84 | stmt.runQuery(null);
85 | stmt.close();
86 | });
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/com/j256/ormlite/jdbc/JdbcRawResultsImplTest.java:
--------------------------------------------------------------------------------
1 | package com.j256.ormlite.jdbc;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertNotNull;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 |
7 | import java.util.List;
8 | import java.util.concurrent.atomic.AtomicBoolean;
9 |
10 | import org.junit.jupiter.api.Test;
11 |
12 | import com.j256.ormlite.dao.Dao;
13 | import com.j256.ormlite.dao.GenericRawResults;
14 | import com.j256.ormlite.dao.RawRowMapper;
15 | import com.j256.ormlite.field.DatabaseField;
16 |
17 | public class JdbcRawResultsImplTest extends BaseJdbcTest {
18 |
19 | @Test
20 | public void testCustomColumnNames() throws Exception {
21 | Dao dao = createDao(Foo.class, true);
22 | Foo foo = new Foo();
23 | foo.val = 1213213;
24 | assertEquals(1, dao.create(foo));
25 |
26 | final String idName = "SOME_ID";
27 | final String valName = "SOME_VAL";
28 | final AtomicBoolean gotResult = new AtomicBoolean(false);
29 | GenericRawResults