Author: pnedonosko
Date: 2009-11-18 07:08:01 -0500 (Wed, 18 Nov 2009)
New Revision: 749
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCStorageConnectionTest.java
Log:
EXOJCR-247: getters optimization
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-18
11:54:25 UTC (rev 748)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-18
12:08:01 UTC (rev 749)
@@ -128,7 +128,7 @@
break;
case REMOVE_NODE :
- doRemove(m, (JDBCStorageConnection) conn);
+ doRemove(m, (JDBCStorageConnection)conn);
break;
case MOVE :
@@ -185,11 +185,11 @@
* @throws RepositoryException
*/
private void doRemove(Modification modification, JDBCStorageConnection conn) throws
IllegalStateException,
- RepositoryException
+ RepositoryException
{
if (modification.getFqn().size() == 2)
{
- String identifier = (String) modification.getFqn().get(1);
+ String identifier = (String)modification.getFqn().get(1);
if (modification.getFqn().get(0).equals(JBossCacheStorage.NODES))
{
@@ -262,7 +262,7 @@
Map<Object, Object> attrs;
- JDBCStorageConnection conn = (JDBCStorageConnection)
dataContainer.openConnection();
+ JDBCStorageConnection conn =
(JDBCStorageConnection)dataContainer.openConnection();
try
{
@@ -277,7 +277,7 @@
NodeData nodeData = (NodeData)conn.getItemData(nodeId);
if (nodeData != null)
{
- // TODO use dedicated select, not child datas
+ // TODO get child props info
List<PropertyDataInfo> childProps =
conn.getChildProperties(nodeId);
if (childProps.size() <= 0)
{
@@ -300,29 +300,19 @@
// /$NODES/<NODE_ID>/<SUB_NODE_NAME>
else if (name.size() == 3)
{
- QPathEntry childNodeName =
QPathEntry.parse(name.getLastElementAsString());
+ String childNodeName = name.getLastElementAsString();
String parentId = (String)name.get(1);
- // TODO use non-data method, check ACL creation
- NodeData parentData = (NodeData)conn.getItemData(parentId);
- if (parentData != null)
+ String nodeId = conn.getItemIdentifier(parentId, childNodeName);
+ if (nodeId != null)
{
- NodeData nodeData = (NodeData)conn.getItemData(parentData,
childNodeName);
- if (nodeData != null)
- {
- attrs = new LinkedHashMap<Object, Object>();
- attrs.put(JBossCacheStorage.ITEM_ID, nodeData.getIdentifier());
- }
- else
- {
- throw new JDBCCacheLoaderException("FATAL Child Node data
not found "
- + parentData.getQPath().getAsString() +
childNodeName.getAsString(true) + " for '" + name
- + "'");
- }
+ attrs = new LinkedHashMap<Object, Object>();
+ attrs.put(JBossCacheStorage.ITEM_ID, nodeId);
}
else
{
- throw new JDBCCacheLoaderException("FATAL Parent not found
" + parentId + " for '" + name + "'");
+ throw new JDBCCacheLoaderException("FATAL Child Node data not
found, parent " + nodeId + " child "
+ + childNodeName + " for '" + name +
"'");
}
}
else
@@ -386,10 +376,10 @@
public boolean exists(Fqn name) throws Exception
{
// TODO Will be created specialization code to checking exist node or property in
DB without getting NodeData or PropertyData from DB.
- JDBCStorageConnection conn = (JDBCStorageConnection)
dataContainer.openConnection();
-
+ JDBCStorageConnection conn =
(JDBCStorageConnection)dataContainer.openConnection();
+
boolean exists;
-
+
try
{
if (name.size() > 1)
@@ -400,11 +390,11 @@
if (name.size() == 2)
{
String nodeId = name.getLastElementAsString();
- String nodeName = "" /* = conn.getNodeName(nodeId)*/;
-
+ String nodeName = conn.getItemName(nodeId);
+
if (nodeName != null)
{
- exists = true;
+ exists = true;
}
else
{
@@ -414,10 +404,10 @@
// /$NODES/<NODE_ID>/<SUB_NODE_NAME>
else if (name.size() == 3)
{
- QPathEntry childNodeName =
QPathEntry.parse(name.getLastElementAsString());
+ String childNodeName = name.getLastElementAsString();
String parentId = (String)name.get(1);
- String nodeId = "" /* = conn.getIdentifier(parentId,
childNodeName)*/;
+ String nodeId = conn.getItemIdentifier(parentId, childNodeName);
if (nodeId != null)
{
exists = true;
@@ -439,11 +429,11 @@
if (name.size() == 2)
{
String propertyId = name.getLastElementAsString();
- String propertyName = "" /* =
conn.getPropertyName(nodeId)*/;
-
+ String propertyName = conn.getItemName(propertyId);
+
if (propertyName != null)
{
- exists = true;
+ exists = true;
}
else
{
@@ -494,25 +484,16 @@
// /$NODES/<NODE_ID>
if (name.size() == 2)
{
- JDBCStorageConnection conn = (JDBCStorageConnection)
dataContainer.openConnection();
+ JDBCStorageConnection conn =
(JDBCStorageConnection)dataContainer.openConnection();
try
{
String nodeId = (String)name.get(1);
- NodeData parentData = (NodeData)conn.getItemData(nodeId);
- if (parentData != null)
+ childs = new LinkedHashSet<String>();
+
+ for (String nodeName : conn.getChildNodeNames(nodeId))
{
- childs = new LinkedHashSet<String>();
- // TODO get child nodes by parent Id, we need only id and name
- for (NodeData node : conn.getChildNodesData(parentData))
- {
-
childs.add(node.getQPath().getEntries()[node.getQPath().getEntries().length -
1].getAsString(true));
- }
+ childs.add(nodeName);
}
- else
- {
- // TODO by JBC API we can just retur null, but it will not be normal for
this loader contract
- throw new JDBCCacheLoaderException("FATAL Parent not found " +
nodeId + " '" + name + "'");
- }
}
finally
{
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2009-11-18
11:54:25 UTC (rev 748)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2009-11-18
12:08:01 UTC (rev 749)
@@ -136,6 +136,16 @@
* FIND_PROPERTIES_IDNAME_BY_PARENTID.
*/
protected String FIND_PROPERTIES_IDNAME_BY_PARENTID;
+
+ /**
+ * FIND_ITEM_IDENTIFIER.
+ */
+ protected String FIND_ITEM_IDENTIFIER;
+
+ /**
+ * FIND_ITEM_NAME.
+ */
+ protected String FIND_ITEM_NAME;
/**
* INSERT_NODE.
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2009-11-18
11:54:25 UTC (rev 748)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2009-11-18
12:08:01 UTC (rev 749)
@@ -1957,7 +1957,7 @@
* @throws RepositoryException
* if some exception occured
* @throws IllegalStateException
- * if connection is closed
+ * if connection closed
*/
public void deleteProperty(String identifier) throws RepositoryException,
UnsupportedOperationException,
InvalidItemStateException, IllegalStateException
@@ -1997,10 +1997,62 @@
}
}
+ /**
+ * Find Item ID in database.
+ *
+ * @param parentId parent Node id
+ * @param name Item name
+ * @return String with ID
+ * @throws RepositoryException if database error occurs
+ * @throws IllegalStateException if connection closed
+ */
public String getItemIdentifier(String parentId, String name) throws
RepositoryException, IllegalStateException
{
+ checkIfOpened();
+
+ try
+ {
+ ResultSet item = findItemIdentifier(getInternalId(parentId), name);
+ if (item.next())
+ {
+ return item.getString(COLUMN_ID);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+
+ return null;
+ }
- return null; // TODO
+ /**
+ * Find Item name in database.
+ *
+ * @param propertyId String
+ * @return String with name
+ * @throws RepositoryException if database error occurs
+ * @throws IllegalStateException if connection closed
+ */
+ public String getItemName(String propertyId) throws RepositoryException,
IllegalStateException
+ {
+
+ checkIfOpened();
+
+ try
+ {
+ ResultSet item = findItemName(getInternalId(propertyId));
+ if (item.next())
+ {
+ return item.getString(COLUMN_NAME);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+
+ return null;
}
/**
@@ -2009,7 +2061,7 @@
* @param parentId parent Node id.
* @return List of PropertyDataInfo
* @throws RepositoryException if error
- * @throws IllegalStateException if the parent in illegal state
+ * @throws IllegalStateException if connection closed
*/
public List<PropertyDataInfo> getChildProperties(String parentId) throws
RepositoryException, IllegalStateException
{
@@ -2134,4 +2186,11 @@
@Deprecated
protected abstract ResultSet findValueByPropertyIdOrderNumber(String cid, int
orderNumb) throws SQLException;
+
+ // JBC related
+
+ protected abstract ResultSet findItemIdentifier(String parentCid, String name) throws
SQLException;
+
+ protected abstract ResultSet findItemName(String cid) throws SQLException;
+
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2009-11-18
11:54:25 UTC (rev 748)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2009-11-18
12:08:01 UTC (rev 749)
@@ -79,9 +79,13 @@
protected PreparedStatement findNodesByParentId;
protected PreparedStatement findPropertiesByParentId;
-
+
protected PreparedStatement findPropertiesIdNameByParentId;
+ protected PreparedStatement findItemIdentifier;
+
+ protected PreparedStatement findItemName;
+
protected PreparedStatement insertNode;
protected PreparedStatement insertProperty;
@@ -189,8 +193,12 @@
FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where
I_CLASS=1 and PARENT_ID=?" + " order by N_ORDER_NUM";
FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where
I_CLASS=2 and PARENT_ID=?" + " order by ID";
+
+ FIND_PROPERTIES_IDNAME_BY_PARENTID = "select ID, NAME from JCR_MITEM" +
" where I_CLASS=2 and PARENT_ID=?";
- FIND_PROPERTIES_IDNAME_BY_PARENTID = "select ID, NAME from JCR_MITEM" +
" where I_CLASS=2 and PARENT_ID=?";
+ FIND_ITEM_IDENTIFIER = "select ID from JCR_MITEM" + " where
PARENT_ID=? and NAME=?";
+
+ FIND_ITEM_NAME = "select NAME from JCR_MITEM" + " where ID=?";
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX,
N_ORDER_NUM) VALUES(?,?,?,?,"
@@ -564,4 +572,35 @@
findValuesStorageDescriptorsByPropertyId.setString(1, cid);
return findValuesStorageDescriptorsByPropertyId.executeQuery();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findItemIdentifier(String parentCid, String name) throws
SQLException
+ {
+ if (findItemIdentifier == null)
+ findItemIdentifier = dbConnection.prepareStatement(FIND_ITEM_IDENTIFIER);
+ else
+ findItemIdentifier.clearParameters();
+
+ findItemIdentifier.setString(1, parentCid);
+ findItemIdentifier.setString(2, name);
+ return findItemIdentifier.executeQuery();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findItemName(String cid) throws SQLException
+ {
+ if (findItemName == null)
+ findItemName = dbConnection.prepareStatement(FIND_ITEM_NAME);
+ else
+ findItemName.clearParameters();
+
+ findItemName.setString(1, cid);
+ return findItemName.executeQuery();
+ }
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2009-11-18
11:54:25 UTC (rev 748)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2009-11-18
12:08:01 UTC (rev 749)
@@ -76,9 +76,13 @@
protected PreparedStatement findNodesByParentId;
protected PreparedStatement findPropertiesByParentId;
-
+
protected PreparedStatement findPropertiesIdNameByParentId;
+ protected PreparedStatement findItemIdentifier;
+
+ protected PreparedStatement findItemName;
+
protected PreparedStatement insertItem;
protected PreparedStatement insertNode;
@@ -201,6 +205,10 @@
FIND_PROPERTIES_IDNAME_BY_PARENTID =
"select ID, NAME from JCR_SITEM" + " where I_CLASS=2 and
CONTAINER_NAME=? and PARENT_ID=?";
+ FIND_ITEM_IDENTIFIER = "select ID from JCR_SITEM" + " where
CONTAINER_NAME=? and PARENT_ID=? and NAME=?";
+
+ FIND_ITEM_NAME = "select NAME from JCR_SITEM" + " where ID=?";
+
INSERT_NODE =
"insert into JCR_SITEM(ID, PARENT_ID, NAME, CONTAINER_NAME, VERSION,
I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,?,"
+ I_CLASS_NODE + ",?,?)";
@@ -355,7 +363,7 @@
findPropertiesByParentId.setString(2, parentCid);
return findPropertiesByParentId.executeQuery();
}
-
+
/**
* {@inheritDoc}
*/
@@ -583,4 +591,36 @@
renameNode.setString(6, getInternalId(data.getIdentifier()));
return renameNode.executeUpdate();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findItemIdentifier(String parentCid, String name) throws
SQLException
+ {
+ if (findItemIdentifier == null)
+ findItemIdentifier = dbConnection.prepareStatement(FIND_ITEM_IDENTIFIER);
+ else
+ findItemIdentifier.clearParameters();
+
+ findItemIdentifier.setString(1, containerName);
+ findItemIdentifier.setString(2, parentCid);
+ findItemIdentifier.setString(3, name);
+ return findItemIdentifier.executeQuery();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findItemName(String cid) throws SQLException
+ {
+ if (findItemName == null)
+ findItemName = dbConnection.prepareStatement(FIND_ITEM_NAME);
+ else
+ findItemName.clearParameters();
+
+ findItemName.setString(1, cid);
+ return findItemName.executeQuery();
+ }
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCStorageConnectionTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCStorageConnectionTest.java 2009-11-18
11:54:25 UTC (rev 748)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCStorageConnectionTest.java 2009-11-18
12:08:01 UTC (rev 749)
@@ -289,7 +289,7 @@
connection.deleteNode(troot.getIdentifier());
connection.commit();
- //check
+ // check
assertNull(dataManager.getItemData(troot.getIdentifier()));
assertNull(dataManager.getItemData(pt.getIdentifier()));
}