Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
Update version to 0.1.0

- Fix some minor bugs.
  • Loading branch information
SMontiel committed Apr 1, 2018
2 parents 9f44c90 + 78ecca4 commit b534d35
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 51 deletions.
Binary file modified .gradle/4.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/4.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/4.5.1/taskHistory/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/4.5.1/taskHistory/taskHistory.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ allprojects {

```groovy
dependencies {
compile 'com.github.SMontiel:SimpleJDBC:0.0.3'
compile 'com.github.SMontiel:SimpleJDBC:0.1.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

jar {
baseName = 'SimpleJDBC'
version = '0.0.3'
version = '0.1.0'
}

sourceCompatibility = 1.7
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/smontiel/simple_jdbc/SimpleJDBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private <S> S execute(Strategy<S> s) {
try {
return s.execute(dataSource.getConnection());
} catch (SQLException e) {
Utils.printSQLException((SQLException) e);
Utils.printSQLException(e);
throw new RuntimeException(e);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/smontiel/simple_jdbc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
*/
public class Utils {

public static void printSQLException(SQLException ex) {
public static void printSQLException(Exception exception) {
if (exception == null || !(exception instanceof SQLException)) return;

for (Throwable e : ex) {
SQLException sqlException = (SQLException) exception;
for (Throwable e : sqlException) {
if (e instanceof SQLException) {
if (!ignoreSQLException(
((SQLException) e).
Expand All @@ -27,7 +29,7 @@ public static void printSQLException(SQLException ex) {

System.err.println("Message: " + e.getMessage());

Throwable t = ex.getCause();
Throwable t = sqlException.getCause();
while(t != null) {
System.out.println("Cause: " + t);
t = t.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -51,7 +50,7 @@ public List<T> execute(Connection connection) {
}
return list;
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
Utils.printSQLException(e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -53,7 +52,7 @@ public List<T> execute(Connection connection) {
throw new IllegalStateException("No data returned from the query.");
} else return list;
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
Utils.printSQLException(e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
* Created by Salvador Montiel on 08/mar/2018.
Expand Down Expand Up @@ -39,8 +38,8 @@ public Integer execute(Connection connection) {

Integer instance = stmt.getUpdateCount();
return instance;
} catch (SQLException e) {
Utils.printSQLException((SQLException) e);
} catch (Exception e) {
Utils.printSQLException(e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
* Created by Salvador Montiel on 08/mar/2018.
Expand Down Expand Up @@ -51,7 +50,7 @@ public T execute(Connection connection) {
}
return instance;
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
Utils.printSQLException(e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
* Created by Salvador Montiel on 08/mar/2018.
Expand Down Expand Up @@ -53,7 +52,7 @@ public T execute(Connection connection) {
}
return instance;
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
Utils.printSQLException(e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
Expand Down Expand Up @@ -39,12 +38,12 @@ public R execute(Connection connection) {
instance = handler.apply(new TransactionExecutor(noCloseConnection));
noCloseConnection.commit();
} catch (Exception e ) {
Utils.printSQLException((SQLException) e);
Utils.printSQLException(e);
if (noCloseConnection != null) {
try {
System.err.print("Transaction is being rolled back");
noCloseConnection.rollback();
} catch(SQLException excep) {
} catch(Exception excep) {
Utils.printSQLException(excep);
throw new RuntimeException(excep);
}
Expand All @@ -57,7 +56,7 @@ public R execute(Connection connection) {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
} catch (Exception e) {
Utils.printSQLException(e);
throw new RuntimeException(e);
}
Expand All @@ -81,55 +80,34 @@ public <T> List<T> any(String sqlQuery, ThrowingFunction<ResultSet, T> handler)

@Override
public <T> List<T> many(String sqlQuery, ThrowingFunction<ResultSet, T> handler) {
try {
Strategy<List<T>> s = StrategyFactory.many(sqlQuery, handler);
return s.execute(connection);
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
throw new RuntimeException(e);
}
return execute(StrategyFactory.many(sqlQuery, handler));
}

@Override
public <T> List<T> manyOrNone(String sqlQuery, ThrowingFunction<ResultSet, T> handler) {
try {
Strategy<List<T>> s = StrategyFactory.manyOrNone(sqlQuery, handler);
return s.execute(connection);
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
throw new RuntimeException(e);
}
return execute(StrategyFactory.manyOrNone(sqlQuery, handler));
}

@Override
public Integer none(String sqlQuery) {
try {
Strategy<Integer> s = StrategyFactory.none(sqlQuery);
return s.execute(connection);
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
throw new RuntimeException(e);
}
return execute(StrategyFactory.none(sqlQuery));
}

@Override
public <T> T one(String sqlQuery, ThrowingFunction<ResultSet, T> handler) {
try {
Strategy<T> s = StrategyFactory.one(sqlQuery, handler);
return s.execute(connection);
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
throw new RuntimeException(e);
}
return execute(StrategyFactory.one(sqlQuery, handler));
}

@Override
public <T> T oneOrNone(String sqlQuery, ThrowingFunction<ResultSet, T> handler) {
return execute(StrategyFactory.oneOrNone(sqlQuery, handler));
}

private <S> S execute(Strategy<S> s) {
try {
Strategy<T> s = StrategyFactory.oneOrNone(sqlQuery, handler);
return s.execute(connection);
} catch (Exception e) {
Utils.printSQLException((SQLException) e);
Utils.printSQLException(e);
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit b534d35

Please sign in to comment.