Author: pnedonosko
Date: 2009-11-19 09:40:34 -0500 (Thu, 19 Nov 2009)
New Revision: 777
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml
Log:
EXOJCR-203: JDBC & JBC conn tests reorg
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java 2009-11-19
14:40:34 UTC (rev 777)
@@ -0,0 +1,340 @@
+package org.exoplatform.services.jcr.impl.storage;
+
+import org.apache.commons.dbcp.BasicDataSourceFactory;
+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.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.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
+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.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.value.StandaloneStoragePluginProvider;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+import org.exoplatform.services.jcr.util.IdGenerator;
+
+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;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 19.11.2009
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
+ * @version $Id$
+ */
+public class JDBCWorkspaceDataContainerTestBase extends TestCase
+{
+
+ protected JDBCWorkspaceDataContainer persistentContainer;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ initPersistence();
+ }
+
+ protected void initPersistence() throws Exception
+ {
+ // 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/values",
+ containerEntry);
+
+ RepositoryEntry re = new RepositoryEntry();
+ re.addWorkspace(ws);
+
+ ValueStoragePluginProvider valueStoragePluginProvider = new
StandaloneStoragePluginProvider(ws);
+
+ persistentContainer = new JDBCWorkspaceDataContainer(ws, re, null,
valueStoragePluginProvider);
+ }
+
+ 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",
"../temp/index/" + IdGenerator.generate()));
+ // QueryHandlerEntry qEntry =
+ // new
QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex",
qParams);
+ // workspaceEntry.setQueryHandler(qEntry);
+ //
+ // // cache
+ // 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);
+ //
+ // // lock
+ // 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 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);
+ }
+
+ protected void createDatabase(DataSource ds, String dbName) throws SQLException
+ {
+ Connection connection = ds.getConnection();
+ PreparedStatement st = connection.prepareStatement("create database " +
dbName);
+ st.executeQuery();
+ }
+
+ protected void initJCRRoot() throws Exception
+ {
+ // prepare
+ WorkspaceStorageConnection conn = persistentContainer.openConnection();
+
+ // add root (/) with jcr:primaryType
+ addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED, Constants.ROOT_PARENT_UUID);
+
+ // 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 void deleteJCRRoot() throws Exception
+ {
+ // prepare
+
+ // delete root (/) etc
+ }
+
+ /**
+ * Add Node to the connection but doesn't save it.
+ *
+ * @param conn WorkspaceStorageConnection
+ * @param root QPath
+ * @param nodeId String
+ * @param primaryType InternalQName
+ * @throws Exception
+ */
+ protected void addDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId,
InternalQName primaryType, String parentNodeId)
+ throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0],
0, parentNodeId,
+ new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ conn.add(createProperty(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
+ */
+ protected 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;
+ }
+
+ /**
+ * Create Property data.
+ *
+ * @param nodePath QPath
+ * @param nodeId String
+ * @param propertyName InternalQName
+ * @param propertyValue Object
+ * @return TransientPropertyData
+ * @throws Exception
+ */
+ protected 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<?>)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.
+ *
+ * NOT IMPLEMENTED!
+ *
+ * @param conn WorkspaceStorageConnection
+ * @param root QPath
+ * @param nodeId String
+ * @param primaryType InternalQName
+ * @throws Exception
+ */
+ protected void deleteDbNode(WorkspaceStorageConnection conn, QPath root, String
nodeId, InternalQName primaryType)
+ throws Exception
+ {
+ // add property (/jcr:primaryType)
+ //deleteDbProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE,
primaryType, false);
+
+ // dlete root (/)
+ //conn.delete(new TransientNodeData(root, nodeId, 1, primaryType, new
InternalQName[0], 0, null,
+ // new AccessControlList()));
+ }
+
+
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java 2009-11-19
14:29:05 UTC (rev 776)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractCacheLoaderTest.java 2009-11-19
14:40:34 UTC (rev 777)
@@ -18,22 +18,16 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import junit.framework.TestCase;
-
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.storage.JDBCWorkspaceDataContainerTestBase;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import org.jboss.cache.Node;
import org.jboss.cache.Modification.ModificationType;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.RepositoryException;
-
/**
* This abstract class contains only methods for creating a fake {@link Modification}
instances. It doesn't use real cache.
*
@@ -41,14 +35,9 @@
* @version $Id$
*
*/
-public abstract class AbstractCacheLoaderTest extends TestCase
+public abstract class AbstractCacheLoaderTest extends JDBCWorkspaceDataContainerTestBase
{
- public void setUp() throws Exception
- {
- super.setUp();
- }
-
/**
* Returns {@link Modification} like as node added. NodeData is written to
/$NODE/IDxxxx as an attribute by key ITEM_DATA.
*
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java 2009-11-19
14:29:05 UTC (rev 776)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java 2009-11-19
14:40:34 UTC (rev 777)
@@ -18,14 +18,16 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import junit.framework.TestCase;
-
import org.exoplatform.services.jcr.datamodel.InternalQName;
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.impl.Constants;
+import org.exoplatform.services.jcr.impl.storage.JDBCWorkspaceDataContainerTestBase;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -42,7 +44,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
* @version $Id$
*/
-public abstract class AbstractJBossCacheStorageConnectionTest extends TestCase
+public abstract class AbstractJBossCacheStorageConnectionTest extends
JDBCWorkspaceDataContainerTestBase
{
protected JBossCacheStorageConnection conn;
@@ -93,7 +95,9 @@
protected void initJBC() throws Exception
{
- // empty here
+ // inject JDBC DC via JBC ComponentRegistry
+ ((CacheSPI<Serializable,
Object>)cache).getComponentRegistry().registerComponent(this.persistentContainer,
+ WorkspaceDataContainer.class);
}
/**
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19
14:29:05 UTC (rev 776)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19
14:40:34 UTC (rev 777)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import junit.framework.TestCase;
-
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.ItemData;
@@ -31,14 +29,10 @@
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.jboss.cache.Cache;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import java.io.IOException;
import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.jcr.lock.LockException;
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-19
14:29:05 UTC (rev 776)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-19
14:40:34 UTC (rev 777)
@@ -18,17 +18,13 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import org.apache.commons.dbcp.BasicDataSourceFactory;
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.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.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;
@@ -45,19 +41,12 @@
import org.jboss.cache.Fqn;
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.Map;
-import java.util.Properties;
import java.util.Set;
import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
/**
* @author <a href="mailto:reshetnyak.alex@gmail.com">Alex
Reshetnyak</a>
@@ -126,264 +115,6 @@
persistentContainer = new JDBCWorkspaceDataContainer(ws, re, null,
valueStoragePluginProvider);
}
- private 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",
"../temp/index/" + IdGenerator.generate()));
- // QueryHandlerEntry qEntry =
- // new
QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex",
qParams);
- // workspaceEntry.setQueryHandler(qEntry);
- //
- // // cache
- // 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);
- //
- // // lock
- // 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;
- }
-
- private 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);
- }
-
- private void createDatabase(DataSource ds, String dbName) throws SQLException
- {
- Connection connection = ds.getConnection();
- PreparedStatement st = connection.prepareStatement("create database " +
dbName);
- st.executeQuery();
- }
-
- private void initJCRRoot() throws Exception
- {
- // prepare
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- // add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED, Constants.ROOT_PARENT_UUID);
-
- // 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 deleteJCRRoot() throws Exception
- {
- // prepare
- WorkspaceStorageConnection conn = persistentContainer.openConnection();
-
- // add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID,
Constants.NT_UNSTRUCTURED, Constants.ROOT_PARENT_UUID);
-
- // 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();
- }
-
- /**
- * Add Node 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,
InternalQName primaryType, String parentNodeId)
- throws Exception
- {
- // add root (/)
- conn.add(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0],
0, parentNodeId,
- new AccessControlList()));
-
- // add property (/jcr:primaryType)
- conn.add(createProperty(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;
- }
-
- /**
- * Create Property data.
- *
- * @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<?>)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()));
- }
-
// ============= TESTS =============
public void testAddNode() throws Exception
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml 2009-11-19
14:29:05 UTC (rev 776)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-config-exoloader.xml 2009-11-19
14:40:34 UTC (rev 777)
@@ -21,7 +21,7 @@
use_incoming_packet_handler="true" />
<PING num_initial_members="3" timeout="2000" /-->
- <TCP bind_addr="localhost" start_port="7800"
loopback="true" recv_buf_size="20000000"
send_buf_size="640000" discard_incompatible_packets="true"
+ <TCP bind_addr="localhost" start_port="9800"
loopback="true" recv_buf_size="20000000"
send_buf_size="640000" discard_incompatible_packets="true"
max_bundle_size="64000" max_bundle_timeout="30"
use_incoming_packet_handler="true" enable_bundling="true"
use_send_queues="false" sock_conn_timeout="300"
skip_suspected_members="true" use_concurrent_stack="true"
thread_pool.enabled="true" thread_pool.min_threads="1"
thread_pool.max_threads="25"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="false" thread_pool.queue_max_size="100"
thread_pool.rejection_policy="run"