Skip to content

Commit

Permalink
Merge pull request #41 from support-project/develop
Browse files Browse the repository at this point in the history
Release v1.11.0
  • Loading branch information
koda-masaru authored Oct 29, 2017
2 parents 5eae943 + 8b4f8e9 commit fc830ac
Show file tree
Hide file tree
Showing 26 changed files with 598 additions and 381 deletions.
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/bash
# mvn clean deploy -DperformRelease=true -Dmaven.javadoc.skip=true -e
# mvn clean site deploy -DperformRelease=true -Dmaven.javadoc.skip=true -e
mvn clean deploy -DperformRelease=true -e
63 changes: 61 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.support-project</groupId>
<artifactId>common</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<packaging>jar</packaging>

<name>common</name>
Expand Down Expand Up @@ -188,8 +188,49 @@
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.10</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

</plugins>

</build>


Expand Down Expand Up @@ -239,6 +280,24 @@
<linkXRef>false</linkXRef>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<excludes>
<exclude>**/ormapping/**</exclude>
</excludes>
</configuration>
</plugin>

</plugins>
</reporting>

Expand Down
50 changes: 24 additions & 26 deletions src/main/java/org/support/project/common/test/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,32 @@
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.logic.H2DBServerLogic;
import org.support.project.di.Container;

@RunWith(OrderedRunner.class)
public class TestCase {
/** ログ */
protected Log LOG = LogFactory.getLog(TestCase.class);

public TestCase() {
super();
LOG = LogFactory.getLog(this.getClass());
}

@Rule
public TestWatcher watchman = new TestWatcher();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
H2DBServerLogic logic = Container.getComp(H2DBServerLogic.class);
logic.start();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
H2DBServerLogic logic = Container.getComp(H2DBServerLogic.class);
logic.stop();
}

@Test
public void test() {
//何もしない
}
/** ログ */
protected Log LOG = LogFactory.getLog(TestCase.class);

public TestCase() {
super();
LOG = LogFactory.getLog(this.getClass());
}

@Rule
public TestWatcher watchman = new TestWatcher();
@BeforeClass
public static void setUpBeforeClass() throws Exception {
if (!H2DBServerLogic.get().isActive()) {
H2DBServerLogic.get().start();
}
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Test
public void test() {
//何もしない
}

}
48 changes: 29 additions & 19 deletions src/main/java/org/support/project/common/test/TestWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,39 @@
import org.junit.runner.Description;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.DateUtils;

/**
* TestWatcher
* @author Koda
*/
public class TestWatcher extends org.junit.rules.TestWatcher {
/** ログ */
private static final Log LOG = LogFactory.getLog(TestWatcher.class);
/** Date */
private Date start;

@Override
protected void starting(Description description) {
super.starting(description);
start = new Date();
LOG.info("@@@@@@ TEST START - " + description.getClassName() + "#" + description.getMethodName());
}

@Override
protected void finished(Description description) {
super.finished(description);
Date end = new Date();
long time = end.getTime() - start.getTime();
LOG.info("@@@@@@ TEST FINISHED - " + time + " [ms]" + " - " + description.getClassName() + "#" + description.getMethodName());
}
/** ログ */
private static final Log LOG = LogFactory.getLog(TestWatcher.class);
/** Date */
private Date start;

@Override
protected void starting(Description description) {
super.starting(description);
start = DateUtils.now();
LOG.info("@@@@@@ TEST START - " + description.getClassName() + "#" + description.getMethodName());
}

@Override
protected void finished(Description description) {
super.finished(description);
Date end = DateUtils.now();
long time = end.getTime() - start.getTime();
LOG.info("@@@@@@ TEST FINISHED - " + time + " [ms]" + " - " + description.getClassName() + "#" + description.getMethodName());
}

@Override
protected void failed(Throwable e, Description description) {
LOG.error(description, e);
}

@Override
protected void succeeded(Description description) {
}
}
39 changes: 35 additions & 4 deletions src/main/java/org/support/project/common/util/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,44 @@
*
*/
public class DateUtils {
/** ログ */
private static final Log LOG = LogFactory.getLog(DateUtils.class);

/** 通信で利用する日付のフォーマット文字列 */
public static final String TRANSFER_DATETIME_FORMAT = "yyyyMMddHHmmssSSS";

private static long offset = 0;
/**
* テストなどで日付を指定して動かすさいに使うオフセットを指定
* @param offset オフセット
*/
public static void setOffset(long offset) {
LOG.warn("Set offset for system timestamp: " + offset);
DateUtils.offset = offset;
}
/**
* 現在の時刻のDateオブジェクトを取得
* テストなどで日付を指定して動かせるために、オフセットを指定でき、そのオフセット分ずらした日付を取得できる
* @return Date
*/
public static Date now() {
Date now = new Date();
if (offset != 0) {
now.setTime(now.getTime() + offset);
}
return now;
}
/**
* 現在の時刻のCalendarオブジェクトを取得
* テストなどで日付を指定して動かせるために、オフセットを指定でき、そのオフセット分ずらした日付を取得できる
* @return Calendar
*/
public static Calendar nowCalendar() {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(calendar.getTimeInMillis() + offset);
return calendar;
}

/**
* 通信で利用する日付のフォーマット
*
Expand Down Expand Up @@ -66,10 +101,6 @@ public static final DateFormat getShortDayFormat() {
public static final DateFormat getSimpleFormat() {
return new SimpleDateFormat(SECOND_FORMAT_STR);
}

/** ログ */
private static final Log LOG = LogFactory.getLog(DateUtils.class);

/**
* 通信に使用する日付フォーマットによる日付文字列の取得
*
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/org/support/project/common/util/PropertyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static void setPropertyValue(Object object, String propertyName, Object v
if (value != null) {
error.append("\tValueClass=").append(value.getClass().getName()).append("\n");
}
LOG.error(error.toString());
LOG.error(error.toString(), e);
SystemException exception = new SystemException(e.getMessage());
exception.setStackTrace(e.getStackTrace());
throw exception;
Expand Down Expand Up @@ -384,6 +384,26 @@ public static String reflectionToString(Object obj) {
// }
//

/**
* 指定のオブジェクトの private フィールドの値を取得する
* テスト用
*
* @param class1 取得するフィールドの型
* @param obj オブジェクト
* @param property プロパティ名
* @return プロパティの値
* @throws NoSuchFieldException NoSuchFieldException
* @throws SecurityException SecurityException
* @throws IllegalArgumentException IllegalArgumentException
* @throws IllegalAccessException IllegalAccessException
*/
public static <T> T getPrivateFeildOnReflection(Class<T> class1, Object obj, String property)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Field field = obj.getClass().getDeclaredField(property);
field.setAccessible(true);
return (T) field.get(obj);
}

