camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/5] camel git commit: CAMEL-7999: More components include documentation
Date Fri, 02 Jan 2015 10:08:41 GMT
CAMEL-7999: More components include documentation


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b7a803d9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b7a803d9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b7a803d9

Branch: refs/heads/master
Commit: b7a803d9d745b92d660b3ff9f0571cb7303245ef
Parents: 6a7773e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Jan 2 10:46:30 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jan 2 10:46:30 2015 +0100

----------------------------------------------------------------------
 .../camel/component/ibatis/IBatisComponent.java |  7 +-
 .../camel/component/ibatis/IBatisEndpoint.java  | 36 +++++--
 .../IBatisBatchConsumerIsolationLevelTest.java  | 99 --------------------
 3 files changed, 33 insertions(+), 109 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b7a803d9/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java
b/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java
index 8e8fdcb..0d5f63c 100644
--- a/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java
+++ b/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java
@@ -22,7 +22,7 @@ import java.util.Map;
 
 import com.ibatis.sqlmap.client.SqlMapClient;
 import com.ibatis.sqlmap.client.SqlMapClientBuilder;
-import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.UriEndpointComponent;
 import org.apache.camel.util.ResourceHelper;
 
 /**
@@ -57,22 +57,25 @@ import org.apache.camel.util.ResourceHelper;
  * @see IBatisProducer
  * @see IBatisConsumer
  */
