Skip to content

Commit

Permalink
Merge pull request #16 from yuu-nkjm/develop
Browse files Browse the repository at this point in the history
Fixing
  • Loading branch information
yuu-nkjm authored Mar 15, 2021
2 parents 35dd7db + a986fe2 commit 68e5d19
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 226 deletions.
203 changes: 52 additions & 151 deletions 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>1.0.0-rc4</version>
<version>1.0.0-rc5</version>
<name>sorm4j</name>
<description>Simple micro Object-Relation Mapper for Java</description>
<url>https://github.com/yuu-nkjm/sorm4j</url>
Expand Down Expand Up @@ -57,19 +57,6 @@
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
<repository>
<id>nkjmlab-public</id>
<name>nkjmlab Public Repository</name>
<url>https://maven.nkjmlab.org/nexus/content/groups/public</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -196,69 +183,7 @@
</includes>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<!-- creating jar-with-dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<dependencies>
<!-- Explicit dep on jaxb-api to avoid problems with JDK9 and later, until a new version
of coveralls-maven-plugin is released. See also https://github.com/trautonen/coveralls-maven-plugin/issues/112 -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -271,49 +196,7 @@
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- ********** for Deployment to remote mvn server START ******* -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<goals>deploy</goals>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- from https://central.sonatype.org/pages/apache-maven.html#distribution-management-and-authentication -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand All @@ -325,48 +208,23 @@
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- ********** for Deployment to remote mvn server END ******* -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<!-- from https://central.sonatype.org/pages/apache-maven.html#javadoc-and-sources-attachments -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>make-a-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<phase>install</phase>
<id>attach-sources</id>
<goals>
<goal>install-file</goal>
<goal>jar-no-fork</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Expand All @@ -389,6 +247,7 @@
</execution>
</executions>
</plugin>
<!-- from https://central.sonatype.org/pages/apache-maven.html#gpg-signed-components -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand All @@ -415,10 +274,10 @@
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
<!-- aggregated reports for multi-module projects -->
<aggregate>true</aggregate>
</configuration>
</plugin>
<!-- for execute test -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -430,5 +289,47 @@
</configuration>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
2 changes: 1 addition & 1 deletion src/main/java/org/nkjmlab/sorm4j/core/mapping/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static Method isValidGetter(Method getter) {
return null;
}
if (getter.getReturnType() == void.class) {
log.warn("Getter [{}] must have return a parameter.");
log.warn("Getter [{}] must have return a parameter.", getter);
}

return getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.nkjmlab.sorm4j.core.sqlstatement;

import static org.nkjmlab.sorm4j.sqlstatement.SqlStatement.*;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
import org.nkjmlab.sorm4j.core.util.SqlUtils;
import org.nkjmlab.sorm4j.sqlstatement.NamedParameterSql;
import org.nkjmlab.sorm4j.sqlstatement.SqlStatement;

Expand Down Expand Up @@ -39,7 +39,7 @@ public NamedParameterSql bindAll(Map<String, Object> namedParams) {
@Override
public NamedParameterSql bind(String key, Object value) {
if (value instanceof List) {
this.parameters.put(key, literal(value));
this.parameters.put(key, SqlUtils.literal(value));
} else {
this.parameters.put(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.nkjmlab.sorm4j.core.sqlstatement;

import static org.nkjmlab.sorm4j.sqlstatement.SqlStatement.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.nkjmlab.sorm4j.core.util.SqlUtils;
import org.nkjmlab.sorm4j.sqlstatement.OrderedParameterSql;
import org.nkjmlab.sorm4j.sqlstatement.SqlStatement;

Expand Down Expand Up @@ -31,7 +31,7 @@ public OrderedParameterSql add(Object... parameters) {
@Override
public OrderedParameterSql add(Object parameter) {
if (parameter instanceof List) {
this.parameters.add(literal(parameter));
this.parameters.add(SqlUtils.literal(parameter));
} else {
this.parameters.add(parameter);
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/org/nkjmlab/sorm4j/core/util/SqlUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.nkjmlab.sorm4j.core.util;

import java.util.List;
import java.util.stream.Collectors;

public final class SqlUtils {

private SqlUtils() {}

/**
* Returns single quoted expression. If it includes single quotations, they will be escaped.
*
* @param expr
* @return
*/
public static String quote(String str) {
return wrapSingleQuote(str.contains("'") ? str.replaceAll("'", "''") : str);
}

private static String wrapSingleQuote(String str) {
return "'" + str + "'";
}

/**
* Convert the given arguments to SQL literal.
*
* @param element
* @return
*/
public static String literal(Object element) {
if (element == null) {
return "null";
} else if (element instanceof Number || element instanceof Boolean) {
return element.toString();
} else if (element instanceof List) {
return String.join(", ",
((List<?>) element).stream().map(e -> literal(e)).collect(Collectors.toList()));
}
String str = element.toString();
switch (str) {
case "?":
return str;
default:
return quote(str);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ public static SelectBuilder.OrderBy order(String column, String ascOrDesc) {
return new SelectBuilder.OrderBy(column, ascOrDesc);
}

/**
* Returns single quoted string.
*
* @param expr
* @return
*/
public static String quote(String expr) {
return "'" + expr + "'";
}

/**
* Creates a select SQL statement from the objects.
Expand Down
Loading

0 comments on commit 68e5d19

Please sign in to comment.