[exo-jcr-commits] exo-jcr SVN: r767 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage: jdbc and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Nov 19 06:51:16 EST 2009
Author: pnedonosko
Date: 2009-11-19 06:51:16 -0500 (Thu, 19 Nov 2009)
New Revision: 767
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
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/HSQLDBSingleDbJDBCConnection.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
Log:
EXOJCR-203: rework of exceptions, childs search, items existsence.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-19 11:32:39 UTC (rev 766)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-19 11:51:16 UTC (rev 767)
@@ -224,7 +224,10 @@
}
else
{
- LOG.warn("FATAL Get child Nodes: parent not found " + parent.getQPath().getAsString());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("FATAL Get child Nodes: parent not found " + parent.getQPath().getAsString());
+ }
// TODO should be Exception, but after OPT branch optimization merge, current impl requires it as null returned
// throw new RepositoryException("FATAL Get child Nodes: parent not found " + parent.getQPath().getAsString());
@@ -291,7 +294,10 @@
}
else
{
- LOG.warn("FATAL Get child Properties: parent not found " + parent.getQPath().getAsString());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("FATAL Get child Properties: parent not found " + parent.getQPath().getAsString());
+ }
// TODO should be Exception, but after OPT branch optimization merge, current impl requires it as null returned
//throw new IllegalStateException("FATAL Get child Properties: parent not found "
@@ -382,8 +388,10 @@
}
else
{
- LOG
- .warn("FATAL Parent not found " + parentData.getQPath().getAsString() + " for " + name.getAsString(true));
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("FATAL Parent not found " + parentData.getQPath().getAsString() + " for " + name.getAsString(true));
+ }
// TODO should be Exception, but after OPT branch optimization merge, current impl requires it as null returned
//throw new RepositoryException("FATAL Parent not found " + parentData.getQPath().getAsString() + " for "
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-19 11:32:39 UTC (rev 766)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-19 11:51:16 UTC (rev 767)
@@ -114,8 +114,10 @@
break;
case PUT_KEY_VALUE :
- if (m.getFqn().size() == 2) {
- if (isUpdate(m, (JDBCStorageConnection) conn)) {
+ if (m.getFqn().size() == 2)
+ {
+ if (isUpdate(m, (JDBCStorageConnection)conn))
+ {
doUpdate(m, conn);
}
else
@@ -148,14 +150,14 @@
/**
* Check update item or add item.
*
- * @param m
- * @param conn
+ * @param m Modification
+ * @param conn JDBCStorageConnection
* @return boolean
- * return true if update
+ * return true if update, false if add
*/
private boolean isUpdate(Modification m, JDBCStorageConnection conn) throws RepositoryException
{
- return (conn.getItemName((String)m.getFqn().get(1)) == null ? false : true);
+ return conn.itemExists((String)m.getFqn().get(1), m.getValue() instanceof NodeData);
}
/**
@@ -320,12 +322,15 @@
QPathEntry childNodeName = QPathEntry.parse(name.getLastElementAsString());
String parentId = (String)name.get(1);
- String nodeId = conn.getItemIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
+ String nodeId =
+ conn.getNodeIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
if (nodeId != null)
{
attrs = new LinkedHashMap<Object, Object>();
attrs.put(JBossCacheStorage.ITEM_ID, nodeId);
- } else {
+ }
+ else
+ {
attrs = null;
}
}
@@ -403,7 +408,7 @@
if (name.size() == 2)
{
String nodeId = name.getLastElementAsString();
- String nodeName = conn.getItemName(nodeId);
+ String nodeName = conn.getNodeName(nodeId);
if (nodeName != null)
{
@@ -420,7 +425,8 @@
QPathEntry childNodeName = QPathEntry.parse(name.getLastElementAsString());
String parentId = (String)name.get(1);
- String nodeId = conn.getItemIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
+ String nodeId =
+ conn.getNodeIdentifier(parentId, childNodeName.getAsString(false), childNodeName.getIndex());
if (nodeId != null)
{
exists = true;
@@ -442,7 +448,7 @@
if (name.size() == 2)
{
String propertyId = name.getLastElementAsString();
- String propertyName = conn.getItemName(propertyId);
+ String propertyName = conn.getPropertyName(propertyId);
if (propertyName != null)
{
@@ -724,5 +730,4 @@
}
}
-
}
\ No newline at end of file
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-19 11:32:39 UTC (rev 766)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2009-11-19 11:51:16 UTC (rev 767)
@@ -145,9 +145,14 @@
/**
* FIND_ITEM_IDENTIFIER.
*/
- protected String FIND_ITEM_IDENTIFIER;
+ protected String FIND_NODE_IDENTIFIER;
/**
+ * FIND_PROPERTY_IDENTIFIER.
+ */
+ protected String FIND_PROPERTY_IDENTIFIER;
+
+ /**
* FIND_ITEM_NAME.
*/
protected String FIND_ITEM_NAME;
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-19 11:32:39 UTC (rev 766)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2009-11-19 11:51:16 UTC (rev 767)
@@ -2000,22 +2000,23 @@
}
/**
- * Find Item ID in database.
+ * Find Node ID in database.
*
* @param parentId String, parent Node id
- * @param name Item, name
- * @param index int, path index (actual for nodes, 1 for properties)
+ * @param name String, Node name
+ * @param index int, path index
* @return String with ID
* @throws RepositoryException if database error occurs
* @throws IllegalStateException if connection closed
*/
- public String getItemIdentifier(String parentId, String name, int index) throws RepositoryException, IllegalStateException
+ public String getNodeIdentifier(String parentId, String name, int index) throws RepositoryException,
+ IllegalStateException
{
checkIfOpened();
try
{
- ResultSet item = findItemIdentifier(getInternalId(parentId), name, index);
+ ResultSet item = findNodeIdentifier(getInternalId(parentId), name, index);
if (item.next())
{
return item.getString(COLUMN_ID);
@@ -2030,14 +2031,108 @@
}
/**
- * Find Item name in database.
+ * Find Property ID in database.
*
+ * TODO not used!
+ *
+ * @param parentId String, parent Node id
+ * @param name String, Property name
+ * @return String with ID
+ * @throws RepositoryException if database error occurs
+ * @throws IllegalStateException if connection closed
+ */
+ @Deprecated
+ public String getPropertyIdentifier(String parentId, String name) throws RepositoryException, IllegalStateException
+ {
+ checkIfOpened();
+
+ try
+ {
+ ResultSet item = findPropertyIdentifier(getInternalId(parentId), name);
+ if (item.next())
+ {
+ return item.getString(COLUMN_ID);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+
+ return null;
+ }
+
+ /**
+ * Check if Item exists in database. <code>isNode</code> flag will be used to filter <code>Node</code> or <code>Property</code> asked.
+ *
+ * @param itemId String
+ * @param isNode boolean, true if Node asked, false if Property
+ * @return boolean, true if Item exists, false otherwise
+ * @throws RepositoryException if database error occurs
+ * @throws IllegalStateException if connection closed
+ */
+ public boolean itemExists(String itemId, boolean isNode) throws RepositoryException, IllegalStateException
+ {
+
+ checkIfOpened();
+
+ try
+ {
+ ResultSet item = findItemName(getInternalId(itemId));
+ if (item.next())
+ {
+ return item.getInt(COLUMN_CLASS) == (isNode ? I_CLASS_NODE : I_CLASS_PROPERTY);
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+
+ return false;
+ }
+
+ /**
+ * Find Node name in database.
+ *
+ * @param nodeId String
+ * @return String with name
+ * @throws RepositoryException if database error occurs
+ * @throws IllegalStateException if connection closed
+ */
+ public String getNodeName(String nodeId) throws RepositoryException, IllegalStateException
+ {
+
+ checkIfOpened();
+
+ try
+ {
+ ResultSet item = findItemName(getInternalId(nodeId));
+ if (item.next())
+ {
+ if (item.getInt(COLUMN_CLASS) == I_CLASS_NODE)
+ {
+ return item.getString(COLUMN_NAME);
+ }
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+
+ return null;
+ }
+
+ /**
+ * Find Property 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
+ public String getPropertyName(String propertyId) throws RepositoryException, IllegalStateException
{
checkIfOpened();
@@ -2047,7 +2142,10 @@
ResultSet item = findItemName(getInternalId(propertyId));
if (item.next())
{
- return item.getString(COLUMN_NAME);
+ if (item.getInt(COLUMN_CLASS) == I_CLASS_PROPERTY)
+ {
+ return item.getString(COLUMN_NAME);
+ }
}
}
catch (SQLException e)
@@ -2241,17 +2339,19 @@
// JBC related
- protected abstract ResultSet findChildPropertiesIdNameByParentIdentifier(String parentCid)
- throws SQLException;
+ protected abstract ResultSet findChildPropertiesIdNameByParentIdentifier(String parentCid) throws SQLException;
protected abstract ResultSet findChildNodesNameByParentIdentifier(String parentCid) throws SQLException;
- protected abstract ResultSet findItemIdentifier(String parentCid, String name, int index) throws SQLException;
+ protected abstract ResultSet findNodeIdentifier(String parentCid, String name, int index) throws SQLException;
+ @Deprecated
+ protected abstract ResultSet findPropertyIdentifier(String parentCid, String name) throws SQLException;
+
protected abstract ResultSet findItemName(String cid) throws SQLException;
-
+
protected abstract ResultSet findAllPropertyIdentifiers() throws SQLException;
-
+
protected abstract ResultSet findAllNodeIdentifiers() throws SQLException;
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2009-11-19 11:32:39 UTC (rev 766)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/HSQLDBSingleDbJDBCConnection.java 2009-11-19 11:51:16 UTC (rev 767)
@@ -87,8 +87,13 @@
FIND_PROPERTIES_BY_PARENTID =
"select * from JCR_SITEM" + " where PARENT_ID=? and I_CLASS=2 and CONTAINER_NAME=?" + " order by ID";
+
FIND_PROPERTIES_IDNAME_BY_PARENTID =
"select ID, NAME from JCR_SITEM" + " where PARENT_ID=? and I_CLASS=2 and CONTAINER_NAME=?";
+
+ FIND_NODE_IDENTIFIER = "select ID from JCR_SITEM" + " where PARENT_ID=? and I_CLASS=1 and CONTAINER_NAME=? and NAME=? and I_INDEX=?";
+
+ FIND_PROPERTY_IDENTIFIER = "select ID from JCR_SITEM" + " where PARENT_ID=? and I_CLASS=2 and CONTAINER_NAME=? and NAME=? and I_INDEX=1";
}
/**
@@ -192,4 +197,45 @@
findNodesNameByParentId.setString(2, containerName);
return findNodesNameByParentId.executeQuery();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findNodeIdentifier(String parentCid, String name, int index) throws SQLException
+ {
+ if (findNodeIdentifier == null)
+ {
+ findNodeIdentifier = dbConnection.prepareStatement(FIND_NODE_IDENTIFIER);
+ }
+ else
+ {
+ findNodeIdentifier.clearParameters();
+ }
+ findNodeIdentifier.setString(1, parentCid);
+ findNodeIdentifier.setString(2, containerName);
+ findNodeIdentifier.setString(3, name);
+ findNodeIdentifier.setInt(4, index);
+ return findNodeIdentifier.executeQuery();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findPropertyIdentifier(String parentCid, String name) throws SQLException
+ {
+ if (findPropertyIdentifier == null)
+ {
+ findPropertyIdentifier = dbConnection.prepareStatement(FIND_PROPERTY_IDENTIFIER);
+ }
+ else
+ {
+ findPropertyIdentifier.clearParameters();
+ }
+ findPropertyIdentifier.setString(1, parentCid);
+ findPropertyIdentifier.setString(2, containerName);
+ findPropertyIdentifier.setString(3, name);
+ return findPropertyIdentifier.executeQuery();
+ }
}
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-19 11:32:39 UTC (rev 766)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java 2009-11-19 11:51:16 UTC (rev 767)
@@ -84,7 +84,9 @@
protected PreparedStatement findPropertiesIdNameByParentId;
- protected PreparedStatement findItemIdentifier;
+ protected PreparedStatement findNodeIdentifier;
+
+ protected PreparedStatement findPropertyIdentifier;
protected PreparedStatement findItemName;
@@ -209,9 +211,11 @@
FIND_ALL_PROPERTIES = "select ID from JCR_MITEM where I_CLASS=2";
- FIND_ITEM_IDENTIFIER = "select ID from JCR_MITEM" + " where PARENT_ID=? and NAME=? and I_INDEX=?";
+ FIND_NODE_IDENTIFIER = "select ID from JCR_MITEM" + " where I_CLASS=1 and PARENT_ID=? and NAME=? and I_INDEX=?";
+
+ FIND_PROPERTY_IDENTIFIER = "select ID from JCR_MITEM" + " where I_CLASS=2 and PARENT_ID=? and NAME=? and I_INDEX=1";
- FIND_ITEM_NAME = "select NAME from JCR_MITEM" + " where ID=?";
+ FIND_ITEM_NAME = "select NAME, I_CLASS from JCR_MITEM" + " where ID=?";
INSERT_NODE =
"insert into JCR_MITEM(ID, PARENT_ID, NAME, VERSION, I_CLASS, I_INDEX, N_ORDER_NUM) VALUES(?,?,?,?,"
@@ -597,21 +601,40 @@
* {@inheritDoc}
*/
@Override
- protected ResultSet findItemIdentifier(String parentCid, String name, int index) throws SQLException
+ protected ResultSet findNodeIdentifier(String parentCid, String name, int index) throws SQLException
{
- if (findItemIdentifier == null)
+ if (findNodeIdentifier == null)
{
- findItemIdentifier = dbConnection.prepareStatement(FIND_ITEM_IDENTIFIER);
+ findNodeIdentifier = dbConnection.prepareStatement(FIND_NODE_IDENTIFIER);
}
else
{
- findItemIdentifier.clearParameters();
+ findNodeIdentifier.clearParameters();
}
- findItemIdentifier.setString(1, parentCid);
- findItemIdentifier.setString(2, name);
- findItemIdentifier.setInt(3, index);
- return findItemIdentifier.executeQuery();
+ findNodeIdentifier.setString(1, parentCid);
+ findNodeIdentifier.setString(2, name);
+ findNodeIdentifier.setInt(3, index);
+ return findNodeIdentifier.executeQuery();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findPropertyIdentifier(String parentCid, String name) throws SQLException
+ {
+ if (findPropertyIdentifier == null)
+ {
+ findPropertyIdentifier = dbConnection.prepareStatement(FIND_PROPERTY_IDENTIFIER);
+ }
+ else
+ {
+ findPropertyIdentifier.clearParameters();
+ }
+ findPropertyIdentifier.setString(1, parentCid);
+ findPropertyIdentifier.setString(2, name);
+ return findPropertyIdentifier.executeQuery();
+ }
/**
* {@inheritDoc}
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-19 11:32:39 UTC (rev 766)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java 2009-11-19 11:51:16 UTC (rev 767)
@@ -81,7 +81,9 @@
protected PreparedStatement findPropertiesIdNameByParentId;
- protected PreparedStatement findItemIdentifier;
+ protected PreparedStatement findNodeIdentifier;
+
+ protected PreparedStatement findPropertyIdentifier;
protected PreparedStatement findItemName;
@@ -219,9 +221,11 @@
FIND_ALL_PROPERTIES = "select ID from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME=?";
- FIND_ITEM_IDENTIFIER = "select ID from JCR_SITEM" + " where CONTAINER_NAME=? and PARENT_ID=? and NAME=? and I_INDEX=?";
+ FIND_NODE_IDENTIFIER = "select ID from JCR_SITEM" + " where I_CLASS=1 and CONTAINER_NAME=? and PARENT_ID=? and NAME=? and I_INDEX=?";
+
+ FIND_PROPERTY_IDENTIFIER = "select ID from JCR_SITEM" + " where I_CLASS=2 and CONTAINER_NAME=? and PARENT_ID=? and NAME=? and I_INDEX=1";
- FIND_ITEM_NAME = "select NAME from JCR_SITEM" + " where ID=?";
+ FIND_ITEM_NAME = "select NAME, I_CLASS 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(?,?,?,?,?,"
@@ -610,19 +614,42 @@
* {@inheritDoc}
*/
@Override
- protected ResultSet findItemIdentifier(String parentCid, String name, int index) throws SQLException
+ protected ResultSet findNodeIdentifier(String parentCid, String name, int index) throws SQLException
{
- if (findItemIdentifier == null)
- findItemIdentifier = dbConnection.prepareStatement(FIND_ITEM_IDENTIFIER);
+ if (findNodeIdentifier == null)
+ {
+ findNodeIdentifier = dbConnection.prepareStatement(FIND_NODE_IDENTIFIER);
+ }
else
- findItemIdentifier.clearParameters();
-
- findItemIdentifier.setString(1, containerName);
- findItemIdentifier.setString(2, parentCid);
- findItemIdentifier.setString(3, name);
- findItemIdentifier.setInt(4, index);
- return findItemIdentifier.executeQuery();
+ {
+ findNodeIdentifier.clearParameters();
+ }
+ findNodeIdentifier.setString(1, containerName);
+ findNodeIdentifier.setString(2, parentCid);
+ findNodeIdentifier.setString(3, name);
+ findNodeIdentifier.setInt(4, index);
+ return findNodeIdentifier.executeQuery();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ResultSet findPropertyIdentifier(String parentCid, String name) throws SQLException
+ {
+ if (findPropertyIdentifier == null)
+ {
+ findPropertyIdentifier = dbConnection.prepareStatement(FIND_PROPERTY_IDENTIFIER);
+ }
+ else
+ {
+ findPropertyIdentifier.clearParameters();
+ }
+ findPropertyIdentifier.setString(1, containerName);
+ findPropertyIdentifier.setString(2, parentCid);
+ findPropertyIdentifier.setString(3, name);
+ return findPropertyIdentifier.executeQuery();
+ }
/**
* {@inheritDoc}
More information about the exo-jcr-commits
mailing list