Author: tolusha
Date: 2011-04-06 02:29:28 -0400 (Wed, 06 Apr 2011)
New Revision: 4208
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
Log:
EXOJCR-1258: open connection based on existing datasource, don't allow query execution
on closed index (when component is supended)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-04-05
10:04:01 UTC (rev 4207)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-04-06
06:29:28 UTC (rev 4208)
@@ -88,6 +88,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
import javax.jcr.RepositoryException;
import javax.jcr.query.InvalidQueryException;
@@ -504,6 +505,11 @@
private boolean asyncReindexing = DEFAULT_ASYNC_REINDEXING;
/**
+ * Waiting query execution until resume.
+ */
+ protected CountDownLatch latcher = null;
+
+ /**
* Working constructor.
*
* @throws RepositoryConfigurationException
@@ -1017,6 +1023,8 @@
public MultiColumnQueryHits executeQuery(SessionImpl session, AbstractQueryImpl
queryImpl, Query query,
QPath[] orderProps, boolean[] orderSpecs, long resultFetchHint) throws IOException,
RepositoryException
{
+ waitForResuming();
+
checkOpen();
Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
@@ -1066,6 +1074,8 @@
public MultiColumnQueryHits executeQuery(SessionImpl session, MultiColumnQuery query,
QPath[] orderProps,
boolean[] orderSpecs, long resultFetchHint) throws IOException,
RepositoryException
{
+ waitForResuming();
+
checkOpen();
Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
@@ -2997,6 +3007,8 @@
*/
public QueryHits executeQuery(Query query) throws IOException
{
+ waitForResuming();
+
checkOpen();
IndexReader reader = getIndexReader(true);
@@ -3052,6 +3064,7 @@
*/
public void suspend() throws SuspendException
{
+ latcher = new CountDownLatch(1);
close();
}
@@ -3064,6 +3077,8 @@
{
closed = false;
doInit();
+
+ latcher.countDown();
}
catch (IOException e)
{
@@ -3074,4 +3089,25 @@
throw new ResumeException(e);
}
}
+
+ /**
+ * If component is suspended need to wait resuming and not allow
+ * execute query on closed index.
+ *
+ * @throws IOException
+ */
+ private void waitForResuming() throws IOException
+ {
+ if (latcher != null && latcher.getCount() != 0)
+ {
+ try
+ {
+ latcher.await();
+ }
+ catch (InterruptedException e)
+ {
+ throw new IOException(e);
+ }
+ }
+ }
}
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-04-05
10:04:01 UTC (rev 4207)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-04-06
06:29:28 UTC (rev 4208)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 eXo Platform SAS.
+z * Copyright (C) 2009 eXo Platform SAS.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
@@ -85,7 +85,6 @@
import javax.jcr.RepositoryException;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.sql.DataSource;
@@ -1108,22 +1107,9 @@
+ containerName + "'");
}
- final DataSource ds = (DataSource)new InitialContext().lookup(dbSourceName);
- if (ds == null)
- {
- throw new NameNotFoundException("Data source " + dbSourceName +
" not found");
- }
+ // using existing DataSource to get a JDBC Connection.
+ Connection jdbcConn = connFactory.getJdbcConnection();
- Connection jdbcConn =
- SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
-
- }
- });
-
DBBackup.backup(storageDir, jdbcConn, scripts);
// backup value storage
@@ -1155,14 +1141,10 @@
{
throw new BackupException(e);
}
- catch (NamingException e)
+ catch (RepositoryException e)
{
throw new BackupException(e);
}
- catch (SQLException e)
- {
- throw new BackupException(e);
- }
finally
{
if (backupInfo != null)
@@ -1390,32 +1372,16 @@
{
try
{
- final DataSource ds = (DataSource)new InitialContext().lookup(dbSourceName);
+ Connection jdbcConn = connFactory.getJdbcConnection();
+ jdbcConn.setAutoCommit(false);
- if (ds != null)
- {
- Connection jdbcConn =
- SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
- }
- });
- jdbcConn.setAutoCommit(false);
-
- return getDataRestorer(storageDir, jdbcConn);
- }
- else
- {
- throw new NameNotFoundException("Data source " + dbSourceName +
" not found");
- }
+ return getDataRestorer(storageDir, jdbcConn);
}
catch (SQLException e)
{
throw new BackupException(e);
}
- catch (NamingException e)
+ catch (RepositoryException e)
{
throw new BackupException(e);
}