Skip to content

DiKode

Coding Journal

Menu
  • Home
  • Author
  • Contact Me
  • Category
    • Java
    • Javascript
  • Privacy Policy
Menu

Integrating Hibernate and jPOS Framework

Posted on April 10, 2015October 26, 2017 by didikhari

Today i want to share about Integrating Hibernate and jPOS Framework.

The implementation will based on my old post about Implementation jPOS Transaction Manager you can read the jPOS project on these post.
The jPOS System is look like:
Integrating Hibernate and jPOS Framework

i will add new participant for FinancialTransaction group called FinancialTransactionLogging, the participant is responsible for inserting the FinancialTransactionQueryRemoteHost response into database using Hibernate framework.
First, For integrating Hibernate and jPOS, i create new qbean called HibernateManager that extends org.jpos.q2.QBeanSupport the initService methods will buildSessionFactory for init the hibernate SessionFactory object.

HibernateManager class will look like:
[java]
package com.didikhari.utility;

import java.io.File;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.jpos.q2.QBeanSupport;
import org.jpos.util.NameRegistrar;

public class HibernateManager extends QBeanSupport {

private SessionFactory sessionFactory;

@SuppressWarnings(“deprecation”)
@Override
protected void initService() throws Exception {
try {
String hibernatePropsFilePath = cfg.get(“hibernate_cfg_path”);
File hibernatePropsFile = new File(hibernatePropsFilePath);

Configuration configuration = new Configuration();
configuration.configure(hibernatePropsFile);
sessionFactory = configuration.buildSessionFactory();
NameRegistrar.register(“hibernate-manager”, this);
} catch (Exception e) {
e.printStackTrace();
}
}

public SessionFactory getSessionFactory() {
return sessionFactory;
}

public void shutdown() {
if (getSessionFactory() != null) {
getSessionFactory().close();
}
}
}
[/java]
and you need to create 60_hibernate_manager.xml file inside your deploy directory. and the xml file is:
[xml]

[/xml]

The hibernate configuration file, and inserting methods using Template Methods Pattern can be found here: Implementation Template Methods Design Pattern

The last thing i need to do is to create the FinancialTransactionLogging class implementation like this:
[java]
package com.didikhari.transaction.participant;

import java.io.Serializable;

import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.Session;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
import org.jpos.transaction.AbortParticipant;
import org.jpos.transaction.Context;

import com.didikhari.constant.Constant;
import com.didikhari.model.ResponseISO;
import com.didikhari.utility.HibernateUtil;
import com.didikhari.utility.TransactionCallAble;

/**
* This class is responsible for log the message to the database
* @author Didik Hari
*
*/
public class FinancialTransactionLogging implements AbortParticipant {

@Override
public void abort(long id, Serializable context) { }

@Override
public void commit(long id, Serializable context) { }

@Override
public int prepare(long id, Serializable context) {
try {
ISOMsg respMsg = (ISOMsg) ((Context)context).get(Constant.RESPONSE_HOST);
ResponseISO responseISO = new ResponseISO();
responseISO.setMti(respMsg.getMTI());
for (int i=2; i < 128; i++) { String prop = "bit"+ ISOUtil.zeropad(String.valueOf(i), 3); PropertyUtils.setProperty(responseISO, prop, respMsg.getString(i)); } save(responseISO); } catch (Exception e) { e.printStackTrace(); return ABORTED; } return PREPARED; } private void save(final ResponseISO responseISO) { HibernateUtil.doInTransaction(new TransactionCallAble() {
@Override
public Integer call(Session session) throws Exception {
session.save(responseISO);
return null;
}
});
}

@Override
public int prepareForAbort(long id, Serializable context) {
return ABORTED;
}

}
[/java]

Thats all my post about Integrating Hibernate and jPOS Framework. Thank you for coming to my blog.

4 thoughts on “Integrating Hibernate and jPOS Framework”

  1. sada says:
    April 22, 2015 at 5:57 am

    where is the project download link?

    Reply
    1. dani says:
      July 29, 2015 at 9:15 am

      you can download the project here: …???

      Reply
  2. mack says:
    August 10, 2018 at 3:30 pm

    Please help out with new full setup tutorial to use hibernate in jpos

    Reply
    1. didikhari says:
      August 29, 2018 at 11:58 am

      you can use jpos EE hibernate module.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Java
  • Javascript
  • jPOS

Recent Post

  • jPOS Server in-out
  • How to Configure Basic Auth Spring RestTemplate
  • Create Custom jPOS ISO8583 Packager
  • Binding Restful XML Parameter
  • Create Dynamic Tree Grid using TreeGrid jQuery Plugin

Tags

Asynchronous Request async request Bind Json Param custom channel custom jPOS packager datatables Design Pattern hibernate http http basic auth http request iso 8583 java javascript jPOS jpos channel jPOS Client jPOS database jPOS deploy directory jPOS Hibernate jpos http jpos rest jPOS Server jpos Space jquery js jsf load balancer moxy mux mux pool prettyfaces primefaces rest client Restful SAF space Specifications spring framework TCP Template Method transaction manager transaction participant tree TreeGrid

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2021 DiKode | Built using WordPress and Responsive Blogily theme by Superb