Author: sergiykarpenko
Date: 2010-01-26 06:25:47 -0500 (Tue, 26 Jan 2010)
New Revision: 1576
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
Log:
EXOJCR-440: ResultSet.isAfterLast() removed
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java 2010-01-26
10:39:57 UTC (rev 1575)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java 2010-01-26
11:25:47 UTC (rev 1576)
@@ -153,10 +153,11 @@
public List<NodeData> getChildNodesData(NodeData parent) throws
RepositoryException, IllegalStateException
{
checkIfOpened();
+ ResultSet resultSet = null;
try
{
// query will return nodes and properties in same result set
- ResultSet resultSet =
findChildNodesByParentIdentifierCQ(getInternalId(parent.getIdentifier()));
+ resultSet =
findChildNodesByParentIdentifierCQ(getInternalId(parent.getIdentifier()));
TempNodeData data = null;
List<NodeData> childNodes = new ArrayList<NodeData>();
while (resultSet.next())
@@ -196,6 +197,20 @@
{
throw new RepositoryException(e);
}
+ finally
+ {
+ if (resultSet != null)
+ {
+ try
+ {
+ resultSet.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error(e.getMessage(), e);
+ }
+ }
+ }
}
/**
@@ -204,14 +219,71 @@
public List<PropertyData> getChildPropertiesData(NodeData parent) throws
RepositoryException, IllegalStateException
{
checkIfOpened();
+ ResultSet resultSet = null;
try
{
- ResultSet resultSet =
findChildPropertiesByParentIdentifierCQ(getInternalId(parent.getIdentifier()));
+ resultSet =
findChildPropertiesByParentIdentifierCQ(getInternalId(parent.getIdentifier()));
List<PropertyData> children = new ArrayList<PropertyData>();
+
+ QPath parentPath = parent.getQPath();
+
if (resultSet.next())
{
- while (!resultSet.isAfterLast())
- children.add(loadPropertyRecord(resultSet, parent.getQPath()));
+ boolean isNotLast = true;
+
+ do
+ {
+ // read property data
+ String cid = resultSet.getString(COLUMN_ID);
+ String identifier = getIdentifier(cid);
+
+ String cname = resultSet.getString(COLUMN_NAME);
+ int cversion = resultSet.getInt(COLUMN_VERSION);
+
+ String cpid = resultSet.getString(COLUMN_PARENTID);
+ // if parent ID is empty string - it's a root node
+
+ int cptype = resultSet.getInt(COLUMN_PTYPE);
+ boolean cpmultivalued = resultSet.getBoolean(COLUMN_PMULTIVALUED);
+ QPath qpath;
+ try
+ {
+ qpath =
+ QPath.makeChildPath(parentPath == null ? traverseQPath(cpid) :
parentPath, InternalQName
+ .parse(cname));
+ }
+ catch (IllegalNameException e)
+ {
+ throw new RepositoryException(e.getMessage(), e);
+ }
+
+ // read values
+ List<ValueData> data = new ArrayList<ValueData>();
+ do
+ {
+ int orderNum = resultSet.getInt(COLUMN_VORDERNUM);
+ // check is there value columns
+ if (!resultSet.wasNull())
+ {
+ final String storageId = resultSet.getString(COLUMN_VSTORAGE_DESC);
+ ValueData vdata =
+ resultSet.wasNull() ? readValueData(cid, orderNum, cversion,
resultSet
+ .getBinaryStream(COLUMN_VDATA)) : readValueData(identifier,
orderNum, storageId);
+ data.add(vdata);
+ }
+
+ isNotLast = resultSet.next();
+ }
+ while (isNotLast && resultSet.getString(COLUMN_ID).equals(cid));
+
+ //create property
+ PersistedPropertyData pdata =
+ new PersistedPropertyData(identifier, qpath, getIdentifier(cpid),
cversion, cptype, cpmultivalued,
+ data);
+
+ children.add(pdata);
+ }
+ while (isNotLast);
}
return children;
}
@@ -223,6 +295,21 @@
{
throw new RepositoryException(e);
}
+ finally
+ {
+ if (resultSet != null)
+ {
+ try
+ {
+ resultSet.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error(e.getMessage(), e);
+ }
+ }
+ }
+
}
/**
@@ -231,9 +318,10 @@
public List<PropertyData> getReferencesData(String nodeIdentifier) throws
RepositoryException, IllegalStateException
{
checkIfOpened();
+ ResultSet refProps = null;
try
{
- ResultSet refProps = findReferencePropertiesCQ(getInternalId(nodeIdentifier));
+ refProps = findReferencePropertiesCQ(getInternalId(nodeIdentifier));
return loadReferences(refProps);
}
catch (SQLException e)
@@ -244,6 +332,21 @@
{
throw new RepositoryException(e);
}
+ finally
+ {
+ if (refProps != null)
+ {
+ try
+ {
+ refProps.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error(e.getMessage(), e);
+ }
+ }
+ }
+
}
/**
@@ -589,67 +692,6 @@
}
/**
- * Load property record from result set. Result set must be ordered by property id.
- * In other way there may be mistaces.
- *
- * @param resultSet - Result set
- * @param parentPath - parent qpath - needed to create property qpath. May be null.
- * @return PersistedPropertyData
- * @throws RepositoryException
- * @throws SQLException
- * @throws IOException
- */
- protected PersistedPropertyData loadPropertyRecord(ResultSet resultSet, QPath
parentPath)
- throws RepositoryException, SQLException, IOException
- {
- String cid = resultSet.getString(COLUMN_ID);
- String cname = resultSet.getString(COLUMN_NAME);
- int cversion = resultSet.getInt(COLUMN_VERSION);
-
- String cpid = resultSet.getString(COLUMN_PARENTID);
- // if parent ID is empty string - it's a root node
- try
- {
- int cptype = resultSet.getInt(COLUMN_PTYPE);
- boolean cpmultivalued = resultSet.getBoolean(COLUMN_PMULTIVALUED);
- QPath qpath =
- QPath.makeChildPath(parentPath == null ? traverseQPath(cpid) : parentPath,
InternalQName.parse(cname));
-
- List<ValueData> data = new ArrayList<ValueData>();
- String identifier = getIdentifier(cid);
-
- do
- {
- int orderNum = resultSet.getInt(COLUMN_VORDERNUM);
- //check is there value columns
- if (!resultSet.wasNull())
- {
- final String storageId = resultSet.getString(COLUMN_VSTORAGE_DESC);
- ValueData vdata =
- resultSet.wasNull() ? readValueData(cid, orderNum, cversion,
resultSet.getBinaryStream(COLUMN_VDATA))
- : readValueData(identifier, orderNum, storageId);
- data.add(vdata);
- }
- }
- while (resultSet.next() && resultSet.getString(COLUMN_ID).equals(cid));
-
- PersistedPropertyData pdata =
- new PersistedPropertyData(identifier, qpath, getIdentifier(cpid), cversion,
cptype, cpmultivalued, data);
-
- return pdata;
- }
- catch (IllegalNameException e)
- {
- throw new RepositoryException(e);
- }
- catch (InvalidItemStateException e)
- {
- throw new InvalidItemStateException("FATAL: Can't build item path for
name " + cname + " id: "
- + getIdentifier(cid) + ". " + e);
- }
- }
-
- /**
* {@inheritDoc}
*/
@Override