-public class IBatisComponent extends DefaultComponent {
+public class IBatisComponent extends UriEndpointComponent {
     private static final String DEFAULT_CONFIG_URI = "classpath:SqlMapConfig.xml";
     private SqlMapClient sqlMapClient;
     private String sqlMapConfig = DEFAULT_CONFIG_URI;
     private boolean useTransactions = true;
 
     public IBatisComponent() {
+        super(IBatisEndpoint.class);
     }
 
     public IBatisComponent(SqlMapClient sqlMapClient) {
+        this();
         this.sqlMapClient = sqlMapClient;
     }
 
     @Override
     protected IBatisEndpoint createEndpoint(String uri, String remaining, Map<String,
Object> parameters) throws Exception {
         IBatisEndpoint answer = new IBatisEndpoint(uri, this, remaining);
+        answer.setUseTransactions(isUseTransactions());
         setProperties(answer, parameters);
         return answer;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/b7a803d9/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
b/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
index 474b244..bfe88e6 100644
--- a/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
+++ b/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.ibatis;
 
 import java.io.IOException;
+
 import com.ibatis.sqlmap.client.SqlMapClient;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
@@ -24,18 +25,29 @@ import org.apache.camel.component.ibatis.strategy.DefaultIBatisProcessingStategy
 import org.apache.camel.component.ibatis.strategy.IBatisProcessingStrategy;
 import org.apache.camel.component.ibatis.strategy.TransactionIsolationLevel;
 import org.apache.camel.impl.DefaultPollingEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
 import org.apache.camel.util.ObjectHelper;
 
 /**
  * An <a href="http://camel.apache.org/ibatis.html>iBatis Endpoint</a>
  * for performing SQL operations using an XML mapping file to abstract away the SQL
  */
+@UriEndpoint(scheme = "ibatis", consumerClass = IBatisConsumer.class, label = "database")
 public class IBatisEndpoint extends DefaultPollingEndpoint {
-    private IBatisProcessingStrategy strategy;
-    private boolean useTransactions;
+    @UriPath
     private String statement;
+    @UriParam(defaultValue = "false")
+    private boolean useTransactions;
+    @UriParam
     private StatementType statementType;
+    @UriParam
     private int maxMessagesPerPoll;
+    @UriParam
+    private IBatisProcessingStrategy strategy;
+    @UriParam
+    private String isolation;
 
     public IBatisEndpoint() {
     }
@@ -79,9 +91,6 @@ public class IBatisEndpoint extends DefaultPollingEndpoint {
      * Gets the IbatisProcessingStrategy to to use when consuming messages from the database
      */
     public IBatisProcessingStrategy getProcessingStrategy() throws Exception {
-        if (strategy == null) {
-            strategy = new DefaultIBatisProcessingStategy();
-        }
         return strategy;
     }
 
@@ -134,12 +143,23 @@ public class IBatisEndpoint extends DefaultPollingEndpoint {
         this.maxMessagesPerPoll = maxMessagesPerPoll;
     }
 
-
     public String getIsolation() throws Exception {
-        return TransactionIsolationLevel.nameOf(strategy.getIsolation());
+        return isolation;
     }
 
     public void setIsolation(String isolation) throws Exception {
-        strategy.setIsolation(TransactionIsolationLevel.intValueOf(isolation));
+        this.isolation = isolation;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        if (strategy == null) {
+            strategy = new DefaultIBatisProcessingStategy();
+        }
+        if (isolation != null) {
+            strategy.setIsolation(TransactionIsolationLevel.intValueOf(isolation));
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b7a803d9/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisBatchConsumerIsolationLevelTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisBatchConsumerIsolationLevelTest.java
b/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisBatchConsumerIsolationLevelTest.java
deleted file mode 100644
index c8bfa8b..0000000
--- a/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisBatchConsumerIsolationLevelTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * 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.ibatis;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.ibatis.strategy.IBatisProcessingStrategy;
-import org.apache.camel.component.ibatis.strategy.TransactionIsolationLevel;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-
-public class IBatisBatchConsumerIsolationLevelTest extends IBatisTestSupport {
-
-    IBatisProcessingStrategy strategyMock = createMock(IBatisProcessingStrategy.class);
-
-    protected boolean createTestData() {
-        return false;
-    }
-
-    protected String getStatement() {
-        return "create table ACCOUNT ( ACC_ID INTEGER , ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME
VARCHAR(255), ACC_EMAIL VARCHAR(255), PROCESSED BOOLEAN DEFAULT false)";
-    }
-
-    @Test
-    public void testConsumeWithIsolation() throws Exception {
-        Account account1 = new Account();
-        account1.setId(1);
-        account1.setFirstName("Bob");
-        account1.setLastName("Denver");
-        account1.setEmailAddress("TryGuessingGilligan@gmail.com");
-
-        Account account2 = new Account();
-        account2.setId(2);
-        account2.setFirstName("Alan");
-        account2.setLastName("Hale");
-        account2.setEmailAddress("TryGuessingSkipper@gmail.com");
-
-        List<Object> accounts = new ArrayList<Object>();
-        accounts.add(account1);
-        accounts.add(account2);
-
-        strategyMock.setIsolation(TransactionIsolationLevel.TRANSACTION_READ_COMMITTED.getValue());
-        expectLastCall().once();
-
-        expect(strategyMock.poll(EasyMock.<IBatisConsumer>anyObject(), EasyMock.<IBatisEndpoint>anyObject())).andReturn(accounts).atLeastOnce();
-
-        strategyMock.commit(EasyMock.<IBatisEndpoint>anyObject(), EasyMock.<Exchange>anyObject(),
anyObject(), EasyMock.<String>anyObject());
-        expectLastCall().atLeastOnce();
-        replay(strategyMock);
-
-        IBatisEndpoint iBatisEndpoint = resolveMandatoryEndpoint("ibatis:selectUnprocessedAccounts?consumer.onConsume=consumeAccount",
IBatisEndpoint.class);
-        iBatisEndpoint.setStrategy(strategyMock);
-        iBatisEndpoint.setIsolation("TRANSACTION_READ_COMMITTED");
-
-
-        template.sendBody("direct:start", account1);
-        template.sendBody("direct:start", account2);
-        //We need to wait for the batch process to complete.
-        Thread.sleep(1000);
-        verify(strategyMock);
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            public void configure() throws Exception {
-                // START SNIPPET: e1
-                from("ibatis:selectUnprocessedAccounts?consumer.onConsume=consumeAccount").to("mock:results");
-                // END SNIPPET: e1
-
-                from("direct:start").to("ibatis:insertAccount?statementType=Insert");
-            }
-        };
-    }
-}
\ No newline at end of file


Mime
View raw message