[exo-jcr-commits] exo-jcr SVN: r5872 - in jcr/trunk: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Mar 16 10:08:30 EDT 2012


Author: nfilotto
Date: 2012-03-16 10:08:29 -0400 (Fri, 16 Mar 2012)
New Revision: 5872

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/DeleteValues.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/WriteValue.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java
   jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/jdbc-data-container-config.xml
Log:
EXOJCR-1763: Fixes needed to work properly on windows in case the streams are not properly closed which prevent the application to rename/delete/move files

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/DeleteValues.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/DeleteValues.java	2012-03-16 12:10:11 UTC (rev 5871)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/DeleteValues.java	2012-03-16 14:08:29 UTC (rev 5872)
@@ -19,7 +19,6 @@
 package org.exoplatform.services.jcr.impl.storage.value.fs.operations;
 
 import org.exoplatform.services.jcr.impl.storage.value.ValueDataResourceHolder;
-import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
 
 import java.io.File;
@@ -102,7 +101,7 @@
             if (file.exists())
             {
                bckFiles[i] = new File(file.getAbsolutePath() + "." + System.currentTimeMillis() + "_" + SEQUENCE.incrementAndGet());
-               DirectoryHelper.renameFile(file, bckFiles[i]);
+               move(file, bckFiles[i]);
             }           
          }
       }
@@ -121,7 +120,13 @@
                File f = bckFiles[i];
                if (f != null)
                {
-                  DirectoryHelper.renameFile(f, files[i]);
+                  // As the files could be registered to the file cleaner 
+                  // to be removed in case of a move that failed
+                  // or in case of a WriteValue.rollback() that could not
+                  // remove the file, we need to unregister the files that
+                  // will be restored thanks to the backup file
+                  cleaner.removeFile(files[i]);
+                  move(f, files[i]);
                }
             }
          }
@@ -143,11 +148,9 @@
             for (File f : bckFiles)
             {
                if (f != null && !f.delete())
-                  // Possible place of error: FileNotFoundException when we delete/update existing
-                  // Value and then add/update again.
-                  // After the time the Cleaner will delete the file which is mapped to the Value.
-                  // Don't use cleaner! Care about transaction-style files isolation per-user etc. 
+               {
                   cleaner.addFile(f);
+               }
             }
          }
          finally

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java	2012-03-16 12:10:11 UTC (rev 5871)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java	2012-03-16 14:08:29 UTC (rev 5872)
@@ -26,6 +26,7 @@
 import org.exoplatform.services.log.Log;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.InetAddress;
@@ -297,4 +298,42 @@
          twoPhaseCommit();         
       }
    }
+   
+   /**
+    * Moves a file from a location to another by using the method {{File.renameTo(File)}}
+    * if it fails it will do a copy and delete. If the source file cannot be deleted
+    * it will be given to the file cleaner
+    * @param srcFile the file to be moved
+    * @param destFile the destination file
+    * @throws IOException if error occurs
+    */
+   protected void move(File srcFile, File destFile) throws IOException
+   {
+      if (!srcFile.renameTo(destFile))
+      {
+         try
+         {
+            copyClose(new FileInputStream(srcFile), new FileOutputStream(destFile));
+         }
+         catch (IOException e)
+         {
+            throw new IOException("Could not move the file from " + srcFile.getAbsolutePath() + " to "
+               + destFile.getAbsolutePath(), e);
+         }
+         if (!srcFile.delete())
+         {
+            if (LOG.isDebugEnabled())
+            {
+               LOG.debug("The file '"
+                  + srcFile.getAbsolutePath()
+                  + "' could not be deleted which prevents the application"
+                  + " to move it properly, it is probably due to a stream used to read this property "
+                  + "that has not been closed as expected. The file will be given to the file cleaner for a later deletion.");
+            }
+            // The source could not be deleted so we add it to the
+            // file cleaner
+            cleaner.addFile(srcFile);
+         }
+      }
+   }
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/WriteValue.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/WriteValue.java	2012-03-16 12:10:11 UTC (rev 5871)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/WriteValue.java	2012-03-16 14:08:29 UTC (rev 5872)
@@ -86,6 +86,13 @@
       {
          // be sure the destination dir exists (case for Tree-style storage)
          file.getParentFile().mkdirs();
+         if (file.exists())
+         {
+            // The file still exists so either it is a file that could not be removed
+            // or it is a multi update use case, in both cases we will need
+            // to prevent the file cleaner to remove it
+            cleaner.removeFile(file);
+         }
          // write value to the file
          writeValue(file, value);
       }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java	2012-03-16 12:10:11 UTC (rev 5871)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/FileCleaner.java	2012-03-16 14:08:29 UTC (rev 5872)
