From 6bda502610c39cc5c82cc6be6ef912f15d266556 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Thu, 21 Jul 2016 15:24:26 -0300 Subject: [PATCH] Upgrade Hibernate to 5.2.1 --- libraries.gradle | 2 +- .../java/org/jpos/ee/usertype/JsonType.java | 28 +++++++++++++++++-- .../java/org/jpos/ee/usertype/TagsType.java | 28 +++++++++++++++++-- .../src/main/java/org/jpos/gl/GLSession.java | 1 - .../main/java/org/jpos/gl/tools/Import.java | 12 ++++---- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/libraries.gradle b/libraries.gradle index 9d47719a7f..0a4b10a202 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -2,7 +2,7 @@ ext { jposVersion = '2.0.7-SNAPSHOT' slf4jVersion = '1.7.21' logbackVersion = '1.1.7' - hibernateVersion = '5.1.0.Final' + hibernateVersion = '5.2.1.Final' geronimoVersion = '1.1.1' jettyVersion = '9.2.17.v20160517' servletApiVersion = '3.1.0' diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/usertype/JsonType.java b/modules/dbsupport/src/main/java/org/jpos/ee/usertype/JsonType.java index d19e9cd28f..23d55b51d7 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/usertype/JsonType.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/usertype/JsonType.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.usertype.UserType; import java.io.IOException; @@ -38,8 +39,19 @@ public int hashCode(Object x) throws HibernateException { return x.hashCode(); } + /** + * Retrieve an instance of the mapped class from a JDBC resultset. Implementors + * should handle possibility of null values. + * + * @param rs a JDBC result set + * @param names the column names + * @param session + * @param owner the containing entity @return Object + * @throws HibernateException + * @throws SQLException + */ @Override - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String json = rs.getString(names[0]); if (rs.wasNull()) return null; @@ -50,8 +62,20 @@ public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessi } } + /** + * Write an instance of the mapped class to a prepared statement. Implementors + * should handle possibility of null values. A multi-column type should be written + * to parameters starting from index. + * + * @param st a JDBC prepared statement + * @param value the object to write + * @param index statement parameter index + * @param session + * @throws HibernateException + * @throws SQLException + */ @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value==null) { st.setNull(index, Types.VARCHAR); } else { diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/usertype/TagsType.java b/modules/dbsupport/src/main/java/org/jpos/ee/usertype/TagsType.java index 7c95584b32..85b564f1bf 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/usertype/TagsType.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/usertype/TagsType.java @@ -20,6 +20,7 @@ import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.usertype.UserType; import java.io.Serializable; @@ -53,16 +54,39 @@ public int hashCode(Object o) throws HibernateException { return o.hashCode(); } + /** + * Retrieve an instance of the mapped class from a JDBC resultset. Implementors + * should handle possibility of null values. + * + * @param rs a JDBC result set + * @param names the column names + * @param session + * @param owner the containing entity @return Object + * @throws HibernateException + * @throws SQLException + */ @Override - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { String tags = rs.getString(names[0]); if (rs.wasNull()) return null; return new Tags(tags); } + /** + * Write an instance of the mapped class to a prepared statement. Implementors + * should handle possibility of null values. A multi-column type should be written + * to parameters starting from index. + * + * @param st a JDBC prepared statement + * @param value the object to write + * @param index statement parameter index + * @param session + * @throws HibernateException + * @throws SQLException + */ @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (value==null) { st.setNull(index, Types.VARCHAR); } else { diff --git a/modules/minigl/src/main/java/org/jpos/gl/GLSession.java b/modules/minigl/src/main/java/org/jpos/gl/GLSession.java index b29ee3c719..5d0a1b72ac 100644 --- a/modules/minigl/src/main/java/org/jpos/gl/GLSession.java +++ b/modules/minigl/src/main/java/org/jpos/gl/GLSession.java @@ -1559,7 +1559,6 @@ private void invalidateCheckpoints (GLTransaction txn) Checkpoint cp = (Checkpoint) iter.next(); session.delete (cp); } - session.flush(); } private BigDecimal applyEntries (BigDecimal balance, List entries) throws GLException diff --git a/modules/minigl/src/main/java/org/jpos/gl/tools/Import.java b/modules/minigl/src/main/java/org/jpos/gl/tools/Import.java index bf26d0a486..a1fd0ac37b 100644 --- a/modules/minigl/src/main/java/org/jpos/gl/tools/Import.java +++ b/modules/minigl/src/main/java/org/jpos/gl/tools/Import.java @@ -64,7 +64,12 @@ public static void usage () { } private void createSchema () throws HibernateException, DocumentException { - new DB().createSchema(null, true); + DB db = new DB(); + db.open(); + db.beginTransaction(); + db.createSchema(null, true); + db.commit(); + db.close(); } private void createCharts (Session sess, Iterator iter) @@ -82,7 +87,6 @@ private void createCharts (Session sess, Iterator iter) sess.flush (); } txn.commit(); - sess.flush (); } private void createCurrencies (Session sess, Iterator iter) throws SQLException, HibernateException, ParseException @@ -94,7 +98,6 @@ private void createCurrencies (Session sess, Iterator iter) sess.save (currency); } txn.commit(); - sess.flush (); } private void createUsers (Session sess, Iterator iter) throws SQLException, HibernateException, ParseException @@ -114,7 +117,6 @@ private void createUsers (Session sess, Iterator iter) sess.save (user); } txn.commit(); - sess.flush (); } private void createJournals (Session sess, Iterator iter) throws SQLException, HibernateException, ParseException @@ -140,7 +142,6 @@ private void createJournals (Session sess, Iterator iter) ); } txn.commit(); - sess.flush (); } private void processChartChildren (Session sess, CompositeAccount parent, Iterator iter) @@ -196,7 +197,6 @@ private void createTransactions (Session sess, Iterator iter) ); txn.commit (); } - sess.flush (); } private void createEntries ( Session sess, GLTransaction glt, Iterator iter)