Skip to content

Commit

Permalink
Now uses gradle 1.1;
Browse files Browse the repository at this point in the history
Improved distributionZip task in order to have a root directory with the project name and version;
Signing is skipped if it's not a release version and the necessary properties are not present;
Improved code quality;
Added support for the format yyyy-mm-dd for columns of type TIMESTAMP
  • Loading branch information
jnizet committed Aug 6, 2012
1 parent 55039db commit 2f8cfca
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ task javadocJar(type: Jar, dependsOn: javadoc) {

task distributionZip(type: Zip, dependsOn: [javadoc, jar]) {
classifier = 'dist'
from jar.archivePath
into('src') {
def rootDir = project.name + '-' + project.version;
into(rootDir) {
from jar.archivePath
}
into(rootDir + '/src') {
from sourceSets.main.java
}
into('javadoc') {
into(rootDir + '/javadoc') {
from javadoc.destinationDir
}
}
Expand Down Expand Up @@ -179,10 +182,12 @@ uploadArchives {
}
}

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

task wrapper(type: Wrapper) {
gradleVersion = '1.0'
gradleVersion = '1.1'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Aug 05 00:31:44 CEST 2012
#Mon Aug 06 18:48:35 CEST 2012
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\:https://services.gradle.org/distributions/gradle-1.0-bin.zip
distributionUrl=http\:https://services.gradle.org/distributions/gradle-1.1-bin.zip
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
JAVA_OPTS="$JAVA_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/ninja_squad/dbsetup/bind/Binders.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static Binder dateBinder() {
* <li><code>java.util.Calendar: the milliseconds of the calendar are used to construct a
* java.sql.Timestamp</code></li>
* <li><code>String</code>: the string is transformed to a <code>java.sql.Timestamp</code> using the
* <code>Timestamp.valueOf()</code> method</li>
* <code>Timestamp.valueOf()</code> method, or using the <code>java.sql.Date.valueOf() method if the
* string has less than 19 characters</li>
* </ul>
* If the value is none of these types, <code>stmt.setObject()</code> is used to bind the value.
*/
Expand Down Expand Up @@ -228,6 +229,9 @@ public String toString() {
* @author JB
*/
private static final class TimestampBinder implements Binder {
// the number of chars in yyyy-mm-dd hh:mm:ss
private static final int MIN_NUMBER_OF_CHARS_FOR_TIMESTAMP = 19;

@Override
public void bind(java.sql.PreparedStatement stmt, int param, Object value) throws java.sql.SQLException {
if (value instanceof Timestamp) {
Expand All @@ -240,7 +244,14 @@ else if (value instanceof java.util.Calendar) {
stmt.setTimestamp(param, new Timestamp(((java.util.Calendar) value).getTimeInMillis()));
}
else if (value instanceof String) {
stmt.setTimestamp(param, Timestamp.valueOf((String) value));
String valueAsString = (String) value;
if (valueAsString.length() >= MIN_NUMBER_OF_CHARS_FOR_TIMESTAMP) {
stmt.setTimestamp(param, Timestamp.valueOf(valueAsString));
}
else {
Date valueAsDate = Date.valueOf(valueAsString);
stmt.setTimestamp(param, new Timestamp(valueAsDate.getTime()));
}
}
else {
stmt.setObject(param, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class CompositeOperation implements Operation {

@Override
public void execute(Connection connection, BinderConfiguration configuration) {
// does nothing since it's a NOP
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/ninja_squad/dbsetup/operation/Truncate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
@Immutable
public final class Truncate implements Operation {

private final String table;
private final String tableToTruncate;

private Truncate(String table) {
this.table = table;
this.tableToTruncate = table;
}

@Override
public void execute(Connection connection, BinderConfiguration configuration) throws SQLException {
Statement stmt = connection.createStatement();
try {
stmt.executeUpdate("truncate table " + table);
stmt.executeUpdate("truncate table " + tableToTruncate);
}
finally {
stmt.close();
Expand Down Expand Up @@ -75,12 +75,12 @@ public static Operation tables(List<String> tables) {

@Override
public String toString() {
return "truncate table " + table;
return "truncate table " + tableToTruncate;
}

@Override
public int hashCode() {
return table.hashCode();
return tableToTruncate.hashCode();
}

@Override
Expand All @@ -95,6 +95,6 @@ public boolean equals(Object obj) {
return false;
}
Truncate other = (Truncate) obj;
return this.table.equals(other.table);
return this.tableToTruncate.equals(other.tableToTruncate);
}
}
9 changes: 8 additions & 1 deletion src/test/java/com/ninja_squad/dbsetup/bind/BindersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,19 @@ public void timestampBinderBindsCalendar() throws SQLException {
}

@Test
public void timestampBinderBindsString() throws SQLException {
public void timestampBinderBindsStringWithTimestampFormat() throws SQLException {
Binder binder = Binders.timestampBinder();
binder.bind(stmt, 1, "1975-07-19 13:14:15");
verify(stmt).setTimestamp(1, Timestamp.valueOf("1975-07-19 13:14:15"));
}

@Test
public void timestampBinderBindsStringWithDateFormat() throws SQLException {
Binder binder = Binders.timestampBinder();
binder.bind(stmt, 1, "1975-07-19");
verify(stmt).setTimestamp(1, Timestamp.valueOf("1975-07-19 00:00:00"));
}

@Test
public void timestampBinderBindsNull() throws SQLException {
Binder binder = Binders.timestampBinder();
Expand Down

0 comments on commit 2f8cfca

Please sign in to comment.