Author: sohil.shah(a)jboss.com
Date: 2009-01-15 04:42:05 -0500 (Thu, 15 Jan 2009)
New Revision: 12512
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java
Log:
JBPORTAL-2258 - Create file in CMS not working for several databases
* locally passed for oracle10g, postgresql8, mysql5, hsqdlb
* contrary to earlier discussion, nothing special needed for postgresql support
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java 2009-01-15
06:38:09 UTC (rev 12511)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/HibernateStore.java 2009-01-15
09:42:05 UTC (rev 12512)
@@ -215,8 +215,7 @@
String name = FileSystemPathUtil.getName(filePath);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
-
+ session.beginTransaction();
try
{
@@ -262,13 +261,12 @@
}
}
+ session.getTransaction().commit();
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to delete file: " + filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -296,8 +294,7 @@
String name = FileSystemPathUtil.getName(folderPath);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
-
+ session.beginTransaction();
try
{
@@ -349,13 +346,12 @@
}
}
+ session.getTransaction().commit();
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to delete folder: " + folderPath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -378,7 +374,7 @@
String name = FileSystemPathUtil.getName(path);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(selectExistStmt)
@@ -394,10 +390,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to check existence of file system entry: " +
path;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -421,7 +415,7 @@
String name = FileSystemPathUtil.getName(path);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(selectFileExistStmt)
@@ -434,14 +428,13 @@
{
return true;
}
+
return false;
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to check existence of file: " + path;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -464,7 +457,7 @@
String name = FileSystemPathUtil.getName(path);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(selectFolderExistStmt)
@@ -477,14 +470,13 @@
{
return true;
}
+
return false;
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to check existence of folder: " + path;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -507,7 +499,7 @@
String name = FileSystemPathUtil.getName(path);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(selectLastModifiedStmt)
@@ -524,10 +516,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to determine lastModified of file system entry: "
+ path;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -550,7 +540,7 @@
String name = FileSystemPathUtil.getName(filePath);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(selectLengthStmt)
@@ -567,10 +557,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to determine length of file: " + filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -595,7 +583,7 @@
}
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(selectChildCountStmt)
@@ -617,10 +605,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to determine child count of file system entry: "
+ path;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -857,8 +843,7 @@
String name = FileSystemPathUtil.getName(filePath);
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
-
+ session.beginTransaction();
try
{
Query query = session.createQuery(selectDataStmt)
@@ -866,20 +851,18 @@
.setString(1, name);
List rs = query.list();
- //
+
Iterator iter = rs.iterator();
//byte[] blob = (byte[])iter.next();
//return new ByteArrayInputStream(blob);
- java.sql.Blob blob = (java.sql.Blob)iter.next();
- return blob.getBinaryStream();
+ java.sql.Blob blob = (java.sql.Blob)iter.next();
+ return new ByteArrayInputStream(IOTools.getBytes(blob.getBinaryStream()));
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to retrieve data of file: " + filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -932,7 +915,7 @@
{
// update
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
long length = f.length();
@@ -997,13 +980,12 @@
session.save(repoEntry);
session.flush();
}
+ session.getTransaction().commit();
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to update existing file: " +
filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -1012,7 +994,7 @@
else // create new
{
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
long length = f.length();
@@ -1041,13 +1023,12 @@
session.save(repoEntry);
session.flush();
}
+ session.getTransaction().commit();
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to create new file: " + filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -1076,13 +1057,6 @@
}
}
- private Blob createBlob(InputStream in)
- throws IOException
- {
- return Hibernate.createBlob(in);
-// return new ByteArrayBlob(in);
- }
-
/**
*
*/
@@ -1153,7 +1127,7 @@
{
// update
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
long length = f.length();
@@ -1219,13 +1193,12 @@
session.save(repoEntry);
session.flush();
}
+ session.getTransaction().commit();
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to update existing file: " +
filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -1234,7 +1207,7 @@
else
{
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
long length = f.length();
@@ -1263,13 +1236,12 @@
session.save(repoEntry);
session.flush();
}
+ session.getTransaction().commit();
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to create new file: " + filePath;
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -1449,7 +1421,7 @@
{
// check if root file system entry exists
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(selectFolderExistStmt)
@@ -1465,10 +1437,7 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
String msg = "failed to check existence of file system root entry";
log.error(msg, e);
throw new FileSystemException(msg, e);
@@ -1500,7 +1469,7 @@
}
Session session = hibernateSessionFactory.getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
if (schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
@@ -1523,13 +1492,12 @@
session.save(repoEntry);
session.flush();
}
+ session.getTransaction().commit();
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to create folder entry: " + folderPath;
log.error(msg, e);
throw new FileSystemException(msg, e);
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2009-01-15
06:38:09 UTC (rev 12511)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2009-01-15
09:42:05 UTC (rev 12512)
@@ -530,13 +530,10 @@
// parse propertyData into propertyState
if (nodeData != null)
{
- Session session = null;
- Transaction tx = null;
+ Session session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
+ session.beginTransaction();
try
{
- session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
- tx = session.beginTransaction();
-
InputStream in = new ByteArrayInputStream(nodeData);
// setup the propertyState
@@ -546,10 +543,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
if (e instanceof NoSuchItemStateException)
{
throw (NoSuchItemStateException)e;
@@ -798,13 +793,10 @@
// parse propertyData into propertyState
if (propertyData != null)
{
- Session session = null;
- Transaction tx = null;
+ Session session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
+ session.beginTransaction();
try
- {
- session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
- tx = session.beginTransaction();
-
+ {
InputStream in = new ByteArrayInputStream(propertyData);
// setup the propertyState
@@ -814,10 +806,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
if (e instanceof NoSuchItemStateException)
{
throw (NoSuchItemStateException)e;
@@ -1104,13 +1094,10 @@
// parse propertyData into propertyState
if (nodeData != null)
{
- Session session = null;
- Transaction tx = null;
+ Session session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
+ session.beginTransaction();
try
{
- session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
- tx = session.beginTransaction();
-
InputStream in = new ByteArrayInputStream(nodeData);
// setup the propertyState
@@ -1120,10 +1107,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
if (e instanceof NoSuchItemStateException)
{
throw (NoSuchItemStateException)e;
@@ -1291,30 +1276,19 @@
*/
public void store(ChangeLog changeLog) throws ItemStateException
{
- Session session = null;
- Transaction tx = null;
+ Session session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
+ session.beginTransaction();
try
- {
- session = HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
- tx = session.beginTransaction();
+ {
storeHB(changeLog);
}
catch (ItemStateException e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
throw e;
}
}
- private Blob createBlob(byte[] bytes)
- {
- return Hibernate.createBlob(bytes);
- // return new ByteArrayBlob(bytes);
- }
-
public void storeHB(ChangeLog changeLog) throws ItemStateException
{
Iterator iter = changeLog.deletedStates();
@@ -1394,7 +1368,7 @@
}
Session session =
HibernateUtil.getSessionFactory(this.jndiName).getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(query).setString(0, id).list();
@@ -1403,10 +1377,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to check existence of node state: " + id;
log.error(msg, e);
throw new ItemStateException(msg, e);
@@ -1449,7 +1421,7 @@
public InputStream get(String blobId) throws Exception
{
Session session =
HibernateUtil.getSessionFactory(jndiName).getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
List rs = session.createQuery(blobSelectData).setString(0, blobId)
@@ -1483,10 +1455,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
if (e instanceof NoSuchItemStateException)
{
throw (NoSuchItemStateException)e;
@@ -1506,7 +1476,7 @@
boolean update = exists(blobId);
Session session =
HibernateUtil.getSessionFactory(jndiName).getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
if (update)
{
try
@@ -1547,10 +1517,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to write node state: " + blobId;
log.error(msg, e);
throw new ItemStateException(msg, e);
@@ -1585,10 +1553,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to write node state: " + blobId;
log.error(msg, e);
throw new ItemStateException(msg, e);
@@ -1603,7 +1569,7 @@
public boolean remove(String blobId) throws Exception
{
Session session =
HibernateUtil.getSessionFactory(jndiName).getCurrentSession();
- Transaction tx = session.beginTransaction();
+ session.beginTransaction();
try
{
Query query = session.createQuery(nodeBinValSelect).setString(0,
@@ -1617,10 +1583,8 @@
}
catch (Exception e)
{
- if(tx != null)
- {
- tx.rollback();
- }
+ session.getTransaction().rollback();
+
String msg = "failed to delete binval: " + blobId;
log.error(msg, e);
throw new ItemStateException(msg, e);
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2009-01-15
06:38:09 UTC (rev 12511)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2009-01-15
09:42:05 UTC (rev 12512)
@@ -418,34 +418,25 @@
}
public Object execute(Command cmd) throws CMSException
- {
- org.apache.jackrabbit.core.XASession session = null;
- try
- {
- session = (org.apache.jackrabbit.core.XASession)jcr.login("anonid",
"");
- }
- catch (Exception e)
- {
- throw new RuntimeException(e); // Fixme
- }
-
+ {
+ org.apache.jackrabbit.core.XASession session = null;
Object obj = null;
boolean isClusterDelegatedRequest = false; //used to indicate this request is from
another cluster node instead of the master node
- boolean clusterWorkflowStatus = false;
-
- TransactionManager tm = null;
- org.hibernate.Session hibernateSession = null;
- UserTransaction tx = null;
+ boolean clusterWorkflowStatus = false;
+ TransactionManager tm = null;
+ UserTransaction tx = null;
boolean isStartedHere = false;
try
{
tm = TransactionManagerProvider.JBOSS_PROVIDER.getTransactionManager();
+ isStartedHere = false;
if(tm.getStatus() == Status.STATUS_NO_TRANSACTION)
{
tm.begin();
isStartedHere = true;
}
- hibernateSession =
HibernateUtil.getSessionFactory(cmsSessionFactory).getCurrentSession();
+
+ session = (org.apache.jackrabbit.core.XASession)jcr.login("anonid",
"");
tx = new JackRabbitTransaction(session);
tx.begin();