Bhim Upadhyaya

Greenhorn
+ Follow
since Jul 11, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bhim Upadhyaya

Here is context loading and client-instance creation:
SSLContext sslContext = getSSLContext();
HostnameVerifier hostnameVerifier = null; // Verification may not be required
HTTPSProperties prop = new HTTPSProperties(hostnameVerifier, sslContext);
ClientConfig config = new DefaultClientConfig();
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, prop);
Client client = Client.create(config);
8 years ago
Has anyone tried two-way SSL with Jersey framework? Here is the scenario:

I have data in a form object (type: com.sun.jersey.api.representation.Form). Let's say:
Form myData = new Form();
form.add("data1", "value1");
form.add("data1","value2");

Now I form my total input data string:
String verb = "POST";
String uri = "/projectname/methodname/indicator";
String inputData = verb+uri+<flattened-value-here>
//[An instance: (String inputData = verb+uri+"data1=value1&data2=value2")]
.....

String encryptedData = hmac-calculating-method-call("key", inputData); // key = some value there

Now I call my web service:
responseData = webResource.path(serviceMethod).accept(MediaType.APPLICATION_FORM_URLENCODED)
.header("HMAC", encryptedData)
.header("msgSentTimeStamp", new SimpleDateFormat(DATE_FORMAT).format(new Date()))
.post(Form.class, myData)

How do I guarantee that when myData is flattened it becomes exactly "data1=value1&data2=value2". Or, is there any way to control this format so that when hmac is calculated it is same both on the client side and on the server side? Please analyze this in the context of two-way SSL.


