Skip to content

Commit d489ff0

Browse files
Merge pull request #16 from Codeforces/dev-mikemirzayanov
JDK 17
2 parents d6b15cb + 6a28f68 commit d489ff0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1813
-1451
lines changed

code/bundle.bat

+8-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
mvn -Dfile.encoding=UTF-8 -DcreateChecksum=true --batch-mode clean source:jar javadoc:jar repository:bundle-create install
1+
setlocal enabledelayedexpansion
2+
3+
if not "!JAVA8_64_HOME!"=="" (
4+
set PATH=!JAVA8_64_HOME!\bin;!PATH!
5+
set JAVA_HOME=!JAVA8_64_HOME!
6+
)
7+
8+
call mvn.cmd -Dfile.encoding=UTF-8 -DcreateChecksum=true --batch-mode clean source:jar javadoc:jar repository:bundle-create install

code/pom.xml

+75-15
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<modelVersion>4.0.0</modelVersion>
1111
<groupId>jacuzzi</groupId>
1212
<artifactId>jacuzzi</artifactId>
13+
<version>0.1.0-SNAPSHOT</version>
1314
<packaging>jar</packaging>
14-
<version>0.0.36-SNAPSHOT</version>
1515
<name>jacuzzi</name>
16-
<url>http://code.google.com/p/jacuzzi</url>
16+
<url>https://github.com/Codeforces/jacuzzi</url>
1717
<developers>
1818
<developer>
1919
<id>MikeMirzayanov</id>
@@ -47,10 +47,22 @@
4747
</properties>
4848
<build>
4949
<plugins>
50+
<plugin>
51+
<groupId>org.apache.maven.plugins</groupId>
52+
<artifactId>maven-repository-plugin</artifactId>
53+
<version>2.4</version>
54+
<dependencies>
55+
<dependency>
56+
<groupId>org.codehaus.plexus</groupId>
57+
<artifactId>plexus-archiver</artifactId>
58+
<version>4.2.5</version>
59+
</dependency>
60+
</dependencies>
61+
</plugin>
5062
<plugin>
5163
<groupId>org.apache.maven.plugins</groupId>
5264
<artifactId>maven-compiler-plugin</artifactId>
53-
<version>3.7.0</version>
65+
<version>3.8.1</version>
5466
<configuration>
5567
<source>1.8</source>
5668
<target>1.8</target>
@@ -60,11 +72,60 @@
6072
<plugin>
6173
<groupId>org.apache.maven.plugins</groupId>
6274
<artifactId>maven-javadoc-plugin</artifactId>
63-
<version>2.10.4</version>
75+
<version>3.3.1</version>
6476
<configuration>
6577
<additionalparam>-Xdoclint:none</additionalparam>
6678
</configuration>
6779
</plugin>
80+
<plugin>
81+
<groupId>org.apache.maven.plugins</groupId>
82+
<artifactId>maven-surefire-plugin</artifactId>
83+
<version>2.22.2</version>
84+
<configuration>
85+
<argLine>-Dfile.encoding=UTF-8</argLine>
86+
<argLine>-Xmx1200M</argLine>
87+
<!-- Uncomment to build with JDK 9+ -->
88+
<!--
89+
<argLine>&#45;&#45;add&#45;opens java.base/java.lang=ALL&#45;UNNAMED &#45;&#45;add&#45;opens java.base/java.util=ALL&#45;UNNAMED &#45;&#45;add&#45;opens java.base/java.io=ALL&#45;UNNAMED</argLine>
90+
-->
91+
</configuration>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.basepom.maven</groupId>
95+
<artifactId>duplicate-finder-maven-plugin</artifactId>
96+
<version>1.5.0</version>
97+
<executions>
98+
<execution>
99+
<id>default</id>
100+
<phase>verify</phase>
101+
<goals>
102+
<goal>check</goal>
103+
</goals>
104+
</execution>
105+
</executions>
106+
<configuration>
107+
<skip>false</skip>
108+
<quiet>false</quiet>
109+
<checkCompileClasspath>true</checkCompileClasspath>
110+
<checkRuntimeClasspath>true</checkRuntimeClasspath>
111+
<checkTestClasspath>true</checkTestClasspath>
112+
<failBuildInCaseOfDifferentContentConflict>false</failBuildInCaseOfDifferentContentConflict>
113+
<failBuildInCaseOfEqualContentConflict>false</failBuildInCaseOfEqualContentConflict>
114+
<failBuildInCaseOfConflict>false</failBuildInCaseOfConflict>
115+
<printEqualFiles>false</printEqualFiles>
116+
<preferLocal>true</preferLocal>
117+
118+
<!-- Version 1.1.1+ -->
119+
<includeBootClasspath>false</includeBootClasspath>
120+
<bootClasspathProperty>sun.boot.class.path</bootClasspathProperty>
121+
<!-- Version 1.1.1+ -->
122+
123+
124+
<!-- Version 1.2.0+ -->
125+
<includePomProjects>false</includePomProjects>
126+
<!-- Version 1.2.0+ -->
127+
</configuration>
128+
</plugin>
68129
</plugins>
69130
</build>
70131
<dependencies>
@@ -76,50 +137,49 @@
76137
<dependency>
77138
<groupId>org.apache.commons</groupId>
78139
<artifactId>commons-lang3</artifactId>
79-
<version>3.6</version>
140+
<version>3.12.0</version>
80141
</dependency>
81142
<dependency>
82143
<groupId>cglib</groupId>
83144
<artifactId>cglib</artifactId>
84-
<version>3.0</version>
145+
<version>3.3.0</version>
85146
</dependency>
86147
<dependency>
87148
<groupId>org.ow2.asm</groupId>
88149
<artifactId>asm</artifactId>
89-
<version>4.0</version>
150+
<version>9.2</version>
90151
</dependency>
91152
<dependency>
92153
<groupId>org.ow2.asm</groupId>
93154
<artifactId>asm-tree</artifactId>
94-
<version>4.0</version>
155+
<version>9.2</version>
95156
</dependency>
96157
<dependency>
97158
<groupId>org.ow2.asm</groupId>
98159
<artifactId>asm-analysis</artifactId>
99-
<version>4.0</version>
160+
<version>9.2</version>
100161
</dependency>
101162
<dependency>
102163
<groupId>org.ow2.asm</groupId>
103164
<artifactId>asm-util</artifactId>
104-
<version>4.0</version>
165+
<version>9.2</version>
105166
</dependency>
106167
<dependency>
107168
<groupId>junit</groupId>
108169
<artifactId>junit</artifactId>
109-
<version>4.11</version>
170+
<version>4.13.2</version>
110171
<scope>test</scope>
111172
</dependency>
112173
<dependency>
113174
<groupId>org.hsqldb</groupId>
114175
<artifactId>hsqldb</artifactId>
115-
<version>2.3.4</version>
176+
<version>2.5.2</version>
116177
<scope>test</scope>
117178
</dependency>
118179
<dependency>
119-
<groupId>c3p0</groupId>
180+
<groupId>com.mchange</groupId>
120181
<artifactId>c3p0</artifactId>
121-
<version>0.9.1.2</version>
122-
<scope>test</scope>
182+
<version>0.9.5.5</version>
123183
</dependency>
124184
<dependency>
125185
<groupId>com.google.code.findbugs</groupId>

