Accessing a Teneo Resource
If you create a property named sessionFactory of type Teneo Resource
Template, TIBCO Business Studio adds the following to the abstract
implementation class:
import org.osoa.sca.annotations.Property;
import com.tibco.amf.sharedresource.runtime.core.teneo.sharedresource.TeneoSessionFactory;
private TeneoSessionFactory sessionFactory;
@Property(name = "sessionFactory")
public void setSessionFactory(TeneoSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public TeneoSessionFactory getSessionFactory() {
return sessionFactory;
}
Procedure
Example
...
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
Session session = null;
Transaction tx = null;
try {
session = getSessionFactory().openSession();
tx = session.beginTransaction();
Query q = session.createQuery("...");
User user = (User)q.uniqueResult();
Trip trip = ...;
...
id = (Long) session.save(trip);
user.getTrips().add(trip);
session.save(user);
}
catch (Throwable th) {
error = true;
result = "failed: " + th.getMessage();
th.printStackTrace();
}
finally {
if (tx != null) {
if (error) {
try {
tx.rollback();
}
catch (Throwable th) {
th.printStackTrace();
}
}
else {
try {
tx.commit();
}
catch (Throwable th) {
th.printStackTrace();
}
}
}
if (session != null) {
try {
session.close();
}
catch (Throwable th) {
th.printStackTrace();
}
}
...
Copyright © Cloud Software Group, Inc. All rights reserved.