From 39b2d97d23d93a5cbeca3e10bf512c969144a218 Mon Sep 17 00:00:00 2001 From: Yuu Nakajima Date: Fri, 5 Mar 2021 13:06:55 +0900 Subject: [PATCH 1/6] Skip mapping if the field or method has OrmIgnore annotation. --- pom.xml | 2 +- src/main/java/org/nkjmlab/sorm4j/mapping/Mapping.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6829a792..30c6cf49 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.nkjmlab sorm4j - 0.9.10 + 1.0.0-rc1 sorm4j Simple micro Object-Relation Mapper for Java https://github.com/yuu-nkjm/sorm4j diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/Mapping.java b/src/main/java/org/nkjmlab/sorm4j/mapping/Mapping.java index 052cceb9..170704c4 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/Mapping.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/Mapping.java @@ -17,6 +17,7 @@ import org.nkjmlab.sorm4j.OrmException; import org.nkjmlab.sorm4j.annotation.OrmColum; import org.nkjmlab.sorm4j.annotation.OrmGetter; +import org.nkjmlab.sorm4j.annotation.OrmIgnore; import org.nkjmlab.sorm4j.annotation.OrmSetter; import org.nkjmlab.sorm4j.mapping.extension.ColumnFieldMapper; import org.nkjmlab.sorm4j.mapping.extension.ResultSetConverter; @@ -135,7 +136,9 @@ private static Map createAccessors(ColumnFieldMapper columnFie private static Map extractedMethodStartWith(Class objectClass, String prefix) { + Class ignoreAnn = OrmIgnore.class; return Arrays.stream(objectClass.getDeclaredMethods()) + .filter(f -> Objects.isNull(f.getAnnotation(ignoreAnn))) .filter(m -> m.getName().length() > prefix.length() && m.getName().substring(0, prefix.length()).equals(prefix)) .collect(Collectors.toMap(m -> new FieldName( @@ -146,7 +149,9 @@ private static Map extractedMethodStartWith(Class objectCl private static Map getAllFields(final Class objectClass) { + Class ignoreAnn = OrmIgnore.class; return Arrays.stream(objectClass.getDeclaredFields()) + .filter(f -> Objects.isNull(f.getAnnotation(ignoreAnn))) .collect(Collectors.toMap(f -> new FieldName(f), f -> { f.setAccessible(true); return f; From 43ff7bfc32f8b8d355339823f6f91c0ea2ead81f Mon Sep 17 00:00:00 2001 From: Yuu Nakajima Date: Fri, 5 Mar 2021 13:26:21 +0900 Subject: [PATCH 2/6] Remove OrmExtension marker interface --- .../mapping/DataSourceConnectionSource.java | 6 ++++++ .../mapping/DriverManagerConnectionSource.java | 7 +++++++ .../sorm4j/mapping/OrmConfigStoreBuilderImpl.java | 6 ++++++ .../nkjmlab/sorm4j/mapping/OrmConnectionImpl.java | 4 ++-- .../java/org/nkjmlab/sorm4j/mapping/SormImpl.java | 6 ++++++ .../sorm4j/mapping/TypedOrmConnectionImpl.java | 11 +++++++++++ .../sorm4j/mapping/TypedOrmMapperImpl.java | 2 +- .../mapping/extension/ColumnFieldMapper.java | 8 +++++++- .../extension/DefaultColumnFieldMapper.java | 2 +- .../mapping/extension/DefaultTableNameMapper.java | 5 +++++ .../sorm4j/mapping/extension/OrmExtension.java | 5 ----- .../mapping/extension/ResultSetConverter.java | 2 +- .../mapping/extension/SqlParameterSetter.java | 2 +- .../sorm4j/mapping/extension/TableNameMapper.java | 8 +++++++- .../sorm4j/sqlstatement/SelectBuilder.java | 15 +++++++++++++++ .../sqlstatement/SqlWithNamedParameters.java | 7 +++++++ .../sqlstatement/SqlWithOrderedParameters.java | 7 +++++++ 17 files changed, 90 insertions(+), 13 deletions(-) delete mode 100644 src/main/java/org/nkjmlab/sorm4j/mapping/extension/OrmExtension.java diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/DataSourceConnectionSource.java b/src/main/java/org/nkjmlab/sorm4j/mapping/DataSourceConnectionSource.java index 42d08d6f..2f6f4ac2 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/DataSourceConnectionSource.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/DataSourceConnectionSource.java @@ -5,6 +5,12 @@ import javax.sql.DataSource; import org.nkjmlab.sorm4j.ConnectionSource; +/** + * A database connection source wrapped a {@link DataSource} + * + * @author nkjm + * + */ public class DataSourceConnectionSource implements ConnectionSource { private final DataSource dataSource; diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/DriverManagerConnectionSource.java b/src/main/java/org/nkjmlab/sorm4j/mapping/DriverManagerConnectionSource.java index 2085acc4..51828fef 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/DriverManagerConnectionSource.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/DriverManagerConnectionSource.java @@ -8,6 +8,13 @@ import org.nkjmlab.sorm4j.OrmException; import org.nkjmlab.sorm4j.util.Try; +/** + * A database connection source wrapped a {@link DriverManager} + * + * @author nkjm + * + */ + public class DriverManagerConnectionSource implements ConnectionSource { private final String jdbcUrl; diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConfigStoreBuilderImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConfigStoreBuilderImpl.java index dfcceede..7293883d 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConfigStoreBuilderImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConfigStoreBuilderImpl.java @@ -11,6 +11,12 @@ import org.nkjmlab.sorm4j.mapping.extension.SqlParameterSetter; import org.nkjmlab.sorm4j.mapping.extension.TableNameMapper; +/** + * A builder for configuration of or mapper. + * + * @author nkjm + * + */ public class OrmConfigStoreBuilderImpl implements OrmConfigStoreBuilder { public static final ColumnFieldMapper DEFAULT_COLUMN_FIELD_MAPPER = diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConnectionImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConnectionImpl.java index 8f229de0..ac9f41a5 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConnectionImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmConnectionImpl.java @@ -12,8 +12,8 @@ * A database connection with object-relation mapping function. The main class for the ORMapper * engine. * - * A OrmMapper instance wraps a {@link java.sql.Connection} object. OrmMapper instances are not - * thread safe, in particular because {@link java.sql.Connection} objects are not thread safe. + * This instance wraps a {@link java.sql.Connection} object. OrmMapper instances are not thread + * safe, in particular because {@link java.sql.Connection} objects are not thread safe. * * @author nkjm * diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/SormImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/SormImpl.java index 2f6f9920..6accceb7 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/SormImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/SormImpl.java @@ -10,6 +10,12 @@ import org.nkjmlab.sorm4j.SormFactory; import org.nkjmlab.sorm4j.TypedOrmConnection; +/** + * An entry point of object-relation mapping. + * + * @author nkjm + * + */ public final class SormImpl implements Sorm { // private static final org.slf4j.Logger log = org.nkjmlab.sorm4j.util.LoggerFactory.getLogger(); diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java index de367635..2fcbf26a 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java @@ -8,6 +8,17 @@ import org.nkjmlab.sorm4j.TypedOrmConnection; import org.nkjmlab.sorm4j.util.Try; +/** + * A database connection with object-relation mapping function with type. The main class for the ORMapper + * engine. + * + * This instance wraps a {@link java.sql.Connection} object. OrmMapper instances are not + * thread safe, in particular because {@link java.sql.Connection} objects are not thread safe. + * + * @author nkjm + * + */ + public class TypedOrmConnectionImpl extends TypedOrmMapperImpl implements TypedOrmConnection { // private static final org.slf4j.Logger log = org.nkjmlab.sorm4j.util.LoggerFactory.getLogger(); diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java index c238624f..c5c0ccf4 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java @@ -10,7 +10,7 @@ import org.nkjmlab.sorm4j.result.LazyResultSet; import org.nkjmlab.sorm4j.sqlstatement.SqlStatement; -public class TypedOrmMapperImpl extends AbstractOrmMapper implements TypedOrmMapper { +class TypedOrmMapperImpl extends AbstractOrmMapper implements TypedOrmMapper { private Class objectClass; diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ColumnFieldMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ColumnFieldMapper.java index 2b771b5f..3583ec4b 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ColumnFieldMapper.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ColumnFieldMapper.java @@ -8,7 +8,13 @@ import org.nkjmlab.sorm4j.mapping.FieldName; -public interface ColumnFieldMapper extends OrmExtension { +/** + * A mapper from column to field name. + * + * @author nkjm + * + */ +public interface ColumnFieldMapper { List getAutoGeneratedColumns(DatabaseMetaData metaData, String tableName) throws SQLException; diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java index 6a52b6c5..773cd4f6 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java @@ -14,7 +14,7 @@ import org.nkjmlab.sorm4j.util.StringUtils; /** - * Defines how a class or field name should be mapped to a table or column. + * Defines how column name should be mapped to field. */ public final class DefaultColumnFieldMapper implements ColumnFieldMapper { private static final org.slf4j.Logger log = org.nkjmlab.sorm4j.util.LoggerFactory.getLogger(); diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java index 81869aa2..35b59018 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java @@ -12,6 +12,11 @@ import org.nkjmlab.sorm4j.mapping.TableName; import org.nkjmlab.sorm4j.util.StringUtils; +/** + * Defines how a class or candidates of table name should be mapped to a valid table name exists on + * database. + */ + public final class DefaultTableNameMapper implements TableNameMapper { diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/OrmExtension.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/OrmExtension.java deleted file mode 100644 index fe4b9e65..00000000 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/OrmExtension.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.nkjmlab.sorm4j.mapping.extension; - -public interface OrmExtension { - -} diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java index 1a109a11..23876ee1 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java @@ -6,7 +6,7 @@ import java.util.Map; -public interface ResultSetConverter extends OrmExtension { +public interface ResultSetConverter { List toObjectsByClasses(ResultSet resultSet, List> setterParameterTypes) throws SQLException; diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/SqlParameterSetter.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/SqlParameterSetter.java index 6e84aaf6..b2647592 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/SqlParameterSetter.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/SqlParameterSetter.java @@ -9,7 +9,7 @@ * @author nkjm * */ -public interface SqlParameterSetter extends OrmExtension { +public interface SqlParameterSetter { /** * Sets parameters in the given prepared statement. i.e. Convert From Java To Sql. * diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java index 590ba5ed..5e1c43cd 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java @@ -4,7 +4,13 @@ import java.sql.SQLException; import org.nkjmlab.sorm4j.mapping.TableName; -public interface TableNameMapper extends OrmExtension { +/** + * A mapper from class or table name to a valid table name exists on database. + * + * @author nkjm + * + */ +public interface TableNameMapper { /** * Get table name corresponding with the object class. diff --git a/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SelectBuilder.java b/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SelectBuilder.java index f09f8d17..e96ddb45 100644 --- a/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SelectBuilder.java +++ b/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SelectBuilder.java @@ -4,6 +4,12 @@ import java.util.stream.Collectors; import org.nkjmlab.sorm4j.TypedOrmConnection; +/** + * An builder of select SQL. + * + * @author nkjm + * + */ public class SelectBuilder { private SelectBuilder() {} @@ -172,6 +178,11 @@ public SelectBuilder where(String expr) { } + + /** + * Value object represents conditions of where clause or having clause. + */ + public static class Condition { private final Object condition; @@ -194,6 +205,10 @@ public String toString() { return condition.toString(); } } + + /** + * Value object for order by clause. + */ public static class OrderBy { private final String column; private final String ascOrDesc; diff --git a/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithNamedParameters.java b/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithNamedParameters.java index b8065961..9847fa79 100644 --- a/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithNamedParameters.java +++ b/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithNamedParameters.java @@ -8,6 +8,13 @@ import java.util.TreeMap; import java.util.stream.Collectors; +/** + * SQL with named parameters. The instance could be convert to {@link SqlStatement}.The class could + * treat {@link List} parameter. + * + * @author nkjm + * + */ public final class SqlWithNamedParameters { private final String sql; diff --git a/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithOrderedParameters.java b/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithOrderedParameters.java index c303adea..21cdcc25 100644 --- a/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithOrderedParameters.java +++ b/src/main/java/org/nkjmlab/sorm4j/sqlstatement/SqlWithOrderedParameters.java @@ -5,6 +5,13 @@ import java.util.Arrays; import java.util.List; +/** + * SQL with ordered parameters. The instance could be convert to {@link SqlStatement}. The class + * could treat {@link List} parameter. + * + * @author nkjm + * + */ public final class SqlWithOrderedParameters { private final String sql; From 5b9949fe3a65ebfa4d5cdb7ee7bc5831c7ecbf9d Mon Sep 17 00:00:00 2001 From: Yuu Nakajima Date: Fri, 5 Mar 2021 13:57:32 +0900 Subject: [PATCH 3/6] Remove redundant interface --- src/main/java/org/nkjmlab/sorm4j/OrmMapper.java | 7 ------- src/main/java/org/nkjmlab/sorm4j/TypedOrmMapper.java | 8 -------- .../java/org/nkjmlab/sorm4j/mapping/OrmMapper.java | 12 ++++++++++++ .../org/nkjmlab/sorm4j/mapping/TypedOrmMapper.java | 11 +++++++++++ 4 files changed, 23 insertions(+), 15 deletions(-) delete mode 100644 src/main/java/org/nkjmlab/sorm4j/OrmMapper.java delete mode 100644 src/main/java/org/nkjmlab/sorm4j/TypedOrmMapper.java create mode 100644 src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapper.java create mode 100644 src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapper.java diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmMapper.java b/src/main/java/org/nkjmlab/sorm4j/OrmMapper.java deleted file mode 100644 index f02253eb..00000000 --- a/src/main/java/org/nkjmlab/sorm4j/OrmMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.nkjmlab.sorm4j; - -public interface OrmMapper extends OrmReader, OrmUpdater, OrmMapReader, SqlExecutor { - - - -} diff --git a/src/main/java/org/nkjmlab/sorm4j/TypedOrmMapper.java b/src/main/java/org/nkjmlab/sorm4j/TypedOrmMapper.java deleted file mode 100644 index d9ace628..00000000 --- a/src/main/java/org/nkjmlab/sorm4j/TypedOrmMapper.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.nkjmlab.sorm4j; - -public interface TypedOrmMapper - extends TypeOrmReader, TypedOrmUpdater, OrmMapReader, SqlExecutor { - - String getTableName(); - -} diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapper.java new file mode 100644 index 00000000..0d25bc12 --- /dev/null +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapper.java @@ -0,0 +1,12 @@ +package org.nkjmlab.sorm4j.mapping; + +import org.nkjmlab.sorm4j.OrmMapReader; +import org.nkjmlab.sorm4j.OrmReader; +import org.nkjmlab.sorm4j.OrmUpdater; +import org.nkjmlab.sorm4j.SqlExecutor; + +interface OrmMapper extends OrmReader, OrmUpdater, OrmMapReader, SqlExecutor { + + + +} diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapper.java new file mode 100644 index 00000000..30576fa4 --- /dev/null +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapper.java @@ -0,0 +1,11 @@ +package org.nkjmlab.sorm4j.mapping; + +import org.nkjmlab.sorm4j.OrmMapReader; +import org.nkjmlab.sorm4j.SqlExecutor; +import org.nkjmlab.sorm4j.TypedOrmReader; +import org.nkjmlab.sorm4j.TypedOrmUpdater; + +interface TypedOrmMapper + extends TypedOrmReader, TypedOrmUpdater, OrmMapReader, SqlExecutor { + +} From 801f0162405b93c73a41da9c6fb3bb89eaa99b05 Mon Sep 17 00:00:00 2001 From: Yuu Nakajima Date: Fri, 5 Mar 2021 13:57:53 +0900 Subject: [PATCH 4/6] Add javadoc comments --- .../org/nkjmlab/sorm4j/ConnectionSource.java | 6 +++ .../nkjmlab/sorm4j/OrmConfigStoreBuilder.java | 7 +++ .../org/nkjmlab/sorm4j/OrmConnection.java | 10 +++- .../java/org/nkjmlab/sorm4j/OrmException.java | 2 +- .../java/org/nkjmlab/sorm4j/OrmMapReader.java | 7 +++ .../java/org/nkjmlab/sorm4j/OrmReader.java | 5 +- .../java/org/nkjmlab/sorm4j/OrmUpdater.java | 7 ++- src/main/java/org/nkjmlab/sorm4j/Sorm.java | 19 +++++++- .../java/org/nkjmlab/sorm4j/SqlExecutor.java | 6 +++ .../nkjmlab/sorm4j/TransactionFunction.java | 6 +++ .../nkjmlab/sorm4j/TypedOrmConnection.java | 14 ++++-- ...TypeOrmReader.java => TypedOrmReader.java} | 9 +++- .../org/nkjmlab/sorm4j/TypedOrmUpdater.java | 7 +++ .../nkjmlab/sorm4j/mapping/OrmMapperImpl.java | 1 - .../mapping/TypedOrmConnectionImpl.java | 12 +++-- .../sorm4j/mapping/TypedOrmMapperImpl.java | 9 +--- .../extension/DefaultColumnFieldMapper.java | 6 ++- .../extension/DefaultResultSetConverter.java | 6 +++ .../extension/DefaultSqlParameterSetter.java | 7 +++ .../extension/DefaultTableNameMapper.java | 6 ++- .../mapping/extension/ResultSetConverter.java | 6 +++ .../mapping/extension/TableNameMapper.java | 2 +- .../sorm4j/mapping/TableMappingTest.java | 5 +- .../sorm4j/performance/PerformanceH2.java | 16 +++---- .../sf/persist/tests/common/TestSimple.java | 47 ++++++++++--------- .../tests/product/framework/BeanTest.java | 20 ++++---- .../sf/persist/tests/product/h2/TestH2.java | 10 ++-- .../tests/product/mysql/TestMysql.java | 10 ++-- 28 files changed, 186 insertions(+), 82 deletions(-) rename src/main/java/org/nkjmlab/sorm4j/{TypeOrmReader.java => TypedOrmReader.java} (78%) diff --git a/src/main/java/org/nkjmlab/sorm4j/ConnectionSource.java b/src/main/java/org/nkjmlab/sorm4j/ConnectionSource.java index 94f1d1d5..a84671e7 100644 --- a/src/main/java/org/nkjmlab/sorm4j/ConnectionSource.java +++ b/src/main/java/org/nkjmlab/sorm4j/ConnectionSource.java @@ -4,6 +4,12 @@ import java.sql.SQLException; import javax.sql.DataSource; +/** + * A source for jdbc connection. + * + * @author nkjm + * + */ public interface ConnectionSource { Connection getConnection() throws SQLException; diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java b/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java index afa82580..07364b4b 100644 --- a/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java +++ b/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java @@ -7,6 +7,13 @@ import org.nkjmlab.sorm4j.mapping.extension.TableNameMapper; +/** + * Builder for {@link OrmConfigStore}. An instance of the class should be get from + * {@link SormFactory}. + * + * @author nkjm + * + */ public interface OrmConfigStoreBuilder { OrmConfigStore build(); diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmConnection.java b/src/main/java/org/nkjmlab/sorm4j/OrmConnection.java index 93c96ad5..a24acfc3 100644 --- a/src/main/java/org/nkjmlab/sorm4j/OrmConnection.java +++ b/src/main/java/org/nkjmlab/sorm4j/OrmConnection.java @@ -5,7 +5,15 @@ import java.util.function.Function; import org.nkjmlab.sorm4j.mapping.OrmConfigStore; -public interface OrmConnection extends OrmMapper, TransactionFunction, Closeable, AutoCloseable { +/** + * Main API for object relation mapping. The api consists of {@link OrmReader}, {@link OrmUpdater}, + * {@link OrmMapReader}, {@link SqlExecutor}and {@link TransactionFunction}. + * + * @author nkjm + * + */ +public interface OrmConnection extends OrmReader, OrmUpdater, OrmMapReader, SqlExecutor, + TransactionFunction, Closeable, AutoCloseable { void runTransaction(Consumer handler); diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmException.java b/src/main/java/org/nkjmlab/sorm4j/OrmException.java index 6f605c6e..5ffcaf01 100644 --- a/src/main/java/org/nkjmlab/sorm4j/OrmException.java +++ b/src/main/java/org/nkjmlab/sorm4j/OrmException.java @@ -1,7 +1,7 @@ package org.nkjmlab.sorm4j; /** - * Represents an exception thrown by Sorm. + * Represents an exception thrown by Sorm4j. */ public final class OrmException extends RuntimeException { diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmMapReader.java b/src/main/java/org/nkjmlab/sorm4j/OrmMapReader.java index 68121d66..4f02a306 100644 --- a/src/main/java/org/nkjmlab/sorm4j/OrmMapReader.java +++ b/src/main/java/org/nkjmlab/sorm4j/OrmMapReader.java @@ -9,6 +9,13 @@ import org.nkjmlab.sorm4j.result.LazyResultSet; import org.nkjmlab.sorm4j.sqlstatement.SqlStatement; + +/** + * A interface for getting result of query as {@link Map}. + * + * @author nkjm + * + */ public interface OrmMapReader { Map readMapOne(SqlStatement sql); diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmReader.java b/src/main/java/org/nkjmlab/sorm4j/OrmReader.java index c24f8277..9588754f 100644 --- a/src/main/java/org/nkjmlab/sorm4j/OrmReader.java +++ b/src/main/java/org/nkjmlab/sorm4j/OrmReader.java @@ -7,10 +7,7 @@ import org.nkjmlab.sorm4j.sqlstatement.SqlStatement; /** - * The main interface of Reading functions of ORM reader. - * - * This interface based on Persist.java + * The interface of reading functions of object-relation mapping. * * @author nkjm * diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmUpdater.java b/src/main/java/org/nkjmlab/sorm4j/OrmUpdater.java index f626b18e..172cf5d9 100644 --- a/src/main/java/org/nkjmlab/sorm4j/OrmUpdater.java +++ b/src/main/java/org/nkjmlab/sorm4j/OrmUpdater.java @@ -3,7 +3,12 @@ import java.util.List; import org.nkjmlab.sorm4j.result.InsertResult; - +/** + * A interface for updating database. + * + * @author nkjm + * + */ public interface OrmUpdater { int[] delete(List objects); diff --git a/src/main/java/org/nkjmlab/sorm4j/Sorm.java b/src/main/java/org/nkjmlab/sorm4j/Sorm.java index 47705714..ca6d2168 100644 --- a/src/main/java/org/nkjmlab/sorm4j/Sorm.java +++ b/src/main/java/org/nkjmlab/sorm4j/Sorm.java @@ -3,7 +3,12 @@ import java.sql.Connection; import org.nkjmlab.sorm4j.mapping.OrmConfigStore; - +/** + * An interface of main entry point of object-relation mapping. + * + * @author nkjm + * + */ public interface Sorm { OrmConnection beginTransaction(); @@ -55,6 +60,12 @@ void runTransaction(Class objectClass, int isolationLevel, void runWithJdbcConnection(OrmConsumerHandler handler); + /** + * Interface for object-relation handling without a return value. e.g. + * {@link Sorm#run(OrmConsumerHandler)}. + * + * @param + */ @FunctionalInterface public interface OrmConsumerHandler { @@ -62,6 +73,12 @@ public interface OrmConsumerHandler { } + /** + * Interface for object-relation handling with a return value. e.g. + * {@link Sorm#execute(OrmConsumerHandler)}. + * + * @param + */ @FunctionalInterface public interface OrmFunctionHandler { diff --git a/src/main/java/org/nkjmlab/sorm4j/SqlExecutor.java b/src/main/java/org/nkjmlab/sorm4j/SqlExecutor.java index 8151030a..01fa3c15 100644 --- a/src/main/java/org/nkjmlab/sorm4j/SqlExecutor.java +++ b/src/main/java/org/nkjmlab/sorm4j/SqlExecutor.java @@ -4,6 +4,12 @@ import java.sql.ResultSet; import org.nkjmlab.sorm4j.sqlstatement.SqlStatement; +/** + * A interface for executing SQL with parameters. + * + * @author nkjm + * + */ public interface SqlExecutor { boolean execute(String sql, Object... parameters); diff --git a/src/main/java/org/nkjmlab/sorm4j/TransactionFunction.java b/src/main/java/org/nkjmlab/sorm4j/TransactionFunction.java index 7e7a67d6..38054225 100644 --- a/src/main/java/org/nkjmlab/sorm4j/TransactionFunction.java +++ b/src/main/java/org/nkjmlab/sorm4j/TransactionFunction.java @@ -1,5 +1,11 @@ package org.nkjmlab.sorm4j; +/** + * Functions of handling transaction. + * + * @author nkjm + * + */ public interface TransactionFunction { /** diff --git a/src/main/java/org/nkjmlab/sorm4j/TypedOrmConnection.java b/src/main/java/org/nkjmlab/sorm4j/TypedOrmConnection.java index da4d25a4..d90f2155 100644 --- a/src/main/java/org/nkjmlab/sorm4j/TypedOrmConnection.java +++ b/src/main/java/org/nkjmlab/sorm4j/TypedOrmConnection.java @@ -5,8 +5,16 @@ import java.util.function.Function; import org.nkjmlab.sorm4j.mapping.OrmConfigStore; -public interface TypedOrmConnection - extends TypedOrmMapper, TransactionFunction, Closeable, AutoCloseable { +/** + * Main API for typed object relation mapping. The api consists of {@link TypedOrmReader}, + * {@link TypedOrmUpdater}, {@link OrmMapReader}, {@link SqlExecutor}and + * {@link TransactionFunction}. + * + * @author nkjm + * + */ +public interface TypedOrmConnection extends TypedOrmReader, TypedOrmUpdater, OrmMapReader, + SqlExecutor, TransactionFunction, Closeable, AutoCloseable { void runTransaction(Consumer> handler); @@ -14,6 +22,6 @@ public interface TypedOrmConnection OrmConfigStore getConfigStore(); - + String getTableName(); } diff --git a/src/main/java/org/nkjmlab/sorm4j/TypeOrmReader.java b/src/main/java/org/nkjmlab/sorm4j/TypedOrmReader.java similarity index 78% rename from src/main/java/org/nkjmlab/sorm4j/TypeOrmReader.java rename to src/main/java/org/nkjmlab/sorm4j/TypedOrmReader.java index c97b3abe..ad8545bc 100644 --- a/src/main/java/org/nkjmlab/sorm4j/TypeOrmReader.java +++ b/src/main/java/org/nkjmlab/sorm4j/TypedOrmReader.java @@ -4,7 +4,14 @@ import org.nkjmlab.sorm4j.result.LazyResultSet; import org.nkjmlab.sorm4j.sqlstatement.SqlStatement; -public interface TypeOrmReader { +/** + * The typed interface of reading functions of object-relation mapping. + * + * @author nkjm + * + */ + +public interface TypedOrmReader { List readAll(); diff --git a/src/main/java/org/nkjmlab/sorm4j/TypedOrmUpdater.java b/src/main/java/org/nkjmlab/sorm4j/TypedOrmUpdater.java index 92237610..dd4a2a3b 100644 --- a/src/main/java/org/nkjmlab/sorm4j/TypedOrmUpdater.java +++ b/src/main/java/org/nkjmlab/sorm4j/TypedOrmUpdater.java @@ -3,6 +3,13 @@ import java.util.List; import org.nkjmlab.sorm4j.result.InsertResult; +/** + * A typed interface for updating database. + * + * @author nkjm + * + */ + public interface TypedOrmUpdater { int[] delete(List objects); diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapperImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapperImpl.java index 4d478f56..13300ef6 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapperImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapperImpl.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Map; import java.util.function.Function; -import org.nkjmlab.sorm4j.OrmMapper; import org.nkjmlab.sorm4j.result.InsertResult; import org.nkjmlab.sorm4j.result.LazyResultSet; import org.nkjmlab.sorm4j.sqlstatement.SqlStatement; diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java index 2fcbf26a..bef7daf7 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmConnectionImpl.java @@ -9,11 +9,11 @@ import org.nkjmlab.sorm4j.util.Try; /** - * A database connection with object-relation mapping function with type. The main class for the ORMapper - * engine. + * A database connection with object-relation mapping function with type. The main class for the + * ORMapper engine. * - * This instance wraps a {@link java.sql.Connection} object. OrmMapper instances are not - * thread safe, in particular because {@link java.sql.Connection} objects are not thread safe. + * This instance wraps a {@link java.sql.Connection} object. OrmMapper instances are not thread + * safe, in particular because {@link java.sql.Connection} objects are not thread safe. * * @author nkjm * @@ -29,6 +29,10 @@ public TypedOrmConnectionImpl(Class objectClass, Connection connection, super(objectClass, connection, options); } + @Override + public String getTableName() { + return getTableMapping(objectClass).getTableName(); + } @Override public void close() { diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java index c5c0ccf4..2bfec212 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/TypedOrmMapperImpl.java @@ -5,26 +5,19 @@ import java.util.List; import java.util.Map; import java.util.function.Function; -import org.nkjmlab.sorm4j.TypedOrmMapper; import org.nkjmlab.sorm4j.result.InsertResult; import org.nkjmlab.sorm4j.result.LazyResultSet; import org.nkjmlab.sorm4j.sqlstatement.SqlStatement; class TypedOrmMapperImpl extends AbstractOrmMapper implements TypedOrmMapper { - private Class objectClass; + protected Class objectClass; public TypedOrmMapperImpl(Class objectClass, Connection connection, OrmConfigStore options) { super(connection, options); this.objectClass = objectClass; } - - @Override - public String getTableName() { - return getTableMapping(objectClass).getTableName(); - } - @Override public T readByPrimaryKey(Object... primaryKeyValues) { return readByPrimaryKeyAux(objectClass, primaryKeyValues); diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java index 773cd4f6..2a4798a2 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultColumnFieldMapper.java @@ -14,8 +14,12 @@ import org.nkjmlab.sorm4j.util.StringUtils; /** - * Defines how column name should be mapped to field. + * Default implementation of {@link ColumnFieldMapper} + * + * @author nkjm + * */ + public final class DefaultColumnFieldMapper implements ColumnFieldMapper { private static final org.slf4j.Logger log = org.nkjmlab.sorm4j.util.LoggerFactory.getLogger(); diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultResultSetConverter.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultResultSetConverter.java index 33927ca7..2aa9e4f1 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultResultSetConverter.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultResultSetConverter.java @@ -10,6 +10,12 @@ import java.util.Map; import java.util.Optional; +/** + * Default implementation of {@link ResultSetConverter} + * + * @author nkjm + * + */ public final class DefaultResultSetConverter implements ResultSetConverter { diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultSqlParameterSetter.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultSqlParameterSetter.java index a0b8982a..3488289b 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultSqlParameterSetter.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultSqlParameterSetter.java @@ -9,6 +9,13 @@ import java.sql.Time; import java.sql.Timestamp; +/** + * Default implementation of {@link SqlParameterSetter} + * + * @author nkjm + * + */ + public final class DefaultSqlParameterSetter implements SqlParameterSetter { // private static org.slf4j.Logger log = org.nkjmlab.sorm4j.util.LoggerFactory.getLogger(); diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java index 35b59018..dc8d9c40 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/DefaultTableNameMapper.java @@ -13,8 +13,10 @@ import org.nkjmlab.sorm4j.util.StringUtils; /** - * Defines how a class or candidates of table name should be mapped to a valid table name exists on - * database. + * Default implementation of {@link TableNameMapper} + * + * @author nkjm + * */ public final class DefaultTableNameMapper implements TableNameMapper { diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java index 23876ee1..6cd6da96 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/ResultSetConverter.java @@ -6,6 +6,12 @@ import java.util.Map; +/** + * Convert {@link ResultSet} from database to specified objects. + * + * @author nkjm + * + */ public interface ResultSetConverter { List toObjectsByClasses(ResultSet resultSet, List> setterParameterTypes) diff --git a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java index 5e1c43cd..b01deeb8 100644 --- a/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java +++ b/src/main/java/org/nkjmlab/sorm4j/mapping/extension/TableNameMapper.java @@ -5,7 +5,7 @@ import org.nkjmlab.sorm4j.mapping.TableName; /** - * A mapper from class or table name to a valid table name exists on database. + * A mapper from a class or candidates of table name to a valid table name exists on database. * * @author nkjm * diff --git a/src/test/java/org/nkjmlab/sorm4j/mapping/TableMappingTest.java b/src/test/java/org/nkjmlab/sorm4j/mapping/TableMappingTest.java index b4227c3b..c232c43b 100644 --- a/src/test/java/org/nkjmlab/sorm4j/mapping/TableMappingTest.java +++ b/src/test/java/org/nkjmlab/sorm4j/mapping/TableMappingTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.nkjmlab.sorm4j.Sorm; -import org.nkjmlab.sorm4j.TypedOrmMapper; +import org.nkjmlab.sorm4j.TypedOrmConnection; import org.nkjmlab.sorm4j.util.Guest; import org.nkjmlab.sorm4j.util.Location; import org.nkjmlab.sorm4j.util.Player; @@ -105,7 +105,8 @@ void testCol() { }); } - public static TableMapping getTableMapping(TypedOrmMapper conn, Class objectClass) { + public static TableMapping getTableMapping(TypedOrmConnection conn, + Class objectClass) { return ((AbstractOrmMapper) conn).getTableMapping(objectClass); } diff --git a/src/test/java/org/nkjmlab/sorm4j/performance/PerformanceH2.java b/src/test/java/org/nkjmlab/sorm4j/performance/PerformanceH2.java index afe2c444..b4facbb6 100644 --- a/src/test/java/org/nkjmlab/sorm4j/performance/PerformanceH2.java +++ b/src/test/java/org/nkjmlab/sorm4j/performance/PerformanceH2.java @@ -19,7 +19,7 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.nkjmlab.sorm4j.OrmMapper; +import org.nkjmlab.sorm4j.OrmConnection; import org.nkjmlab.sorm4j.SormFactory; import org.nkjmlab.sorm4j.util.DataSourceHelper; import org.sql2o.Sql2o; @@ -105,7 +105,7 @@ public void run() { private void dropAndCreateTable() { try (Connection connection = connectionHelper.getConnection()) { - OrmMapper orm = SormFactory.getOrmConnection(connection); + OrmConnection orm = SormFactory.getOrmConnection(connection); connection.createStatement().execute("drop table if exists all_types"); connection.createStatement().execute( "create table if not exists all_types ( int_col int, boolean_col boolean, tinyint_col tinyint, smallint_col smallint, bigint_col bigint, decimal_col decimal, double_col double, real_col real, time_col time, date_col date, timestamp_col timestamp, binary_col binary, blob_col blob, other_col other, uuid_col uuid, varchar_col varchar, varchar_ignorecase_col varchar_ignorecase, char_col char, clob_col clob, id int auto_increment primary key )"); @@ -320,7 +320,7 @@ private void execJdbcSingleInsert(String sql, AllTypes a) { private void profileReadSingleByPrimaryKey() { try (Connection connection = connectionHelper.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(connection); + OrmConnection persist = SormFactory.getOrmConnection(connection); // find a single id to be used by select by primary key int id = persist.readFirst(int.class, "select min(id) from all_types"); @@ -401,7 +401,7 @@ private void execPersistSingleRead(int id) { private void execOrmSingleRead(int id) { try (Connection connection = connectionHelper.getConnection()) { - OrmMapper orm = SormFactory.getOrmConnection(connection); + OrmConnection orm = SormFactory.getOrmConnection(connection); orm.readByPrimaryKey(AllTypes.class, id); } catch (Exception e) { e.printStackTrace(); @@ -410,7 +410,7 @@ private void execOrmSingleRead(int id) { private void execOrmMapSingleRead(String sql, int id) { try (Connection connection = connectionHelper.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(connection); + OrmConnection persist = SormFactory.getOrmConnection(connection); persist.readMapFirst(sql, id); } catch (Exception e) { e.printStackTrace(); @@ -480,7 +480,7 @@ private void execSql2oReadAll(Sql2o sql2o, String sql) { private void execOrmReadListAll(String sql) { Monitor mon = MonitorFactory.start("[" + mode + "]" + "[read list all] orm"); try (Connection connection = connectionHelper.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(connection); + OrmConnection persist = SormFactory.getOrmConnection(connection); persist.readAll(AllTypes.class); } catch (Exception e) { e.printStackTrace(); @@ -491,7 +491,7 @@ private void execOrmReadListAll(String sql) { private void execOrmReadListAllLazy(String sql) { Monitor mon = MonitorFactory.start("[" + mode + "]" + "[read list all lazy] orm"); try (Connection connection = connectionHelper.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(connection); + OrmConnection persist = SormFactory.getOrmConnection(connection); persist.readAllLazy(AllTypes.class).stream().collect(Collectors.toList()); } catch (Exception e) { e.printStackTrace(); @@ -502,7 +502,7 @@ private void execOrmReadListAllLazy(String sql) { private void execOrmMapReadListAll(String sql) { Monitor mon = MonitorFactory.start("[" + mode + "]" + "[read list all] orm map"); try (Connection connection = connectionHelper.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(connection); + OrmConnection persist = SormFactory.getOrmConnection(connection); persist.readMapList("select * from all_types"); } catch (Exception e) { e.printStackTrace(); diff --git a/src/test/java/repackage/net/sf/persist/tests/common/TestSimple.java b/src/test/java/repackage/net/sf/persist/tests/common/TestSimple.java index 18b2d67f..a14f5907 100644 --- a/src/test/java/repackage/net/sf/persist/tests/common/TestSimple.java +++ b/src/test/java/repackage/net/sf/persist/tests/common/TestSimple.java @@ -21,7 +21,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.nkjmlab.sorm4j.OrmMapper; +import org.nkjmlab.sorm4j.OrmConnection; import org.nkjmlab.sorm4j.SormFactory; import org.nkjmlab.sorm4j.TypedOrmConnection; import org.nkjmlab.sorm4j.result.InsertResult; @@ -78,7 +78,7 @@ public static Simple buildSimple() { @Test public void testNoTable() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple simple = buildSimple(); simpleOrMapper.insert(simple); @@ -93,7 +93,7 @@ public void testNoTable() throws SQLException { @Test public void testExecuteUpdate() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple createdSimple = buildSimple(); @@ -123,7 +123,8 @@ public void testExecuteUpdate() throws SQLException { @Test public void testExecuteUpdateAutoGeneratedKeys() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - TypedOrmConnection simpleOrMapper = SormFactory.getTypedOrmConnection(conn, Simple.class); + TypedOrmConnection simpleOrMapper = + SormFactory.getTypedOrmConnection(conn, Simple.class); simpleOrMapper.insert(buildSimple()); @@ -157,7 +158,7 @@ public void testExecuteUpdateAutoGeneratedKeys() throws SQLException { @Test public void testSetAutoGeneratedKeys() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple s = TestSimple.buildSimple(); InsertResult result = simpleOrMapper.insertAndGet(s); long id = simpleOrMapper.readFirst(long.class, "select id from simple where long_col=?", @@ -175,7 +176,7 @@ public void testSetAutoGeneratedKeys() throws SQLException { @Test public void testReturnNativeTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple simple = buildSimple(); simpleOrMapper.insert(simple); @@ -192,7 +193,7 @@ public void testReturnNativeTypes() throws SQLException { @Test public void testBatch() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple simple1 = buildSimple(); Simple simple2 = buildSimple(); @@ -235,7 +236,7 @@ public void testBatch() throws SQLException { @Test public void testObject() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple simpleInsert = buildSimple(); simpleOrMapper.insert(simpleInsert); @@ -271,7 +272,7 @@ private static String randomString(int i) { @Test public void testObjectList() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple simple1 = buildSimple(); Simple simple2 = buildSimple(); @@ -299,7 +300,7 @@ public void testObjectList() throws SQLException { @Test public void testMap() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Simple simple = buildSimple(); simpleOrMapper.insert(simple); @@ -319,7 +320,7 @@ public void testMap() throws SQLException { @Test public void testMapList() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.executeUpdate("DELETE FROM SIMPLE"); Simple simple1 = buildSimple(); @@ -360,7 +361,7 @@ public void testMapList() throws SQLException { public void testMappingSimple01() { // Simple01 specifies an invalid column name but field is used. try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); long id = simpleOrMapper.readFirst(long.class, "select id from simple limit 1"); simpleOrMapper.readByPrimaryKey(Simple01.class, id); @@ -373,7 +374,7 @@ public void testMappingSimple01() { public void testMappingSimple02() { // Simple02 specifies an invalid table try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); long id = simpleOrMapper.readFirst(long.class, "select id from simple limit 1"); simpleOrMapper.readByPrimaryKey(Simple02.class, id); @@ -388,7 +389,7 @@ public void testMappingSimple02() { public void testMappingSimple03() { // Simple03 lacks a field try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); simpleOrMapper.readByPrimaryKey(Simple03.class, 1); failBecauseExceptionWasNotThrown(Exception.class); @@ -402,7 +403,7 @@ public void testMappingSimple03() { public void testMappingSimple04() { // Simple04 has incompatible setter try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); Simple04 ret = simpleOrMapper.readByPrimaryKey(Simple04.class, 1); fail("Object with incompatible getter and setter did not trigger exception"); @@ -417,7 +418,7 @@ public void testMappingSimple04() { public void testMappingSimple05() { // Simple05 doesn't specify a table name and guessed names won't work try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); simpleOrMapper.readByPrimaryKey(Simple05.class, 1); fail("Object with invalid table name did not trigger exception"); @@ -430,7 +431,7 @@ public void testMappingSimple05() { public void testMappingSimple06() { // Simple06 has different annotations for getter and setter try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); simpleOrMapper.readByPrimaryKey(Simple06.class, 1); fail("Object without getter and setter did not trigger exception"); @@ -443,7 +444,7 @@ public void testMappingSimple06() { public void testMappingSimple07() { // Simple07 doesn't have a getter and setter for string_col try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); simpleOrMapper.readByPrimaryKey(Simple07.class, 1); fail("Object without getter and setter did not trigger exception"); @@ -456,7 +457,7 @@ public void testMappingSimple07() { public void testMappingSimple08() { // Simple07 doesn't have a getter and setter for string_col try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); simpleOrMapper.readByPrimaryKey(Simple08.class, 1); fail("Object with conflicting annotations did not trigger exception"); @@ -469,7 +470,7 @@ public void testMappingSimple08() { public void testMappingSimple10() { // Simple10 has setter with no parameters try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.readByPrimaryKey(Simple10.class, 1); } catch (Exception e) { fail(); @@ -480,7 +481,7 @@ public void testMappingSimple10() { public void testMappingSimple11() { // Simple10 has setter with no parameters try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(new Simple11()); } catch (Exception e) { assertThat(e.getCause().getMessage()).contains("does not match any field"); @@ -491,7 +492,7 @@ public void testMappingSimple11() { public void testMappingSimple12() { // Simple10 has setter with no parameters try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(new Simple12(1)); simpleOrMapper.readAll(Simple12.class); } catch (Exception e) { @@ -502,7 +503,7 @@ public void testMappingSimple12() { @Test public void testMapping() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); simpleOrMapper.insert(buildSimple()); long id = simpleOrMapper.readFirst(long.class, "select id from simple limit 1"); // Simple09 has getter which returns void diff --git a/src/test/java/repackage/net/sf/persist/tests/product/framework/BeanTest.java b/src/test/java/repackage/net/sf/persist/tests/product/framework/BeanTest.java index bd2e9d00..3def63dd 100644 --- a/src/test/java/repackage/net/sf/persist/tests/product/framework/BeanTest.java +++ b/src/test/java/repackage/net/sf/persist/tests/product/framework/BeanTest.java @@ -7,7 +7,7 @@ import java.sql.SQLException; import java.util.List; import java.util.Map; -import org.nkjmlab.sorm4j.OrmMapper; +import org.nkjmlab.sorm4j.OrmConnection; public class BeanTest { @@ -15,7 +15,7 @@ public class BeanTest { private static final org.slf4j.Logger log = org.nkjmlab.sorm4j.util.LoggerFactory.getLogger(); - public static void test(Class caller, OrmMapper persist, BeanMap beanMap) { + public static void test(Class caller, OrmConnection persist, BeanMap beanMap) { Connection connection = persist.getJdbcConnection(); Class cls = DynamicBean.createBeanClass(caller, beanMap); @@ -42,7 +42,7 @@ public static void test(Class caller, OrmMapper persist, BeanMap beanMap) { /** * Perform tests using a bean with non-null values */ - public static void testAll(OrmMapper persist, Class cls, BeanMap beanMap) { + public static void testAll(OrmConnection persist, Class cls, BeanMap beanMap) { Object obj = DynamicBean.createInstance(cls, beanMap, false); BeanTest.testInsert(persist, obj, beanMap); BeanTest.testSelectByFields(persist, obj, beanMap); @@ -53,7 +53,7 @@ public static void testAll(OrmMapper persist, Class cls, BeanMap beanMap) { /** * Perform tests using a bean with null values */ - public static void testAllNull(OrmMapper persist, Class cls, BeanMap beanMap) { + public static void testAllNull(OrmConnection persist, Class cls, BeanMap beanMap) { Object objNull = DynamicBean.createInstance(cls, beanMap, true); BeanTest.testInsert(persist, objNull, beanMap); BeanTest.testSelectByFieldsNull(persist, objNull, beanMap); @@ -64,7 +64,7 @@ public static void testAllNull(OrmMapper persist, Class cls, BeanMap beanMap) /** * tests insertion of a bean */ - public static void testInsert(OrmMapper persist, Object obj, BeanMap beanMap) { + public static void testInsert(OrmConnection persist, Object obj, BeanMap beanMap) { Class cls = obj.getClass(); String tableName = dbName(obj.getClass().getSimpleName()); @@ -90,7 +90,7 @@ public static void testInsert(OrmMapper persist, Object obj, BeanMap beanMap) { /** * tests reading with NoTable class */ - public static void testReadNoTable(OrmMapper persist, Object obj, Class clsNoTable) { + public static void testReadNoTable(OrmConnection persist, Object obj, Class clsNoTable) { String tableName = dbName(obj.getClass().getSimpleName()); @@ -108,7 +108,7 @@ public static void testReadNoTable(OrmMapper persist, Object obj, Class clsNo * For each field and each field type, execute a query in the format select * from tableName where * columnName=? */ - public static void testSelectByFields(OrmMapper persist, Object obj, BeanMap beanMap) { + public static void testSelectByFields(OrmConnection persist, Object obj, BeanMap beanMap) { Class cls = obj.getClass(); String tableName = dbName(obj.getClass().getSimpleName()); @@ -150,7 +150,7 @@ public static void testSelectByFields(OrmMapper persist, Object obj, BeanMap bea /** * For each field, execute a query in the format select * from tableName where columnName is null */ - public static void testSelectByFieldsNull(OrmMapper persist, Object obj, BeanMap beanMap) { + public static void testSelectByFieldsNull(OrmConnection persist, Object obj, BeanMap beanMap) { Class cls = obj.getClass(); String tableName = dbName(obj.getClass().getSimpleName()); @@ -181,7 +181,7 @@ public static void testSelectByFieldsNull(OrmMapper persist, Object obj, BeanMap * for each field, and for each field type perform a query in the form select columnName from * tableName */ - public static void testSelectFields(OrmMapper persist, Object obj, BeanMap beanMap, + public static void testSelectFields(OrmConnection persist, Object obj, BeanMap beanMap, boolean useNulls) { String tableName = dbName(obj.getClass().getSimpleName()); @@ -229,7 +229,7 @@ public static void testSelectFields(OrmMapper persist, Object obj, BeanMap beanM /** * perform [select * from tableName] and get the results as a map */ - public static void testSelectMap(OrmMapper persist, Object obj, BeanMap beanMap) { + public static void testSelectMap(OrmConnection persist, Object obj, BeanMap beanMap) { String tableName = dbName(obj.getClass().getSimpleName()); // read list of all data in the table as a map diff --git a/src/test/java/repackage/net/sf/persist/tests/product/h2/TestH2.java b/src/test/java/repackage/net/sf/persist/tests/product/h2/TestH2.java index 426cd255..3aaf0d0d 100644 --- a/src/test/java/repackage/net/sf/persist/tests/product/h2/TestH2.java +++ b/src/test/java/repackage/net/sf/persist/tests/product/h2/TestH2.java @@ -17,7 +17,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.nkjmlab.sorm4j.OrmMapper; +import org.nkjmlab.sorm4j.OrmConnection; import org.nkjmlab.sorm4j.SormFactory; import repackage.net.sf.persist.tests.product.framework.BeanMap; import repackage.net.sf.persist.tests.product.framework.BeanTest; @@ -53,7 +53,7 @@ void beforeEach() throws SQLException {} public void testStringTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Class[] stringTypes = new Class[] {String.class, char[].class, Character[].class}; Class[] clobTypes = @@ -73,7 +73,7 @@ public void testStringTypes() throws SQLException { @Test public void testNumericTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Class[] integerTypes = new Class[] {Integer.class, int.class}; Class[] booleanTypes = new Class[] {Boolean.class, boolean.class}; @@ -102,7 +102,7 @@ public void testNumericTypes() throws SQLException { @Test public void testDatetimeTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); BeanMap beanMap = new BeanMap("DatetimeTypes") .addField(new FieldMap("timeCol").setTypes(java.sql.Time.class)) @@ -118,7 +118,7 @@ public void testDatetimeTypes() throws SQLException { @Test public void testBinaryTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper simpleOrMapper = SormFactory.getOrmConnection(conn); + OrmConnection simpleOrMapper = SormFactory.getOrmConnection(conn); Class[] binaryTypes = new Class[] {byte[].class, Byte[].class, InputStream.class, Blob.class}; diff --git a/src/test/java/repackage/net/sf/persist/tests/product/mysql/TestMysql.java b/src/test/java/repackage/net/sf/persist/tests/product/mysql/TestMysql.java index a8ed5a62..2db0c7cf 100644 --- a/src/test/java/repackage/net/sf/persist/tests/product/mysql/TestMysql.java +++ b/src/test/java/repackage/net/sf/persist/tests/product/mysql/TestMysql.java @@ -15,7 +15,7 @@ import org.h2.jdbcx.JdbcConnectionPool; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.nkjmlab.sorm4j.OrmMapper; +import org.nkjmlab.sorm4j.OrmConnection; import org.nkjmlab.sorm4j.SormFactory; import repackage.net.sf.persist.tests.product.framework.BeanMap; import repackage.net.sf.persist.tests.product.framework.BeanTest; @@ -45,7 +45,7 @@ static void beforAll() { @Test public void testStringTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(conn); + OrmConnection persist = SormFactory.getOrmConnection(conn); Class[] characterTypes = new Class[] {Character.class, char.class, String.class}; Class[] stringTypes = new Class[] {String.class, char[].class, Character[].class}; @@ -71,7 +71,7 @@ public void testStringTypes() throws SQLException { public void testNumericTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(conn); + OrmConnection persist = SormFactory.getOrmConnection(conn); Class[] integerTypes = new Class[] {Integer.class, int.class}; Class[] booleanTypes = new Class[] {Boolean.class, boolean.class}; Class[] byteTypes = new Class[] {Byte.class, byte.class}; @@ -100,7 +100,7 @@ public void testNumericTypes() throws SQLException { @Test public void testDatetimeTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(conn); + OrmConnection persist = SormFactory.getOrmConnection(conn); // not testing timestamp here, it doesn't support null values BeanMap beanMap = new BeanMap("DatetimeTypes") @@ -121,7 +121,7 @@ public void testDatetimeTypes() throws SQLException { @Test public void testBinaryTypes() throws SQLException { try (Connection conn = connectionPool.getConnection()) { - OrmMapper persist = SormFactory.getOrmConnection(conn); + OrmConnection persist = SormFactory.getOrmConnection(conn); Class[] binaryTypes = new Class[] {byte[].class, Byte[].class, InputStream.class, Blob.class}; From 41290cc3b14bccde7ba32225d6b44c47b538b75f Mon Sep 17 00:00:00 2001 From: Yuu Nakajima Date: Fri, 5 Mar 2021 14:01:10 +0900 Subject: [PATCH 5/6] Add javadoc comments --- src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java | 3 +++ src/main/java/org/nkjmlab/sorm4j/Sorm.java | 2 +- src/main/java/org/nkjmlab/sorm4j/SormFactory.java | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java b/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java index 07364b4b..434afd9a 100644 --- a/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java +++ b/src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java @@ -34,6 +34,9 @@ public interface OrmConfigStoreBuilder { OrmConfigStoreBuilder setBatchSizeWithMultiRow(int size); + /** + * Type of how to execute multi-row query. + */ public enum MultiRowProcessorType { SIMPLE_BATCH, MULTI_ROW, MULTI_ROW_AND_BATCH } diff --git a/src/main/java/org/nkjmlab/sorm4j/Sorm.java b/src/main/java/org/nkjmlab/sorm4j/Sorm.java index ca6d2168..1858a350 100644 --- a/src/main/java/org/nkjmlab/sorm4j/Sorm.java +++ b/src/main/java/org/nkjmlab/sorm4j/Sorm.java @@ -4,7 +4,7 @@ import org.nkjmlab.sorm4j.mapping.OrmConfigStore; /** - * An interface of main entry point of object-relation mapping. + * An interface of executing object-relation mapping. * * @author nkjm * diff --git a/src/main/java/org/nkjmlab/sorm4j/SormFactory.java b/src/main/java/org/nkjmlab/sorm4j/SormFactory.java index fc2a7aef..0652b56b 100644 --- a/src/main/java/org/nkjmlab/sorm4j/SormFactory.java +++ b/src/main/java/org/nkjmlab/sorm4j/SormFactory.java @@ -12,6 +12,12 @@ import org.nkjmlab.sorm4j.mapping.SormImpl; import org.nkjmlab.sorm4j.mapping.TypedOrmConnectionImpl; +/** + * Main entry point of Som4j, which is factory for {@link Sorm} object. + * + * @author nkjm + * + */ public class SormFactory { private SormFactory() {}; From 4c928bc9e1950ac0ea996313eab632e682a275f9 Mon Sep 17 00:00:00 2001 From: Yuu Nakajima Date: Fri, 5 Mar 2021 14:05:44 +0900 Subject: [PATCH 6/6] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62015e33..a1a71c45 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ You can get the binary using Maven from [Central Repository](http://mvnrepositor org.nkjmlab sorm4j - 0.9.10 + 1.0.0-rc1 ```