code/src/main/java/org/jacuzzi/core/CachedTypeOracle.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CachedTypeOracle<T> extends TypeOracle<T> {
1111
private static final ThreadLocal<Map<Class<?>, TypeOracle<?>>> threadLocalCache = new ThreadLocal<Map<Class<?>, TypeOracle<?>>>() {
1212
@Override
1313
protected Map<Class<?>, TypeOracle<?>> initialValue() {
14-
return new HashMap<Class<?>, TypeOracle<?>>();
14+
return new HashMap<>();
1515
}
1616
};
1717

@@ -22,7 +22,7 @@ TypeOracle<T> getTypeOracle() {
2222
}
2323

2424
CachedTypeOracle(Class<T> typeClass) {
25-
typeOracle = new TypeOracleImpl<T>(typeClass);
25+
typeOracle = new TypeOracleImpl<>(typeClass);
2626
}
2727

2828
static Map<Class<?>, TypeOracle<?>> getThreadLocalCache() {

code/src/main/java/org/jacuzzi/core/DataSourceUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* This class is used to manipulate with dataSource. Jacuzzi don't call
1111
* dataSource.getConnection() explicitly. It uses DataSourceUtil.getConnection(dataSource).
12-
* <p/>
12+
*
1313
* If you are using any pooling dataSource, DataSourceUtil.getConnection(dataSource) can return
1414
* new connection each call. Use DataSourceUtil.attachConnection() / DataSourceUtil.detachConnection()
1515
* if you want to attach one connection to the thread. It can be usefull if you want to be sure

code/src/main/java/org/jacuzzi/core/GenericDao.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
/**
77
* Provides some usefull methods for entity.
8-
* <p/>
8+
*
99
* Example usage:
10-
* <code>
11-
* public class UserDao extends GenericDaoImpl<User,String> {
12-
* public UserDao(DataSource source) {
13-
* super(source);
14-
* }
10+
* {@code
11+
* public class UserDao extends GenericDaoImpl<User,String> {
12+
* public UserDao(DataSource source) {
13+
* super(source);
14+
* }
15+
* }
1516
* }
16-
* </code>
1717
*
1818
* @author Mike Mirzayanov
1919
*/
@@ -37,10 +37,9 @@ public interface GenericDao<T, K> {
3737
* Returns entity list using query to find them.
3838
* You can use reduced form of the query.
3939
* Examples:
40-
* <code>
41-
* users = userDao.findBy("id > 4");
42-
* users = userDao.findBy("SELECT * FROM Users WHERE age >= 21");
43-
* </code>
40+
*
41+
* {@code users = userDao.findBy("id > 4")};
42+
* {@code users = userDao.findBy("SELECT * FROM Users WHERE age >= 21")};
4443
*
4544
* @param query Query (possibly in reduced form).
4645
* @param args Arguments to replace "?" jokers in {@code query}.

code/src/main/java/org/jacuzzi/core/GenericDaoImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ protected GenericDaoImpl(DataSource source) {
4040
/**
4141
* Call it to begin transaction around
4242
* current connection in current thread.
43-
* <p/>
43+
*
4444
* You should call commit() or rollback() at
4545
* the end of transaction.
46-
* <p/>
46+
*
4747
* Usually you should call commit or rollback
4848
* in the current DAO method.
4949
*/

code/src/main/java/org/jacuzzi/core/Jacuzzi.java

+43-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
package org.jacuzzi.core;
22

3+
import org.apache.commons.lang3.StringUtils;
4+
import org.apache.log4j.Logger;
5+
36
import javax.sql.DataSource;
47
import java.lang.reflect.Constructor;
58
import java.sql.Connection;
69
import java.sql.SQLException;
10+
import java.time.LocalDateTime;
11+
import java.time.OffsetDateTime;
12+
import java.time.ZoneOffset;
713
import java.util.*;
814

915
/**
1016
* @author Mike Mirzayanov
1117
*/
1218
public class Jacuzzi {
19+
private static final Logger logger = Logger.getLogger(Jacuzzi.class);
20+
21+
public static final ZoneOffset ZONE_OFFSET;
22+
1323
/**
1424
* {@code DataSource} instance,
1525
* all database routine will use connections
@@ -63,7 +73,7 @@ public void detachConnectionOrThrowException() {
6373
/**
6474
* Call it to begin transaction around
6575
* current connection in current thread.
66-
* <p/>
76+
*
6777
* You should call commit() or rollback() at
6878
* the end of transaction.
6979
*
@@ -85,7 +95,7 @@ public void beginTransaction(int isolationLevel) {
8595
/**
8696
* Call it to begin transaction around
8797
* current connection in current thread.
88-
* <p/>
98+
*
8999
* You should call commit() or rollback() at
90100
* the end of transaction.
91101
*/
@@ -164,7 +174,7 @@ public InsertResult insert(String query, Object... args) {
164174
List<Row> generated = new ArrayList<>(1);
165175
int count = PreparedStatementUtil.execute(dataSource, dataSourceUtil, query, args, generated);
166176
if (generated.isEmpty()) {
167-
List<Row> generatedKeys = new ArrayList<Row>(1);
177+
List<Row> generatedKeys = new ArrayList<>(1);
168178
generatedKeys.add(new Row(1));
169179
return new InsertResult(count, generatedKeys);
170180
} else {
@@ -191,7 +201,7 @@ public InsertResult insert(String query, Object... args) {
191201
*/
192202
public InsertResult multipleInsert(String query, Object... args) {
193203
try {
194-
List<Row> generated = new ArrayList<Row>();
204+
List<Row> generated = new ArrayList<>();
195205
int count = PreparedStatementUtil.execute(dataSource, dataSourceUtil, query, args, generated);
196206

197207
return new InsertResult(count, generated);
@@ -313,14 +323,29 @@ public String findString(String query, Object... args) {
313323
* @return The only value in the only row as {@code Date}.
314324
*/
315325
public Date findDate(String query, Object... args) {
316-
return (Date) findOne(query, args);
326+
Object result = findOne(query, args);
327+
if (result == null) {
328+
return null;
329+
}
330+
if (result instanceof Date) {
331+
return (Date) result;
332+
}
333+
if (result instanceof OffsetDateTime) {
334+
long epochMilli = ((OffsetDateTime) result).toInstant().toEpochMilli();
335+
return new Date(epochMilli);
336+
}
337+
if (result instanceof LocalDateTime) {
338+
return Date.from(((LocalDateTime) result).toInstant(ZONE_OFFSET));
339+
}
340+
throw new DatabaseException("Query `" + query + "` expected to return Date, OffsetDateTime or LocalDateTime.");
317341
}
318342

319343
/**
320344
* Returns DAO instance by given DAO class.
321345
* Gets it from the cache or creates if needed.
322346
*
323-
* @param daoClazz of type Class<T> Class<? extends GenericDao<?,?>> instance.
347+
* @param <T> Entity type.
348+
* @param daoClazz Instance class.
324349
* @return T DAO instance.
325350
*/
326351
@SuppressWarnings({"unchecked"})
@@ -330,7 +355,7 @@ public Date findDate(String query, Object... args) {
330355
return (T) daoCache.get(daoClazz);
331356
} else {
332357
try {
333-
Constructor constructor = daoClazz.getDeclaredConstructor(DataSource.class);
358+
Constructor<?> constructor = daoClazz.getDeclaredConstructor(DataSource.class);
334359
constructor.setAccessible(true);
335360
GenericDao<?, ?> dao = (GenericDao<?, ?>) constructor.newInstance(dataSource);
336361
daoCache.put(daoClazz, dao);
@@ -346,6 +371,7 @@ public Date findDate(String query, Object... args) {
346371
* This method you can use to convert the data from JDBC into specific
347372
* java instances. For example, JDBC returns string but we need enum instance.
348373
*
374+
* @param <T> Type convert to.
349375
* @param instance Instance to be converted.
350376
* @param clazz Target class.
351377
* @return T Converted instance.
@@ -426,4 +452,14 @@ public List<Row> getGeneratedKeys() {
426452
return Collections.unmodifiableList(generatedKeys);
427453
}
428454
}
455+
456+
static {
457+
String zoneOffsetId = System.getProperty("jacuzzi.zoneOffsetId");
458+
if (StringUtils.isBlank(zoneOffsetId)) {
459+
logger.warn("No JVM option -Djacuzzi.zoneOffsetId, use +3.");
460+
zoneOffsetId = "+3";
461+
}
462+
logger.info("Property jacuzzi.zoneOffsetId='" + zoneOffsetId + "'.");
463+
ZONE_OFFSET = ZoneOffset.of(zoneOffsetId);
464+
}
429465
}

0 commit comments

Comments
 (0)