camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r826686 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/component/file/strategy/ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/came...
Date Mon, 19 Oct 2009 14:27:53 GMT
Author: davsclaus
Date: Mon Oct 19 14:27:53 2009
New Revision: 826686

URL: http://svn.apache.org/viewvc?rev=826686&view=rev
Log:
CAMEL-2058: File operations on Windows uses retry to work around issues on this platform.

Added:
    camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/QueryBuilderTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileBigFileCopyManually.java
    camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/QueryBuilder.java
    camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
Mon Oct 19 14:27:53 2009
@@ -29,6 +29,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -53,72 +54,13 @@
 
     public boolean deleteFile(String name) throws GenericFileOperationFailedException { 
      
         File file = new File(name);
-
-        // do not try to delete non existing files
-        if (!file.exists()) {
-            return false;
-        }
-
-        // some OS such as Windows can have problem doing delete IO operations so we may
need to
-        // retry a couple of times to let it work
-        boolean deleted = false;
-        int count = 0;
-        while (!deleted && count < 3) {
-            if (LOG.isDebugEnabled() && count > 0) {
-                LOG.debug("Retrying attempt " + count + " to delete file: " + name);
-            }
-
-            deleted = file.delete();
-            if (!deleted && count > 0) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException e) {
-                    // ignore
-                }
-            }
-            count++;
-        }
-
-
-        if (LOG.isDebugEnabled() && count > 0) {
-            LOG.debug("Tried " + count + " to delete file: " + name + " with result: " +
deleted);
-        }
-        return deleted;
+        return FileUtil.deleteFile(file);
     }
 
     public boolean renameFile(String from, String to) throws GenericFileOperationFailedException
{
         File file = new File(from);
         File target = new File(to);
-
-        // do not try to rename non existing files
-        if (!file.exists()) {
-            return false;
-        }
-
-        // some OS such as Windows can have problem doing rename IO operations so we may
need to
-        // retry a couple of times to let it work
-        boolean renamed = false;
-        int count = 0;
-        while (!renamed && count < 3) {
-            if (LOG.isDebugEnabled() && count > 0) {
-                LOG.debug("Retrying attempt " + count + " to rename file from: " + from +
" to: " + to);
-            }
-
-            renamed = file.renameTo(target);
-            if (!renamed && count > 0) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException e) {
-                    // ignore
-                }
-            }
-            count++;
-        }
-
-        if (LOG.isDebugEnabled() && count > 0) {
-            LOG.debug("Tried " + count + " to rename file: " + from + " to: " + to + " with
result: " + renamed);
-        }
-        return renamed;
+        return FileUtil.renameFile(file, target);
     }
 
     public boolean existsFile(String name) throws GenericFileOperationFailedException {
@@ -204,7 +146,7 @@
 
         File file = new File(fileName);
 
-        // if an existing file already exsists what should we do?
+        // if an existing file already exists what should we do?
         if (file.exists()) {
             if (endpoint.getFileExist() == GenericFileExist.Ignore) {
                 // ignore but indicate that the file was written
@@ -267,7 +209,8 @@
         if (LOG.isTraceEnabled()) {
             LOG.trace("Using local work file being renamed from: " + source + " to: " + file);
         }
-        return source.renameTo(file);
+
+        return FileUtil.renameFile(source, file);
     }
 
     private void writeFileByFile(File source, File target) throws IOException {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileOperations.java
Mon Oct 19 14:27:53 2009
@@ -63,7 +63,7 @@
      *
      * @param directory the directory path to build as a relative string name
      * @param absolute wether the directory is an absolute or relative path
-     * @return true if build or already exists, false if not possbile (could be lack of permissions)
+     * @return true if build or already exists, false if not possible (could be lack of permissions)
      * @throws GenericFileOperationFailedException can be thrown
      */
     boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileProcessStrategySupport.java
Mon Oct 19 14:27:53 2009
@@ -24,6 +24,7 @@
 import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
 import org.apache.camel.component.file.GenericFileOperations;
 import org.apache.camel.component.file.GenericFileProcessStrategy;
+import org.apache.camel.util.FileUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -32,11 +33,11 @@
     protected GenericFileExclusiveReadLockStrategy<T> exclusiveReadLockStrategy;
 
     public boolean begin(GenericFileOperations<T> operations, GenericFileEndpoint<T>
endpoint, Exchange exchange, GenericFile<T> file) throws Exception {
-        // is we use excluse read then acquire the exclusive read (waiting until we got it)
+        // if we use exclusive read then acquire the exclusive read (waiting until we got
it)
         if (exclusiveReadLockStrategy != null) {
             boolean lock = exclusiveReadLockStrategy.acquireExclusiveReadLock(operations,
file, exchange);
             if (!lock) {
-                // do not begin sice we could not get the exclusive read lcok
+                // do not begin since we could not get the exclusive read lock
                 return false;
             }
         }
@@ -72,7 +73,7 @@
         // delete local work file, if it was used (eg by ftp component)
         File local = exchange.getIn().getHeader(Exchange.FILE_LOCAL_WORK_PATH, File.class);
         if (local != null && local.exists()) {
-            boolean deleted = local.delete();
+            boolean deleted = FileUtil.deleteFile(local);
             if (log.isTraceEnabled()) {
                 log.trace("Local work file: " + local + " was deleted: " + deleted);
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
Mon Oct 19 14:27:53 2009
@@ -24,6 +24,7 @@
 import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy;
 import org.apache.camel.component.file.GenericFileOperations;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.FileUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -64,7 +65,7 @@
             LOG.trace("Unlocking file: " + lockFileName);
         }
 
-        boolean deleted = lock.delete();
+        boolean deleted = FileUtil.deleteFile(lock);
         if (LOG.isTraceEnabled()) {
             LOG.trace("Lock file: " + lockFileName + " was deleted: " + deleted);
         }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java Mon Oct 19 14:27:53
2009
@@ -23,11 +23,15 @@
 import java.util.Random;
 import java.util.Stack;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * File utilities
  */
 public final class FileUtil {
     
+    private static final transient Log LOG = LogFactory.getLog(FileUtil.class);
     private static final int RETRY_SLEEP_MILLIS = 10;
     private static File defaultTempDir;
 
@@ -260,4 +264,70 @@
         }
     }
 
+    public static boolean renameFile(File from, File to) {
+        // do not try to rename non existing files
+        if (!from.exists()) {
+            return false;
+        }
+
+        // some OS such as Windows can have problem doing rename IO operations so we may
need to
+        // retry a couple of times to let it work
+        boolean renamed = false;
+        int count = 0;
+        while (!renamed && count < 3) {
+            if (LOG.isDebugEnabled() && count > 0) {
+                LOG.debug("Retrying attempt " + count + " to rename file from: " + from +
" to: " + to);
+            }
+
+            renamed = from.renameTo(to);
+            if (!renamed && count > 0) {
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    // ignore
+                }
+            }
+            count++;
+        }
+
+        if (LOG.isDebugEnabled() && count > 0) {
+            LOG.debug("Tried " + count + " to rename file: " + from + " to: " + to + " with
result: " + renamed);
+        }
+        return renamed;
+    }
+
+    public static boolean deleteFile(File file) {
+        // do not try to delete non existing files
+        if (!file.exists()) {
+            return false;
+        }
+
+        // some OS such as Windows can have problem doing delete IO operations so we may
need to
+        // retry a couple of times to let it work
+        boolean deleted = false;
+        int count = 0;
+        while (!deleted && count < 3) {
+            if (LOG.isDebugEnabled() && count > 0) {
+                LOG.debug("Retrying attempt " + count + " to delete file: " + file);
+            }
+
+            deleted = file.delete();
+            if (!deleted && count > 0) {
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    // ignore
+                }
+            }
+            count++;
+        }
+
+
+        if (LOG.isDebugEnabled() && count > 0) {
+            LOG.debug("Tried " + count + " to delete file: " + file + " with result: " +
deleted);
+        }
+        return deleted;
+    }
+
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileBigFileCopyManually.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileBigFileCopyManually.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileBigFileCopyManually.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileBigFileCopyManually.java
Mon Oct 19 14:27:53 2009
@@ -22,7 +22,7 @@
 
 /**
  * A manual test by copying a big file into the target/big/in folder and check
- * that it is copied completly, eg its file size is the same as the original file
+ * that it is copied completely, eg its file size is the same as the original file
  *
  * @version $Revision$
  */

Modified: camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/QueryBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/QueryBuilder.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/QueryBuilder.java
(original)
+++ camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/QueryBuilder.java
Mon Oct 19 14:27:53 2009
@@ -46,7 +46,7 @@
 
             @Override
             public String toString() {
-                return "Query: " + query + " params: " + getParameterDescription();
+                return "Query: " + query + getParameterDescription();
             }
         };
     }

