Author: sohil.shah(a)jboss.com
Date: 2007-03-30 17:03:45 -0400 (Fri, 30 Mar 2007)
New Revision: 6887
Modified:
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
Log:
fixing large file support issue in HibernatePersistenceManager
Modified:
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java
===================================================================
---
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java 2007-03-30
17:20:07 UTC (rev 6886)
+++
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java 2007-03-30
21:03:45 UTC (rev 6887)
@@ -69,7 +69,8 @@
{
/** Logger instance */
- private static Logger log = Logger.getLogger(HibernatePersistenceManager.class);
+ private static Logger log = Logger
+ .getLogger(HibernatePersistenceManager.class);
protected static final String SCHEMA_OBJECT_PREFIX_VARIABLE =
"${schemaObjectPrefix}";
@@ -120,7 +121,10 @@
/** file system where BLOB data is stored (if
<code>externalBLOBs==true</code>) */
protected FileSystem blobFS;
- /** BLOBStore that manages BLOB data in the file system (if
<code>externalBLOBs==true</code>) */
+ /**
+ * BLOBStore that manages BLOB data in the file system (if
+ * <code>externalBLOBs==true</code>)
+ */
protected BLOBStore blobStore;
/** Creates a new <code>SimpleDbPersistenceManager</code> instance. */
@@ -131,10 +135,10 @@
initialized = false;
}
- //---------------------------------------------------< PersistenceManager >
+ // ---------------------------------------------------< PersistenceManager >
/**
- *
+ *
*/
public void init(PMContext context) throws Exception
{
@@ -143,30 +147,39 @@
throw new IllegalStateException("already initialized");
}
- //hibernateSessionFactory = HibernateUtil.getSessionFactory(jndiName);
+ // hibernateSessionFactory = HibernateUtil.getSessionFactory(jndiName);
org.jboss.portal.cms.hibernate.state.Tools.init(jndiName);
- hibernateSessionFactory =
org.jboss.portal.cms.hibernate.state.Tools.getSessionFactory();
+ hibernateSessionFactory = org.jboss.portal.cms.hibernate.state.Tools
+ .getSessionFactory();
- nodeBinValSelect = "from " + schemaObjectPrefix + "BinVal where
BINVAL_ID = ?";
+ nodeBinValSelect = "from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
nodeStateSelect = "from " + schemaObjectPrefix + "Node where NODE_ID
= ?";
- nodeStateSelectData = "select data from " + schemaObjectPrefix +
"Node where NODE_ID = ?";
- nodeStateSelectExist = "select 1 from " + schemaObjectPrefix + "Node
where NODE_ID = ?";
+ nodeStateSelectData = "select data from " + schemaObjectPrefix
+ + "Node where NODE_ID = ?";
+ nodeStateSelectExist = "select 1 from " + schemaObjectPrefix
+ + "Node where NODE_ID = ?";
- propertyStateSelect = "from " + schemaObjectPrefix + "Prop where
PROP_ID = ?";
- propertyStateSelectData = "select data from " + schemaObjectPrefix +
"Prop where PROP_ID = ?";
- propertyStateSelectExist = "select 1 from " + schemaObjectPrefix +
"Prop where PROP_ID = ?";
+ propertyStateSelect = "from " + schemaObjectPrefix
+ + "Prop where PROP_ID = ?";
+ propertyStateSelectData = "select data from " + schemaObjectPrefix
+ + "Prop where PROP_ID = ?";
+ propertyStateSelectExist = "select 1 from " + schemaObjectPrefix
+ + "Prop where PROP_ID = ?";
- nodeReferenceSelect = "from " + schemaObjectPrefix + "Refs where
NODE_ID = ?";
- nodeReferenceSelectData = "select data from " + schemaObjectPrefix +
"Refs where NODE_ID = ?";
- nodeReferenceSelectExist = "select 1 from " + schemaObjectPrefix +
"Refs where NODE_ID = ?";
+ nodeReferenceSelect = "from " + schemaObjectPrefix
+ + "Refs where NODE_ID = ?";
+ nodeReferenceSelectData = "select data from " + schemaObjectPrefix
+ + "Refs where NODE_ID = ?";
+ nodeReferenceSelectExist = "select 1 from " + schemaObjectPrefix
+ + "Refs where NODE_ID = ?";
-
if (externalBLOBs)
{
/**
- * store BLOBs in local file system in a sub directory
- * of the workspace home directory
+ * store BLOBs in local file system in a sub directory of the workspace
+ * home directory
*/
LocalFileSystem blobFS = new LocalFileSystem();
blobFS.setRoot(new File(context.getHomeDir(), "blobs"));
@@ -181,18 +194,21 @@
*/
blobStore = new DbBLOBStore();
- blobSelect = "from " + schemaObjectPrefix + "BinVal where
BINVAL_ID = ?";
- blobSelectData = "select data from " + schemaObjectPrefix +
"BinVal where BINVAL_ID = ?";
- blobSelectExist = "select 1 from " + schemaObjectPrefix + "BinVal
where BINVAL_ID = ?";
+ blobSelect = "from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
+ blobSelectData = "select data from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
+ blobSelectExist = "select 1 from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
}
initialized = true;
}
- //---------------------------------------------------< PersistenceManager >
+ // ---------------------------------------------------< PersistenceManager >
/**
- *
+ *
*/
public void close() throws Exception
{
@@ -248,7 +264,7 @@
public void setSchemaObjectPrefix(String schemaObjectPrefix)
{
- this.schemaObjectPrefix = schemaObjectPrefix;//.toUpperCase();
+ this.schemaObjectPrefix = schemaObjectPrefix;// .toUpperCase();
}
public boolean isExternalBLOBs()
@@ -266,7 +282,7 @@
this.externalBLOBs = Boolean.valueOf(externalBLOBs).booleanValue();
}
- //---------------------------------------------------< PersistenceManager >
+ // ---------------------------------------------------< PersistenceManager >
public void store(ChangeLog changeLog) throws ItemStateException
{
@@ -306,46 +322,46 @@
Iterator iter = changeLog.deletedStates();
while (iter.hasNext())
{
- ItemState state = (ItemState)iter.next();
+ ItemState state = (ItemState) iter.next();
if (state.isNode())
{
- destroy((NodeState)state);
+ destroy((NodeState) state);
}
else
{
- destroy((PropertyState)state);
+ destroy((PropertyState) state);
}
}
iter = changeLog.addedStates();
while (iter.hasNext())
{
- ItemState state = (ItemState)iter.next();
+ ItemState state = (ItemState) iter.next();
if (state.isNode())
{
- store((NodeState)state);
+ store((NodeState) state);
}
else
{
- store((PropertyState)state);
+ store((PropertyState) state);
}
}
iter = changeLog.modifiedStates();
while (iter.hasNext())
{
- ItemState state = (ItemState)iter.next();
+ ItemState state = (ItemState) iter.next();
if (state.isNode())
{
- update((NodeState)state);
+ update((NodeState) state);
}
else
{
- update((PropertyState)state);
+ update((PropertyState) state);
}
}
iter = changeLog.modifiedRefs();
while (iter.hasNext())
{
- NodeReferences refs = (NodeReferences)iter.next();
+ NodeReferences refs = (NodeReferences) iter.next();
if (refs.hasReferences())
{
store(refs);
@@ -360,7 +376,8 @@
}
}
- public NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException
+ public NodeState load(NodeId id) throws NoSuchItemStateException,
+ ItemStateException
{
if (!initialized)
{
@@ -373,13 +390,14 @@
InputStream in = null;
try
{
- List rs = session.createQuery(nodeStateSelectData).setString(0,
id.toString()).list();
+ List rs = session.createQuery(nodeStateSelectData).setString(0,
+ id.toString()).list();
Iterator iter = rs.iterator();
- //java.sql.Blob blob = (java.sql.Blob) iter.next();
- //in = blob.getBinaryStream();
- byte[] data = (byte[])iter.next();
+ // java.sql.Blob blob = (java.sql.Blob) iter.next();
+ // in = blob.getBinaryStream();
+ byte[] data = (byte[]) iter.next();
in = new java.io.ByteArrayInputStream(data);
NodeState state = createNew(id);
@@ -393,7 +411,7 @@
tx.rollback();
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
String msg = "failed to read node state: " + id;
log.error(msg, e);
@@ -405,7 +423,8 @@
}
}
- public PropertyState load(PropertyId id) throws NoSuchItemStateException,
ItemStateException
+ public PropertyState load(PropertyId id) throws NoSuchItemStateException,
+ ItemStateException
{
if (!initialized)
{
@@ -418,15 +437,15 @@
InputStream in = null;
try
{
- List rs =
session.createQuery(propertyStateSelectData).setCacheable(true).setString(0,
id.toString()).list();
+ List rs = session.createQuery(propertyStateSelectData).setCacheable(
+ true).setString(0, id.toString()).list();
Iterator iter = rs.iterator();
- //java.sql.Blob blob = (java.sql.Blob) iter.next();
- //in = blob.getBinaryStream();
- byte[] data = (byte[])iter.next();
+ // java.sql.Blob blob = (java.sql.Blob) iter.next();
+ // in = blob.getBinaryStream();
+ byte[] data = (byte[]) iter.next();
in = new java.io.ByteArrayInputStream(data);
-
PropertyState state = createNew(id);
Serializer.deserialize(state, in, blobStore);
Tools.safeClose(in);
@@ -438,7 +457,7 @@
tx.rollback();
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
String msg = "failed to read property state: " + id.toString();
log.error(msg, e);
@@ -451,9 +470,10 @@
}
/**
- *
+ *
*/
- public NodeReferences load(NodeReferencesId targetId) throws NoSuchItemStateException,
ItemStateException
+ public NodeReferences load(NodeReferencesId targetId)
+ throws NoSuchItemStateException, ItemStateException
{
if (!initialized)
{
@@ -465,13 +485,14 @@
InputStream in = null;
try
{
- List rs =
session.createQuery(nodeReferenceSelectData).setCacheable(true).setString(0,
targetId.toString()).list();
+ List rs = session.createQuery(nodeReferenceSelectData).setCacheable(
+ true).setString(0, targetId.toString()).list();
Iterator iter = rs.iterator();
if (!iter.hasNext())
{
throw new NoSuchItemStateException(targetId.toString());
}
- byte[] data = (byte[])iter.next();
+ byte[] data = (byte[]) iter.next();
in = new java.io.ByteArrayInputStream(data);
NodeReferences refs = new NodeReferences(targetId);
@@ -485,7 +506,7 @@
tx.rollback();
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
String msg = "failed to read references: " + targetId;
log.error(msg, e);
@@ -511,15 +532,19 @@
try
{
Serializer.serialize(state, out);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionNode versionNode = new VersionNode(state.getId().toString(),
out.toByteArray());
+ VersionNode versionNode = new VersionNode(state.getId().toString(),
+ out.toByteArray());
session.save(versionNode);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPNode wspNode = new WSPNode(state.getId().toString(), out.toByteArray());
+ WSPNode wspNode = new WSPNode(state.getId().toString(), out
+ .toByteArray());
session.save(wspNode);
}
}
@@ -546,7 +571,7 @@
private Blob createBlob(byte[] bytes)
{
return Hibernate.createBlob(bytes);
-// return new ByteArrayBlob(bytes);
+ // return new ByteArrayBlob(bytes);
}
private void store(NodeReferences refs) throws ItemStateException
@@ -563,17 +588,20 @@
try
{
Serializer.serialize(refs, out);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionRefs versionRefs = new VersionRefs(refs.getTargetId().toString(), out
- .toByteArray());
+ VersionRefs versionRefs = new VersionRefs(refs.getTargetId()
+ .toString(), out.toByteArray());
session.save(versionRefs);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPRefs wspRefs = new WSPRefs(refs.getTargetId().toString(),
out.toByteArray());
+ WSPRefs wspRefs = new WSPRefs(refs.getTargetId().toString(), out
+ .toByteArray());
session.save(wspRefs);
}
}
@@ -598,12 +626,13 @@
}
/**
- * <p/>
- * This method uses shared <code>PreparedStatement</code>s which must be
executed strictly sequentially. Because this
- * method synchronizes on the persistence manager instance there is no need to
synchronize on the shared statement.
- * If the method would not be sychronized the shared statements would have to be
synchronized.
+ * <p/> This method uses shared <code>PreparedStatement</code>s
which must
+ * be executed strictly sequentially. Because this method synchronizes on the
+ * persistence manager instance there is no need to synchronize on the shared
+ * statement. If the method would not be sychronized the shared statements
+ * would have to be synchronized.
*/
- // public synchronized void store(PropertyState state)
+ // public synchronized void store(PropertyState state)
private void store(PropertyState state) throws ItemStateException
{
if (!initialized)
@@ -619,14 +648,18 @@
{
Serializer.serialize(state, out, blobStore);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionProp versionProp = new VersionProp(state.getId().toString(),
out.toByteArray());
+ VersionProp versionProp = new VersionProp(state.getId().toString(),
+ out.toByteArray());
session.save(versionProp);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPProp wspProp = new WSPProp(state.getId().toString(), out.toByteArray());
+ WSPProp wspProp = new WSPProp(state.getId().toString(), out
+ .toByteArray());
session.save(wspProp);
}
}
@@ -666,20 +699,22 @@
Serializer.serialize(state, out);
Query query = session.createQuery(nodeStateSelect).setCacheable(true);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
query.setString(0, state.getId().toString());
- VersionNode versionNode = (VersionNode)query.uniqueResult();
+ VersionNode versionNode = (VersionNode) query.uniqueResult();
if (versionNode == null)
{
throw new Exception("No such Node: " + state.getId());
}
versionNode.setData(out.toByteArray());
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
query.setString(0, state.getId().toString());
- WSPNode wspNode = (WSPNode)query.uniqueResult();
+ WSPNode wspNode = (WSPNode) query.uniqueResult();
if (wspNode == null)
{
throw new Exception("No such Node: " + state.getId());
@@ -722,21 +757,24 @@
{
Serializer.serialize(state, out, blobStore);
- Query query = session.createQuery(propertyStateSelect).setCacheable(true);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ Query query = session.createQuery(propertyStateSelect).setCacheable(
+ true);
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
query.setString(0, state.getId().toString());
- VersionProp versionProp = (VersionProp)query.uniqueResult();
+ VersionProp versionProp = (VersionProp) query.uniqueResult();
if (versionProp == null)
{
throw new Exception("No such Property: " + state.getId());
}
versionProp.setData(out.toByteArray());
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
query.setString(0, state.getId().toString());
- WSPProp wspProp = (WSPProp)query.uniqueResult();
+ WSPProp wspProp = (WSPProp) query.uniqueResult();
if (wspProp == null)
{
throw new Exception("No such Property: " + state.getId());
@@ -775,10 +813,8 @@
Session session = hibernateSessionFactory.getCurrentSession();
try
{
- Query query = session.
- createQuery(nodeStateSelect).
- setCacheable(true).
- setString(0, state.getId().toString());
+ Query query = session.createQuery(nodeStateSelect).setCacheable(true)
+ .setString(0, state.getId().toString());
Object result = query.uniqueResult();
if (result != null)
{
@@ -812,11 +848,12 @@
{
if (val.getType() == PropertyType.BINARY)
{
- BLOBFileValue blobVal = (BLOBFileValue)val.internalValue();
+ BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
// delete internal resource representation of BLOB value
blobVal.delete(true);
// also remove from BLOBStore
- String blobId = blobStore.createId((PropertyId)state.getId(), i);
+ String blobId = blobStore.createId(
+ (PropertyId) state.getId(), i);
try
{
blobStore.remove(blobId);
@@ -835,8 +872,8 @@
try
{
- Query query =
session.createQuery(propertyStateSelect).setCacheable(true).setString(0,
- state.getId().toString());
+ Query query = session.createQuery(propertyStateSelect).setCacheable(
+ true).setString(0, state.getId().toString());
Object result = query.uniqueResult();
if (result != null)
{
@@ -854,7 +891,7 @@
}
/**
- *
+ *
*/
private void destroy(NodeReferences refs) throws ItemStateException
{
@@ -866,8 +903,8 @@
Session session = hibernateSessionFactory.getCurrentSession();
try
{
- Query query =
session.createQuery(nodeReferenceSelect).setCacheable(true).setString(0,
- refs.getTargetId().toString());
+ Query query = session.createQuery(nodeReferenceSelect).setCacheable(
+ true).setString(0, refs.getTargetId().toString());
List list = query.list();
if (list == null)
@@ -895,7 +932,7 @@
}
/**
- *
+ *
*/
public boolean exists(NodeId id) throws ItemStateException
{
@@ -903,7 +940,7 @@
}
/**
- *
+ *
*/
protected boolean exists(String blobid) throws ItemStateException
{
@@ -911,7 +948,7 @@
}
/**
- *
+ *
*/
public boolean exists(PropertyId id) throws ItemStateException
{
@@ -919,7 +956,7 @@
}
/**
- *
+ *
*/
public boolean exists(NodeReferencesId targetId) throws ItemStateException
{
@@ -936,7 +973,8 @@
Session session = hibernateSessionFactory.openSession();
try
{
- List rs = session.createQuery(query).setCacheable(true).setString(0,
id).list();
+ List rs = session.createQuery(query).setCacheable(true).setString(0,
+ id).list();
Iterator iter = rs.iterator();
return iter.hasNext();
}
@@ -953,7 +991,7 @@
}
- //-------------------------------------------------< misc. helper methods >
+ // -------------------------------------------------< misc. helper methods >
protected void logException(String message, SQLException se)
{
@@ -966,12 +1004,12 @@
log.debug(" dump:", se);
}
- //--------------------------------------------------------< inner classes >
+ // --------------------------------------------------------< inner classes >
class DbBLOBStore implements BLOBStore
{
/**
- *
+ *
*/
public String createId(PropertyId id, int index)
{
@@ -985,16 +1023,17 @@
}
/**
- *
+ *
*/
public InputStream get(String blobId) throws Exception
{
Session session = hibernateSessionFactory.getCurrentSession();
try
{
- List rs = session.createQuery(blobSelectData).setCacheable(true).setString(0,
blobId).list();
+ List rs = session.createQuery(blobSelectData).setCacheable(true)
+ .setString(0, blobId).list();
Iterator iter = rs.iterator();
- java.sql.Blob blob = (java.sql.Blob)iter.next();
+ java.sql.Blob blob = (java.sql.Blob) iter.next();
InputStream is = blob.getBinaryStream();
return is;
}
@@ -1002,7 +1041,7 @@
{
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
String msg = "failed to read binary data: " + blobId;
log.error(msg, e);
@@ -1011,9 +1050,10 @@
}
/**
- *
+ *
*/
- public void put(String blobId, InputStream in, long size) throws Exception
+ public void put(String blobId, InputStream in, long size)
+ throws Exception
{
boolean update = exists(blobId);
@@ -1025,10 +1065,12 @@
{
Query query = session.createQuery(blobSelect).setCacheable(true);
- if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
query.setString(0, blobId);
- VersionBinVal versionNode = (VersionBinVal)query.uniqueResult();
+ VersionBinVal versionNode = (VersionBinVal) query
+ .uniqueResult();
if (versionNode == null)
{
throw new Exception("No such Node: " + blobId);
@@ -1036,10 +1078,11 @@
versionNode.setId(blobId);
versionNode.setData(Hibernate.createBlob(in));
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
query.setString(0, blobId);
- WSPBinVal wspNode = (WSPBinVal)query.uniqueResult();
+ WSPBinVal wspNode = (WSPBinVal) query.uniqueResult();
if (wspNode == null)
{
throw new Exception("No such Node: " + blobId);
@@ -1054,6 +1097,10 @@
log.error(msg, e);
throw new ItemStateException(msg, e);
}
+ finally
+ {
+ session.flush();
+ }
}
else
// insert
@@ -1061,14 +1108,18 @@
try
{
- if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionBinVal versionNode = new VersionBinVal(blobId,
Hibernate.createBlob(in));
+ VersionBinVal versionNode = new VersionBinVal(blobId,
+ Hibernate.createBlob(in));
session.save(versionNode);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPBinVal wspNode = new WSPBinVal(blobId, Hibernate.createBlob(in));
+ WSPBinVal wspNode = new WSPBinVal(blobId, Hibernate
+ .createBlob(in));
session.save(wspNode);
}
}
@@ -1078,19 +1129,24 @@
log.error(msg, e);
throw new ItemStateException(msg, e);
}
+ finally
+ {
+ session.flush();
+ }
}
}
/**
- *
+ *
*/
- // public synchronized boolean remove(String blobId) throws Exception
+ // public synchronized boolean remove(String blobId) throws Exception
public boolean remove(String blobId) throws Exception
{
Session session = hibernateSessionFactory.getCurrentSession();
try
{
- Query query =
session.createQuery(nodeBinValSelect).setCacheable(true).setString(0, blobId);
+ Query query = session.createQuery(nodeBinValSelect).setCacheable(
+ true).setString(0, blobId);
Object result = query.uniqueResult();
if (result != null)
{
@@ -1104,23 +1160,27 @@
log.error(msg, e);
throw new ItemStateException(msg, e);
}
+ finally
+ {
+ session.flush();
+ }
}
}
}
/*
- * Copyright 2004-2005 The Apache Software Foundation or its licensors,
- * as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
*/
\ No newline at end of file
Modified:
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
===================================================================
---
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-03-30
17:20:07 UTC (rev 6886)
+++
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-03-30
21:03:45 UTC (rev 6887)
@@ -22,7 +22,6 @@
******************************************************************************/
package org.jboss.portal.cms.hibernate.state;
-
import org.apache.jackrabbit.core.NodeId;
import org.apache.jackrabbit.core.PropertyId;
import org.apache.jackrabbit.core.fs.FileSystem;
@@ -58,7 +57,6 @@
import javax.jcr.PropertyType;
import javax.management.MBeanServer;
-import javax.naming.InitialContext;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -71,13 +69,14 @@
/*
* Created on Aug 28, 2006
- *
+ *
* @author <a href="mailto:sohil.shah@jboss.com">Sohil Shah</a>
*/
public class JBossCachePersistenceManager implements PersistenceManager
{
/** Logger instance */
- private static Logger log = Logger.getLogger(JBossCachePersistenceManager.class);
+ private static Logger log = Logger
+ .getLogger(JBossCachePersistenceManager.class);
protected static final String SCHEMA_OBJECT_PREFIX_VARIABLE =
"${schemaObjectPrefix}";
@@ -92,7 +91,6 @@
// initial size of buffer used to serialize objects
protected static final int INITIAL_BUFFER_SIZE = 1024;
-
// shared statements for BLOB management
// (if <code>externalBLOBs==false</code>)
protected String blobSelect = null;
@@ -106,23 +104,27 @@
/** file system where BLOB data is stored (if
<code>externalBLOBs==true</code>) */
protected FileSystem blobFS = null;
- /** BLOBStore that manages BLOB data in the file system (if
<code>externalBLOBs==true</code>) */
+ /**
+ * BLOBStore that manages BLOB data in the file system (if
+ * <code>externalBLOBs==true</code>)
+ */
protected BLOBStore blobStore = null;
/**
- * JackRabbit initalizes multiple instances of the Persistence Manager to perform its
operations.
- * A static TreeCache is used to make sure there is only once instance of the cache
per VM where
- * the CMS node runs.
+ * JackRabbit initalizes multiple instances of the Persistence Manager to
+ * perform its operations. A static TreeCache is used to make sure there is
+ * only once instance of the cache per VM where the CMS node runs.
*
- * One side effect of using a static instance is proper cleanup which is addressed in
the close
- * method
+ * One side effect of using a static instance is proper cleanup which is
+ * addressed in the close method
*/
private static TreeCacheMBean pmCache = null;
+
private static boolean preloaded = false;
/**
*
- *
+ *
*/
public JBossCachePersistenceManager()
{
@@ -131,7 +133,7 @@
initialized = false;
}
-
//------------------------------------------------------------------------------------------------------------------------------------------------
+ //
------------------------------------------------------------------------------------------------------------------------------------------------
public String getJNDIName()
{
return jndiName;
@@ -149,7 +151,7 @@
public void setSchemaObjectPrefix(String schemaObjectPrefix)
{
- this.schemaObjectPrefix = schemaObjectPrefix;//.toUpperCase();
+ this.schemaObjectPrefix = schemaObjectPrefix;// .toUpperCase();
}
public boolean isExternalBLOBs()
@@ -167,24 +169,24 @@
this.externalBLOBs = Boolean.valueOf(externalBLOBs).booleanValue();
}
-
/*
- *
- */
+ *
+ */
public void init(PMContext context) throws Exception
- {
+ {
if (initialized)
{
throw new IllegalStateException("already initialized");
}
- nodeBinValSelect = "from " + schemaObjectPrefix + "BinVal where
BINVAL_ID = ?";
+ nodeBinValSelect = "from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
if (externalBLOBs)
{
/**
- * store BLOBs in local file system in a sub directory
- * of the workspace home directory
+ * store BLOBs in local file system in a sub directory of the workspace
+ * home directory
*/
LocalFileSystem blobFS = new LocalFileSystem();
blobFS.setRoot(new File(context.getHomeDir(), "blobs"));
@@ -199,9 +201,12 @@
*/
blobStore = new DbBLOBStore();
- blobSelect = "from " + schemaObjectPrefix + "BinVal where
BINVAL_ID = ?";
- blobSelectData = "select data from " + schemaObjectPrefix +
"BinVal where BINVAL_ID = ?";
- blobSelectExist = "select 1 from " + schemaObjectPrefix + "BinVal
where BINVAL_ID = ?";
+ blobSelect = "from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
+ blobSelectData = "select data from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
+ blobSelectExist = "select 1 from " + schemaObjectPrefix
+ + "BinVal where BINVAL_ID = ?";
}
initialized = true;
@@ -213,27 +218,32 @@
{
/*
- * performing an mbean lookup of the tree cache service. Ideally it would be
nice to avoid this
- * and have the service be injected from the sar config. But, a
PersistenceManager's lifecycle is managed
+ * performing an mbean lookup of the tree cache service. Ideally it
+ * would be nice to avoid this and have the service be injected from
+ * the sar config. But, a PersistenceManager's lifecycle is managed
* by JackRabbit and is not easily modeled as a JMX mbean service.
*
- * The typical mbean lifecycle doesn't map here unless the PM serves as a
wrapper/proxy to an mbean
- * service, but not sure if the extra layer is necessary.
+ * The typical mbean lifecycle doesn't map here unless the PM serves
+ * as a wrapper/proxy to an mbean service, but not sure if the extra
+ * layer is necessary.
*
- * Also, see the close method to see how the PM cache service is cleaned up.
+ * Also, see the close method to see how the PM cache service is
+ * cleaned up.
*/
try
{
MBeanServer server = MBeanServerLocator.locateJBoss();
- pmCache = (TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class,
- "cms.pm.cache:service=TreeCache", server);
+ pmCache = (TreeCacheMBean) MBeanProxyExt.create(
+ TreeCacheMBean.class, "cms.pm.cache:service=TreeCache",
+ server);
}
catch (Exception e)
{
- }
+ }
- //try to load from specified configuration if any
- //if nothing found in the environment...chances are running in a non-managed
environment
+ // try to load from specified configuration if any
+ // if nothing found in the environment...chances are running in a
+ // non-managed environment
if (pmCache == null)
{
InputStream is = null;
@@ -241,9 +251,10 @@
{
pmCache = new TreeCache();
- //configure the cache
+ // configure the cache
PropertyConfigurator configurator = new PropertyConfigurator();
- is =
JBossCachePersistenceManager.class.getClassLoader().getResourceAsStream("pm-cache.xml");
+ is = JBossCachePersistenceManager.class.getClassLoader()
+ .getResourceAsStream("pm-cache.xml");
configurator.configure(pmCache, is);
pmCache.createService();
@@ -259,7 +270,7 @@
}
}
- //pre-load the cache with property nodes
+ // pre-load the cache with property nodes
if (!JBossCachePersistenceManager.preloaded)
{
JBossCachePersistenceManager.loadProperties();
@@ -275,8 +286,8 @@
}
/**
- *
- *
+ *
+ *
*/
private static synchronized void loadProperties() throws Exception
{
@@ -285,19 +296,26 @@
return;
}
- log.info("Pre-loading the PersistenceManager Cache in the background
(started).......");
+ log
+ .info("Pre-loading the PersistenceManager Cache in the background
(started).......");
- CacheLoader wspProp = new CacheLoader(CacheLoader.wspProp,
PortalCMSCacheLoader.WSP_PROP_NODE);
+ CacheLoader wspProp = new CacheLoader(CacheLoader.wspProp,
+ PortalCMSCacheLoader.WSP_PROP_NODE);
Thread wspPropLoader = new Thread(wspProp);
- CacheLoader versionProp = new CacheLoader(CacheLoader.versionProp,
PortalCMSCacheLoader.VERSION_PROP_NODE);
+ CacheLoader versionProp = new CacheLoader(CacheLoader.versionProp,
+ PortalCMSCacheLoader.VERSION_PROP_NODE);
Thread versionPropLoader = new Thread(versionProp);
- CacheLoader wspNode = new CacheLoader(CacheLoader.wspNode,
PortalCMSCacheLoader.WSP_NODE_NODE);
+ CacheLoader wspNode = new CacheLoader(CacheLoader.wspNode,
+ PortalCMSCacheLoader.WSP_NODE_NODE);
Thread wspNodeLoader = new Thread(wspNode);
- CacheLoader versionNode = new CacheLoader(CacheLoader.versionNode,
PortalCMSCacheLoader.VERSION_NODE_NODE);
+ CacheLoader versionNode = new CacheLoader(CacheLoader.versionNode,
+ PortalCMSCacheLoader.VERSION_NODE_NODE);
Thread versionNodeLoader = new Thread(versionNode);
- CacheLoader wspRef = new CacheLoader(CacheLoader.wspRef,
PortalCMSCacheLoader.WSP_REF_NODE);
+ CacheLoader wspRef = new CacheLoader(CacheLoader.wspRef,
+ PortalCMSCacheLoader.WSP_REF_NODE);
Thread wspRefLoader = new Thread(wspRef);
- CacheLoader versionRef = new CacheLoader(CacheLoader.versionRef,
PortalCMSCacheLoader.VERSION_REF_NODE);
+ CacheLoader versionRef = new CacheLoader(CacheLoader.versionRef,
+ PortalCMSCacheLoader.VERSION_REF_NODE);
Thread versionRefLoader = new Thread(versionRef);
wspPropLoader.start();
@@ -307,18 +325,14 @@
wspRefLoader.start();
versionRefLoader.start();
- //hang out here till the cache loader threads have pre-loaded the busy nodes
- //of the CMS...don't allow the usage of CMS till this operation is completed.
- while (
- !wspProp.done ||
- !versionProp.done ||
- !wspNode.done ||
- !versionNode.done ||
- !wspRef.done ||
- !versionRef.done
- )
+ // hang out here till the cache loader threads have pre-loaded the busy
+ // nodes
+ // of the CMS...don't allow the usage of CMS till this operation is
+ // completed.
+ while (!wspProp.done || !versionProp.done || !wspNode.done
+ || !versionNode.done || !wspRef.done || !versionRef.done)
{
- Thread.currentThread().sleep((long)2000);
+ Thread.currentThread().sleep((long) 2000);
}
JBossCachePersistenceManager.preloaded = true;
@@ -327,21 +341,27 @@
private static class CacheLoader implements Runnable
{
/**
- *
+ *
*/
private static final String wspProp = "from
org.jboss.portal.cms.hibernate.state.WSPProp";
+
private static final String versionProp = "from
org.jboss.portal.cms.hibernate.state.VersionProp";
+
private static final String wspNode = "from
org.jboss.portal.cms.hibernate.state.WSPNode";
+
private static final String versionNode = "from
org.jboss.portal.cms.hibernate.state.VersionNode";
+
private static final String wspRef = "from
org.jboss.portal.cms.hibernate.state.WSPRefs";
+
private static final String versionRef = "from
org.jboss.portal.cms.hibernate.state.VersionRefs";
-
/**
- *
+ *
*/
private String nodeQuery = null;
+
private String nodePrefix = null;
+
private boolean done = false;
private CacheLoader(String nodeQuery, String nodePrefix)
@@ -361,42 +381,63 @@
{
for (Iterator itr = rs.iterator(); itr.hasNext();)
{
- Base cour = (Base)itr.next();
+ Base cour = (Base) itr.next();
cour.disableCacheItemPersistence();
if (cour instanceof WSPProp)
{
- String node = this.nodePrefix + "/" +
PortalCMSCacheLoader.parseNodeName(((WSPProp)cour).getPropId());
- pmCache.put(node, ((WSPProp)cour).getPropId(), cour);
+ String node = this.nodePrefix
+ + "/"
+ + PortalCMSCacheLoader
+ .parseNodeName(((WSPProp) cour).getPropId());
+ pmCache.put(node, ((WSPProp) cour).getPropId(), cour);
}
else if (cour instanceof VersionProp)
{
- String node = this.nodePrefix + "/" +
PortalCMSCacheLoader.parseNodeName(((VersionProp)cour).getPropId());
- pmCache.put(node, ((VersionProp)cour).getPropId(), cour);
+ String node = this.nodePrefix
+ + "/"
+ + PortalCMSCacheLoader
+ .parseNodeName(((VersionProp) cour)
+ .getPropId());
+ pmCache.put(node, ((VersionProp) cour).getPropId(), cour);
}
else if (cour instanceof WSPNode)
{
- String node = this.nodePrefix + "/" +
PortalCMSCacheLoader.parseNodeName(((WSPNode)cour).getNodeId());
- pmCache.put(node, ((WSPNode)cour).getNodeId(), cour);
+ String node = this.nodePrefix
+ + "/"
+ + PortalCMSCacheLoader
+ .parseNodeName(((WSPNode) cour).getNodeId());
+ pmCache.put(node, ((WSPNode) cour).getNodeId(), cour);
}
else if (cour instanceof VersionNode)
{
- String node = this.nodePrefix + "/" +
PortalCMSCacheLoader.parseNodeName(((VersionNode)cour).getNodeId());
- pmCache.put(node, ((VersionNode)cour).getNodeId(), cour);
+ String node = this.nodePrefix
+ + "/"
+ + PortalCMSCacheLoader
+ .parseNodeName(((VersionNode) cour)
+ .getNodeId());
+ pmCache.put(node, ((VersionNode) cour).getNodeId(), cour);
}
else if (cour instanceof WSPRefs)
{
- String node = this.nodePrefix + "/" +
PortalCMSCacheLoader.parseNodeName(((WSPRefs)cour).getRefId());
- pmCache.put(node, ((WSPRefs)cour).getRefId(), cour);
+ String node = this.nodePrefix
+ + "/"
+ + PortalCMSCacheLoader
+ .parseNodeName(((WSPRefs) cour).getRefId());
+ pmCache.put(node, ((WSPRefs) cour).getRefId(), cour);
}
else if (cour instanceof VersionRefs)
{
- String node = this.nodePrefix + "/" +
PortalCMSCacheLoader.parseNodeName(((VersionRefs)cour).getRefId());
- pmCache.put(node, ((VersionRefs)cour).getRefId(), cour);
+ String node = this.nodePrefix
+ + "/"
+ + PortalCMSCacheLoader
+ .parseNodeName(((VersionRefs) cour).getRefId());
+ pmCache.put(node, ((VersionRefs) cour).getRefId(), cour);
}
}
}
- log.info("Pre-loading the PersistenceManager Cache for" +
this.nodePrefix + " (finished).......");
+ log.info("Pre-loading the PersistenceManager Cache for"
+ + this.nodePrefix + " (finished).......");
}
catch (CacheException ce)
{
@@ -410,19 +451,22 @@
}
}
- //----------actions for node
entities-------------------------------------------------------------------------------------------------------------
+ // ----------actions for node
+ //
entities-------------------------------------------------------------------------------------------------------------
/*
- *
- */
+ *
+ */
public boolean exists(NodeId node) throws ItemStateException
{
try
{
boolean exists = false;
String nodeId = node.toString();
- if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_NODE_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_NODE_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
if (o != null)
{
if (o instanceof WSPNode)
@@ -432,12 +476,16 @@
}
else
{
- this.pmCache.put(PortalCMSCacheLoader.WSP_NODE_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(nodeId), nodeId, new Boolean(false));
+ this.pmCache.put(PortalCMSCacheLoader.WSP_NODE_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId,
+ new Boolean(false));
}
}
- else if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ else if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_NODE_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_NODE_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
if (o != null)
{
if (o instanceof VersionNode)
@@ -447,7 +495,9 @@
}
else
{
- this.pmCache.put(PortalCMSCacheLoader.VERSION_NODE_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(nodeId), nodeId, new Boolean(false));
+ this.pmCache.put(PortalCMSCacheLoader.VERSION_NODE_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId,
+ new Boolean(false));
}
}
return exists;
@@ -459,29 +509,34 @@
}
/*
- *
- */
- public NodeState load(NodeId node) throws NoSuchItemStateException,
ItemStateException
+ *
+ */
+ public NodeState load(NodeId node) throws NoSuchItemStateException,
+ ItemStateException
{
try
{
NodeState nodeState = null;
String nodeId = node.toString();
- //get the nodeData
+ // get the nodeData
byte[] nodeData = null;
- if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_NODE_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
- nodeData = ((WSPNode)o).getData();
+ Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_NODE_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ nodeData = ((WSPNode) o).getData();
}
- else if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ else if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_NODE_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
- nodeData = ((VersionNode)o).getData();
+ Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_NODE_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ nodeData = ((VersionNode) o).getData();
}
- //parse propertyData into propertyState
+ // parse propertyData into propertyState
if (nodeData != null)
{
Session session = null;
@@ -491,11 +546,10 @@
{
session = Tools.getOpenSession();
tx = session.beginTransaction();
-
-
+
InputStream in = new ByteArrayInputStream(nodeData);
- //setup the propertyState
+ // setup the propertyState
nodeState = createNew(node);
Serializer.deserialize(nodeState, in);
org.jboss.portal.common.util.Tools.safeClose(in);
@@ -507,9 +561,10 @@
{
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
- String msg = "failed to read node state from cache: " +
node.toString();
+ String msg = "failed to read node state from cache: "
+ + node.toString();
log.error(msg, e);
throw new ItemStateException(msg, e);
}
@@ -532,8 +587,8 @@
}
/**
- *
- *
+ *
+ *
*/
private void store(NodeState state) throws ItemStateException
{
@@ -546,23 +601,29 @@
try
{
Serializer.serialize(state, out);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionNode versionNode = new VersionNode(state.getId().toString(),
out.toByteArray());
+ VersionNode versionNode = new VersionNode(state.getId().toString(),
+ out.toByteArray());
- //place this in the cache
+ // place this in the cache
versionNode.resetCacheItemPersistence();
- String cacheNode = PortalCMSCacheLoader.VERSION_NODE_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(versionNode.getNodeId());
+ String cacheNode = PortalCMSCacheLoader.VERSION_NODE_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(versionNode.getNodeId());
pmCache.put(cacheNode, versionNode.getNodeId(), versionNode);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPNode wspNode = new WSPNode(state.getId().toString(), out.toByteArray());
+ WSPNode wspNode = new WSPNode(state.getId().toString(), out
+ .toByteArray());
- //place this in the cache
+ // place this in the cache
wspNode.resetCacheItemPersistence();
- String cacheNode = PortalCMSCacheLoader.WSP_NODE_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(wspNode.getNodeId());
+ String cacheNode = PortalCMSCacheLoader.WSP_NODE_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(wspNode.getNodeId());
pmCache.put(cacheNode, wspNode.getNodeId(), wspNode);
}
}
@@ -586,8 +647,8 @@
}
/**
- *
- *
+ *
+ *
*/
private void update(NodeState state) throws ItemStateException
{
@@ -602,27 +663,34 @@
Serializer.serialize(state, out);
String id = state.getId().toString();
String cacheNodeName = PortalCMSCacheLoader.parseNodeName(id);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionNode versionNode =
(VersionNode)pmCache.get(PortalCMSCacheLoader.VERSION_NODE_NODE + "/" +
cacheNodeName, id);
+ VersionNode versionNode = (VersionNode) pmCache.get(
+ PortalCMSCacheLoader.VERSION_NODE_NODE + "/" +
cacheNodeName,
+ id);
if (versionNode == null)
{
throw new Exception("No such Node: " + state.getId());
}
versionNode.setData(out.toByteArray());
versionNode.resetCacheItemPersistence();
- pmCache.put(PortalCMSCacheLoader.VERSION_NODE_NODE + "/" +
cacheNodeName, id, versionNode);
+ pmCache.put(PortalCMSCacheLoader.VERSION_NODE_NODE + "/"
+ + cacheNodeName, id, versionNode);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPNode wspNode = (WSPNode)pmCache.get(PortalCMSCacheLoader.WSP_NODE_NODE +
"/" + cacheNodeName, id);
+ WSPNode wspNode = (WSPNode) pmCache.get(
+ PortalCMSCacheLoader.WSP_NODE_NODE + "/" + cacheNodeName,
id);
if (wspNode == null)
{
throw new Exception("No such Node: " + state.getId());
}
wspNode.setData(out.toByteArray());
wspNode.resetCacheItemPersistence();
- pmCache.put(PortalCMSCacheLoader.WSP_NODE_NODE + "/" +
cacheNodeName, id, wspNode);
+ pmCache.put(PortalCMSCacheLoader.WSP_NODE_NODE + "/"
+ + cacheNodeName, id, wspNode);
}
}
catch (Exception e)
@@ -656,13 +724,17 @@
String cacheNodeName = PortalCMSCacheLoader.parseNodeName(id);
try
{
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- pmCache.remove(PortalCMSCacheLoader.VERSION_NODE_NODE + "/" +
cacheNodeName, id);
+ pmCache.remove(PortalCMSCacheLoader.VERSION_NODE_NODE + "/"
+ + cacheNodeName, id);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- pmCache.remove(PortalCMSCacheLoader.WSP_NODE_NODE + "/" +
cacheNodeName, id);
+ pmCache.remove(PortalCMSCacheLoader.WSP_NODE_NODE + "/"
+ + cacheNodeName, id);
}
}
catch (Exception e)
@@ -673,19 +745,22 @@
}
}
- //----------actions for property
entities-------------------------------------------------------------------------------------------------------------
+ // ----------actions for property
+ //
entities-------------------------------------------------------------------------------------------------------------
/*
- *
- */
+ *
+ */
public boolean exists(PropertyId property) throws ItemStateException
{
try
{
boolean exists = false;
String propId = property.toString();
- if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_PROP_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_PROP_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
if (o != null)
{
if (o instanceof WSPProp)
@@ -695,12 +770,16 @@
}
else
{
- this.pmCache.put(PortalCMSCacheLoader.WSP_PROP_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(propId), propId, new Boolean(false));
+ this.pmCache.put(PortalCMSCacheLoader.WSP_PROP_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(propId), propId,
+ new Boolean(false));
}
}
- else if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ else if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_PROP_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_PROP_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
if (o != null)
{
if (o instanceof VersionProp)
@@ -710,7 +789,9 @@
}
else
{
- this.pmCache.put(PortalCMSCacheLoader.VERSION_PROP_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(propId), propId, new Boolean(false));
+ this.pmCache.put(PortalCMSCacheLoader.VERSION_PROP_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(propId), propId,
+ new Boolean(false));
}
}
return exists;
@@ -722,29 +803,34 @@
}
/*
- *
- */
- public PropertyState load(PropertyId property) throws NoSuchItemStateException,
ItemStateException
+ *
+ */
+ public PropertyState load(PropertyId property)
+ throws NoSuchItemStateException, ItemStateException
{
try
{
PropertyState propertyState = null;
String propId = property.toString();
- //get the propertyData
+ // get the propertyData
byte[] propertyData = null;
- if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_PROP_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
- propertyData = ((WSPProp)o).getData();
+ Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_PROP_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
+ propertyData = ((WSPProp) o).getData();
}
- else if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ else if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_PROP_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
- propertyData = ((VersionProp)o).getData();
+ Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_PROP_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(propId), propId);
+ propertyData = ((VersionProp) o).getData();
}
- //parse propertyData into propertyState
+ // parse propertyData into propertyState
if (propertyData != null)
{
Session session = null;
@@ -757,7 +843,7 @@
InputStream in = new ByteArrayInputStream(propertyData);
- //setup the propertyState
+ // setup the propertyState
propertyState = createNew(property);
Serializer.deserialize(propertyState, in, blobStore);
org.jboss.portal.common.util.Tools.safeClose(in);
@@ -769,9 +855,10 @@
{
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
- String msg = "failed to read property state from cache: " +
property.toString();
+ String msg = "failed to read property state from cache: "
+ + property.toString();
log.error(msg, e);
throw new ItemStateException(msg, e);
}
@@ -794,7 +881,7 @@
}
/**
- *
+ *
*/
private void store(PropertyState state) throws ItemStateException
{
@@ -807,23 +894,29 @@
try
{
Serializer.serialize(state, out, blobStore);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionProp versionProp = new VersionProp(state.getId().toString(),
out.toByteArray());
+ VersionProp versionProp = new VersionProp(state.getId().toString(),
+ out.toByteArray());
- //place this in the cache
+ // place this in the cache
versionProp.resetCacheItemPersistence();
- String cacheNode = PortalCMSCacheLoader.VERSION_PROP_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(versionProp.getPropId());
+ String cacheNode = PortalCMSCacheLoader.VERSION_PROP_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(versionProp.getPropId());
pmCache.put(cacheNode, versionProp.getPropId(), versionProp);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPProp wspProp = new WSPProp(state.getId().toString(), out.toByteArray());
+ WSPProp wspProp = new WSPProp(state.getId().toString(), out
+ .toByteArray());
- //place this in the cache
+ // place this in the cache
wspProp.resetCacheItemPersistence();
- String cacheNode = PortalCMSCacheLoader.WSP_PROP_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(wspProp.getPropId());
+ String cacheNode = PortalCMSCacheLoader.WSP_PROP_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(wspProp.getPropId());
pmCache.put(cacheNode, wspProp.getPropId(), wspProp);
}
}
@@ -847,8 +940,8 @@
}
/**
- *
- *
+ *
+ *
*/
private void update(PropertyState state) throws ItemStateException
{
@@ -863,27 +956,34 @@
Serializer.serialize(state, out, blobStore);
String id = state.getId().toString();
String cacheNodeName = PortalCMSCacheLoader.parseNodeName(id);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionProp versionProp =
(VersionProp)pmCache.get(PortalCMSCacheLoader.VERSION_PROP_NODE + "/" +
cacheNodeName, id);
+ VersionProp versionProp = (VersionProp) pmCache.get(
+ PortalCMSCacheLoader.VERSION_PROP_NODE + "/" +
cacheNodeName,
+ id);
if (versionProp == null)
{
throw new Exception("No such Property: " + state.getId());
}
versionProp.setData(out.toByteArray());
versionProp.resetCacheItemPersistence();
- pmCache.put(PortalCMSCacheLoader.VERSION_PROP_NODE + "/" +
cacheNodeName, id, versionProp);
+ pmCache.put(PortalCMSCacheLoader.VERSION_PROP_NODE + "/"
+ + cacheNodeName, id, versionProp);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPProp wspProp = (WSPProp)pmCache.get(PortalCMSCacheLoader.WSP_PROP_NODE +
"/" + cacheNodeName, id);
+ WSPProp wspProp = (WSPProp) pmCache.get(
+ PortalCMSCacheLoader.WSP_PROP_NODE + "/" + cacheNodeName,
id);
if (wspProp == null)
{
throw new Exception("No such Property: " + state.getId());
}
wspProp.setData(out.toByteArray());
wspProp.resetCacheItemPersistence();
- pmCache.put(PortalCMSCacheLoader.WSP_PROP_NODE + "/" +
cacheNodeName, id, wspProp);
+ pmCache.put(PortalCMSCacheLoader.WSP_PROP_NODE + "/"
+ + cacheNodeName, id, wspProp);
}
}
catch (Exception e)
@@ -924,11 +1024,12 @@
{
if (val.getType() == PropertyType.BINARY)
{
- BLOBFileValue blobVal = (BLOBFileValue)val.internalValue();
+ BLOBFileValue blobVal = (BLOBFileValue) val.internalValue();
// delete internal resource representation of BLOB value
blobVal.delete(true);
// also remove from BLOBStore
- String blobId = blobStore.createId((PropertyId)state.getId(), i);
+ String blobId = blobStore.createId(
+ (PropertyId) state.getId(), i);
try
{
blobStore.remove(blobId);
@@ -942,18 +1043,22 @@
}
}
- //remove the property node
+ // remove the property node
String id = state.getId().toString();
String cacheNodeName = PortalCMSCacheLoader.parseNodeName(id);
try
{
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- pmCache.remove(PortalCMSCacheLoader.VERSION_PROP_NODE + "/" +
cacheNodeName, id);
+ pmCache.remove(PortalCMSCacheLoader.VERSION_PROP_NODE + "/"
+ + cacheNodeName, id);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- pmCache.remove(PortalCMSCacheLoader.WSP_PROP_NODE + "/" +
cacheNodeName, id);
+ pmCache.remove(PortalCMSCacheLoader.WSP_PROP_NODE + "/"
+ + cacheNodeName, id);
}
}
catch (Exception e)
@@ -964,9 +1069,10 @@
}
}
- //----------actions for nodereferences
entities-------------------------------------------------------------------------------------------------------------
+ // ----------actions for nodereferences
+ //
entities-------------------------------------------------------------------------------------------------------------
/**
- *
+ *
*/
public boolean exists(NodeReferencesId targetId) throws ItemStateException
{
@@ -974,9 +1080,11 @@
{
boolean exists = false;
String nodeId = targetId.toString();
- if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_REF_NODE + "/"
+ PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_REF_NODE +
"/"
+ + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
if (o != null)
{
if (o instanceof WSPRefs)
@@ -986,12 +1094,16 @@
}
else
{
- this.pmCache.put(PortalCMSCacheLoader.WSP_REF_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(nodeId), nodeId, new Boolean(false));
+ this.pmCache.put(PortalCMSCacheLoader.WSP_REF_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId,
+ new Boolean(false));
}
}
- else if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ else if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_REF_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_REF_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
if (o != null)
{
if (o instanceof VersionRefs)
@@ -1001,7 +1113,9 @@
}
else
{
- this.pmCache.put(PortalCMSCacheLoader.VERSION_REF_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(nodeId), nodeId, new Boolean(false));
+ this.pmCache.put(PortalCMSCacheLoader.VERSION_REF_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId,
+ new Boolean(false));
}
}
return exists;
@@ -1013,37 +1127,42 @@
}
/**
- *
+ *
*/
- public NodeReferences load(NodeReferencesId targetId) throws NoSuchItemStateException,
ItemStateException
+ public NodeReferences load(NodeReferencesId targetId)
+ throws NoSuchItemStateException, ItemStateException
{
try
{
NodeReferences refs = null;
String nodeId = targetId.toString();
- //get the nodeData
+ // get the nodeData
byte[] nodeData = null;
- if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_REF_NODE + "/"
+ PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.WSP_REF_NODE +
"/"
+ + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
if (o == null || !(o instanceof Base))
{
throw new NoSuchItemStateException(targetId.toString());
}
- nodeData = ((WSPRefs)o).getData();
+ nodeData = ((WSPRefs) o).getData();
}
- else if
(this.schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ else if (this.schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_REF_NODE +
"/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
+ Object o = this.pmCache.get(PortalCMSCacheLoader.VERSION_REF_NODE
+ + "/" + PortalCMSCacheLoader.parseNodeName(nodeId), nodeId);
if (o == null || !(o instanceof Base))
{
throw new NoSuchItemStateException(targetId.toString());
}
- nodeData = ((VersionRefs)o).getData();
+ nodeData = ((VersionRefs) o).getData();
}
- //parse propertyData into propertyState
+ // parse propertyData into propertyState
if (nodeData != null)
{
Session session = null;
@@ -1056,7 +1175,7 @@
InputStream in = new ByteArrayInputStream(nodeData);
- //setup the propertyState
+ // setup the propertyState
refs = new NodeReferences(targetId);
Serializer.deserialize(refs, in);
org.jboss.portal.common.util.Tools.safeClose(in);
@@ -1068,9 +1187,10 @@
{
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
- String msg = "failed to read reference from cache: " +
targetId.toString();
+ String msg = "failed to read reference from cache: "
+ + targetId.toString();
log.error(msg, e);
throw new ItemStateException(msg, e);
}
@@ -1093,8 +1213,8 @@
}
/**
- *
- *
+ *
+ *
*/
private void store(NodeReferences refs) throws ItemStateException
{
@@ -1107,23 +1227,29 @@
try
{
Serializer.serialize(refs, out);
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionRefs versionRefs = new VersionRefs(refs.getId().toString(),
out.toByteArray());
+ VersionRefs versionRefs = new VersionRefs(refs.getId().toString(),
+ out.toByteArray());
- //place this in the cache
+ // place this in the cache
versionRefs.resetCacheItemPersistence();
- String cacheNode = PortalCMSCacheLoader.VERSION_REF_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(versionRefs.getRefId());
+ String cacheNode = PortalCMSCacheLoader.VERSION_REF_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(versionRefs.getRefId());
pmCache.put(cacheNode, versionRefs.getRefId(), versionRefs);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPRefs wspRefs = new WSPRefs(refs.getId().toString(), out.toByteArray());
+ WSPRefs wspRefs = new WSPRefs(refs.getId().toString(), out
+ .toByteArray());
- //place this in the cache
+ // place this in the cache
wspRefs.resetCacheItemPersistence();
- String cacheNode = PortalCMSCacheLoader.WSP_REF_NODE + "/" +
PortalCMSCacheLoader.parseNodeName(wspRefs.getRefId());
+ String cacheNode = PortalCMSCacheLoader.WSP_REF_NODE + "/"
+ + PortalCMSCacheLoader.parseNodeName(wspRefs.getRefId());
pmCache.put(cacheNode, wspRefs.getRefId(), wspRefs);
}
}
@@ -1147,7 +1273,7 @@
}
/**
- *
+ *
*/
private void destroy(NodeReferences refs) throws ItemStateException
{
@@ -1160,13 +1286,17 @@
String cacheNodeName = PortalCMSCacheLoader.parseNodeName(id);
try
{
- if (schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- pmCache.remove(PortalCMSCacheLoader.VERSION_REF_NODE + "/" +
cacheNodeName, id);
+ pmCache.remove(PortalCMSCacheLoader.VERSION_REF_NODE + "/"
+ + cacheNodeName, id);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- pmCache.remove(PortalCMSCacheLoader.WSP_REF_NODE + "/" +
cacheNodeName, id);
+ pmCache.remove(PortalCMSCacheLoader.WSP_REF_NODE + "/"
+ + cacheNodeName, id);
}
}
catch (Exception e)
@@ -1177,24 +1307,24 @@
}
}
-
//----------------------------------------------------------------------------------------------------------------------------------------
+ //
----------------------------------------------------------------------------------------------------------------------------------------
/**
- *
+ *
*/
public void close() throws Exception
{
- //cleanup session factory.
- Tools.destroy();
-
- //cleanup the jboss cache service
- if(pmCache != null)
- {
- pmCache.stopService();
- pmCache.destroyService();
- pmCache = null;
- preloaded = false;
- }
-
+ // cleanup session factory.
+ Tools.destroy();
+
+ // cleanup the jboss cache service
+ if (pmCache != null)
+ {
+ pmCache.stopService();
+ pmCache.destroyService();
+ pmCache = null;
+ preloaded = false;
+ }
+
if (!initialized)
{
throw new IllegalStateException("not initialized");
@@ -1204,7 +1334,7 @@
{
if (externalBLOBs)
{
- //close BLOB file system
+ // close BLOB file system
blobFS.close();
blobFS = null;
}
@@ -1229,7 +1359,7 @@
}
/**
- *
+ *
*/
public void store(ChangeLog changeLog) throws ItemStateException
{
@@ -1256,7 +1386,7 @@
private Blob createBlob(byte[] bytes)
{
return Hibernate.createBlob(bytes);
- //return new ByteArrayBlob(bytes);
+ // return new ByteArrayBlob(bytes);
}
public void storeHB(ChangeLog changeLog) throws ItemStateException
@@ -1264,46 +1394,46 @@
Iterator iter = changeLog.deletedStates();
while (iter.hasNext())
{
- ItemState state = (ItemState)iter.next();
+ ItemState state = (ItemState) iter.next();
if (state.isNode())
{
- destroy((NodeState)state);
+ destroy((NodeState) state);
}
else
{
- destroy((PropertyState)state);
+ destroy((PropertyState) state);
}
}
iter = changeLog.addedStates();
while (iter.hasNext())
{
- ItemState state = (ItemState)iter.next();
+ ItemState state = (ItemState) iter.next();
if (state.isNode())
{
- store((NodeState)state);
+ store((NodeState) state);
}
else
{
- store((PropertyState)state);
+ store((PropertyState) state);
}
}
iter = changeLog.modifiedStates();
while (iter.hasNext())
{
- ItemState state = (ItemState)iter.next();
+ ItemState state = (ItemState) iter.next();
if (state.isNode())
{
- update((NodeState)state);
+ update((NodeState) state);
}
else
{
- update((PropertyState)state);
+ update((PropertyState) state);
}
}
iter = changeLog.modifiedRefs();
while (iter.hasNext())
{
- NodeReferences refs = (NodeReferences)iter.next();
+ NodeReferences refs = (NodeReferences) iter.next();
if (refs.hasReferences())
{
store(refs);
@@ -1319,7 +1449,7 @@
}
/**
- *
+ *
*/
protected boolean exists(String blobid) throws ItemStateException
{
@@ -1327,8 +1457,8 @@
}
/**
- *
- *
+ *
+ *
*/
private boolean exists(String query, String id) throws ItemStateException
{
@@ -1357,7 +1487,7 @@
}
- //-------------------------------------------------< misc. helper methods >
+ // -------------------------------------------------< misc. helper methods >
protected void logException(String message, SQLException se)
{
if (message != null)
@@ -1369,12 +1499,12 @@
log.debug(" dump:", se);
}
- //--------------------------------------------------------< inner classes >
+ // --------------------------------------------------------< inner classes >
class DbBLOBStore implements BLOBStore
{
/**
- *
+ *
*/
public String createId(PropertyId id, int index)
{
@@ -1388,16 +1518,17 @@
}
/**
- *
+ *
*/
public InputStream get(String blobId) throws Exception
{
Session session = Tools.getCurrentSession();
try
{
- List rs = session.createQuery(blobSelectData).setString(0, blobId).list();
+ List rs = session.createQuery(blobSelectData).setString(0, blobId)
+ .list();
Iterator iter = rs.iterator();
- java.sql.Blob blob = (java.sql.Blob)iter.next();
+ java.sql.Blob blob = (java.sql.Blob) iter.next();
InputStream is = blob.getBinaryStream();
return is;
}
@@ -1405,7 +1536,7 @@
{
if (e instanceof NoSuchItemStateException)
{
- throw(NoSuchItemStateException)e;
+ throw (NoSuchItemStateException) e;
}
String msg = "failed to read binary data: " + blobId;
log.error(msg, e);
@@ -1414,9 +1545,10 @@
}
/**
- *
+ *
*/
- public void put(String blobId, InputStream in, long size) throws Exception
+ public void put(String blobId, InputStream in, long size)
+ throws Exception
{
boolean update = exists(blobId);
@@ -1427,10 +1559,12 @@
{
Query query = session.createQuery(blobSelect);
- if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
query.setString(0, blobId);
- VersionBinVal versionNode = (VersionBinVal)query.uniqueResult();
+ VersionBinVal versionNode = (VersionBinVal) query
+ .uniqueResult();
if (versionNode == null)
{
throw new Exception("No such Node: " + blobId);
@@ -1438,10 +1572,11 @@
versionNode.setId(blobId);
versionNode.setData(Hibernate.createBlob(in));
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
query.setString(0, blobId);
- WSPBinVal wspNode = (WSPBinVal)query.uniqueResult();
+ WSPBinVal wspNode = (WSPBinVal) query.uniqueResult();
if (wspNode == null)
{
throw new Exception("No such Node: " + blobId);
@@ -1458,7 +1593,7 @@
}
finally
{
- session.flush();
+ session.flush();
}
}
else
@@ -1467,14 +1602,18 @@
try
{
- if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
+ if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.versionPrefix))
{
- VersionBinVal versionNode = new VersionBinVal(blobId,
Hibernate.createBlob(in));
+ VersionBinVal versionNode = new VersionBinVal(blobId,
+ Hibernate.createBlob(in));
session.save(versionNode);
}
- else if
(schemaObjectPrefix.equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
+ else if (schemaObjectPrefix
+ .equalsIgnoreCase(HibernateStoreConstants.wspPrefix))
{
- WSPBinVal wspNode = new WSPBinVal(blobId, Hibernate.createBlob(in));
+ WSPBinVal wspNode = new WSPBinVal(blobId, Hibernate
+ .createBlob(in));
session.save(wspNode);
}
}
@@ -1486,21 +1625,22 @@
}
finally
{
- session.flush();
+ session.flush();
}
}
}
/**
- *
+ *
*/
- // public synchronized boolean remove(String blobId) throws Exception
+ // public synchronized boolean remove(String blobId) throws Exception
public boolean remove(String blobId) throws Exception
{
Session session = Tools.getCurrentSession();
try
{
- Query query = session.createQuery(nodeBinValSelect).setString(0, blobId);
+ Query query = session.createQuery(nodeBinValSelect).setString(0,
+ blobId);
Object result = query.uniqueResult();
if (result != null)
{
@@ -1516,7 +1656,7 @@
}
finally
{
- session.flush();
+ session.flush();
}
}
}