/**
* 指定のクラスが値を持つクラスかどうか
* @param c class type
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/support/project/ormapping/common/IDGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IDGen get() {

public IDGen() {
super();
Date now = new Date();
Date now = DateUtils.now();
count = now.getTime();
}

Expand All @@ -34,7 +34,7 @@ public String gen(String key) {
digest = MessageDigest.getInstance(ALGORITHM);
StringBuilder builder = new StringBuilder();
builder.append(key);
builder.append(DateUtils.getTransferDateFormat().format(new Date()));
builder.append(DateUtils.getTransferDateFormat().format(DateUtils.now()));
builder.append(count);
byte[] hash = digest.digest(builder.toString().getBytes());
StringBuilder sb = new StringBuilder();
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/org/support/project/ormapping/common/SQLManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
import java.util.List;
import java.util.Map;

import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.StringUtils;
import org.support.project.ormapping.connection.ConnectionManager;
import org.support.project.ormapping.exception.ORMappingException;

/**
* SQLのリソースを読み込む
*/
public class SQLManager {
/** ログ */
private static Log LOG = LogFactory.getLog(SQLManager.class);

/**
* シングルトンで管理されたconnectionManagerのインスタンス
Expand Down Expand Up @@ -63,6 +69,48 @@ public String getSql(String sqlFilePath) {
*
*/
public String[] getSqls(String sqlFilePath) {
List<String> sqlFilePaths = getSqlFilePaths(sqlFilePath);
LOG.trace("load sql");
for (String path : sqlFilePaths) {
LOG.trace(path);
if (this.getClass().getResourceAsStream(path) != null) {
return readSqls(path);
}
}
throw new ORMappingException("SQL Resource is not found. " + sqlFilePath);
}

private List<String> getSqlFilePaths(String sqlFilePath) {
List<String> paths = new ArrayList<>();
// 現在のコネクションを取得
String driver = ConnectionManager.getInstance().getDriverClass();
if (!StringUtils.isEmpty(driver)) {
if (driver.indexOf("postgresql") != -1) {
paths.add(connectDatabaseToSqlFileName(sqlFilePath, "postgresql"));
} else if (driver.indexOf("h2") != -1) {
paths.add(connectDatabaseToSqlFileName(sqlFilePath, "h2"));
}
}
paths.add(sqlFilePath);
return paths;
}

private String connectDatabaseToSqlFileName(String sqlFilePath, String databasename) {
StringBuilder path = new StringBuilder();
if (sqlFilePath.indexOf(".") != -1) {
path.append(sqlFilePath.substring(0, sqlFilePath.lastIndexOf(".")));
path.append("_");
path.append(databasename);
path.append(sqlFilePath.substring(sqlFilePath.lastIndexOf(".")));
} else {
path.append(sqlFilePath);
path.append("_");
path.append(databasename);
}
return path.toString();
}

private String[] readSqls(String sqlFilePath) {
try {
if (sqlMap.containsKey(sqlFilePath)) {
return sqlMap.get(sqlFilePath);
Expand Down Expand Up @@ -108,5 +156,7 @@ public String[] getSqls(String sqlFilePath) {
throw new ORMappingException(e);
}
}



}
5 changes: 5 additions & 0 deletions src/main/java/org/support/project/ormapping/config/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.support.project.ormapping.config;

public enum Order {
DESC, ASC
}
Loading

0 comments on commit fc830ac

Please sign in to comment.