Modified: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java?rev=826686&r1=826685&r2=826686&view=diff
==============================================================================
--- camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
(original)
+++ camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaWithNamedQueryTest.java
Mon Oct 19 14:27:53 2009
@@ -133,6 +133,9 @@
                 return null;
             }
         });
+
+        JpaConsumer jpaConsumer = (JpaConsumer) consumer;
+        assertEquals("step1", jpaConsumer.getNamedQuery());
     }
 
     @Before

Added: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/QueryBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/QueryBuilderTest.java?rev=826686&view=auto
==============================================================================
--- camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/QueryBuilderTest.java
(added)
+++ camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/QueryBuilderTest.java
Mon Oct 19 14:27:53 2009
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jpa;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class QueryBuilderTest extends CamelTestSupport {
+
+    @Test
+    public void testQueryBuilder() throws Exception {
+        QueryBuilder q = QueryBuilder.query("select x from SendEmail x");
+        assertNotNull(q);
+        assertEquals("Query: select x from SendEmail x", q.toString());
+    }
+
+    @Test
+    public void testNamedQueryBuilder() throws Exception {
+        QueryBuilder q = QueryBuilder.namedQuery("step1");
+        assertNotNull(q);
+        assertEquals("Named: step1", q.toString());
+    }
+
+    @Test
+    public void testNativeQueryBuilder() throws Exception {
+        QueryBuilder q = QueryBuilder.nativeQuery("select count(*) from SendEmail");
+        assertNotNull(q);
+        assertEquals("NativeQuery: select count(*) from SendEmail", q.toString());
+    }
+
+    @Test
+    public void testQueryBuilderWithParameters() throws Exception {
+        QueryBuilder q = QueryBuilder.query("select x from SendEmail x where x.id = :a");
+        assertNotNull(q);
+        q.parameters(1);
+        assertEquals("Query: select x from SendEmail x where x.id = :a Parameters: [1]",
q.toString());
+    }
+
+    @Test
+    public void testQueryBuilderWithParametersMap() throws Exception {
+        QueryBuilder q = QueryBuilder.query("select x from SendEmail x where x.id = :a");
+        assertNotNull(q);
+        Map map = new HashMap();
+        map.put("a", 1);
+        q.parameters(map);
+        assertEquals("Query: select x from SendEmail x where x.id = :a Parameters: {a=1}",
q.toString());
+    }
+
+
+}

Propchange: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/QueryBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/QueryBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message