@@ -129,7 +129,14 @@
       }
    }
 
-   @Override
+   /**
+    * @param file
+    */
+   public void removeFile(File file)
+   {
+      files.remove(file);
+   }
+   
    public void halt()
    {
       try

Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/jdbc-data-container-config.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/jdbc-data-container-config.xml	2012-03-16 12:10:11 UTC (rev 5871)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/configuration/jdbc-data-container-config.xml	2012-03-16 14:08:29 UTC (rev 5872)
@@ -7,244 +7,244 @@
   <title>JDBC Data Container Config</title>
 
   <para>eXo JCR persistent data container can work in two configuration
-    modes:<itemizedlist>
-        <listitem>
-          <para><phrase>Multi-database</phrase>: One database for each
-          workspace (used in standalone eXo JCR service mode)</para>
-        </listitem>
+  modes:<itemizedlist>
+      <listitem>
+        <para><phrase>Multi-database</phrase>: One database for each workspace
+        (used in standalone eXo JCR service mode)</para>
+      </listitem>
 
-        <listitem>
-          <para><phrase>Single-database</phrase>: All workspaces persisted in
-          one database (used in embedded eXo JCR service mode, e.g. in eXo
-          portal)</para>
-        </listitem>
-      </itemizedlist></para>
+      <listitem>
+        <para><phrase>Single-database</phrase>: All workspaces persisted in
+        one database (used in embedded eXo JCR service mode, e.g. in eXo
+        portal)</para>
+      </listitem>
+    </itemizedlist></para>
 
-    <para>The data container uses the JDBC driver to communicate with the
-    actual database software, i.e. any JDBC-enabled data storage can be used
-    with eXo JCR implementation.</para>
+  <para>The data container uses the JDBC driver to communicate with the actual
+  database software, i.e. any JDBC-enabled data storage can be used with eXo
+  JCR implementation.</para>
 
-    <para>Currently the data container is tested with the following
-    configurations:<itemizedlist>
-        <listitem>
-          <para>MySQL 5.0.18 MYSQL Connector/J 5.0.8</para>
-        </listitem>
+  <para>Currently the data container is tested with the following
+  configurations:<itemizedlist>
+      <listitem>
+        <para>MySQL 5.0.18 MYSQL Connector/J 5.0.8</para>
+      </listitem>
 
-        <listitem>
-          <para>MySQL 5.1.36 MYSQL Connector/J 5.1.14</para>
-        </listitem>
+      <listitem>
+        <para>MySQL 5.1.36 MYSQL Connector/J 5.1.14</para>
+      </listitem>
 
-        <listitem>
-          <para>PostgresSQL 8.2.4 JDBC4 Driver, Version 8.2-507</para>
-        </listitem>
+      <listitem>
+        <para>PostgresSQL 8.2.4 JDBC4 Driver, Version 8.2-507</para>
+      </listitem>
 
-        <listitem>
-          <para>PostgresSQL 8.3.7 JDBC4 Driver, Version 8.3-606</para>
-        </listitem>
+      <listitem>
+        <para>PostgresSQL 8.3.7 JDBC4 Driver, Version 8.3-606</para>
+      </listitem>
 
-        <listitem>
-          <para>Oracle DB 10g R2 (10.2.0.4), JDBC Driver Oracle 10g R2
-          (10.2.0.4)</para>
-        </listitem>
+      <listitem>
+        <para>Oracle DB 10g R2 (10.2.0.4), JDBC Driver Oracle 10g R2
+        (10.2.0.4)</para>
+      </listitem>
 
-        <listitem>
-          <para>Oracle DB 11g R1 (11.1.0.6.0), JDBC Driver Oracle 11g R1
-          (11.1.0.6.0)</para>
-        </listitem>
+      <listitem>
+        <para>Oracle DB 11g R1 (11.1.0.6.0), JDBC Driver Oracle 11g R1
+        (11.1.0.6.0)</para>
+      </listitem>
 
-        <listitem>
-          <para>Oracle DB 11g R2 (11.2.0.1.0), JDBC Driver Oracle 11g R2
-          (11.2.0.1.0)</para>
-        </listitem>
+      <listitem>
+        <para>Oracle DB 11g R2 (11.2.0.1.0), JDBC Driver Oracle 11g R2
+        (11.2.0.1.0)</para>
+      </listitem>
 
-        <listitem>
-          <para>DB2 9.7.4 IBM Data Server Driver for JDBC and SQLJ (JCC
-          Driver) v.9.7</para>
-        </listitem>
+      <listitem>
+        <para>DB2 9.7.4 IBM Data Server Driver for JDBC and SQLJ (JCC Driver)
+        v.9.7</para>
+      </listitem>
 
-        <listitem>
-          <para>MS SQL Server 2005 SP3 JDBC Driver 3.0</para>
-        </listitem>
+      <listitem>
+        <para>MS SQL Server 2005 SP3 JDBC Driver 3.0</para>
+      </listitem>
 
-        <listitem>
-          <para>MS SQL Server 2008 JDBC Driver 3.0</para>
-        </listitem>
+      <listitem>
+        <para>MS SQL Server 2008 JDBC Driver 3.0</para>
+      </listitem>
 
-        <listitem>
-          <para>Sybase 15.0.3 ASE Driver: Sybase jConnect JDBC driver v7
-          (Build 26502)</para>
-        </listitem>
+      <listitem>
+        <para>Sybase 15.0.3 ASE Driver: Sybase jConnect JDBC driver v7 (Build
+        26502)</para>
+      </listitem>
 
-        <listitem>
-          <para>HSQLDB (2.0.0)</para>
-        </listitem>
-      </itemizedlist></para>
+      <listitem>
+        <para>HSQLDB (2.0.0)</para>
+      </listitem>
+    </itemizedlist></para>
 
-    <para>Each database software supports ANSI SQL standards but also has its
-    own specifics. So, each database has its own configuration in eXo JCR as a
-    database dialect parameter. If you need a more detailed configuration of
-    the database, it's possible to do that by editing the metadata SQL-script
-    files.</para>
+  <para>Each database software supports ANSI SQL standards but also has its
+  own specifics. So, each database has its own configuration in eXo JCR as a
+  database dialect parameter. If you need a more detailed configuration of the
+  database, it's possible to do that by editing the metadata SQL-script
+  files.</para>
 
-    <para>SQL-scripts you can obtain from jar-file
-    exo.jcr.component.core-XXX.XXX.jar:conf/storage/. They also can be found
-    at SVN <ulink
-    url="https://anonsvn.jboss.org/repos/exo-jcr/jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/">here.</ulink></para>
+  <para>SQL-scripts you can obtain from jar-file
+  exo.jcr.component.core-XXX.XXX.jar:conf/storage/. They also can be found at
+  SVN <ulink
+  url="https://anonsvn.jboss.org/repos/exo-jcr/jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/">here.</ulink></para>
 
-    <para>In the next two tables correspondence between the scripts and
-    databases is shown.</para>
+  <para>In the next two tables correspondence between the scripts and
+  databases is shown.</para>
 
-    <table border="1">
-      <caption>Single-database</caption>
+  <table border="1">
+    <caption>Single-database</caption>
 
-      <tr>
-        <td>MySQL DB</td>
+    <tr>
+      <td>MySQL DB</td>
 
-        <td>jcr-sjdbc.mysql.sql</td>
-      </tr>
+      <td>jcr-sjdbc.mysql.sql</td>
+    </tr>
 
-      <tr>
-        <td>MySQL DB with utf-8</td>
+    <tr>
+      <td>MySQL DB with utf-8</td>
 
-        <td>jcr-sjdbc.mysql-utf8.sql</td>
-      </tr>
+      <td>jcr-sjdbc.mysql-utf8.sql</td>
+    </tr>
 
-      <tr>
-        <td>MySQL DB with MyISAM*</td>
+    <tr>
+      <td>MySQL DB with MyISAM*</td>
 
-        <td>jcr-sjdbc.mysql-myisam.sql</td>
-      </tr>
+      <td>jcr-sjdbc.mysql-myisam.sql</td>
+    </tr>
 
-      <tr>
-        <td>MySQL DB with MyISAM and utf-8*</td>
+    <tr>
+      <td>MySQL DB with MyISAM and utf-8*</td>
 
-        <td>jcr-sjdbc.mysql-myisam-utf8.sql</td>
-      </tr>
+      <td>jcr-sjdbc.mysql-myisam-utf8.sql</td>
+    </tr>
 
-      <tr>
-        <td>PostgresSQL</td>
+    <tr>
+      <td>PostgresSQL</td>
 
-        <td>jcr-sjdbc.pqsql.sql</td>
-      </tr>
+      <td>jcr-sjdbc.pqsql.sql</td>
+    </tr>
 
-      <tr>
-        <td>Oracle DB</td>
+    <tr>
+      <td>Oracle DB</td>
 
-        <td>jcr-sjdbc.ora.sql</td>
-      </tr>
+      <td>jcr-sjdbc.ora.sql</td>
+    </tr>
 
-      <tr>
-        <td>DB2</td>
+    <tr>
+      <td>DB2</td>
 
-        <td>jcr-sjdbc.db2.sql</td>
-      </tr>
+      <td>jcr-sjdbc.db2.sql</td>
+    </tr>
 
-      <tr>
-        <td>MS SQL Server</td>
+    <tr>
+      <td>MS SQL Server</td>
 
-        <td>jcr-sjdbc.mssql.sql</td>
-      </tr>
+      <td>jcr-sjdbc.mssql.sql</td>
+    </tr>
 
-      <tr>
-        <td>Sybase</td>
+    <tr>
+      <td>Sybase</td>
 
-        <td>jcr-sjdbc.sybase.sql</td>
-      </tr>
+      <td>jcr-sjdbc.sybase.sql</td>
+    </tr>
 
-      <tr>
-        <td>HSQLDB</td>
+    <tr>
+      <td>HSQLDB</td>
 
-        <td>jcr-sjdbc.sql</td>
-      </tr>
-    </table>
+      <td>jcr-sjdbc.sql</td>
+    </tr>
+  </table>
 
-    <table border="1">
-      <caption>Multi-database</caption>
+  <table border="1">
+    <caption>Multi-database</caption>
 
-      <tr>
-        <td>MySQL DB</td>
+    <tr>
+      <td>MySQL DB</td>
 
-        <td>jcr-mjdbc.mysql.sql</td>
-      </tr>
+      <td>jcr-mjdbc.mysql.sql</td>
+    </tr>
 
-      <tr>
-        <td>MySQL DB with utf-8</td>
+    <tr>
+      <td>MySQL DB with utf-8</td>
 
-        <td>jcr-mjdbc.mysql-utf8.sql</td>
-      </tr>
+      <td>jcr-mjdbc.mysql-utf8.sql</td>
+    </tr>
 
-      <tr>
-        <td>MySQL DB with MyISAM*</td>
+    <tr>
+      <td>MySQL DB with MyISAM*</td>
 
-        <td>jcr-mjdbc.mysql-myisam.sql</td>
-      </tr>
+      <td>jcr-mjdbc.mysql-myisam.sql</td>
+    </tr>
 
-      <tr>
-        <td>MySQL DB with MyISAM and utf-8*</td>
+    <tr>
+      <td>MySQL DB with MyISAM and utf-8*</td>
 
-        <td>jcr-mjdbc.mysql-myisam-utf8.sql</td>
-      </tr>
+      <td>jcr-mjdbc.mysql-myisam-utf8.sql</td>
+    </tr>
 
-      <tr>
-        <td>PostgresSQL</td>
+    <tr>
+      <td>PostgresSQL</td>
 
-        <td>jcr-mjdbc.pqsql.sql</td>
-      </tr>
+      <td>jcr-mjdbc.pqsql.sql</td>
+    </tr>
 
-      <tr>
-        <td>Oracle DB</td>
+    <tr>
+      <td>Oracle DB</td>
 
-        <td>jcr-mjdbc.ora.sql</td>
-      </tr>
+      <td>jcr-mjdbc.ora.sql</td>
+    </tr>
 
-      <tr>
-        <td>DB2</td>
+    <tr>
+      <td>DB2</td>
 
-        <td>jcr-mjdbc.db2.sql</td>
-      </tr>
+      <td>jcr-mjdbc.db2.sql</td>
+    </tr>
 
-      <tr>
-        <td>MS SQL Server</td>
+    <tr>
+      <td>MS SQL Server</td>
 
-        <td>jcr-mjdbc.mssql.sql</td>
-      </tr>
+      <td>jcr-mjdbc.mssql.sql</td>
+    </tr>
 
-      <tr>
-        <td>Sybase</td>
+    <tr>
+      <td>Sybase</td>
 
-        <td>jcr-mjdbc.sybase.sql</td>
-      </tr>
+      <td>jcr-mjdbc.sybase.sql</td>
+    </tr>
 
-      <tr>
-        <td>HSQLDB</td>
+    <tr>
+      <td>HSQLDB</td>
 
-        <td>jcr-mjdbc.sql</td>
-      </tr>
-    </table>
+      <td>jcr-mjdbc.sql</td>
+    </tr>
+  </table>
 
-    <para>In case the non-ANSI node name is used, it's necessary to use a
-    database with MultiLanguage support[TODO link to MultiLanguage]. Some JDBC
-    drivers need additional parameters for establishing a Unicode friendly
-    connection. E.g. under mysql it's necessary to add an additional parameter
-    for the JDBC driver at the end of JDBC URL. For instance:
-    <code>jdbc:mysql://exoua.dnsalias.net/portal?characterEncoding=utf8</code></para>
+  <para>In case the non-ANSI node name is used, it's necessary to use a
+  database with MultiLanguage support[TODO link to MultiLanguage]. Some JDBC
+  drivers need additional parameters for establishing a Unicode friendly
+  connection. E.g. under mysql it's necessary to add an additional parameter
+  for the JDBC driver at the end of JDBC URL. For instance:
+  <code>jdbc:mysql://exoua.dnsalias.net/portal?characterEncoding=utf8</code></para>
 
-    <para>There are preconfigured configuration files for HSQLDB. Look for
-    these files in /conf/portal and /conf/standalone folders of the jar-file
-    <package>exo.jcr.component.core-XXX.XXX.jar</package> or
-    source-distribution of eXo JCR implementation.</para>
+  <para>There are preconfigured configuration files for HSQLDB. Look for these
+  files in /conf/portal and /conf/standalone folders of the jar-file
+  <package>exo.jcr.component.core-XXX.XXX.jar</package> or source-distribution
+  of eXo JCR implementation.</para>
 
-    <para>By default, the configuration files are located in service jars
-    <filename>/conf/portal/configuration.xml</filename> (eXo services
-    including JCR Repository Service) and
-    <filename>exo-jcr-config.xml</filename> (repositories configuration). In
-    eXo portal product, JCR is configured in portal web application
-    <filename>portal/WEB-INF/conf/jcr/jcr-configuration.xml</filename> (JCR
-    Repository Service and related serivces) and repository-configuration.xml
-    (repositories configuration).</para>
+  <para>By default, the configuration files are located in service jars
+  <filename>/conf/portal/configuration.xml</filename> (eXo services including
+  JCR Repository Service) and <filename>exo-jcr-config.xml</filename>
+  (repositories configuration). In eXo portal product, JCR is configured in
+  portal web application
+  <filename>portal/WEB-INF/conf/jcr/jcr-configuration.xml</filename> (JCR
+  Repository Service and related serivces) and repository-configuration.xml
+  (repositories configuration).</para>
 
-    <para>Read more about <link linkend="JCR.eXoJCRconfiguration">Repository
-    configuration</link>.</para>
+  <para>Read more about <link linkend="JCR.eXoJCRconfiguration">Repository
+  configuration</link>.</para>
 
   <section>
     <title>General recommendations for database configuration</title>
@@ -292,11 +292,23 @@
 
       <itemizedlist>
         <listitem>
+          <para>To prevent any consistency issues please ensure that InnoDB is
+          configured as default MySQL engine (instead of MyISAM by default)
+          before launching your application for the very first time otherwise
+          when the application will create the tables MyISAM will be used as
+          MySQL engine which is a non transactional engine that doesn't not
+          support integrity constraints so even if later you swicth to InnoDB
+          using an alter table all the integrity constraints would be missing
+          as they would have been removed at table creation table by
+          MyISAM.</para>
+        </listitem>
+
+        <listitem>
           <para>MyISAM is not supported due to its lack of transaction support
           and integrity check, so use it only if you don't expect any support
           and if performances in read accesses are more important than the
-          consistency in your use-case. This dialect is only dedicated to the
-          community.</para>
+          consistency in your use-case. Therefore the dialects mysql-myisam
+          and mysql-myisam-utf8 are only dedicated to the community.</para>
         </listitem>
 
         <listitem>



More information about the exo-jcr-commits mailing list