Author: sergiykarpenko
Date: 2009-11-19 09:22:41 -0500 (Thu, 19 Nov 2009)
New Revision: 775
Removed:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java
Log:
EXOJCR-202: IndexerCacheLoaderRuntime test removed
Deleted:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java 2009-11-19
14:07:11 UTC (rev 774)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java 2009-11-19
14:22:41 UTC (rev 775)
@@ -1,922 +0,0 @@
-/*
- * Copyright (C) 2003-2009 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not,
see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.storage.jbosscache;
-
-import org.apache.commons.dbcp.BasicDataSourceFactory;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.exoplatform.container.configuration.ConfigurationManager;
-import org.exoplatform.container.configuration.ConfigurationManagerImpl;
-import org.exoplatform.services.document.DocumentReaderService;
-import org.exoplatform.services.idgenerator.impl.IDGeneratorServiceImpl;
-import org.exoplatform.services.jcr.access.AccessControlList;
-import org.exoplatform.services.jcr.config.ContainerEntry;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.SimpleParameterEntry;
-import org.exoplatform.services.jcr.config.ValueStorageEntry;
-import org.exoplatform.services.jcr.config.ValueStorageFilterEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-import org.exoplatform.services.jcr.datamodel.ItemData;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.datamodel.PropertyData;
-import org.exoplatform.services.jcr.datamodel.QPath;
-import org.exoplatform.services.jcr.datamodel.ValueData;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.core.LocationFactory;
-import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
-import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeDataManagerImpl;
-import
org.exoplatform.services.jcr.impl.core.nodetype.registration.JcrNodeTypeDataPersister;
-import
org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister;
-import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
-import org.exoplatform.services.jcr.impl.core.query.SearchManager;
-import org.exoplatform.services.jcr.impl.core.query.SystemSearchManagerHolder;
-import org.exoplatform.services.jcr.impl.core.query.cacheloader.IndexerCacheLoader;
-import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
-import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
-import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
-import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
-import
org.exoplatform.services.jcr.impl.dataflow.persistent.JBossCacheWorkspaceDataManager;
-import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
-import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
-import org.exoplatform.services.jcr.impl.storage.value.StandaloneStoragePluginProvider;
-import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
-import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
-import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
-import org.exoplatform.services.jcr.util.IdGenerator;
-import org.jboss.cache.Modification;
-
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date:
- *
- * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
- * @version $Id: IndexerCacheLoaderRuntimeTest.java 111 2008-11-11 11:11:11Z serg $
- */
-public class IndexerCacheLoaderRuntimeTest extends AbstractCacheLoaderTest
-{
-
- private JDBCWorkspaceDataContainer persistentContainer;
-
- private IndexerCacheLoader loader;
-
- SearchManager manager;
-
- //IndexInterceptorHolder holder;
-
- public void createNewDataSource(String dataSourceName) throws Exception
- {
-
- Properties properties = new Properties();
-
- properties.setProperty("driverClassName",
"org.hsqldb.jdbcDriver");
- String newurl = "jdbc:hsqldb:file:target/temp/data/" + dataSourceName;
-
- properties.setProperty("url", newurl);
- properties.setProperty("username", "sa");
- properties.setProperty("password", "");
- DataSource bds = BasicDataSourceFactory.createDataSource(properties);
- if (!newurl.contains("hsqldb"))
- {
- createDatabase(bds, dataSourceName);
- }
-
- new InitialContext().rebind(dataSourceName, bds);
- }
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- initPersistence();
-
- loader = new IndexerCacheLoader();
- //loader.injectDependencies(holder);
-
- initJCRRoot();
-
- manager.start();
- }
-
- public void testAddNode() throws Exception
- {
- List<Modification> modifications = new ArrayList<Modification>();
-
- // prepare add node to storage
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- String node1id = IdGenerator.generate();
- QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
-
- // add node (/) with jcr:primaryType
- NodeData nodeData =
- new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new
InternalQName[0], 0,
- Constants.ROOT_UUID, new AccessControlList());
- conn.add(nodeData);
- modifications.addAll(this.addNode(nodeData));
-
- // add property (/jcr:primaryType)
- TransientPropertyData propData =
- createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE,
Constants.NT_UNSTRUCTURED, false);
- conn.add(propData);
- modifications.addAll(this.addProperty(propData));
-
- conn.commit();
- loader.put(modifications);
-
- // check do we really have node and its property
- conn = persistentContainer.openConnection();
- NodeData nd = (NodeData)conn.getItemData(node1id);
- assertNotNull(nd);
- assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
-
- PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
- assertNotNull(pd);
- assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
-
- // find node by search engine
- SearchIndex index = ((SearchIndex)manager.getHandler());
- IndexReader reader = index.getIndexReader();
-
- IndexSearcher searcher = new IndexSearcher(reader);
-
- Query query = new TermQuery(new Term("_:UUID", node1id));
- Hits hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- }
-
- public void testRemoveNode() throws Exception
- {
- List<Modification> modifications = new ArrayList<Modification>();
-
- // prepare add node to storage
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- String node1id = IdGenerator.generate();
- QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
-
- // add node (/) with jcr:primaryType
- NodeData nodeData =
- new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new
InternalQName[0], 0,
- Constants.ROOT_UUID, new AccessControlList());
- conn.add(nodeData);
- modifications.addAll(this.addNode(nodeData));
-
- // add property (/jcr:primaryType)
- TransientPropertyData propData =
- createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE,
Constants.NT_UNSTRUCTURED, false);
- conn.add(propData);
- modifications.addAll(this.addProperty(propData));
-
- conn.commit();
- loader.put(modifications);
-
- // check do we really have node and its property
- conn = persistentContainer.openConnection();
- NodeData nd = (NodeData)conn.getItemData(node1id);
- assertNotNull(nd);
- assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
-
- PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
- assertNotNull(pd);
- assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
-
- // find node by search engine
- SearchIndex index = ((SearchIndex)manager.getHandler());
- IndexReader reader = index.getIndexReader();
-
- IndexSearcher searcher = new IndexSearcher(reader);
-
- Query query = new TermQuery(new Term("_:UUID", node1id));
- Hits hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- // remove node1
- modifications.clear();
-
- // PropertyData prop = (PropertyData)node.get(1);
- // NodeData n = (NodeData)node.get(0);
-
- conn.delete(pd);
- modifications.addAll(removeProperty(pd));
- conn.delete(nd);
- modifications.addAll(removeNode(nd));
- conn.commit();
-
- // check removing
- conn = persistentContainer.openConnection();
- nd = (NodeData)conn.getItemData(node1id);
- assertNull(nd);
-
- loader.put(modifications);
-
- // check index;
- reader = index.getIndexReader();
-
- searcher = new IndexSearcher(reader);
- hit = searcher.search(query);
- assertEquals(0, hit.length());
- }
-
- // public void testRenameNode() throws Exception
- // {
- // List<Modification> modifications = new ArrayList<Modification>();
- //
- // // prepare add node to storage
- // WorkspaceStorageConnection conn = persistentContainer.openConnection();
- //
- // String node1id = IdGenerator.generate();
- // QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH,
"[]node:1");
- //
- // // add node (/) with jcr:primaryType
- // NodeData nodeData =
- // new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new
InternalQName[0], 0,
- // Constants.ROOT_UUID, new AccessControlList());
- // conn.add(nodeData);
- // modifications.addAll(this.addNode(nodeData));
- //
- // // add property (/jcr:primaryType)
- // TransientPropertyData propData =
- // createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE,
Constants.NT_UNSTRUCTURED, false);
- // conn.add(propData);
- // modifications.addAll(this.addProperty(propData));
- //
- // conn.commit();
- // loader.put(modifications);
- //
- // // check do we really have node and its property
- // conn = persistentContainer.openConnection();
- // NodeData nd = (NodeData)conn.getItemData(node1id);
- // assertNotNull(nd);
- // assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
- //
- // PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
- // assertNotNull(pd);
- // assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
- //
- // // find node by search engine
- // SearchIndex index = ((SearchIndex)manager.getHandler());
- // IndexReader reader = index.getIndexReader();
- //
- // IndexSearcher searcher = new IndexSearcher(reader);
- //
- // Query query = new TermQuery(new Term("_:UUID", node1id));
- // Hits hit = searcher.search(query);
- // assertEquals(1, hit.length());
- //
- // modifications.clear();
- //
- // conn = persistentContainer.openConnection();
- //
- // QPath newnode1path = QPath.makeChildPath(Constants.ROOT_PATH,
"[]node:1");
- // NodeData newnodeData =
- // new TransientNodeData(newnode1path, node1id, 1, Constants.NT_UNSTRUCTURED,
new InternalQName[0], 0,
- // Constants.ROOT_UUID, new AccessControlList());
- //
- // conn.rename(newnodeData);
- //
- // }
-
- public void testUpdateAddProperty() throws Exception
- {
-
- List<Modification> modifications = new ArrayList<Modification>();
-
- // prepare add node to storage
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- String node1id = IdGenerator.generate();
- QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
-
- // add node (/) with jcr:primaryType
- NodeData nodeData =
- new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new
InternalQName[0], 0,
- Constants.ROOT_UUID, new AccessControlList());
- conn.add(nodeData);
- modifications.addAll(this.addNode(nodeData));
-
- // add property (/jcr:primaryType)
- TransientPropertyData propData =
- createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE,
Constants.NT_UNSTRUCTURED, false);
- conn.add(propData);
- modifications.addAll(this.addProperty(propData));
-
- conn.commit();
- loader.put(modifications);
-
- // check do we really have node and its property
- conn = persistentContainer.openConnection();
- NodeData nd = (NodeData)conn.getItemData(node1id);
- assertNotNull(nd);
- assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
-
- PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
- assertNotNull(pd);
- assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
-
- // find node by search engine
- SearchIndex index = ((SearchIndex)manager.getHandler());
- IndexReader reader = index.getIndexReader();
-
- IndexSearcher searcher = new IndexSearcher(reader);
-
- Query query = new TermQuery(new Term("_:UUID", node1id));
- Hits hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- modifications.clear();
- // prepare
- TransientPropertyData newPropData =
- createProperty(node1path, node1id, new InternalQName(Constants.NS_DEFAULT_URI,
"myProp"), "JCR DATA VALUE",
- false);
-
- conn = persistentContainer.openConnection();
- conn.add(newPropData);
- modifications.addAll(addProperty(newPropData));
- conn.commit();
-
- loader.put(modifications);
-
- // tests it
- WorkspaceStorageConnection connection = persistentContainer.openConnection();
-
- PropertyData destPropData =
(PropertyData)connection.getItemData(newPropData.getIdentifier());
-
- assertNotNull(destPropData);
- assertEquals(newPropData.getIdentifier(), destPropData.getIdentifier());
- assertEquals(newPropData.getParentIdentifier(),
destPropData.getParentIdentifier());
- assertEquals(newPropData.getPersistedVersion(),
destPropData.getPersistedVersion());
- assertEquals(newPropData.getType(), destPropData.getType());
- assertEquals(newPropData.getQPath(), destPropData.getQPath());
- assertEquals(newPropData.getValues().size(), destPropData.getValues().size());
- assertEquals(1, destPropData.getValues().size());
-
- ValueData valueData = destPropData.getValues().get(0);
- assertEquals("JCR DATA VALUE", new String(valueData.getAsByteArray(),
"UTF-8"));
-
- reader = index.getIndexReader();
-
- searcher = new IndexSearcher(reader);
-
- query = new TermQuery(new Term("_:UUID", node1id));
- hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- query = new TermQuery(new Term("FULL:myProp", "data"));
- hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- }
-
- public void testUpdateRemoveProperty() throws Exception
- {
-
- List<Modification> modifications = new ArrayList<Modification>();
-
- // prepare add node to storage
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- String node1id = IdGenerator.generate();
- QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
-
- // add node (/) with jcr:primaryType
- NodeData nodeData =
- new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new
InternalQName[0], 0,
- Constants.ROOT_UUID, new AccessControlList());
- conn.add(nodeData);
- modifications.addAll(this.addNode(nodeData));
-
- // add property (/jcr:primaryType)
- TransientPropertyData propData =
- createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE,
Constants.NT_UNSTRUCTURED, false);
- conn.add(propData);
- modifications.addAll(this.addProperty(propData));
-
- // add additonal property
- TransientPropertyData propData2 =
- createProperty(node1path, node1id, new InternalQName(Constants.NS_DEFAULT_URI,
"myProp2"), "JCR DATA VALUE",
- false);
- conn.add(propData2);
- modifications.addAll(addProperty(propData2));
-
- conn.commit();
- loader.put(modifications);
-
- // check do we really have node and its property
- conn = persistentContainer.openConnection();
- NodeData nd = (NodeData)conn.getItemData(node1id);
- assertNotNull(nd);
- assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
-
- PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
- assertNotNull(pd);
- assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
-
- // find node by search engine
- SearchIndex index = ((SearchIndex)manager.getHandler());
- IndexReader reader = index.getIndexReader();
-
- IndexSearcher searcher = new IndexSearcher(reader);
-
- Query query = new TermQuery(new Term("_:UUID", node1id));
- Hits hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- query = new TermQuery(new Term("FULL:myProp2", "data"));
- hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- modifications.clear();
-
- // remove property
- conn = persistentContainer.openConnection();
- conn.delete(propData2);
- modifications.addAll(removeProperty(propData2));
- conn.commit();
-
- loader.put(modifications);
-
- // tests it
- WorkspaceStorageConnection connection = persistentContainer.openConnection();
-
- PropertyData destPropData =
(PropertyData)connection.getItemData(propData2.getIdentifier());
-
- assertNull(destPropData);
-
- reader = index.getIndexReader();
-
- searcher = new IndexSearcher(reader);
-
- query = new TermQuery(new Term("_:UUID", node1id));
- hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- query = new TermQuery(new Term("FULL:myProp2", "data"));
- hit = searcher.search(query);
- assertEquals(0, hit.length());
-
- }
-
- public void testUpdateProperty() throws Exception
- {
-
- List<Modification> modifications = new ArrayList<Modification>();
-
- // prepare add node to storage
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- String node1id = IdGenerator.generate();
- QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
-
- // add node (/) with jcr:primaryType
- NodeData nodeData =
- new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new
InternalQName[0], 0,
- Constants.ROOT_UUID, new AccessControlList());
- conn.add(nodeData);
- modifications.addAll(this.addNode(nodeData));
-
- // add property (/jcr:primaryType)
- TransientPropertyData propData =
- createProperty(node1path, node1id, Constants.JCR_PRIMARYTYPE,
Constants.NT_UNSTRUCTURED, false);
- conn.add(propData);
- modifications.addAll(this.addProperty(propData));
-
- // add additonal property
- TransientPropertyData propData2 =
- createProperty(node1path, node1id, new InternalQName(Constants.NS_DEFAULT_URI,
"myProp2"), "JCR DATA VALUE",
- false);
- conn.add(propData2);
- modifications.addAll(addProperty(propData2));
-
- conn.commit();
- loader.put(modifications);
-
- // check do we really have node and its property
- conn = persistentContainer.openConnection();
- NodeData nd = (NodeData)conn.getItemData(node1id);
- assertNotNull(nd);
- assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
-
- PropertyData pd = (PropertyData)conn.getItemData(propData.getIdentifier());
- assertNotNull(pd);
- assertEquals(propData.getQPath().getAsString(), pd.getQPath().getAsString());
-
- // find node by search engine
- SearchIndex index = ((SearchIndex)manager.getHandler());
- IndexReader reader = index.getIndexReader();
-
- IndexSearcher searcher = new IndexSearcher(reader);
-
- Query query = new TermQuery(new Term("_:UUID", node1id));
- Hits hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- query = new TermQuery(new Term("FULL:myProp2", "data"));
- hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- modifications.clear();
-
- // update property
- conn = persistentContainer.openConnection();
-
- TransientPropertyData newpropData2 =
- new TransientPropertyData(propData2.getQPath(), propData2.getIdentifier(),
propData2.getPersistedVersion(),
- propData2.getType(), propData2.getParentIdentifier(),
propData2.isMultiValued());
-
- newpropData2.setValue(new TransientValueData("newvalue"));
-
- conn.update(newpropData2);
- modifications.addAll(updateProperty(newpropData2));
- conn.commit();
-
- loader.put(modifications);
-
- // tests it
- WorkspaceStorageConnection connection = persistentContainer.openConnection();
-
- PropertyData destPropData =
(PropertyData)connection.getItemData(propData2.getIdentifier());
-
- assertNotNull(destPropData);
-
- reader = index.getIndexReader();
-
- searcher = new IndexSearcher(reader);
-
- query = new TermQuery(new Term("_:UUID", node1id));
- hit = searcher.search(query);
- assertEquals(1, hit.length());
-
- query = new TermQuery(new Term("FULL:myProp2", "data"));
- hit = searcher.search(query);
- assertEquals(0, hit.length());
-
- query = new TermQuery(new Term("FULL:myProp2", "newvalue"));
- hit = searcher.search(query);
- assertEquals(1, hit.length());
- }
-
- /**
- * Add Property to the connection but doesn't save it.
- *
- * @param conn WorkspaceStorageConnection
- * @param root QPath
- * @param nodeId String
- * @param primaryType InternalQName
- * @throws Exception
- */
- private void addDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId,
String parentId,
- InternalQName primaryType) throws Exception
- {
- // add root (/)
- conn.add(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0],
0, parentId,
- new AccessControlList()));
-
- // add property (/jcr:primaryType)
- addDbProperty(conn, root, nodeId, Constants.JCR_PRIMARYTYPE, primaryType, false);
- }
-
- /**
- * Add Property to the connection but doesn't save it.
- *
- * @param conn WorkspaceStorageConnection
- * @param nodePath QPath
- * @param nodeId String
- * @param propertyName InternalQName
- * @param propertyValue Object
- * @return TransientPropertyData
- * @throws Exception
- */
- private TransientPropertyData addDbProperty(WorkspaceStorageConnection conn, QPath
nodePath, String nodeId,
- InternalQName propertyName, Object propertyValue, boolean multiValued) throws
Exception
- {
- TransientPropertyData propData = createProperty(nodePath, nodeId, propertyName,
propertyValue, multiValued);
-
- conn.add(propData);
-
- return propData;
- }
-
- private void createDatabase(DataSource ds, String dbName) throws SQLException
- {
- Connection connection = ds.getConnection();
- PreparedStatement st = connection.prepareStatement("create database " +
dbName);
- st.executeQuery();
- }
-
- /**
- * Create Node to the connection but doesn't save it.
- *
- * @param path QPath
- * @param nodeId String
- * @param primaryType InternalQName
- * @param mixinTypeNames InternalQName
- * @throws Exception
- */
- private List<ItemData> createNode(QPath path, String nodeId, InternalQName
primaryType,
- InternalQName[] mixinTypeNames) throws Exception
- {
- List<ItemData> list = new ArrayList<ItemData>();
-
- // add node
- list.add(new TransientNodeData(path, nodeId, 1, primaryType, (mixinTypeNames ==
null ? new InternalQName[0]
- : null), 0, null, new AccessControlList()));
-
- // add property (/jcr:primaryType)
- list.add(createProperty(path, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE,
primaryType, false));
-
- return list;
- }
-
- /**
- * Create Property.
- *
- * @param nodePath QPath
- * @param nodeId String
- * @param propertyName InternalQName
- * @param propertyValue Object
- * @return TransientPropertyData
- * @throws Exception
- */
- private TransientPropertyData createProperty(QPath nodePath, String nodeId,
InternalQName propertyName,
- Object propertyValue, boolean multiValued) throws Exception
- {
- String propId = IdGenerator.generate();
- QPath propPath = QPath.makeChildPath(nodePath, propertyName);
- TransientPropertyData propData = new TransientPropertyData(propPath, propId, 1, 1,
nodeId, multiValued);
-
- List<Object> values = new ArrayList<Object>();
- if (multiValued)
- {
- if (propertyValue instanceof List)
- {
- values.addAll((List<Object>)propertyValue);
- }
- else
- throw new Exception("propertyValue should be a List");
- }
- else
- {
- values.add(propertyValue);
- }
-
- for (Object value : values)
- {
- if (value instanceof InternalQName)
- {
- propData.setValue(new TransientValueData((InternalQName)value));
- }
- else if (value instanceof String)
- {
- propData.setValue(new TransientValueData((String)value));
- }
- else if (value instanceof InputStream)
- {
- propData.setValue(new TransientValueData((InputStream)value));
- }
- }
-
- return propData;
- }
-
- /**
- * Delete Property to the connection but doesn't save it.
- *
- * @param conn WorkspaceStorageConnection
- * @param root QPath
- * @param nodeId String
- * @param primaryType InternalQName
- * @throws Exception
- */
- private void deleteDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId,
InternalQName primaryType)
- throws Exception
- {
- // add property (/jcr:primaryType)
- addDbProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE,
primaryType, false);
-
- // add root (/)
- conn.delete(new TransientNodeData(root, nodeId, 1, primaryType, new
InternalQName[0], 0, null,
- new AccessControlList()));
- }
-
- private void deleteJCRRoot() throws Exception
- {
- // prepare
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- // add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, null,
Constants.NT_UNSTRUCTURED);
-
- // add property (/jcr:mixinTypes)
- List<InternalQName> mixins = new ArrayList<InternalQName>();
- mixins.add(Constants.MIX_REFERENCEABLE);
- mixins.add(Constants.EXO_PRIVILEGEABLE);
- mixins.add(Constants.EXO_OWNEABLE);
- addDbProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.JCR_MIXINTYPES, mixins, true);
-
- conn.commit();
- }
-
- private void initJCRRoot() throws Exception
- {
- // prepare
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- // add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, null,
Constants.NT_UNSTRUCTURED);
-
- // add property (/jcr:mixinTypes)
- //List<InternalQName> mixins = new ArrayList<InternalQName>();
- // mixins.add(Constants.MIX_REFERENCEABLE);
- // mixins.add(Constants.EXO_PRIVILEGEABLE);
- // mixins.add(Constants.EXO_OWNEABLE);
- //addDbProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.JCR_MIXINTYPES, mixins, true);
-
- conn.commit();
- }
-
- protected WorkspaceEntry getNewWs(String wsName, boolean isMultiDb, String dsName,
String vsPath,
- ContainerEntry entry) throws Exception
- {
-
- List params = new ArrayList();
-
- params.add(new SimpleParameterEntry("sourceName", dsName));
- params.add(new SimpleParameterEntry("db-type", "generic"));
- params.add(new SimpleParameterEntry("multi-db", isMultiDb ?
"true" : "false"));
- params.add(new SimpleParameterEntry("update-storage",
"true"));
- params.add(new SimpleParameterEntry("max-buffer-size",
"204800"));
-
- if (entry.getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT) != null)
- {
- params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT,
entry
- .getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT)));
- }
-
- String oldSwap = entry.getParameterValue("swap-directory");
- String newSwap = oldSwap.substring(0, oldSwap.lastIndexOf('/')) +
'/' + wsName;
-
- params.add(new SimpleParameterEntry("swap-directory", newSwap));
-
- ContainerEntry containerEntry =
- new
ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
- (ArrayList)params);
- containerEntry.setParameters(params);
-
- if (vsPath != null)
- {
-
- ArrayList<ValueStorageFilterEntry> vsparams = new
ArrayList<ValueStorageFilterEntry>();
- ValueStorageFilterEntry filterEntry = new ValueStorageFilterEntry();
- filterEntry.setPropertyType("Binary");
- vsparams.add(filterEntry);
-
- ValueStorageEntry valueStorageEntry =
- new
ValueStorageEntry("org.exoplatform.services.jcr.impl.storage.value.fs.SimpleFileValueStorage",
vsparams);
- ArrayList<SimpleParameterEntry> spe = new
ArrayList<SimpleParameterEntry>();
- spe.add(new SimpleParameterEntry("path", vsPath));
- valueStorageEntry.setId(IdGenerator.generate());
- valueStorageEntry.setParameters(spe);
- valueStorageEntry.setFilters(vsparams);
-
- // containerEntry.setValueStorages();
- containerEntry.setParameters(params);
- ArrayList list = new ArrayList(1);
- list.add(valueStorageEntry);
-
- containerEntry.setValueStorages(list);
-
- }
-
- WorkspaceEntry workspaceEntry =
- new WorkspaceEntry(wsName != null ? wsName : IdGenerator.generate(),
"nt:unstructured");
- workspaceEntry.setContainer(containerEntry);
-
- // Indexer
- ArrayList qParams = new ArrayList();
- qParams.add(new SimpleParameterEntry("indexDir",
"target/temp/index/db1/ws" + IdGenerator.generate()));
- QueryHandlerEntry qEntry =
- new
QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex",
qParams);
- workspaceEntry.setQueryHandler(qEntry);
-
- // ArrayList cacheParams = new ArrayList();
- //
- // cacheParams.add(new SimpleParameterEntry("maxSize",
"2000"));
- // cacheParams.add(new SimpleParameterEntry("liveTime",
"20m"));
- // CacheEntry cacheEntry = new CacheEntry(cacheParams);
- //
cacheEntry.setType("org.exoplatform.services.jcr.impl.dataflow.persistent.LinkedWorkspaceStorageCacheImpl");
- //
- // workspaceEntry.setCache(cacheEntry);
-
- // LockManagerEntry lockManagerEntry = new LockManagerEntry();
- // lockManagerEntry.setTimeout(900000);
- // LockPersisterEntry persisterEntry = new LockPersisterEntry();
- //
persisterEntry.setType("org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister");
- // ArrayList lpParams = new ArrayList();
- // lpParams.add(new SimpleParameterEntry("path",
"../temp/lock"));
- // persisterEntry.setParameters(lpParams);
- // lockManagerEntry.setPersister(persisterEntry);
- // workspaceEntry.setLockManager(lockManagerEntry);
-
- // workspaceEntry
- return workspaceEntry;
- }
-
- protected void initPersistence() throws Exception
- {
- //holder = new IndexInterceptorHolder();
-
- // Create WorkspaceEntry
- ContainerEntry containerEntry = new ContainerEntry();
- List<SimpleParameterEntry> params = new
ArrayList<SimpleParameterEntry>();
- params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT,
"hsqldb"));
- params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.SWAPDIR_PROP,
"/target/temp/swap/ws"));
- containerEntry.setParameters(params);
-
- // Initialize id generator.
- new IdGenerator(new IDGeneratorServiceImpl());
-
- // Set system property Context.INITIAL_CONTEXT_FACTORY to initial context.
- System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.exoplatform.services.naming.SimpleContextFactory");
-
- // Create data source. Will be created new data source to new test.
- String dataSourceName = "jdbcjcr_" + IdGenerator.generate();
- createNewDataSource(dataSourceName);
-
- WorkspaceEntry ws =
- getNewWs("ws_to_jbdc_cache_loader", true, dataSourceName,
"/target/temp/ws_to_jbdc_cache_loader/lalues",
- containerEntry);
-
- RepositoryEntry re = new RepositoryEntry();
- re.addWorkspace(ws);
-
- ValueStoragePluginProvider valueStoragePluginProvider = new
StandaloneStoragePluginProvider(ws);
-
- persistentContainer = new JDBCWorkspaceDataContainer(ws, re, null,
valueStoragePluginProvider);
-
- NamespaceRegistryImpl nsReg = new NamespaceRegistryImpl();
- nsReg.start();
- SystemDataContainerHolder<WorkspaceDataContainer> systemDataContainerHolder
=
- new SystemDataContainerHolder(persistentContainer);
-
- WorkspacePersistentDataManager itemMgr =
- new JBossCacheWorkspaceDataManager(persistentContainer,
systemDataContainerHolder);
-
- RepositoryIndexSearcherHolder indexSearcherHolder = new
RepositoryIndexSearcherHolder();
-
- NodeTypeDataPersister persister = new JcrNodeTypeDataPersister(itemMgr, false);
- NodeTypeDataManager ntReg =
- new NodeTypeDataManagerImpl(re, new LocationFactory(nsReg), nsReg, persister,
itemMgr, indexSearcherHolder);
-
- SystemSearchManagerHolder parentSearchManager = null;
- DocumentReaderService extractor = null;
- ConfigurationManager cfm = new ConfigurationManagerImpl();
-
- // manager =
- // new SearchManager(ws.getQueryHandler(), nsReg, ntReg, itemMgr,
parentSearchManager, extractor, cfm,
- // indexSearcherHolder, holder);
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- // delete all in DB
- super.tearDown();
- }
-
-}