exo-jcr SVN: r4569 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-06-30 10:54:37 -0400 (Thu, 30 Jun 2011)
New Revision: 4569
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
Log:
EXOJCR-1068 : SystemSearchManager was registered under same name as SearchManager, so one of them was overridden in JMX MBean Server. Fixed.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2011-06-30 10:09:14 UTC (rev 4568)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2011-06-30 14:54:37 UTC (rev 4569)
@@ -18,6 +18,8 @@
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.Property;
import org.exoplatform.services.document.DocumentReaderService;
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.config.QueryHandlerEntry;
@@ -47,6 +49,7 @@
* @version $Id: SystemSearchManager.java 13891 2008-05-05 16:02:30Z pnedonosko
* $
*/
+@NameTemplate(@Property(key = "service", value = "SystemSearchManager"))
public class SystemSearchManager extends SearchManager
{
12 years, 10 months
exo-jcr SVN: r4568 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/backup and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2011-06-30 06:09:14 -0400 (Thu, 30 Jun 2011)
New Revision: 4568
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
Log:
EXOJCR-1405 : The backup-dir in repository backup-log was tested for relatove path and implemented resolving system variables
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2011-06-30 08:29:42 UTC (rev 4567)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/RepositoryBackupChainLog.java 2011-06-30 10:09:14 UTC (rev 4568)
@@ -18,6 +18,7 @@
import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.container.xml.Deserializer;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.RepositoryServiceConfiguration;
import org.exoplatform.services.jcr.ext.backup.server.RepositoryRestoreExeption;
@@ -476,7 +477,7 @@
}
else
{
- conf.setBackupDir(new File(dir));
+ conf.setBackupDir(new File(Deserializer.resolveVariables(dir)));
}
}
else
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2011-06-30 08:29:42 UTC (rev 4567)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupTestCase.java 2011-06-30 10:09:14 UTC (rev 4568)
@@ -110,7 +110,9 @@
}
}
- @Override
+ /**
+ * {@inheritDoc}
+ */
public void setUp() throws Exception
{
super.setUp();// this
@@ -119,6 +121,16 @@
blob = createBLOBTempFile(300);
}
+ /**
+ * {@inheritDoc}
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ blob.delete();
+ }
+
protected abstract ExtendedBackupManager getBackupManager();
protected ExtendedBackupManager getJCRBackupManager()
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2011-06-30 08:29:42 UTC (rev 4567)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/AbstractBackupUseCasesTest.java 2011-06-30 10:09:14 UTC (rev 4568)
@@ -17,14 +17,20 @@
package org.exoplatform.services.jcr.ext.backup;
import org.apache.commons.collections.map.HashedMap;
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
+import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.util.IdGenerator;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Map;
/**
@@ -1189,4 +1195,154 @@
checkConent(repositoryService.getRepository(config.getRepository()),
repositoryService.getRepository(config.getRepository()).getConfiguration().getSystemWorkspaceName());
}
+
+ public void testEnvironmentVariablesToBackupDir() throws Exception
+ {
+ // prepare stage #1
+ ManageableRepository repository = helper.createRepository(container, true, null);
+ addConent(repository, repository.getConfiguration().getSystemWorkspaceName());
+
+ String tempDir = PrivilegedSystemHelper.getProperty("java.io.tmpdir");
+
+ // backup
+ File backDir = new File(tempDir);
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getConfiguration().getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+ config.setBackupDir(backDir);
+
+ RepositoryBackupChain bch = backup.startBackup(config);
+ waitEndOfBackup(bch);
+ backup.stopBackup(bch);
+
+ // prepare stage #2
+ String repositoryBackupChainLogPath = bch.getLogFilePath();
+
+ String backupDitEnv = backDir.getCanonicalPath();
+
+ String newBackupDir =
+ "\\${java.io.tmpdir}"
+ + bch.getBackupConfig().getBackupDir().getCanonicalPath()
+ .replaceAll(backupDitEnv, "");
+
+ File dest = new File(repositoryBackupChainLogPath + ".xml");
+ dest.createNewFile();
+
+ RepositoryBackupChainLog newRepositoryBackupChainLog = null;
+ try
+ {
+ String sConfig =
+ setNewBackupDirInRepositoryBackupChainLog(new File(repositoryBackupChainLogPath), dest, newBackupDir);
+
+ assertTrue(sConfig.contains(newBackupDir.subSequence(1, newBackupDir.length())));
+
+ // check
+ newRepositoryBackupChainLog = new RepositoryBackupChainLog(dest);
+
+ assertEquals(bch.getBackupConfig().getBackupDir().getCanonicalPath(),
+ newRepositoryBackupChainLog.getBackupConfig().getBackupDir().getCanonicalPath());
+
+ }
+ finally
+ {
+ newRepositoryBackupChainLog = null;
+ dest.delete();
+
+ deleteFolder(bch.getBackupConfig().getBackupDir());
+ }
+ }
+
+ public void testRelativeBackupDir() throws Exception
+ {
+ // prepare stage #1
+ ManageableRepository repository = helper.createRepository(container, true, null);
+ addConent(repository, repository.getConfiguration().getSystemWorkspaceName());
+
+ // backup
+ File backDir = new File("target");
+
+ RepositoryBackupConfig config = new RepositoryBackupConfig();
+ config.setRepository(repository.getConfiguration().getName());
+ config.setBackupType(BackupManager.FULL_BACKUP_ONLY);
+ config.setBackupDir(backDir);
+
+ RepositoryBackupChain bch = backup.startBackup(config);
+ waitEndOfBackup(bch);
+ backup.stopBackup(bch);
+
+ // prepare stage #2
+ String repositoryBackupChainLogPath = bch.getLogFilePath();
+
+ String relativePrefixBackupDir = backDir.getCanonicalFile().getParent() + File.separator;
+
+ String newBackupDir =
+ bch.getBackupConfig().getBackupDir().getCanonicalPath().replaceAll(relativePrefixBackupDir, "");
+
+ File dest = new File(repositoryBackupChainLogPath + ".xml");
+ dest.createNewFile();
+
+ RepositoryBackupChainLog newRepositoryBackupChainLog = null;
+
+ String sConfig =
+ setNewBackupDirInRepositoryBackupChainLog(new File(repositoryBackupChainLogPath), dest, newBackupDir);
+
+ assertTrue(sConfig.contains(newBackupDir));
+
+ // check
+ newRepositoryBackupChainLog = new RepositoryBackupChainLog(dest);
+
+ assertEquals(bch.getBackupConfig().getBackupDir().getCanonicalPath(), newRepositoryBackupChainLog
+ .getBackupConfig().getBackupDir().getCanonicalPath());
+ }
+
+ /**
+ * Set new backup directory in RepositoryBackupChainLog
+ *
+ * @param src
+ * source file of RepositoryBackupChainLog
+ * @param dest
+ * destination file of RepositoryBackupChainLog
+ * @param newBackupDir
+ * @return String
+ * the content of file destination
+ * @throws IOException
+ */
+ protected String setNewBackupDirInRepositoryBackupChainLog(File src, File dest, String newBackupDir)
+ throws IOException
+ {
+ InputStream in = PrivilegedFileHelper.fileInputStream(src);
+ OutputStream out = PrivilegedFileHelper.fileOutputStream(dest);
+
+ byte[] buf = new byte[(int) (PrivilegedFileHelper.length(src))];
+ in.read(buf);
+
+ String sConfig = new String(buf, Constants.DEFAULT_ENCODING);
+ sConfig = sConfig.replaceAll("<backup-dir>.+</backup-dir>", "<backup-dir>" + newBackupDir + "</backup-dir>");
+
+ out.write(sConfig.getBytes(Constants.DEFAULT_ENCODING));
+
+ in.close();
+ out.close();
+
+ return sConfig;
+ }
+
+ protected void deleteFolder(File f)
+ {
+ if (f.isDirectory())
+ {
+ for (File file : f.listFiles())
+ {
+ deleteFolder(file);
+ }
+
+ f.delete();
+ }
+ else
+ {
+ f.delete();
+ }
+ }
+
}
12 years, 10 months
exo-jcr SVN: r4567 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: util/jdbc and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-06-30 04:29:42 -0400 (Thu, 30 Jun 2011)
New Revision: 4567
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
Log:
EXOJCR-1415: no need invoke commit when setAutoCommit mode is true
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java 2011-06-24 09:31:10 UTC (rev 4566)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java 2011-06-30 08:29:42 UTC (rev 4567)
@@ -398,7 +398,6 @@
st.executeUpdate(sql = initSQL);
st.close();
- con.commit();
con.close();
// one new conn
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2011-06-24 09:31:10 UTC (rev 4566)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2011-06-30 08:29:42 UTC (rev 4567)
@@ -380,7 +380,6 @@
}
postInit(connection);
- connection.commit();
LOG.info("DB schema of DataSource: '" + containerName + "' initialized succesfully");
}
catch (SQLException e)
12 years, 10 months
exo-jcr SVN: r4566 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: storage/jdbc and 1 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-06-24 05:31:10 -0400 (Fri, 24 Jun 2011)
New Revision: 4566
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
Log:
EXOJCR-1374: AutoCommit is set to true when creating DB structrure.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java 2011-06-24 09:26:03 UTC (rev 4565)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java 2011-06-24 09:31:10 UTC (rev 4566)
@@ -184,8 +184,9 @@
configTableName = configTableName.toUpperCase().toLowerCase(); // ingres needs it
binType = "LONG BYTE";
}
- else if (DBConstants.DB_DIALECT_MYSQL.equalsIgnoreCase(dialect)
- || DBConstants.DB_DIALECT_MYSQL_UTF8.equalsIgnoreCase(dialect)) {
+ else if (DBConstants.DB_DIALECT_MYSQL.equalsIgnoreCase(dialect)
+ || DBConstants.DB_DIALECT_MYSQL_UTF8.equalsIgnoreCase(dialect))
+ {
binType = "LONGBLOB";
}
@@ -322,12 +323,16 @@
return config.getStream();
}
else
+ {
throw new ConfigurationNotFoundException("No configuration data is found in database. Source name "
+ sourceName);
+ }
}
else
+ {
throw new ConfigurationNotInitializedException(
"Configuration table not is found in database. Source name " + sourceName);
+ }
}
finally
@@ -385,12 +390,10 @@
PreparedStatement ps = null;
try
{
-
- con.setAutoCommit(false);
-
if (!isDbInitialized(con))
{
// init db
+ con.setAutoCommit(true);
Statement st = con.createStatement();
st.executeUpdate(sql = initSQL);
st.close();
@@ -400,8 +403,8 @@
// one new conn
con = openConnection();
- con.setAutoCommit(false);
}
+ con.setAutoCommit(false);
if (isDbInitialized(con))
{
@@ -425,15 +428,15 @@
if (ps.executeUpdate() <= 0)
{
LOG.warn("Repository service configuration doesn't stored ok. "
- + "No rows was affected in JDBC operation. Datasource " + sourceName + ". SQL: " + sql);
+ + "No rows was affected in JDBC operation. Datasource " + sourceName + ". SQL: " + sql);
}
}
else
+ {
throw new ConfigurationNotInitializedException(
"Configuration table can not be created in database. Source name " + sourceName + ". SQL: " + sql);
-
+ }
con.commit();
-
}
finally
{
@@ -448,7 +451,6 @@
LOG.error("Can't close the Statement: " + e);
}
}
-
con.close();
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java 2011-06-24 09:26:03 UTC (rev 4565)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java 2011-06-24 09:31:10 UTC (rev 4566)
@@ -24,7 +24,6 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Savepoint;
import java.sql.Statement;
/**
@@ -52,36 +51,14 @@
{
Statement stmt = null;
ResultSet trs = null;
- Savepoint savePoint = null;
- Boolean autoCommit = null;
try
{
- // safe get autoCommit value
- autoCommit = con.getAutoCommit();
- // set autoCommit to true
- con.setAutoCommit(false);
- // make a savepoint (snapshot)
- savePoint = con.setSavepoint(Thread.currentThread().getName()+System.currentTimeMillis());
stmt = con.createStatement();
trs = stmt.executeQuery("SELECT count(*) FROM " + tableName);
return trs.next();
}
catch (SQLException e)
{
- if (savePoint != null)
- {
- try
- {
- // revert state to savePoint after failed query in transaction. This will allow following queries to
- // be executed in an ordinary way, like no failed query existed.
- // Obligatory operation for PostgreSQL.
- con.rollback(savePoint);
- }
- catch (SQLException e1)
- {
- LOG.error("Can't rollback to savePoint", e1);
- }
- }
if (LOG.isDebugEnabled())
{
LOG.debug("SQLException occurs while checking the table " + tableName, e);
@@ -90,17 +67,6 @@
}
finally
{
- if (autoCommit != null)
- {
- try
- {
- con.setAutoCommit(autoCommit);
- }
- catch (SQLException e)
- {
- LOG.error("Can't set autoCommit value back", e);
- }
- }
if (trs != null)
{
try
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2011-06-24 09:26:03 UTC (rev 4565)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2011-06-24 09:31:10 UTC (rev 4566)
@@ -182,7 +182,7 @@
}
});
}
-
+
protected boolean isSequenceExists(Connection conn, String sequenceName) throws SQLException
{
return false;
@@ -247,7 +247,8 @@
{
if (LOG.isDebugEnabled())
{
- LOG.debug("The table " + tableName + " already exists so we assume that the index " + indexName + " exists also.");
+ LOG.debug("The table " + tableName + " already exists so we assume that the index " + indexName
+ + " exists also.");
}
return true;
}
@@ -295,7 +296,8 @@
{
if (LOG.isDebugEnabled())
{
- LOG.debug("At least one table has been created so we assume that the trigger " + triggerName + " exists also");
+ LOG.debug("At least one table has been created so we assume that the trigger " + triggerName
+ + " exists also");
}
return true;
}
@@ -346,8 +348,10 @@
try
{
st = connection.createStatement();
- connection.setAutoCommit(false);
-
+ // all DDL queries executed in separated transactions
+ // Required for SyBase, when checking table existence
+ // and performing DDLs inside single transaction.
+ connection.setAutoCommit(true);
for (String scr : scripts)
{
String s = cleanWhitespaces(scr.trim());
@@ -376,20 +380,18 @@
}
postInit(connection);
-
connection.commit();
LOG.info("DB schema of DataSource: '" + containerName + "' initialized succesfully");
}
catch (SQLException e)
{
- try
+ if (LOG.isDebugEnabled())
{
- connection.rollback();
+ LOG.error("Problem creating database structure.", e);
}
- catch (SQLException re)
- {
- LOG.error("Rollback error " + e, e);
- }
+ LOG
+ .warn("Some tables were created and not rolled back. Please make sure to drop them manually in datasource : '"
+ + containerName + "'");
boolean isAlreadyCreated = false;
try
12 years, 10 months
exo-jcr SVN: r4565 - in kernel/trunk/exo.kernel.commons: src/main/java/org/exoplatform/commons/utils and 1 other directories.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2011-06-24 05:26:03 -0400 (Fri, 24 Jun 2011)
New Revision: 4565
Modified:
kernel/trunk/exo.kernel.commons/pom.xml
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java
Log:
EXOJCR-1378: added new method to MimeTypeResolver to obtain mime type from InputStream
Modified: kernel/trunk/exo.kernel.commons/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.commons/pom.xml 2011-06-24 08:30:34 UTC (rev 4564)
+++ kernel/trunk/exo.kernel.commons/pom.xml 2011-06-24 09:26:03 UTC (rev 4565)
@@ -62,6 +62,7 @@
<directory>src/test/resources</directory>
<includes>
<include>**/*.properties</include>
+ <include>**/test*</include>
</includes>
</testResource>
</testResources>
Modified: kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-06-24 08:30:34 UTC (rev 4564)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/MimeTypeResolver.java 2011-06-24 09:26:03 UTC (rev 4565)
@@ -23,10 +23,8 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
@@ -113,45 +111,47 @@
}
/**
- * Get MIMEType which corresponds to file extension or, in case if file extension
- * does not exist, file content. If file extension is unknown, or file content
+ * Get MIMEType which corresponds to file extension. If file extension is unknown the default
+ * MIMEType will be returned. If there are more than one MIMETypes for specific extension the
+ * first occurred in the list will be returned.
+ *
+ * @param filename
+ * @return String MIMEType
+ */
+ public String getMimeType(String filename)
+ {
+ String ext = filename.substring(filename.lastIndexOf(".") + 1);
+ if (ext.isEmpty())
+ {
+ ext = filename;
+ }
+
+ List<String> values = mimeTypes.get(ext);
+ return values == null ? defaultMimeType : values.get(0);
+ }
+
+ /**
+ * Get MIMEType which corresponds to file content. If file content
* does not allow to determine MIMEtype, the default MIMEType will be returned.
- * If there are more than one MIMETypes for specific extension the first occurred
- * in the list will be returned.
- *
+ *
* @param fileName
+ * @param is
* @return String MIMEType
*/
- public String getMimeType(String fileName)
+ public String getMimeType(String fileName, InputStream is)
{
- final File file = new File(fileName);
- String extension = MimeUtil.getExtension(file);
+ String mimeType = getMimeType(fileName);
- if (extension.isEmpty())
+ if (mimeType == defaultMimeType)
{
- if (PrivilegedFileHelper.exists(file))
+ Collection<?> mimeTypes = MimeUtil.getMimeTypes(is);
+ if (!mimeTypes.isEmpty())
{
- Collection<?> mimeTypes = SecurityHelper.doPrivilegedAction(new PrivilegedAction<Collection<?>>()
- {
- public Collection<?> run()
- {
- return MimeUtil.getMimeTypes(file);
- }
- });
-
- return mimeTypes.isEmpty() ? defaultMimeType : mimeTypes.toArray()[0].toString();
+ mimeType = mimeTypes.toArray()[0].toString();
}
- else
- {
- log.warn("You're trying to resolve mime type of non-existing file with no extension.");
- return defaultMimeType;
- }
}
- else
- {
- List<String> values = mimeTypes.get(extension);
- return values == null ? defaultMimeType : values.get(0);
- }
+
+ return mimeType;
}
/**
Modified: kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java
===================================================================
--- kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java 2011-06-24 08:30:34 UTC (rev 4564)
+++ kernel/trunk/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestMimeTypeResolver.java 2011-06-24 09:26:03 UTC (rev 4565)
@@ -20,6 +20,9 @@
import junit.framework.TestCase;
+import java.io.IOException;
+import java.io.InputStream;
+
/**
* Created by The eXo Platform SAS.
*
@@ -63,7 +66,7 @@
* Here we're going to test MimeTypeResolver to obtain corresponding or
* at least most corresponding mime types for files without extensions.
*/
- public void testGetMimeTypeFromContent()
+ public void testGetMimeTypeFromContent() throws IOException
{
// should return default mime type as file name has no extension
// and file does not exist to read its content
@@ -74,12 +77,24 @@
// and file does not exist to read its content
assertEquals(resolver.getDefaultMimeType(), resolver.getMimeType("file."));
- assertEquals("image/jpeg", resolver.getMimeType("src/test/resources/testjpg"));
- assertEquals("application/pdf", resolver.getMimeType("src/test/resources/testpdf"));
- assertEquals("application/msword", resolver.getMimeType("src/test/resources/testdoc"));
- assertEquals("text/xml", resolver.getMimeType("src/test/resources/testxml"));
- assertEquals("application/msword", resolver.getMimeType("src/test/resources/testxls"));
+ InputStream is;
+ is = TestMimeTypeResolver.class.getResourceAsStream("/testjpg");
+ assertEquals("image/jpeg", resolver.getMimeType("testjpg", is));
+ is.close();
+ is = TestMimeTypeResolver.class.getResourceAsStream("/testpdf");
+ assertEquals("application/pdf", resolver.getMimeType("testpdf", is));
+ is.close();
+ is = TestMimeTypeResolver.class.getResourceAsStream("/testdoc");
+ assertEquals("application/msword", resolver.getMimeType("testdoc", is));
+ is.close();
+ is = TestMimeTypeResolver.class.getResourceAsStream("/testxml");
+ assertEquals("text/xml", resolver.getMimeType("testxml", is));
+ is.close();
+ is = TestMimeTypeResolver.class.getResourceAsStream("/testxls");
+ assertEquals("application/msword", resolver.getMimeType("testxls", is));
+ is.close();
+
}
public void testGetExtension()
12 years, 10 months
exo-jcr SVN: r4564 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2011-06-24 04:30:34 -0400 (Fri, 24 Jun 2011)
New Revision: 4564
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseJDBCConnectionHelper.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseConnectionFactory.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseMultiDbJDBCConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseSingleDbJDBCConnection.java
Log:
EXOJCR-1383 : The RDBMS re-indexing was implemented for Sybase.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseConnectionFactory.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseConnectionFactory.java 2011-06-24 08:08:19 UTC (rev 4563)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseConnectionFactory.java 2011-06-24 08:30:34 UTC (rev 4564)
@@ -130,6 +130,6 @@
@Override
public boolean isReindexingSupport()
{
- return false;
+ return true;
}
}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseJDBCConnectionHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseJDBCConnectionHelper.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseJDBCConnectionHelper.java 2011-06-24 08:30:34 UTC (rev 4564)
@@ -0,0 +1,927 @@
+/*
+ * Copyright (C) 2003-2011 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.jdbc.optimisation.db;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Map;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2011
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: SybaseJDBCConnectionHelper.java 111 2011-11-11 11:11:11Z rainf0x $
+ */
+public class SybaseJDBCConnectionHelper
+{
+
+ /**
+ * The name for temporary table.
+ */
+ public final static String TEMP_A_TABLE_NAME = "#tempA";
+
+ /**
+ * The name for temporary table.
+ */
+ public final static String TEMP_B_TABLE_NAME = "#tempB";
+
+ /**
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: SybaseJDBCConnectionHelper.java 111 2011-11-11 11:11:11Z rainf0x $
+ *
+ * The class EmptyResultSet will be used if need return empty result set for query.
+ */
+ static public class EmptyResultSet
+ implements ResultSet
+ {
+
+ public boolean absolute(int row) throws SQLException
+ {
+ return false;
+ }
+
+ public void afterLast() throws SQLException
+ {
+ }
+
+ public void beforeFirst() throws SQLException
+ {
+ }
+
+ public void cancelRowUpdates() throws SQLException
+ {
+ }
+
+ public void clearWarnings() throws SQLException
+ {
+ }
+
+ public void close() throws SQLException
+ {
+ }
+
+ public void deleteRow() throws SQLException
+ {
+ }
+
+ public int findColumn(String columnLabel) throws SQLException
+ {
+ return 0;
+ }
+
+ public boolean first() throws SQLException
+ {
+ return false;
+ }
+
+ public Array getArray(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Array getArray(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public InputStream getAsciiStream(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public InputStream getAsciiStream(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public BigDecimal getBigDecimal(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
+ {
+ return null;
+ }
+
+ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException
+ {
+ return null;
+ }
+
+ public InputStream getBinaryStream(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public InputStream getBinaryStream(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Blob getBlob(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Blob getBlob(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public boolean getBoolean(int columnIndex) throws SQLException
+ {
+ return false;
+ }
+
+ public boolean getBoolean(String columnLabel) throws SQLException
+ {
+ return false;
+ }
+
+ public byte getByte(int columnIndex) throws SQLException
+ {
+ return 0;
+ }
+
+ public byte getByte(String columnLabel) throws SQLException
+ {
+ return 0;
+ }
+
+ public byte[] getBytes(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public byte[] getBytes(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Reader getCharacterStream(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Reader getCharacterStream(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Clob getClob(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Clob getClob(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public int getConcurrency() throws SQLException
+ {
+ return 0;
+ }
+
+ public String getCursorName() throws SQLException
+ {
+ return null;
+ }
+
+ public Date getDate(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Date getDate(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Date getDate(int columnIndex, Calendar cal) throws SQLException
+ {
+ return null;
+ }
+
+ public Date getDate(String columnLabel, Calendar cal) throws SQLException
+ {
+ return null;
+ }
+
+ public double getDouble(int columnIndex) throws SQLException
+ {
+ return 0;
+ }
+
+ public double getDouble(String columnLabel) throws SQLException
+ {
+ return 0;
+ }
+
+ public int getFetchDirection() throws SQLException
+ {
+ return 0;
+ }
+
+ public int getFetchSize() throws SQLException
+ {
+ return 0;
+ }
+
+ public float getFloat(int columnIndex) throws SQLException
+ {
+ return 0;
+ }
+
+ public float getFloat(String columnLabel) throws SQLException
+ {
+ return 0;
+ }
+
+ public int getHoldability() throws SQLException
+ {
+ return 0;
+ }
+
+ public int getInt(int columnIndex) throws SQLException
+ {
+ return 0;
+ }
+
+ public int getInt(String columnLabel) throws SQLException
+ {
+ return 0;
+ }
+
+ public long getLong(int columnIndex) throws SQLException
+ {
+ return 0;
+ }
+
+ public long getLong(String columnLabel) throws SQLException
+ {
+ return 0;
+ }
+
+ public ResultSetMetaData getMetaData() throws SQLException
+ {
+ return null;
+ }
+
+ public Reader getNCharacterStream(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Reader getNCharacterStream(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public NClob getNClob(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public NClob getNClob(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public String getNString(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public String getNString(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Object getObject(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Object getObject(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException
+ {
+ return null;
+ }
+
+ public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException
+ {
+ return null;
+ }
+
+ public Ref getRef(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Ref getRef(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public int getRow() throws SQLException
+ {
+ return 0;
+ }
+
+ public RowId getRowId(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public RowId getRowId(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public SQLXML getSQLXML(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public SQLXML getSQLXML(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public short getShort(int columnIndex) throws SQLException
+ {
+ return 0;
+ }
+
+ public short getShort(String columnLabel) throws SQLException
+ {
+ return 0;
+ }
+
+ public Statement getStatement() throws SQLException
+ {
+ return null;
+ }
+
+ public String getString(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public String getString(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Time getTime(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Time getTime(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Time getTime(int columnIndex, Calendar cal) throws SQLException
+ {
+ return null;
+ }
+
+ public Time getTime(String columnLabel, Calendar cal) throws SQLException
+ {
+ return null;
+ }
+
+ public Timestamp getTimestamp(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public Timestamp getTimestamp(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException
+ {
+ return null;
+ }
+
+ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException
+ {
+ return null;
+ }
+
+ public int getType() throws SQLException
+ {
+ return 0;
+ }
+
+ public URL getURL(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public URL getURL(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public InputStream getUnicodeStream(int columnIndex) throws SQLException
+ {
+ return null;
+ }
+
+ public InputStream getUnicodeStream(String columnLabel) throws SQLException
+ {
+ return null;
+ }
+
+ public SQLWarning getWarnings() throws SQLException
+ {
+ return null;
+ }
+
+ public void insertRow() throws SQLException
+ {
+
+ }
+
+ public boolean isAfterLast() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean isBeforeFirst() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean isClosed() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean isFirst() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean isLast() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean last() throws SQLException
+ {
+ return false;
+ }
+
+ public void moveToCurrentRow() throws SQLException
+ {
+
+ }
+
+ public void moveToInsertRow() throws SQLException
+ {
+
+ }
+
+ public boolean next() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean previous() throws SQLException
+ {
+ return false;
+ }
+
+ public void refreshRow() throws SQLException
+ {
+
+ }
+
+ public boolean relative(int rows) throws SQLException
+ {
+ return false;
+ }
+
+ public boolean rowDeleted() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean rowInserted() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean rowUpdated() throws SQLException
+ {
+ return false;
+ }
+
+ public void setFetchDirection(int direction) throws SQLException
+ {
+ }
+
+ public void setFetchSize(int rows) throws SQLException
+ {
+ }
+
+ public void updateArray(int columnIndex, Array x) throws SQLException
+ {
+ }
+
+ public void updateArray(String columnLabel, Array x) throws SQLException
+ {
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException
+ {
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException
+ {
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException
+ {
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException
+ {
+ }
+
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException
+ {
+ }
+
+ public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException
+ {
+ }
+
+ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException
+ {
+ }
+
+ public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException
+ {
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException
+ {
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException
+ {
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException
+ {
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException
+ {
+ }
+
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException
+ {
+ }
+
+ public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException
+ {
+ }
+
+ public void updateBlob(int columnIndex, Blob x) throws SQLException
+ {
+ }
+
+ public void updateBlob(String columnLabel, Blob x) throws SQLException
+ {
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException
+ {
+ }
+
+ public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException
+ {
+ }
+
+ public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException
+ {
+ }
+
+ public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException
+ {
+ }
+
+ public void updateBoolean(int columnIndex, boolean x) throws SQLException
+ {
+ }
+
+ public void updateBoolean(String columnLabel, boolean x) throws SQLException
+ {
+ }
+
+ public void updateByte(int columnIndex, byte x) throws SQLException
+ {
+ }
+
+ public void updateByte(String columnLabel, byte x) throws SQLException
+ {
+ }
+
+ public void updateBytes(int columnIndex, byte[] x) throws SQLException
+ {
+ }
+
+ public void updateBytes(String columnLabel, byte[] x) throws SQLException
+ {
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x) throws SQLException
+ {
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException
+ {
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException
+ {
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException
+ {
+ }
+
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException
+ {
+ }
+
+ public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException
+ {
+ }
+
+ public void updateClob(int columnIndex, Clob x) throws SQLException
+ {
+ }
+
+ public void updateClob(String columnLabel, Clob x) throws SQLException
+ {
+ }
+
+ public void updateClob(int columnIndex, Reader reader) throws SQLException
+ {
+ }
+
+ public void updateClob(String columnLabel, Reader reader) throws SQLException
+ {
+ }
+
+ public void updateClob(int columnIndex, Reader reader, long length) throws SQLException
+ {
+ }
+
+ public void updateClob(String columnLabel, Reader reader, long length) throws SQLException
+ {
+ }
+
+ public void updateDate(int columnIndex, Date x) throws SQLException
+ {
+ }
+
+ public void updateDate(String columnLabel, Date x) throws SQLException
+ {
+ }
+
+ public void updateDouble(int columnIndex, double x) throws SQLException
+ {
+ }
+
+ public void updateDouble(String columnLabel, double x) throws SQLException
+ {
+ }
+
+ public void updateFloat(int columnIndex, float x) throws SQLException
+ {
+ }
+
+ public void updateFloat(String columnLabel, float x) throws SQLException
+ {
+ }
+
+ public void updateInt(int columnIndex, int x) throws SQLException
+ {
+ }
+
+ public void updateInt(String columnLabel, int x) throws SQLException
+ {
+ }
+
+ public void updateLong(int columnIndex, long x) throws SQLException
+ {
+ }
+
+ public void updateLong(String columnLabel, long x) throws SQLException
+ {
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException
+ {
+ }
+
+ public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException
+ {
+ }
+
+ public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException
+ {
+ }
+
+ public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException
+ {
+ }
+
+ public void updateNClob(int columnIndex, NClob nClob) throws SQLException
+ {
+ }
+
+ public void updateNClob(String columnLabel, NClob nClob) throws SQLException
+ {
+ }
+
+ public void updateNClob(int columnIndex, Reader reader) throws SQLException
+ {
+ }
+
+ public void updateNClob(String columnLabel, Reader reader) throws SQLException
+ {
+ }
+
+ public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException
+ {
+ }
+
+ public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException
+ {
+ }
+
+ public void updateNString(int columnIndex, String nString) throws SQLException
+ {
+ }
+
+ public void updateNString(String columnLabel, String nString) throws SQLException
+ {
+ }
+
+ public void updateNull(int columnIndex) throws SQLException
+ {
+ }
+
+ public void updateNull(String columnLabel) throws SQLException
+ {
+ }
+
+ public void updateObject(int columnIndex, Object x) throws SQLException
+ {
+ }
+
+ public void updateObject(String columnLabel, Object x) throws SQLException
+ {
+ }
+
+ public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException
+ {
+ }
+
+ public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException
+ {
+ }
+
+ public void updateRef(int columnIndex, Ref x) throws SQLException
+ {
+ }
+
+ public void updateRef(String columnLabel, Ref x) throws SQLException
+ {
+ }
+
+ public void updateRow() throws SQLException
+ {
+ }
+
+ public void updateRowId(int columnIndex, RowId x) throws SQLException
+ {
+ }
+
+ public void updateRowId(String columnLabel, RowId x) throws SQLException
+ {
+ }
+
+ public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException
+ {
+ }
+
+ public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException
+ {
+ }
+
+ public void updateShort(int columnIndex, short x) throws SQLException
+ {
+ }
+
+ public void updateShort(String columnLabel, short x) throws SQLException
+ {
+ }
+
+ public void updateString(int columnIndex, String x) throws SQLException
+ {
+ }
+
+ public void updateString(String columnLabel, String x) throws SQLException
+ {
+ }
+
+ public void updateTime(int columnIndex, Time x) throws SQLException
+ {
+ }
+
+ public void updateTime(String columnLabel, Time x) throws SQLException
+ {
+ }
+
+ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException
+ {
+ }
+
+ public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException
+ {
+ }
+
+ public boolean wasNull() throws SQLException
+ {
+ return false;
+ }
+
+ public boolean isWrapperFor(Class<?> iface) throws SQLException
+ {
+ return false;
+ }
+
+ public <T> T unwrap(Class<T> iface) throws SQLException
+ {
+ return null;
+ }
+
+ }
+}
\ No newline at end of file
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseMultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseMultiDbJDBCConnection.java 2011-06-24 08:08:19 UTC (rev 4563)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseMultiDbJDBCConnection.java 2011-06-24 08:30:34 UTC (rev 4564)
@@ -16,11 +16,15 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+import org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.SybaseJDBCConnectionHelper.EmptyResultSet;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+import org.exoplatform.services.jcr.util.IdGenerator;
import java.io.File;
import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
/**
@@ -34,6 +38,41 @@
public class SybaseMultiDbJDBCConnection extends MultiDbJDBCConnection
{
+ /**
+ * SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE
+ */
+ protected String SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE;
+
+ /**
+ * COUNT_NODES_IN_TEMPORARY_TABLE
+ */
+ protected String COUNT_NODES_IN_TEMPORARY_TABLE;
+
+ /**
+ * SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE
+ */
+ protected String SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE;
+
+ /**
+ * DELETE_TEMPORARY_TABLE_A
+ */
+ protected String DELETE_TEMPORARY_TABLE_A;
+
+ /**
+ * DELETE_TEMPORARY_TABLE_B
+ */
+ protected String DELETE_TEMPORARY_TABLE_B;
+
+ protected PreparedStatement selectLimitOffsetNodesIntoTemporaryTable;
+
+ protected PreparedStatement selectLimitNodesInTemporaryTable;
+
+ protected PreparedStatement deleteTemporaryTableA;
+
+ protected PreparedStatement deleteTemporaryTableB;
+
+ protected PreparedStatement countNodesInTemporaryTable;
+
public SybaseMultiDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
throws SQLException
@@ -68,4 +107,173 @@
return sb.toString();
}
-}
+ /**
+ * {@inheritDoc}
+ */
+ protected void prepareQueries() throws SQLException
+ {
+
+ super.prepareQueries();
+
+ SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE =
+ "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM into "
+ + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME
+ + " from JCR_MITEM I where I.I_CLASS=1 AND I.ID > ? order by I.ID ASC";
+
+ COUNT_NODES_IN_TEMPORARY_TABLE = "select count(*) from " + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME;
+
+ SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE =
+ "select * into " + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME + " from "
+ + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME + " order by "
+ + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME + ".ID DESC";
+
+ FIND_NODES_AND_PROPERTIES =
+ "select " + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME
+ + ".*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_MVALUE V, JCR_MITEM P, "
+ + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME + " where P.PARENT_ID = "
+ + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME
+ + ".ID and P.I_CLASS=2 and V.PROPERTY_ID=P.ID order by "
+ + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME + ".ID";
+
+ DELETE_TEMPORARY_TABLE_A = "drop table " + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME;
+
+ DELETE_TEMPORARY_TABLE_B = "drop table " + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findNodesAndProperties(String lastNodeId, int offset, int limit) throws SQLException
+ {
+ String tempTableAName = "#a" + IdGenerator.generate();
+ String tempTableBName = "#b" + IdGenerator.generate();
+
+ boolean tempTableACreated = false;
+ boolean tempTableBCreated = false;
+
+ try
+ {
+ // the Sybase is not allowed DDL query (CREATE TABLE, DROP TABLE, etc. ) within a multi-statement transaction
+ dbConnection.setAutoCommit(true);
+
+ selectLimitOffsetNodesIntoTemporaryTable =
+ dbConnection.prepareStatement(SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));
+
+ countNodesInTemporaryTable =
+ dbConnection.prepareStatement(COUNT_NODES_IN_TEMPORARY_TABLE.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));
+
+ selectLimitNodesInTemporaryTable =
+ dbConnection.prepareStatement(SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName).replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME, tempTableBName));
+
+ if (findNodesAndProperties != null)
+ {
+ findNodesAndProperties.close();
+ }
+
+ findNodesAndProperties =
+ dbConnection.prepareStatement(FIND_NODES_AND_PROPERTIES.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME, tempTableBName));
+
+ deleteTemporaryTableA =
+ dbConnection.prepareStatement(DELETE_TEMPORARY_TABLE_A.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));
+
+ deleteTemporaryTableB =
+ dbConnection.prepareStatement(DELETE_TEMPORARY_TABLE_B.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME, tempTableBName));
+
+ selectLimitOffsetNodesIntoTemporaryTable.setMaxRows(limit + offset);
+ selectLimitOffsetNodesIntoTemporaryTable.setString(1, lastNodeId);
+ selectLimitOffsetNodesIntoTemporaryTable.execute();
+
+ tempTableACreated = true;
+
+ ResultSet nodesCountInTemporaryTable = countNodesInTemporaryTable.executeQuery();
+
+ if (!nodesCountInTemporaryTable.next())
+ {
+ throw new SQLException("Can not count nodes in temporary table.");
+ }
+
+ int count = nodesCountInTemporaryTable.getInt(1);
+
+ // define newLimit if number of records in temporary table #tempA is equal offset + limit
+ int newLimit = limit;
+
+ if (offset > count)
+ {
+ // return empty ResultSet because there are no enough nodes to return
+ return new EmptyResultSet();
+ }
+ else if (offset + limit > count)
+ {
+ // it is possible to select only count-offset nodes from temporary table #tempA
+ newLimit = count - offset;
+ }
+
+ selectLimitNodesInTemporaryTable.setMaxRows(newLimit);
+ selectLimitNodesInTemporaryTable.execute();
+
+ tempTableBCreated = true;
+
+ return findNodesAndProperties.executeQuery();
+ }
+ finally
+ {
+ if (tempTableACreated)
+ {
+ try
+ {
+ deleteTemporaryTableA.execute();
+ }
+ catch (SQLException e)
+ {
+ LOG.warn("Can not delete temporary table " + tempTableAName);
+ }
+ }
+
+ if (tempTableBCreated)
+ {
+ try
+ {
+ deleteTemporaryTableB.execute();
+ }
+ catch (SQLException e)
+ {
+ LOG.warn("Can not delete temporary table " + tempTableBName);
+ }
+ }
+
+ // close prepared statement since we always create new
+ if (selectLimitOffsetNodesIntoTemporaryTable != null)
+ {
+ selectLimitOffsetNodesIntoTemporaryTable.close();
+ }
+
+ if (selectLimitNodesInTemporaryTable != null)
+ {
+ selectLimitNodesInTemporaryTable.close();
+ }
+
+ if (deleteTemporaryTableA != null)
+ {
+ deleteTemporaryTableA.close();
+ }
+
+ if (deleteTemporaryTableB != null)
+ {
+ deleteTemporaryTableB.close();
+ }
+
+ if (countNodesInTemporaryTable != null)
+ {
+ countNodesInTemporaryTable.close();
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseSingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseSingleDbJDBCConnection.java 2011-06-24 08:08:19 UTC (rev 4563)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SybaseSingleDbJDBCConnection.java 2011-06-24 08:30:34 UTC (rev 4564)
@@ -16,11 +16,15 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+import org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.SybaseJDBCConnectionHelper.EmptyResultSet;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+import org.exoplatform.services.jcr.util.IdGenerator;
import java.io.File;
import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
/**
@@ -34,9 +38,44 @@
public class SybaseSingleDbJDBCConnection extends SingleDbJDBCConnection
{
+ /**
+ * SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE
+ */
+ protected String SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE;
+
+ /**
+ * COUNT_NODES_IN_TEMPORARY_TABLE
+ */
+ protected String COUNT_NODES_IN_TEMPORARY_TABLE;
+
+ /**
+ * SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE
+ */
+ protected String SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE;
+
+ /**
+ * DELETE_TEMPORARY_TABLE_A
+ */
+ protected String DELETE_TEMPORARY_TABLE_A;
+
+ /**
+ * DELETE_TEMPORARY_TABLE_B
+ */
+ protected String DELETE_TEMPORARY_TABLE_B;
+
+ protected PreparedStatement selectLimitOffsetNodesIntoTemporaryTable;
+
+ protected PreparedStatement selectLimitNodesInTemporaryTable;
+
+ protected PreparedStatement deleteTemporaryTableA;
+
+ protected PreparedStatement deleteTemporaryTableB;
+
+ protected PreparedStatement countNodesInTemporaryTable;
+
public SybaseSingleDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
- ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
- throws SQLException
+ ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory,
+ FileCleaner swapCleaner) throws SQLException
{
super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
}
@@ -68,4 +107,177 @@
return sb.toString();
}
+ /**
+ * {@inheritDoc}
+ */
+ protected void prepareQueries() throws SQLException
+ {
+
+ super.prepareQueries();
+
+ SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE =
+ "select I.ID, I.PARENT_ID, I.NAME, I.VERSION, I.I_INDEX, I.N_ORDER_NUM into "
+ + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME
+ + " from JCR_SITEM I where I.CONTAINER_NAME=? AND I.I_CLASS=1 AND I.ID > ? order by I.ID ASC";
+
+ COUNT_NODES_IN_TEMPORARY_TABLE = "select count(*) from " + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME;
+
+ SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE =
+ "select * into " + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME + " from "
+ + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME + " order by "
+ + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME + ".ID DESC";
+
+ FIND_NODES_AND_PROPERTIES =
+ "select " + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME
+ + ".*, P.ID AS P_ID, P.NAME AS P_NAME, P.VERSION AS P_VERSION, P.P_TYPE, P.P_MULTIVALUED,"
+ + " V.DATA, V.ORDER_NUM, V.STORAGE_DESC from JCR_SVALUE V, JCR_SITEM P, "
+ + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME + " where P.PARENT_ID = "
+ + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME
+ + ".ID and P.I_CLASS=2 and P.CONTAINER_NAME=? and V.PROPERTY_ID=P.ID order by "
+ + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME + ".ID";
+
+ DELETE_TEMPORARY_TABLE_A = "drop table " + SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME;
+
+ DELETE_TEMPORARY_TABLE_B = "drop table " + SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ResultSet findNodesAndProperties(String lastNodeId, int offset, int limit) throws SQLException
+ {
+ String tempTableAName = "#a" + IdGenerator.generate();
+ String tempTableBName = "#b" + IdGenerator.generate();
+
+ boolean tempTableACreated = false;
+ boolean tempTableBCreated = false;
+
+ try
+ {
+ // the Sybase is not allowed DDL query (CREATE TABLE, DROP TABLE, etc. ) within a multi-statement transaction
+ dbConnection.setAutoCommit(true);
+
+ selectLimitOffsetNodesIntoTemporaryTable =
+ dbConnection.prepareStatement(SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));
+
+ countNodesInTemporaryTable =
+ dbConnection.prepareStatement(COUNT_NODES_IN_TEMPORARY_TABLE.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));
+
+ selectLimitNodesInTemporaryTable =
+ dbConnection.prepareStatement(SELECT_LIMIT_NODES_FROM_TEMPORARY_TABLE.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName).replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME, tempTableBName));
+
+ if (findNodesAndProperties != null)
+ {
+ findNodesAndProperties.close();
+ }
+
+ findNodesAndProperties =
+ dbConnection.prepareStatement(FIND_NODES_AND_PROPERTIES.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME, tempTableBName));
+
+ deleteTemporaryTableA =
+ dbConnection.prepareStatement(DELETE_TEMPORARY_TABLE_A.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));
+
+ deleteTemporaryTableB =
+ dbConnection.prepareStatement(DELETE_TEMPORARY_TABLE_B.replaceAll(
+ SybaseJDBCConnectionHelper.TEMP_B_TABLE_NAME, tempTableBName));
+
+
+ selectLimitOffsetNodesIntoTemporaryTable.setMaxRows(limit + offset);
+ selectLimitOffsetNodesIntoTemporaryTable.setString(1, containerName);
+ selectLimitOffsetNodesIntoTemporaryTable.setString(2, getInternalId(lastNodeId));
+ selectLimitOffsetNodesIntoTemporaryTable.execute();
+
+ tempTableACreated = true;
+
+ ResultSet nodesCountInTemporaryTable = countNodesInTemporaryTable.executeQuery();
+
+ if (!nodesCountInTemporaryTable.next())
+ {
+ throw new SQLException("Can not count nodes in temporary table.");
+ }
+
+ int count = nodesCountInTemporaryTable.getInt(1);
+
+ // define newLimit if number of records in temporary table #tempA is equal offset + limit
+ int newLimit = limit;
+
+ if (offset > count)
+ {
+ // return empty ResultSet because there are no enough nodes to return
+ return new EmptyResultSet();
+ }
+ else if (offset + limit > count)
+ {
+ // it is possible to select only count-offset nodes from temporary table #tempA
+ newLimit = count - offset;
+ }
+
+ selectLimitNodesInTemporaryTable.setMaxRows(newLimit);
+ selectLimitNodesInTemporaryTable.execute();
+
+ tempTableBCreated = true;
+
+ findNodesAndProperties.setString(1, containerName);
+
+ return findNodesAndProperties.executeQuery();
+ }
+ finally
+ {
+ if (tempTableACreated)
+ {
+ try
+ {
+ deleteTemporaryTableA.execute();
+ }
+ catch (SQLException e)
+ {
+ LOG.warn("Can not delete temporary table " + tempTableAName);
+ }
+ }
+
+ if (tempTableBCreated)
+ {
+ try
+ {
+ deleteTemporaryTableB.execute();
+ }
+ catch (SQLException e)
+ {
+ LOG.warn("Can not delete temporary table " + tempTableBName);
+ }
+ }
+
+ // close prepared statement since we always create new
+ if (selectLimitOffsetNodesIntoTemporaryTable != null)
+ {
+ selectLimitOffsetNodesIntoTemporaryTable.close();
+ }
+
+ if (selectLimitNodesInTemporaryTable != null)
+ {
+ selectLimitNodesInTemporaryTable.close();
+ }
+
+ if (deleteTemporaryTableA != null)
+ {
+ deleteTemporaryTableA.close();
+ }
+
+ if (deleteTemporaryTableB != null)
+ {
+ deleteTemporaryTableB.close();
+ }
+
+ if (countNodesInTemporaryTable != null)
+ {
+ countNodesInTemporaryTable.close();
+ }
+ }
+ }
}
12 years, 10 months
exo-jcr SVN: r4562 - core/branches/2.3.x/patch/2.3.10/COR-34.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-06-24 03:37:58 -0400 (Fri, 24 Jun 2011)
New Revision: 4562
Modified:
core/branches/2.3.x/patch/2.3.10/COR-34/COR-34.patch
Log:
COR-34: patch updated
Modified: core/branches/2.3.x/patch/2.3.10/COR-34/COR-34.patch
===================================================================
--- core/branches/2.3.x/patch/2.3.10/COR-34/COR-34.patch 2011-06-23 15:04:40 UTC (rev 4561)
+++ core/branches/2.3.x/patch/2.3.10/COR-34/COR-34.patch 2011-06-24 07:37:58 UTC (rev 4562)
@@ -1,3 +1,242 @@
+Index: exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java
+===================================================================
+--- exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java (revision 4560)
++++ exo.core.component.ldap/src/main/java/org/exoplatform/services/ldap/impl/LDAPServiceImpl.java (working copy)
+@@ -207,6 +207,7 @@
+ }
+ catch (CommunicationException e1)
+ {
++ release(ctx);
+ // create new LDAP context
+ ctx = getLdapContext(true);
+ // try repeat operation where communication error occurs
+@@ -214,6 +215,7 @@
+ }
+ catch (ServiceUnavailableException e2)
+ {
++ release(ctx);
+ // do the same as for CommunicationException
+ ctx = getLdapContext(true);
+ //
+@@ -274,6 +276,7 @@
+ }
+ catch (CommunicationException e1)
+ {
++ release(ctx);
+ // create new LDAP context
+ ctx = getLdapContext(true);
+ // try repeat operation where communication error occurs
+@@ -281,6 +284,7 @@
+ }
+ catch (ServiceUnavailableException e2)
+ {
++ release(ctx);
+ // do the same as for CommunicationException
+ ctx = getLdapContext(true);
+ //
+Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java
+===================================================================
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java (revision 4560)
++++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java (working copy)
+@@ -29,6 +29,7 @@
+ import org.exoplatform.services.organization.MembershipType;
+ import org.exoplatform.services.organization.User;
+ import org.exoplatform.services.organization.impl.MembershipImpl;
++import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
+
+ import java.util.ArrayList;
+ import java.util.Collection;
+@@ -70,12 +71,15 @@
+ * mapping LDAP attributes to eXo organization service items (users, groups, etc)
+ * @param ldapService
+ * {@link LDAPService}
++ * @param cacheHandler
++ * The Cache Handler
+ * @throws Exception
+ * if any errors occurs
+ */
+- public MembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService) throws Exception
++ public MembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService, CacheHandler cacheHandler)
++ throws Exception
+ {
+- super(ldapAttrMapping, ldapService);
++ super(ldapAttrMapping, ldapService, cacheHandler);
+ this.listeners = new ArrayList<MembershipEventListener>(3);
+ }
+
+@@ -131,6 +135,8 @@
+ ctx.createSubcontext(membershipDN, ldapAttrMapping.membershipToAttributes(m, userDN));
+ if (broadcast)
+ postSave(m, true);
++
++ cacheHandler.put(cacheHandler.getMembershipKey(m), m, CacheType.MEMBERSHIP);
+ return;
+ }
+ // if contains membership
+@@ -148,15 +154,14 @@
+ ctx.modifyAttributes(membershipDN, mods);
+ if (broadcast)
+ postSave(m, true);
++
++ cacheHandler.put(cacheHandler.getMembershipKey(m), m, CacheType.MEMBERSHIP);
+ return;
+
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -245,23 +250,25 @@
+ ctx.modifyAttributes(membershipDN, mods);
+ if (broadcast)
+ postSave(m, true);
++
++ cacheHandler.put(cacheHandler.getMembershipKey(m), m, CacheType.MEMBERSHIP);
+ }
+ else
+ {
+ if (broadcast)
+ preDelete(m);
+ ctx.destroySubcontext(membershipDN);
++
+ if (broadcast)
+ postDelete(m);
++
++ cacheHandler.remove(cacheHandler.getMembershipKey(m), CacheType.MEMBERSHIP);
+ }
+ return m;
+ }
+ catch (NamingException e1)
+ {
+- if (isConnectionError(e1) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e1;
++ ctx = reloadCtx(ctx, err, e1);
+ }
+ }
+ }
+@@ -318,9 +325,13 @@
+ new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(
+ ldapAttrMapping.membershipTypeMemberValue, userDN));
+ ctx.modifyAttributes(membershipDN, mods);
++ cacheHandler.put(cacheHandler.getMembershipKey(membership), membership, CacheType.MEMBERSHIP);
+ }
+ else
++ {
+ ctx.destroySubcontext(membershipDN);
++ cacheHandler.remove(cacheHandler.getMembershipKey(membership), CacheType.MEMBERSHIP);
++ }
+ }
+ catch (Exception e1)
+ {
+@@ -331,10 +342,7 @@
+ }
+ catch (NamingException e2)
+ {
+- if (isConnectionError(e2) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e2;
++ ctx = reloadCtx(ctx, err, e2);
+ }
+ finally
+ {
+@@ -365,12 +373,19 @@
+ */
+ public Membership findMembershipByUserGroupAndType(String userName, String groupId, String type) throws Exception
+ {
++ MembershipImpl membership =
++ (MembershipImpl)cacheHandler.get(cacheHandler.getMembershipKey(userName, groupId, type), CacheType.MEMBERSHIP);
++ if (membership != null)
++ {
++ return membership;
++ }
++
+ LdapContext ctx = ldapService.getLdapContext();
+ try
+ {
+ for (int err = 0;; err++)
+ {
+- Membership membership = null;
++ membership = null;
+ try
+ {
+ String userDN = getDNFromUsername(ctx, userName);
+@@ -395,14 +410,15 @@
+ membership = createMembershipObject(userName, groupId, type);
+ }
+
++ if (membership != null)
++ {
++ cacheHandler.put(cacheHandler.getMembershipKey(membership), membership, CacheType.MEMBERSHIP);
++ }
+ return membership;
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -457,10 +473,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
+@@ -538,9 +551,9 @@
+ {
+ SearchResult sr = results.next();
+ String membershipDN = sr.getNameInNamespace();
+- Group group = getGroupFromMembershipDN(ctx, membershipDN);
++ String groupId = getGroupIdFromGroupDN(getGroupDNFromMembershipDN(membershipDN));
+ String type = explodeDN(membershipDN, true)[0];
+- Membership membership = createMembershipObject(userName, group.getId(), type);
++ Membership membership = createMembershipObject(userName, groupId, type);
+ memberships.add(membership);
+ }
+ if (LOG.isDebugEnabled())
+@@ -551,10 +564,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
+@@ -619,10 +629,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/CacheHandler.java
===================================================================
--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/CacheHandler.java (revision 0)
@@ -2,3 +241,3 @@
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/CacheHandler.java (revision 0)
-@@ -0,0 +1,182 @@
+@@ -0,0 +1,176 @@
+/*
@@ -45,11 +284,6 @@
+ public static final String USER_PREFIX = "u=";
+
+ /**
-+ * The cache service.
-+ */
-+ private final CacheService cservice;
-+
-+ /**
+ * Cache for Users.
+ */
+ private final ExoCache<Serializable, User> userCache;
@@ -77,7 +311,6 @@
+ */
+ public CacheHandler(CacheService cservice)
+ {
-+ this.cservice = cservice;
+ this.userCache = cservice.getCacheInstance(this.getClass().getName() + "userCache");
+ this.membershipTypeCache = cservice.getCacheInstance(this.getClass().getName() + "membershipTypeCache");
+ this.groupCache = cservice.getCacheInstance(this.getClass().getName() + "groupCache");
@@ -185,135 +418,9 @@
+ USER, GROUP, MEMBERSHIP, MEMBERSHIPTYPE
+ }
+}
-Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java
-===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java (revision 4450)
-+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipDAOImpl.java (working copy)
-@@ -29,6 +29,7 @@
- import org.exoplatform.services.organization.MembershipType;
- import org.exoplatform.services.organization.User;
- import org.exoplatform.services.organization.impl.MembershipImpl;
-+import org.exoplatform.services.organization.ldap.CacheHandler.CacheType;
-
- import java.util.ArrayList;
- import java.util.Collection;
-@@ -70,12 +71,15 @@
- * mapping LDAP attributes to eXo organization service items (users, groups, etc)
- * @param ldapService
- * {@link LDAPService}
-+ * @param cacheHandler
-+ * The Cache Handler
- * @throws Exception
- * if any errors occurs
- */
-- public MembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService) throws Exception
-+ public MembershipDAOImpl(LDAPAttributeMapping ldapAttrMapping, LDAPService ldapService, CacheHandler cacheHandler)
-+ throws Exception
- {
-- super(ldapAttrMapping, ldapService);
-+ super(ldapAttrMapping, ldapService, cacheHandler);
- this.listeners = new ArrayList<MembershipEventListener>(3);
- }
-
-@@ -131,6 +135,8 @@
- ctx.createSubcontext(membershipDN, ldapAttrMapping.membershipToAttributes(m, userDN));
- if (broadcast)
- postSave(m, true);
-+
-+ cacheHandler.put(cacheHandler.getMembershipKey(m), m, CacheType.MEMBERSHIP);
- return;
- }
- // if contains membership
-@@ -148,6 +154,8 @@
- ctx.modifyAttributes(membershipDN, mods);
- if (broadcast)
- postSave(m, true);
-+
-+ cacheHandler.put(cacheHandler.getMembershipKey(m), m, CacheType.MEMBERSHIP);
- return;
-
- }
-@@ -245,14 +253,19 @@
- ctx.modifyAttributes(membershipDN, mods);
- if (broadcast)
- postSave(m, true);
-+
-+ cacheHandler.put(cacheHandler.getMembershipKey(m), m, CacheType.MEMBERSHIP);
- }
- else
- {
- if (broadcast)
- preDelete(m);
- ctx.destroySubcontext(membershipDN);
-+
- if (broadcast)
- postDelete(m);
-+
-+ cacheHandler.remove(cacheHandler.getMembershipKey(m), CacheType.MEMBERSHIP);
- }
- return m;
- }
-@@ -318,9 +331,13 @@
- new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(
- ldapAttrMapping.membershipTypeMemberValue, userDN));
- ctx.modifyAttributes(membershipDN, mods);
-+ cacheHandler.put(cacheHandler.getMembershipKey(membership), membership, CacheType.MEMBERSHIP);
- }
- else
-+ {
- ctx.destroySubcontext(membershipDN);
-+ cacheHandler.remove(cacheHandler.getMembershipKey(membership), CacheType.MEMBERSHIP);
-+ }
- }
- catch (Exception e1)
- {
-@@ -365,12 +382,19 @@
- */
- public Membership findMembershipByUserGroupAndType(String userName, String groupId, String type) throws Exception
- {
-+ MembershipImpl membership =
-+ (MembershipImpl)cacheHandler.get(cacheHandler.getMembershipKey(userName, groupId, type), CacheType.MEMBERSHIP);
-+ if (membership != null)
-+ {
-+ return membership;
-+ }
-+
- LdapContext ctx = ldapService.getLdapContext();
- try
- {
- for (int err = 0;; err++)
- {
-- Membership membership = null;
-+ membership = null;
- try
- {
- String userDN = getDNFromUsername(ctx, userName);
-@@ -395,6 +419,10 @@
- membership = createMembershipObject(userName, groupId, type);
- }
-
-+ if (membership != null)
-+ {
-+ cacheHandler.put(cacheHandler.getMembershipKey(membership), membership, CacheType.MEMBERSHIP);
-+ }
- return membership;
- }
- catch (NamingException e)
-@@ -538,9 +566,9 @@
- {
- SearchResult sr = results.next();
- String membershipDN = sr.getNameInNamespace();
-- Group group = getGroupFromMembershipDN(ctx, membershipDN);
-+ String groupId = getGroupIdFromGroupDN(getGroupDNFromMembershipDN(membershipDN));
- String type = explodeDN(membershipDN, true)[0];
-- Membership membership = createMembershipObject(userName, group.getId(), type);
-+ Membership membership = createMembershipObject(userName, groupId, type);
- memberships.add(membership);
- }
- if (LOG.isDebugEnabled())
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/GroupDAOImpl.java (working copy)
@@ -26,11 +26,14 @@
import org.exoplatform.services.organization.GroupEventListenerHandler;
@@ -347,7 +454,7 @@
this.listeners = new ArrayList<GroupEventListener>(3);
}
-@@ -136,6 +142,8 @@
+@@ -136,14 +142,13 @@
ctx.createSubcontext(groupDN, ldapAttrMapping.groupToAttributes(child));
if (broadcast)
postSave(group, true);
@@ -356,7 +463,16 @@
return;
}
catch (NamingException e)
-@@ -192,6 +200,8 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
+@@ -192,14 +197,13 @@
ctx.modifyAttributes(groupDN, mods);
if (broadcast)
postSave(group, true);
@@ -365,7 +481,16 @@
return;
}
catch (NamingException e)
-@@ -255,6 +265,7 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -255,15 +259,13 @@
removeAllSubtree(ctx, groupDN);
if (broadcast)
postDelete(group);
@@ -373,7 +498,29 @@
return group;
}
-@@ -348,6 +359,13 @@
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
+@@ -323,10 +325,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
+@@ -348,6 +347,13 @@
{
if (groupId == null)
return null;
@@ -387,7 +534,7 @@
String parentId = null;
StringBuffer buffer = new StringBuffer();
String[] groupIdParts = groupId.split("/");
-@@ -366,9 +384,14 @@
+@@ -366,17 +372,19 @@
try
{
Attributes attrs = ctx.getAttributes(groupDN);
@@ -403,7 +550,16 @@
return group;
}
catch (NamingException e)
-@@ -402,6 +425,13 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -402,6 +410,13 @@
{
if (groupId == null)
return null;
@@ -417,7 +573,7 @@
String parentId = null;
StringBuffer buffer = new StringBuffer();
String[] groupIdParts = groupId.split("/");
-@@ -415,9 +445,14 @@
+@@ -415,9 +430,14 @@
try
{
Attributes attrs = ctx.getAttributes(groupDN);
@@ -433,7 +589,7 @@
return group;
}
catch (NameNotFoundException e)
-@@ -473,7 +508,7 @@
+@@ -473,7 +493,7 @@
{
Name entryName = parser.parse(name.get(0));
String groupDN = entryName + "," + ldapAttrMapping.groupsURL;
@@ -442,7 +598,19 @@
if (group != null)
addGroup(groups, group);
}
-@@ -555,7 +590,7 @@
+@@ -482,10 +502,7 @@
+ }
+ catch (NamingException e2)
+ {
+- if (isConnectionError(e2) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e2;
++ ctx = reloadCtx(ctx, err, e2);
+ }
+ finally
+ {
+@@ -555,7 +572,7 @@
{
Name entryName = parser.parse(name.get(0));
String groupDN = entryName + "," + searchBase;
@@ -451,7 +619,19 @@
if (group != null)
addGroup(groups, group);
}
-@@ -613,21 +648,24 @@
+@@ -564,10 +581,7 @@
+ }
+ catch (NamingException e2)
+ {
+- if (isConnectionError(e2) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e2;
++ ctx = reloadCtx(ctx, err, e2);
+ }
+ finally
+ {
+@@ -613,21 +627,24 @@
results = ctx.search(ldapAttrMapping.groupsURL, filter, constraints);
// add groups for memberships matching user
@@ -481,9 +661,21 @@
if (LOG.isDebugEnabled())
{
LOG.debug("Retrieved " + groups.size() + " groups from ldap for user " + userName);
+@@ -636,10 +653,7 @@
+ }
+ catch (NamingException e2)
+ {
+- if (isConnectionError(e2) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e2;
++ ctx = reloadCtx(ctx, err, e2);
+ }
+ finally
+ {
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/MembershipTypeDAOImpl.java (working copy)
@@ -24,6 +24,7 @@
import org.exoplatform.services.organization.MembershipType;
@@ -510,7 +702,7 @@
}
/**
-@@ -95,6 +99,8 @@
+@@ -95,15 +99,14 @@
mt.setCreatedDate(now);
mt.setModifiedDate(now);
ctx.createSubcontext(membershipTypeDN, ldapAttrMapping.membershipTypeToAttributes(mt));
@@ -519,7 +711,17 @@
}
return mt;
}
-@@ -146,6 +152,8 @@
+ catch (NamingException e1)
+ {
+- if (isConnectionError(e1) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e1;
++ ctx = reloadCtx(ctx, err, e1);
+ }
+ }
+ }
+@@ -146,14 +149,13 @@
ldapAttrMapping.ldapDescriptionAttr, mt.getDescription()));
}
ctx.modifyAttributes(membershipTypeDN, mods);
@@ -528,7 +730,16 @@
return mt;
}
catch (NamingException e)
-@@ -181,6 +189,8 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -181,14 +183,13 @@
MembershipType m = ldapAttrMapping.attributesToMembershipType(attrs);
removeMembership(ctx, name);
ctx.destroySubcontext(membershipTypeDN);
@@ -537,7 +748,16 @@
return m;
}
catch (NamingException e)
-@@ -209,6 +219,12 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -209,6 +210,12 @@
*/
public MembershipType findMembershipType(String name) throws Exception
{
@@ -550,7 +770,7 @@
String membershipTypeDN =
ldapAttrMapping.membershipTypeNameAttr + "=" + name + "," + ldapAttrMapping.membershipTypeURL;
LdapContext ctx = ldapService.getLdapContext();
-@@ -219,7 +235,12 @@
+@@ -219,14 +226,16 @@
try
{
Attributes attrs = ctx.getAttributes(membershipTypeDN);
@@ -564,7 +784,27 @@
}
catch (NamingException e)
{
-@@ -307,6 +328,8 @@
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -274,10 +283,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
+@@ -307,6 +313,8 @@
{
SearchResult sr = results.next();
ctx.destroySubcontext(sr.getNameInNamespace());
@@ -575,7 +815,7 @@
finally
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserProfileDAOImpl.java (working copy)
@@ -61,9 +61,10 @@
*/
@@ -590,9 +830,57 @@
this.listeners = new ArrayList<UserProfileEventListener>(3);
}
+@@ -107,10 +108,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -153,10 +151,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -191,10 +186,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -229,10 +221,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADMembershipDAOImpl.java (working copy)
@@ -22,6 +22,7 @@
import org.exoplatform.services.organization.Group;
@@ -634,7 +922,7 @@
LdapContext ctx = ldapService.getLdapContext(true);
String groupDN = getGroupDNFromGroupId(groupId);
try
-@@ -74,7 +84,11 @@
+@@ -74,15 +84,16 @@
{
Collection memberships = findMemberships(ctx, userName, groupDN, type);
if (memberships.size() > 0)
@@ -647,7 +935,40 @@
return null;
}
catch (NamingException e)
-@@ -184,7 +198,7 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -110,10 +121,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -142,10 +150,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -184,7 +189,7 @@
results = ctx.search(userDN, filter, constraints);
while (results.hasMore())
{
@@ -658,7 +979,7 @@
for (int x = 0; x < attr.size(); x++)
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/OrganizationServiceImpl.java (working copy)
@@ -47,25 +47,27 @@
LDAPAttributeMapping ldapAttrMapping =
@@ -697,7 +1018,7 @@
if (param != null)
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADGroupDAOImpl.java (working copy)
@@ -48,12 +48,14 @@
* items
@@ -717,9 +1038,47 @@
adSearch = ad;
}
+@@ -126,10 +128,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ finally
+ {
+Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LDAPUserPageList.java
+===================================================================
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LDAPUserPageList.java (revision 4560)
++++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LDAPUserPageList.java (working copy)
+@@ -141,7 +141,10 @@
+ catch (NamingException e)
+ {
+ if (BaseDAO.isConnectionError(e) && err < BaseDAO.getMaxConnectionError())
++ {
++ ldapService.release(ctx);
+ ctx = ldapService.getLdapContext(true);
++ }
+ else
+ throw e;
+ }
+@@ -197,7 +200,10 @@
+ catch (NamingException e)
+ {
+ if (BaseDAO.isConnectionError(e) && err < 1)
++ {
++ ldapService.release(ctx);
+ ctx = ldapService.getLdapContext(true);
++ }
+ else
+ throw e;
+ }
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/UserDAOImpl.java (working copy)
@@ -21,8 +21,13 @@
import org.exoplatform.commons.utils.LazyPageList;
@@ -753,7 +1112,7 @@
}
/**
-@@ -104,6 +112,8 @@
+@@ -104,14 +112,13 @@
ctx.createSubcontext(userDN, attrs);
if (broadcast)
postSave(user, true);
@@ -762,7 +1121,16 @@
break;
}
catch (NamingException e)
-@@ -145,6 +155,8 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -145,14 +152,13 @@
ctx.modifyAttributes(userDN, mods);
if (broadcast)
postSave(user, false);
@@ -771,7 +1139,16 @@
break;
}
catch (NamingException e)
-@@ -174,7 +186,7 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -174,7 +180,7 @@
* @param userDN Distinguished Name
* @throws Exception if any errors occurs
*/
@@ -780,7 +1157,19 @@
{
ModificationItem[] mods =
new ModificationItem[]{new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(
-@@ -227,6 +239,9 @@
+@@ -191,10 +197,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -227,14 +230,14 @@
ctx.destroySubcontext(userDN);
if (broadcast)
postDelete(user);
@@ -790,7 +1179,16 @@
return user;
}
catch (NamingException e)
-@@ -249,6 +264,12 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -249,6 +252,12 @@
*/
public User findUserByName(String userName) throws Exception
{
@@ -803,7 +1201,7 @@
LdapContext ctx = ldapService.getLdapContext();
try
{
-@@ -256,7 +277,12 @@
+@@ -256,14 +265,16 @@
{
try
{
@@ -817,7 +1215,15 @@
}
catch (NamingException e)
{
-@@ -283,51 +309,6 @@
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -283,51 +294,6 @@
*/
public ListAccess<User> findUsersByGroupId(String groupId) throws Exception
{
@@ -869,7 +1275,7 @@
String searchBase = this.getGroupDNFromGroupId(groupId);
String filter = ldapAttrMapping.membershipObjectClassFilter;
return new ByGroupLdapUserListAccess(ldapAttrMapping, ldapService, searchBase, filter);
-@@ -346,8 +327,6 @@
+@@ -346,8 +312,6 @@
String searchBase = ldapAttrMapping.userURL;
String filter = ldapAttrMapping.userObjectClassFilter;
@@ -880,7 +1286,7 @@
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/ADUserDAOImpl.java (working copy)
@@ -20,6 +20,7 @@
@@ -907,7 +1313,7 @@
LDAPUserPageList.SEARCH_CONTROL = Control.CRITICAL;
}
-@@ -93,6 +97,8 @@
+@@ -93,14 +97,13 @@
ctx.createSubcontext(userDN, attrs);
if (broadcast)
postSave(user, true);
@@ -916,7 +1322,16 @@
break;
}
catch (NamingException e)
-@@ -118,7 +124,7 @@
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -118,7 +121,7 @@
* {@inheritDoc}
*/
@Override
@@ -925,9 +1340,47 @@
{
Object v = ldapService.getLdapContext().getEnvironment().get(Context.SECURITY_PROTOCOL);
if (v == null)
+@@ -147,10 +150,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LdapUserListAccess.java
+===================================================================
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LdapUserListAccess.java (revision 4560)
++++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/LdapUserListAccess.java (working copy)
+@@ -84,7 +84,10 @@
+ catch (NamingException e)
+ {
+ if (BaseDAO.isConnectionError(e) && err < BaseDAO.getMaxConnectionError())
++ {
++ ldapService.release(ctx);
+ ctx = ldapService.getLdapContext(true);
++ }
+ else
+ throw e;
+ }
+@@ -113,7 +116,10 @@
+ catch (NamingException e)
+ {
+ if (BaseDAO.isConnectionError(e) && err < BaseDAO.getMaxConnectionError())
++ {
++ ldapService.release(ctx);
+ ctx = ldapService.getLdapContext(true);
++ }
+ else
+ throw e;
+ }
Index: exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java
===================================================================
---- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java (revision 4450)
+--- exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java (revision 4560)
+++ exo.core.component.organization.ldap/src/main/java/org/exoplatform/services/organization/ldap/BaseDAO.java (working copy)
@@ -24,6 +24,7 @@
import org.exoplatform.services.organization.Group;
@@ -1018,7 +1471,52 @@
}
/**
-@@ -270,6 +311,26 @@
+@@ -245,12 +286,7 @@
+ }
+ catch (NamingException e)
+ {
+- // check is allowed to try one more time
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- // not connection exception or error occurs more than MAX_CONNECTION_ERROR
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -261,6 +297,30 @@
+ }
+
+ /**
++ * Re-load the ctx if the context allows it
++ * @param ctx the previous context
++ * @param err the total of errors that have already occurred
++ * @param e the last exception that occurs
++ * @return the new context if the context reload is allowed throws an exception otherwise
++ * @throws NamingException if context could not be reloaded
++ */
++ protected LdapContext reloadCtx(LdapContext ctx, int err, NamingException e) throws NamingException
++ {
++ // check is allowed to try one more time
++ if (isConnectionError(e) && err < getMaxConnectionError())
++ {
++ // release the previous context
++ ldapService.release(ctx);
++ // reload the context
++ ctx = ldapService.getLdapContext(true);
++ }
++ else
++ // not connection exception or error occurs more than MAX_CONNECTION_ERROR
++ throw e;
++ return ctx;
++ }
++
++ /**
+ * Get Group what reflected to object with specified Distinguished Name.
+ *
+ * @param ctx {@link LdapContext}
+@@ -270,6 +330,26 @@
*/
protected Group getGroupByDN(LdapContext ctx, String groupDN) throws NamingException
{
@@ -1045,7 +1543,7 @@
StringBuffer idBuffer = new StringBuffer();
String parentId = null;
String[] baseParts = explodeDN(ldapAttrMapping.groupsURL, true);
-@@ -280,25 +341,17 @@
+@@ -280,25 +360,17 @@
if (x == 1)
parentId = idBuffer.toString();
}
@@ -1078,7 +1576,19 @@
}
/**
-@@ -381,9 +434,7 @@
+@@ -352,10 +424,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -381,9 +450,7 @@
answer = findUser(ctx, username, true);
while (answer.hasMoreElements())
{
@@ -1089,7 +1599,19 @@
}
return null;
}
-@@ -525,6 +576,10 @@
+@@ -465,10 +532,7 @@
+ }
+ catch (NamingException e)
+ {
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- ctx = ldapService.getLdapContext(true);
+- else
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
+@@ -525,6 +589,10 @@
removeAllSubtree(ctx, sr.getNameInNamespace());
}
ctx.destroySubcontext(dn);
@@ -1100,3 +1622,19 @@
}
finally
{
+@@ -649,14 +717,7 @@
+ }
+ catch (NamingException e)
+ {
+- // check is allowed to try one more time
+- if (isConnectionError(e) && err < getMaxConnectionError())
+- // update LdapContext
+- ctx = ldapService.getLdapContext(true);
+- else
+- // not connection exception or error occurs more than
+- // MAX_CONNECTION_ERROR times
+- throw e;
++ ctx = reloadCtx(ctx, err, e);
+ }
+ }
+ }
12 years, 10 months
exo-jcr SVN: r4561 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc: update and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2011-06-23 11:04:40 -0400 (Thu, 23 Jun 2011)
New Revision: 4561
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/update/StorageUpdateManager.java
Log:
EXOJCR-1404: Deprecate StorageUpdateManager. Remove "update-storage" parameter reading, since it useless.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-06-22 11:46:51 UTC (rev 4560)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-06-23 15:04:40 UTC (rev 4561)
@@ -460,21 +460,8 @@
initDatabase();
- String suParam = null;
+ // enableStorageUpdate left unchanged since it is never used in StorageUpdateManager.checkVersion
boolean enableStorageUpdate = false;
- try
- {
- suParam = wsConfig.getContainer().getParameterValue("update-storage");
- enableStorageUpdate = Boolean.parseBoolean(suParam);
- }
- catch (RepositoryConfigurationException e)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("update-storage parameter is not set " + dbSourceName);
- }
- }
-
this.storageVersion =
StorageUpdateManager.checkVersion(dbSourceName, this.connFactory.getJdbcConnection(), multiDb,
enableStorageUpdate);
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/update/StorageUpdateManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/update/StorageUpdateManager.java 2011-06-22 11:46:51 UTC (rev 4560)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/update/StorageUpdateManager.java 2011-06-23 15:04:40 UTC (rev 4561)
@@ -36,12 +36,13 @@
import javax.jcr.RepositoryException;
/**
- * Created by The eXo Platform SAS.
+ * Created by The eXo Platform SAS.<p>
+ * This feature is deprecated and going to be removed in 1.15 version.
*
* @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady Azarenkov</a>
* @version $Id: StorageUpdateManager.java 34801 2009-07-31 15:44:50Z dkatayev $
*/
-
+@Deprecated
public class StorageUpdateManager
{
@@ -258,12 +259,15 @@
/**
* Check current storage version and update if updateNow==true
+ * <p>
+ * This feature is deprecated and going to be removed in 1.15 version.
*
* @param ds
* @param updateNow
* @return
* @throws RepositoryException
*/
+ @Deprecated
public static synchronized String checkVersion(String sourceName, Connection connection, boolean multiDB,
boolean updateNow) throws RepositoryException
{
12 years, 10 months
exo-jcr SVN: r4560 - core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/j2ee.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-06-22 07:46:51 -0400 (Wed, 22 Jun 2011)
New Revision: 4560
Modified:
core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/j2ee/JbossLoginModule.java
Log:
EXOJCR-1303: WARN No principal found when performing JBoss security manager cache eviction. log.warn() was replaced by log.degug()
Modified: core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/j2ee/JbossLoginModule.java
===================================================================
--- core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/j2ee/JbossLoginModule.java 2011-06-22 08:07:20 UTC (rev 4559)
+++ core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/j2ee/JbossLoginModule.java 2011-06-22 11:46:51 UTC (rev 4560)
@@ -146,7 +146,7 @@
}
else
{
- log.warn("No principal found when performing JBoss security manager cache eviction for user "
+ log.debug("No principal found when performing JBoss security manager cache eviction for user "
+ userName);
}
}
12 years, 10 months
exo-jcr SVN: r4559 - jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-06-22 04:07:20 -0400 (Wed, 22 Jun 2011)
New Revision: 4559
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java
Log:
EXOJCR-852: fix tests
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java 2011-06-22 06:21:00 UTC (rev 4558)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java 2011-06-22 08:07:20 UTC (rev 4559)
@@ -22,10 +22,8 @@
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -47,11 +45,6 @@
*/
public class TestWorkspaceRestore extends JcrImplBaseTest
{
-
- private static boolean isDefaultWsCreated = false;
-
- private final Log log = ExoLogger.getLogger("exo.jcr.component.core.TestWorkspaceRestore");
-
private final TesterConfigurationHelper helper = TesterConfigurationHelper.getInstance();
private WorkspaceEntry wsEntry;
@@ -63,43 +56,33 @@
{
super.setUp();
wsEntry = (WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
- if ("true".equals(wsEntry.getContainer().getParameterValue("multi-db")))
- {
- isDefaultWsMultiDb = true;
- }
- if (!isDefaultWsCreated)
- {
-
- WorkspaceEntry workspaceEntry = null;
- workspaceEntry =
- helper.getNewWs("defWs", isDefaultWsMultiDb,
- wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME), null,
- wsEntry.getContainer(), true);
-
- helper.createWorkspace(workspaceEntry, container);
- isDefaultWsCreated = true;
- }
+
+ isDefaultWsMultiDb = "true".equals(wsEntry.getContainer().getParameterValue("multi-db"));
}
public void testRestore() throws RepositoryConfigurationException, Exception
{
+ String dsName = helper.createDatasource();
+ ManageableRepository repository = helper.createRepository(container, isDefaultWsMultiDb, dsName);
+
WorkspaceEntry workspaceEntry =
- helper.getNewWs("testResotore", isDefaultWsMultiDb,
- wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME), null,
- wsEntry.getContainer(), true);
+ helper.createWorkspaceEntry(isDefaultWsMultiDb, isDefaultWsMultiDb ? helper.createDatasource() : dsName);
+ helper.addWorkspace(repository, workspaceEntry);
- RepositoryService service = (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
- RepositoryImpl defRep;
-
- defRep = (RepositoryImpl)service.getDefaultRepository();
- defRep.configWorkspace(workspaceEntry);
InputStream is = TestWorkspaceManagement.class.getResourceAsStream("/import-export/db1_ws1-20071220_0430.xml");
- repository.importWorkspace("testResotore", is);
+ repository.importWorkspace(workspaceEntry.getName(), is);
}
public void testRestoreBadXml() throws Exception
{
- Session defSession = repository.login(this.credentials /* session.getCredentials() */, "defWs");
+ String dsName = helper.createDatasource();
+ ManageableRepository repository = helper.createRepository(container, isDefaultWsMultiDb, dsName);
+
+ WorkspaceEntry workspaceEntry =
+ helper.createWorkspaceEntry(isDefaultWsMultiDb, isDefaultWsMultiDb ? helper.createDatasource() : dsName);
+ helper.addWorkspace(repository, workspaceEntry);
+
+ Session defSession = repository.login(this.credentials, workspaceEntry.getName());
Node defRoot = defSession.getRootNode();
Node node1 = defRoot.addNode("node1");
@@ -112,22 +95,12 @@
defSession.exportSystemView(node1.getPath(), os, false, false);
os.close();
defSession.logout();
- WorkspaceEntry workspaceEntry = null;
- workspaceEntry =
- helper.getNewWs("testRestoreBadXml", isDefaultWsMultiDb,
- wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME), null,
- wsEntry.getContainer(), true);
- assertNotNull(workspaceEntry);
-
- RepositoryService service = (RepositoryService)container.getComponentInstanceOfType(RepositoryService.class);
- RepositoryImpl defRep;
-
- defRep = (RepositoryImpl)service.getDefaultRepository();
- defRep.configWorkspace(workspaceEntry);
-
+
try
{
- defRep.importWorkspace(workspaceEntry.getName(), new BufferedInputStream(new FileInputStream(content)));
+ InputStream is = TestWorkspaceManagement.class.getResourceAsStream("/import-export/db1_ws1-20071220_0430.xml");
+ repository.importWorkspace(workspaceEntry.getName(), new BufferedInputStream(new FileInputStream(content)));
+
fail();
}
catch (RepositoryException e)
12 years, 10 months