Skip to content

Commit

Permalink
Merge pull request #14 from yuu-nkjm/develop
Browse files Browse the repository at this point in the history
Modify interface
  • Loading branch information
yuu-nkjm authored Mar 5, 2021
2 parents 5ed64e6 + 4c928bc commit 6a9f20a
Show file tree
Hide file tree
Showing 47 changed files with 307 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can get the binary using Maven from [Central Repository](http://mvnrepositor
<dependency>
<groupId>org.nkjmlab</groupId>
<artifactId>sorm4j</artifactId>
<version>0.9.10</version>
<version>1.0.0-rc1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nkjmlab</groupId>
<artifactId>sorm4j</artifactId>
<version>0.9.10</version>
<version>1.0.0-rc1</version>
<name>sorm4j</name>
<description>Simple micro Object-Relation Mapper for Java</description>
<url>https://github.com/yuu-nkjm/sorm4j</url>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/ConnectionSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/OrmConfigStoreBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -27,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
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/nkjmlab/sorm4j/OrmConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrmConnection> handler);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/nkjmlab/sorm4j/OrmException.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/OrmMapReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> readMapOne(SqlStatement sql);

Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/nkjmlab/sorm4j/OrmMapper.java

This file was deleted.

5 changes: 1 addition & 4 deletions src/main/java/org/nkjmlab/sorm4j/OrmReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.nkjmlab.sorm4j.sqlstatement.SqlStatement;

/**
* The main interface of Reading functions of ORM reader.
*
* This interface based on <a href=
* "https://github.com/r5v9/persist/blob/master/src/main/net/sf/persist/Persist.java">Persist.java</a>
* The interface of reading functions of object-relation mapping.
*
* @author nkjm
*
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/nkjmlab/sorm4j/OrmUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import java.util.List;
import org.nkjmlab.sorm4j.result.InsertResult;


/**
* A interface for updating database.
*
* @author nkjm
*
*/
public interface OrmUpdater {

<T> int[] delete(List<T> objects);
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/org/nkjmlab/sorm4j/Sorm.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import java.sql.Connection;
import org.nkjmlab.sorm4j.mapping.OrmConfigStore;


/**
* An interface of executing object-relation mapping.
*
* @author nkjm
*
*/
public interface Sorm {

OrmConnection beginTransaction();
Expand Down Expand Up @@ -55,13 +60,25 @@ <T> void runTransaction(Class<T> objectClass, int isolationLevel,

void runWithJdbcConnection(OrmConsumerHandler<Connection> handler);

/**
* Interface for object-relation handling without a return value. e.g.
* {@link Sorm#run(OrmConsumerHandler)}.
*
* @param <T>
*/
@FunctionalInterface
public interface OrmConsumerHandler<T> {

void accept(T t) throws Throwable;

}

/**
* Interface for object-relation handling with a return value. e.g.
* {@link Sorm#execute(OrmConsumerHandler)}.
*
* @param <T>
*/
@FunctionalInterface
public interface OrmFunctionHandler<T, R> {

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/SormFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {};
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/SqlExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/TransactionFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.nkjmlab.sorm4j;

/**
* Functions of handling transaction.
*
* @author nkjm
*
*/
public interface TransactionFunction {

/**
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/nkjmlab/sorm4j/TypedOrmConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
import java.util.function.Function;
import org.nkjmlab.sorm4j.mapping.OrmConfigStore;

public interface TypedOrmConnection<T>
extends TypedOrmMapper<T>, TransactionFunction, Closeable, AutoCloseable {
/**
* Main API for typed object relation mapping. The api consists of {@link TypedOrmReader<T>},
* {@link TypedOrmUpdater<T>}, {@link OrmMapReader}, {@link SqlExecutor}and
* {@link TransactionFunction}.
*
* @author nkjm
*
*/
public interface TypedOrmConnection<T> extends TypedOrmReader<T>, TypedOrmUpdater<T>, OrmMapReader,
SqlExecutor, TransactionFunction, Closeable, AutoCloseable {

void runTransaction(Consumer<TypedOrmConnection<T>> handler);

<R> R executeTransaction(Function<TypedOrmConnection<T>, R> handler);

OrmConfigStore getConfigStore();


String getTableName();

}
8 changes: 0 additions & 8 deletions src/main/java/org/nkjmlab/sorm4j/TypedOrmMapper.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
import org.nkjmlab.sorm4j.result.LazyResultSet;
import org.nkjmlab.sorm4j.sqlstatement.SqlStatement;

public interface TypeOrmReader<T> {
/**
* The typed interface of reading functions of object-relation mapping.
*
* @author nkjm
*
*/

public interface TypedOrmReader<T> {

List<T> readAll();

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/TypedOrmUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {

int[] delete(List<T> objects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/mapping/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,7 +136,9 @@ private static Map<String, Accessor> createAccessors(ColumnFieldMapper columnFie

private static Map<FieldName, Method> extractedMethodStartWith(Class<?> objectClass,
String prefix) {
Class<OrmIgnore> 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(
Expand All @@ -146,7 +149,9 @@ private static Map<FieldName, Method> extractedMethodStartWith(Class<?> objectCl


private static Map<FieldName, Field> getAllFields(final Class<?> objectClass) {
Class<OrmIgnore> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/mapping/OrmMapper.java
Original file line number Diff line number Diff line change
@@ -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 {



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/mapping/SormImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading

0 comments on commit 6a9f20a

Please sign in to comment.