8 years ago
This thread aims to house experience of developing or consuming RESTful services using Jersey framework (https://jersey.java.net/).
8 years ago
How to get event based index of an item in FlexTable:

11 years ago
GWT
MAKING A SUCCESSFUL REMOTE PROCEDURE CALL IN GWT
[DISCLAIMER: The content here does not reflect any orginational affiliation, these are hypothetical so far as legal issues are concernted. The code presented here is a part of executable GWT project]

STEP 1:
Create a Client side interface:

STEP 2:
Create Async interface on client side:




Note: If you are using Maven, make sure that you exlude <goal>generateAsync </goal>, otherwise it will create a duplicate class and that becomes a road block for maven builder.

STEP 3:

Create Server side implementation:



STEP 4:
Declare server side class in TestAdmin.gwt.xml (module xml file):


STEP 5:
Make a corresponding entry in web.xml:

STEP 6:

Make a call from client side code:
Variable declaration portion:


Calling portion:





This was simplest possible GWT RPC example.
11 years ago
GWT
Creating a simple CXF SOAP client:


(Its a two step process: first GWT client side code makes an RPC call to GWT server side code and then GWT server side code makes a SOAP call to CXF services)



Step 1:


Generate client side stubs using Maven plug-in:


<plugin>

<groupId>org.apache.cxf</groupId>

<artifactId>cxf-codegen-plugin</artifactId>

<version>2.2.9</version>

<executions>

<execution>

<id>generate-sources</id>

<phase>generate-sources</phase>

<configuration>

<sourceRoot>target/generated/src/main/java</sourceRoot>

<wsdlOptions>

<wsdlOption>

<wsdl>src/main/webapp/WEB-INF/wsdl/MyWService.wsdl</wsdl>

</wsdlOption>

</wsdlOptions>

</configuration>

<goals>

<goal>wsdl2java</goal>

</goals>

</execution>

</executions>

</plugin>







Step 2:

If you want to assemble the code from target folder you can use:


<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>build-helper-maven-plugin</artifactId>

<executions>

<execution>

<id>add-source</id>

<phase>generate-sources</phase>

<goals>

<goal>add-source</goal>

</goals>

<configuration>

<sources>

<source>target/generated/src/main/java</source>

</sources>

</configuration>

</execution>

</executions>

</plugin>




Step 3: Create Service interface and ServiceAsync Interfaces:


public interface MyService extends RemoteService {
String callRemoteService(String name) throws IllegalArgumentException;

}




public interface MyServiceAsync {
void callRemoteService(String input, AsyncCallback<String> callback) throws IllegalArgumentException;

}



Step 4:

Create GWT client class that implements:

com.google.gwt.core.client.EntryPoint



This class also requires a field something like this:


private final MyServiceAsync myService = GWT.create(MyService.class);


In an appropriate location, we make a call to remote service:


myService.callRemoteService(textToServer,new AsyncCallback<String>()



Step 5:

Create server side class:

public class MyServiceImpl extends RemoteServiceServlet implements


MyService {...}


at some point in this class we make a SOAP call:


String callWS(String gwtString){
String response =null;
URL wsdlURL =null;
try{
wsdlURL = MyWImplService.WSDL_LOCATION;
}catch(Exception e){
System.err.println("Can not initialize the default wsdl ");
e.printStackTrace();
}

MyWImplService service =new MyWImplService(wsdlURL, SERVICE_NAME);
MyWService port = service.getMyWImplImplPort();
response = port.sayHi("SOAP test::"+gwtString);
return response;

}





(Please share your thoughts on this. It would be nice if we can have a single step process, that is, GWT client making direct SOAP call to CXF services)


11 years ago
GWT
Here is a Maven pom content :


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.uhg</groupId>
<artifactId>TestProject</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>

<properties>

<gwt.version>2.0.4</gwt.version>

<!-- tell the compiler we can use 1.5 -->
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>

</properties>

<dependencies>
<dependency>
<groupId>com.mycompany.myproject</groupId>
<artifactId>company-parent-pom</artifactId>
<version>2.0.0</version>
<type>pom</type>
</dependency>

<!-- GWT dependencies (from central repo) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>com.uhg.wi4f.Application/Appplication.html</runTarget>
</configuration>
</plugin>
<!--
If you want to use the target/web.xml file mergewebxml produces,
tell the war plugin to use it. Also, exclude what you want from the
final artifact here. <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId> <configuration>
<webXml>target/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes> </configuration>
</plugin>
-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<!-- To copy jar files -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-sources</phase>
<configuration>
<outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
11 years ago
GWT
This thread aims to document GWT experience including maven based GWT projects:
11 years ago
GWT
iBATIS 2.3.4, I think I did not have any syntantical issues and I got data from back-end.
I carried out a rudimentry test to compare memory utilization by Hibernate (utilizing full resources vs only using connection manager), iBATIS and JDBC. Here is the order of call (if that matters):

1. Plain JDBC call

2. Hibernate connection manager

3. Hibernate

4. iBATIS


Each flow created a new connection but the memory calculation only inlcluded portion of code that is directly responsible for stored procedure execution / query execution. When I executed the code multiple times (over 10) in the same order (and for same data), the memory utilization was not consistent but porportion was somewhat consistent: JDBC took the least memory, and then hibernate with only connection manager, iBATIS and Hibernate. It was hard to record execution time (even milliseconds scale could not record).


If other goups have gone through similar path it would be nice to discuss. Also, about any sophisticated tools available for the same purpose besides WAS profiling mode.


Here is a typical memory snapshot:



----------------------USING ONLY THE CONNECTION MANAGER-------------

1. Total memory allocated for JVM: 15110 KB

2. BEFORE SP CALL: Total memory used: 10415 KB

3. AFTER SP CALL: Total memory used: 11721 KB

4. Additional memory used: 1306 KB

----------------------USING FULL HIBERNATE RESOURCES-------------

1. Total memory allocated for JVM: 15110 KB

2. BEFORE SP CALL: Total memory used: 12235 KB

3. AFTER SP CALL: Total memory used: 13839 KB

4. Additional memory used: 1604 KB

----------------------USING PLAIN JDBC RESOURCES-------------

1. Total memory allocated for JVM: 15110 KB

2. BEFORE SP CALL: Total memory used: 15087360 B

3. AFTER SP CALL: Total memory used: 15087416 B

4. Additional memory used: 56 B

----------------------USING iBATIS-------------

1. Total memory allocated for JVM: 14355 KB

2. BEFORE SP CALL: Total memory used: 9349 KB

3. AFTER SP CALL: Total memory used: 10389 KB

4. Additional memory used: 1040 KB
If you want to quickly hookup stored procedures and do little performance testing with iBATIS, here is the code:

(NOTE: THE CODE MAY CONTAIN REDUNDANT/UNUSED/UNNECESSARY LOCs, PLEASE USE IT WITH YOUR JUDGEMENT. ALSO, THE CODE PRESENTED HERE IS NOT RELATED TO ANY ORGANIZATION, ALL NAMES USED ARE HYPOTHETICAL!)

Step 1: Sample Calling Method:

public static void callDBIBATIS(BufferedWriter bw){
Runtime runtime = Runtime.getRuntime();
long mem1 = 0l;
long mem2 = 0l;
List<CMCClass> classes = null;


try {
Reader reader = Resources.getResourceAsReader("SqlMapConfig_dbsw9079.xml");
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);

bw.write("\n");
bw.write("\n");
bw.write("----------------------USING iBATIS-------------");
bw.write("\n");
bw.write("1. Total memory allocated for JVM: "+(runtime.totalMemory()/1024)+" KB");
mem1 = (runtime.totalMemory()-runtime.freeMemory())/1024;
bw.write("\n");
bw.write("2. BEFORE SP CALL: Total memory used: "+mem1+" KB");

classes = (List<CMCClass>)sqlMap.queryForList("CMCClass.selectCMCClass_SP_10");

bw.write("\n");
mem2 = (runtime.totalMemory()-runtime.freeMemory())/1024;
bw.write("3. AFTER SP CALL: Total memory used: "+mem2+" KB");
bw.write("\n");
bw.write("4. Additional memory used: "+(mem2-mem1)+" KB");

CMCClass cmcClass = null;
for (CMCClass cmc : classes) {
cmcClass = cmc;
System.out.print(" CSCS ID: " + cmcClass.getCscsId());
System.out.print(" GRGR CK: " + cmcClass.getGrgrCK());
System.out.print(" CSCS DESC " + cmcClass.getCscsDesc());
System.out.println("");
}

}catch (Exception e){
e.printStackTrace();
}
}


Step 2: iBATIS SQL Mapping File:


(SqlMapConfig.xml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
<settings useStatementNamespaces="true"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="JDBC.ConnectionURL"
value="YOUR-DB-CONNECTION-URL-HERE"/>
<property name="JDBC.Username" value="YOUR-DB-CONNECTION-USERNAME-HERE"/>
<property name="JDBC.Password" value="YOUR-DB-CONNECTION-PASSWORD-HERE"/>
</dataSource>
</transactionManager>
<sqlMap resource="CMCClass.xml"/>
</sqlMapConfig>


Step 3: Other Configuration / Mapping File(s):

(CMCClass.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="CMCClass">

<resultMap id="cmcSearchResult" class="com.rivervalley.cmc_class.CMCClass">
<result property="cscsId" column="CSCS_ID" javaType="java.lang.String"/>
<result property="grgrCK" column="GRGR_CK" javaType="java.lang.Integer"/>
<result property="cscsDesc" column="CSCS_DESC" javaType="java.lang.String"/>
</resultMap>

<parameterMap id="selectCMCClass_SP_8_Call" class="com.rivervalley.ibatis.CMCSPParam">
<parameter property="startIndex" jdbcType="INT" javaType="java.lang.Integer" mode="IN"/>
<parameter property="endIndex" jdbcType="INT" javaType="java.lang.Integer" mode="IN"/>
</parameterMap>

<procedure id="selectCMCClass_SP_7" resultMap="cmcSearchResult">
{ call [MS\xxx].CMC_CLASS_SP_7()}
</procedure>

<procedure id="selectCMCClass_SP_10" resultMap="cmcSearchResult">
{ call [MS\xxx].CMC_CLASS_SP_10()}
</procedure>

<select id="getAllCMC" resultMap="cmcSearchResult">
SELECT * FROM [MS\bupadhy].CMC_CSCS_CLASS
</select>


</sqlMap>


Step 4: Sample Domain Class

(CMCClass.java)

package com.rivervalley.cmc_class;
public class CMCClass implements java.io.Serializable {

private String cscsId;
private String cscsDesc;
private int grgrCK;

public CMCClass() {
}

public CMCClass(String cscsDesc) {
this.cscsDesc = cscsDesc;
}

public String getCscsId() {
return this.cscsId;
}

public void setCscsId(String cscsId) {
this.cscsId = cscsId;
}

public String getCscsDesc() {
return this.cscsDesc;
}

public void setCscsDesc(String cscsDesc) {
this.cscsDesc = cscsDesc;
}
public int getGrgrCK() {
return grgrCK;
}

public void setGrgrCK(int grgrCK) {
this.grgrCK = grgrCK;
}

}


I did not find much resources for using stored procedures in hibernate, thought of sharing some of my work for feedback! It seems there are two major approaches of integrating persistence sytems with java based business tiers. The first one, architects first design databases (from entity-relationship view point) and design business tiers to adapt with those DB structures. Most of the old/legacy systems are found falling in this category. The architects who have rich experience in OO design, they first model the real world business with objects, i. e. first the object systems, these objects are actually data, then they think about persisting those data. In this approach, DB structure is driven by OO system. I THINK THAT'S WHERE HIBERNATE FITS THE BEST. However, it can adapt with E-R driven system design though it may not be the best. iBATIS might provide more flexibility for legacy systems.

DISCLAIMER: THE CODE MAY CONTAIN UNUSED/REDUNDANT/UNNECESSARY LOCs, PLEASE USE WITH YOUR JUDGEMENT! ANY NAMES USED ARE HYPOTHETICAL AND DO NOT REFLECT ANY ORGANIZATIONAL NAMES. THE CODE ALSO DOES NOT REFLECT ANY ORGANIZATIONAL POLICIES AND IT IS NOT ATTACHED TO ANY ORGANIZATION.

STEP 1: Java Calling Methods:
---------------------------------------------------
Step 1-a (Only Using Hibernate Connection Manager):

// PERMISSION OK : grant exec on CMC_CLASS_SP_7 to ECONUSER
public static void callDBResultSetMSSQL(){
Session session = null;
CallableStatement callable = null;
Connection con = null;
List<CMCClass> classes = null;
Transaction transaction = null;

session = HibernateUtil.getSessionFactoryDBSW9079().openSession();

try {
con = session.connection();
//transaction = session.beginTransaction();
callable = con.prepareCall("{call [MS\\xxxx].CMC_CLASS_SP_7}");
ResultSet rs1 = callable.executeQuery();

while(rs1.next()){
System.out.println("cscsId: "+rs1.getString("CSCS_ID")+" grgrCK: "+rs1.getInt("GRGR_CK")+" cscsDesc: "+rs1.getString("CSCS_DESC"));
}
// transaction.commit();
} catch(HibernateException e){
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
} finally {
session.close();
}

}
/* ALTER PROCEDURE CMC_CLASS_SP_7
AS
SELECT CSCS_ID, GRGR_CK, CSCS_DESC FROM CMC_CSCS_CLASS WHERE GRGR_CK > 0 AND GRGR_CK < 3
*/


Step 1-b (Calling Unparameterized Stored Procedure):

// WORKS, UNPARAMETERIZED
public static void callDBXMLMSSQL(){
Session session = null;
CallableStatement callable = null;
Connection con = null;
List<CMCClass> classes = null;
Transaction transaction = null;

session = HibernateUtil.getSessionFactoryDBSW9079().openSession();
try {
transaction = session.beginTransaction();
classes = session.getNamedQuery("selectCMCClass_SP_7").list();
for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
CMCClass cmcClass = (CMCClass) iterator.next();
System.out.println(cmcClass.getCscsId()+" :: "+cmcClass.getCscsDesc()+" :: "+cmcClass.getGrgrCK());
}
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}

}


Step 1-c (Calling Parameterized Stored Procedure):


// PARAMETERIZED
public static void callDBXMLMSSQLP(){
Session session = null;
CallableStatement callable = null;
Connection con = null;
List<CMCClass> classes = null;
Transaction transaction = null;

session = HibernateUtil.getSessionFactoryDBSW9079().openSession();
try {
transaction = session.beginTransaction();
classes = session.getNamedQuery("selectCMCClass_SP_8")
.setParameter("startIndex", 1)
.setParameter("endIndex", 3)
.list();
for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
CMCClass cmcClass = (CMCClass) iterator.next();
System.out.println(cmcClass.getCscsId()+" :: "+cmcClass.getCscsDesc()+" :: "+cmcClass.getGrgrCK());
}
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}

}


STEP 2: Hibernate configuration file (contains driver info):
----------------------------------------------------------------------------------
[dbsw9079.cfg.xml] (you could name hibernate.cfg.xml too or anything else that makes sense)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.password">YOUR-DB-PASSWORD</property>
<!--
<property name="hibernate.connection.url">YOUR-DB-CONNECTION-URL-HERE</property>
-->
<!--
<property name="hibernate.connection.url">YOUR-DB-CONNECTION-URL-HERE</property>
-->
<property name="hibernate.connection.url">YOUR-DB-CONNECTION-URL-HERE</property>
<property name="hibernate.connection.username">YOUR-DB-USER-NAME</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.pool_size">1</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<!--
<mapping resource="com/rivervalley/policy/Policy.hbm.xml"/>
-->
<mapping resource="ECIMPhysician.hbm.xml"/>
<mapping resource="CMCClass.hbm.xml"/>
<mapping resource="CMCClassSP.hbm.xml"/>
</session-factory>
</hibernate-configuration>





STEP 3: Named Query, Stored Procedures Mapping File:
---------------------------------------------------------------------------------
[CMCClassSP.hbm.xml]

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<sql-query name="selectCMCClass_SP_3" callable="true">
<return alias="cmcClass" class="com.rivervalley.cmc_class.CMCClass">
<return-property name="cscsId" column="CSCS_ID"/>
<return-property name="grgrCK" column="GRGR_CK"/>
<return-property name="cscsDesc" column="CSCS_DESC"/>
</return>
{ call CMC_CLASS_SP_3(?,:startIndex,:endIndex)}
</sql-query>

<sql-query name="selectCMCClass_SP_7" callable="true">
<return alias="cmcClass" class="com.rivervalley.cmc_class.CMCClass">
<return-property name="cscsId" column="CSCS_ID"/>
<return-property name="grgrCK" column="GRGR_CK"/>
<return-property name="cscsDesc" column="CSCS_DESC"/>
</return>
{ call [MS\xxxx].CMC_CLASS_SP_7()}
</sql-query>

<sql-query name="selectCMCClass_SP_8" callable="true">
<return alias="cmcClass" class="com.rivervalley.cmc_class.CMCClass">
<return-property name="cscsId" column="CSCS_ID"/>
<return-property name="grgrCK" column="GRGR_CK"/>
<return-property name="cscsDesc" column="CSCS_DESC"/>
</return>
{ call [MS\xxxx].CMC_CLASS_SP_8(:startIndex,:endIndex)}
</sql-query>

</hibernate-mapping>

===========================================================
If you are curious, how CMCClass.hbm.xml looks like:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.rivervalley.cmc_class.CMCClass" table="CMC_CSCS_CLASS">
<meta attribute="class-description">
This class contains the CMC class description.
</meta>
<id name="cscsId" type="string" column="CSCS_ID">
<generator class="native"/>
</id>
<property name="grgrCK" type="int" column="GRGR_CK" not-null="true" />
<property name="cscsDesc" type="string" column="CSCS_DESC" not-null="true" />
</class>
</hibernate-mapping>

===========================================================
ADDITIONAL STUFFS:

HibernateUtil.java (for multiple database connectivity)

package com.rivervalley.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
//private static final SessionFactory sessionFactory;
private static final SessionFactory sfFacetsd2;
private static final SessionFactory sf_dbsw9079;
private static final SessionFactory sfFacetst2;
static {
try {
sfFacetsd2 = new Configuration().configure("facetsd2.cfg.xml").buildSessionFactory();
sf_dbsw9079 = new Configuration().configure("dbsw9079.cfg.xml").buildSessionFactory();
sfFacetst2 = new Configuration().configure("facetst2.cfg.xml").buildSessionFactory();
//sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactoryFacetsD2() {
return sfFacetsd2;
}

public static SessionFactory getSessionFactoryDBSW9079() {
return sf_dbsw9079;
}

public static SessionFactory getSessionFactoryFacetsT2() {
return sfFacetst2;
}
}