You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/09/07 21:59:12 UTC
svn commit: r573683 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/util/ components/
components/camel-ibatis/src/main/java/org/
components/camel-ibatis/src/main/java/org/apache/
components/camel-ibatis/src/main/java/org/apache/ca...
Author: jstrachan
Date: Fri Sep 7 12:59:10 2007
New Revision: 573683
URL: http://svn.apache.org/viewvc?rev=573683&view=rev
Log:
added suppor for iBatis for CAMEL-139
Added:
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java (with props)
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java (with props)
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java (with props)
activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java (with props)
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/LICENSE.txt
- copied unchanged from r572881, activemq/camel/trunk/components/camel-jdbc/src/main/resources/META-INF/LICENSE.txt
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/NOTICE.txt
- copied unchanged from r572881, activemq/camel/trunk/components/camel-jdbc/src/main/resources/META-INF/NOTICE.txt
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/camel/
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/camel/component/
activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/camel/component/ibatis
- copied, changed from r572881, activemq/camel/trunk/components/camel-jdbc/src/main/resources/META-INF/services/org/apache/camel/component/jdbc
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/Account.java (with props)
activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java (with props)
activemq/camel/trunk/components/camel-ibatis/src/test/resources/SqlMapConfig.xml (with props)
activemq/camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties (with props)
activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/
activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/
activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/
activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/
activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/
activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
activemq/camel/trunk/components/pom.xml
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=573683&r1=573682&r2=573683&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Fri Sep 7 12:59:10 2007
@@ -94,6 +94,18 @@
* Returns the mandatory inbound message body of the correct type or throws
* an exception if it is not present
*/
+ public static Object getMandatoryInBody(Exchange exchange) throws InvalidPayloadException {
+ Object answer = exchange.getIn().getBody();
+ if (answer == null) {
+ throw new InvalidPayloadException(exchange, Object.class);
+ }
+ return answer;
+ }
+
+ /**
+ * Returns the mandatory inbound message body of the correct type or throws
+ * an exception if it is not present
+ */
public static <T> T getMandatoryInBody(Exchange exchange, Class<T> type) throws InvalidPayloadException {
T answer = exchange.getIn().getBody(type);
if (answer == null) {
Added: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java Fri Sep 7 12:59:10 2007
@@ -0,0 +1,88 @@
+/**
+ *
+ * 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.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import com.ibatis.sqlmap.client.SqlMapClient;
+import com.ibatis.sqlmap.client.SqlMapClientBuilder;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+/**
+ * An <a href="http://activemq.apache.org/camel/ibatis.html>iBatis Component</a>
+ * for performing SQL operations using an XML mapping file to abstract away the SQL
+ *
+ * @version $Revision: 1.1 $
+ */
+public class IBatisComponent extends DefaultComponent {
+ private static final transient Log LOG = LogFactory.getLog(IBatisComponent.class);
+
+ public static final String DEFAULT_CONFIG_URI = "SqlMapConfig.xml";
+ private SqlMapClient sqlMapClient;
+ private Resource sqlMapResource;
+
+ public IBatisComponent() {
+ }
+
+ public IBatisComponent(SqlMapClient sqlMapClient) {
+ this.sqlMapClient = sqlMapClient;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public SqlMapClient getSqlMapClient() throws IOException {
+ if (sqlMapClient == null) {
+ sqlMapClient = createSqlMapClient();
+ }
+ return sqlMapClient;
+ }
+
+ public void setSqlMapClient(SqlMapClient sqlMapClient) {
+ this.sqlMapClient = sqlMapClient;
+ }
+
+ public Resource getSqlMapResource() {
+ if (sqlMapResource == null) {
+ sqlMapResource = new ClassPathResource(DEFAULT_CONFIG_URI);
+ LOG.debug("Defaulting to use the iBatis configuration from: " + sqlMapResource);
+ }
+ return sqlMapResource;
+ }
+
+ public void setSqlMapResource(Resource sqlMapResource) {
+ this.sqlMapResource = sqlMapResource;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+ return new IBatisEndpoint(uri, this, remaining);
+ }
+
+ protected SqlMapClient createSqlMapClient() throws IOException {
+ InputStream in = getSqlMapResource().getInputStream();
+ return SqlMapClientBuilder.buildSqlMapClient(in);
+ }
+}
Propchange: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java Fri Sep 7 12:59:10 2007
@@ -0,0 +1,69 @@
+/**
+ *
+ * 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.io.IOException;
+
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultPollingEndpoint;
+import com.ibatis.sqlmap.client.SqlMapClient;
+
+/**
+ * An <a href="http://activemq.apache.org/camel/ibatis.html>iBatis Endpoint</a>
+ * for performing SQL operations using an XML mapping file to abstract away the SQL
+ *
+ * @version $Revision: 1.1 $
+ */
+public class IBatisEndpoint extends DefaultPollingEndpoint {
+ private final String entityName;
+
+ public IBatisEndpoint(String endpointUri, IBatisComponent component, String entityName) {
+ super(endpointUri, component);
+ this.entityName = entityName;
+ }
+
+ @Override
+ public IBatisComponent getComponent() {
+ return (IBatisComponent) super.getComponent();
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public Producer createProducer() throws Exception {
+ return new IBatisProducer(this);
+ }
+
+ @Override
+ public PollingConsumer createPollingConsumer() throws Exception {
+ return new IBatisPollingConsumer(this);
+ }
+
+ /**
+ * Returns the iBatis SQL client
+ */
+ public SqlMapClient getSqlClient() throws IOException {
+ return getComponent().getSqlMapClient();
+ }
+
+ public String getEntityName() {
+ return entityName;
+ }
+}
Propchange: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java Fri Sep 7 12:59:10 2007
@@ -0,0 +1,73 @@
+/**
+ *
+ * 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.sql.SQLException;
+import java.util.List;
+
+import com.ibatis.sqlmap.client.SqlMapClient;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.PollingConsumerSupport;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class IBatisPollingConsumer extends PollingConsumerSupport {
+ private final IBatisEndpoint endpoint;
+ private SqlMapClient sqlClient;
+ private String queryName;
+
+ public IBatisPollingConsumer(IBatisEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ queryName = endpoint.getEntityName();
+ }
+
+ public Exchange receive(long timeout) {
+ return receiveNoWait();
+ }
+
+ public Exchange receive() {
+ return receiveNoWait();
+ }
+
+ public Exchange receiveNoWait() {
+ try {
+ if (sqlClient == null) {
+ sqlClient = endpoint.getSqlClient();
+ }
+ List list = sqlClient.queryForList(queryName);
+ Exchange exchange = endpoint.createExchange();
+ Message in = exchange.getIn();
+ in.setBody(list);
+ in.setHeader("org.apache.camel.ibatis.queryName", queryName);
+ return exchange;
+ }
+ catch (Exception e) {
+ throw new RuntimeCamelException("Failed to poll: " + endpoint + ". Reason: " + e, e);
+ }
+ }
+
+ protected void doStart() throws Exception {
+ }
+
+ protected void doStop() throws Exception {
+ }
+}
Propchange: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisPollingConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java Fri Sep 7 12:59:10 2007
@@ -0,0 +1,57 @@
+/**
+ *
+ * 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 com.ibatis.sqlmap.client.SqlMapClient;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ExchangeHelper;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class IBatisProducer extends DefaultProducer {
+ private SqlMapClient sqlClient;
+ private final IBatisEndpoint endpoint;
+
+ public IBatisProducer(IBatisEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ }
+
+ @Override
+ public IBatisEndpoint getEndpoint() {
+ return (IBatisEndpoint) super.getEndpoint();
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ if (sqlClient == null) {
+ sqlClient = endpoint.getSqlClient();
+ }
+ Object body = ExchangeHelper.getMandatoryInBody(exchange);
+ String operation = getOperationName(exchange);
+ sqlClient.insert(operation, body);
+ }
+
+ /**
+ * Returns the iBatis insert operation name
+ */
+ protected String getOperationName(Exchange exchange) {
+ return endpoint.getEntityName();
+ }
+}
Propchange: activemq/camel/trunk/components/camel-ibatis/src/main/java/org/apache/camel/component/ibatis/IBatisProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/camel/component/ibatis (from r572881, activemq/camel/trunk/components/camel-jdbc/src/main/resources/META-INF/services/org/apache/camel/component/jdbc)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/camel/component/ibatis?p2=activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/camel/component/ibatis&p1=activemq/camel/trunk/components/camel-jdbc/src/main/resources/META-INF/services/org/apache/camel/component/jdbc&r1=572881&r2=573683&rev=573683&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jdbc/src/main/resources/META-INF/services/org/apache/camel/component/jdbc (original)
+++ activemq/camel/trunk/components/camel-ibatis/src/main/resources/META-INF/services/org/apache/camel/component/ibatis Fri Sep 7 12:59:10 2007
@@ -15,4 +15,4 @@
# limitations under the License.
#
-class=org.apache.camel.component.jdbc.JdbcComponent
+class=org.apache.camel.component.ibatis.IBatisComponent
Added: activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/Account.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/Account.java?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/Account.java (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/Account.java Fri Sep 7 12:59:10 2007
@@ -0,0 +1,65 @@
+/**
+ *
+ * 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;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class Account {
+ private int id;
+ private String firstName;
+ private String lastName;
+ private String emailAddress;
+
+ @Override
+ public String toString() {
+ return "Account[id: " + id + " name: " + firstName + " " + lastName + " email: " + emailAddress + "]";
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getEmailAddress() {
+ return emailAddress;
+ }
+
+ public void setEmailAddress(String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/Account.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java Fri Sep 7 12:59:10 2007
@@ -0,0 +1,82 @@
+/**
+ *
+ * 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.List;
+import java.sql.Statement;
+import java.sql.Connection;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class IBatisRouteTest extends ContextTestSupport {
+ public void testSendAccountBean() throws Exception {
+ MockEndpoint endpoint = getMockEndpoint("mock:results");
+ endpoint.expectedMessageCount(1);
+
+ Account account = new Account();
+ account.setId(123);
+ account.setFirstName("James");
+ account.setLastName("Strachan");
+ account.setEmailAddress("TryGuessing@gmail.com");
+
+ template.sendBody("direct:start", account);
+
+ assertMockEndpointsSatisifed();
+
+ List<Exchange> list = endpoint.getReceivedExchanges();
+ Exchange exchange = list.get(0);
+ List body = exchange.getIn().getBody(List.class);
+ assertNotNull("Should have returned a List!", body);
+ assertEquals("Wrong size: " + body, 1, body.size());
+ Account actual = assertIsInstanceOf(Account.class, body.get(0));
+
+ assertEquals("Account.getFirstName()", "James", actual.getFirstName());
+ assertEquals("Account.getLastName()", "Strachan", actual.getLastName());
+
+ log.info("Found: " + actual);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("ibatis:selectAllAccounts").to("mock:results");
+
+ from("direct:start").to("ibatis:insertAccount");
+ }
+ };
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // lets create the database...
+ IBatisEndpoint endpoint = resolveMandatoryEndpoint("ibatis:Account", IBatisEndpoint.class);
+ Connection connection = endpoint.getSqlClient().getDataSource().getConnection();
+ Statement statement = connection.createStatement();
+ statement.execute("create table ACCOUNT ( ACC_ID INTEGER , ACC_FIRST_NAME VARCHAR(255), ACC_LAST_NAME VARCHAR(255), ACC_EMAIL VARCHAR(255) )");
+ connection.close();
+ }
+}
Propchange: activemq/camel/trunk/components/camel-ibatis/src/test/java/org/apache/camel/component/ibatis/IBatisRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-ibatis/src/test/resources/SqlMapConfig.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/test/resources/SqlMapConfig.xml?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/test/resources/SqlMapConfig.xml (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/test/resources/SqlMapConfig.xml Fri Sep 7 12:59:10 2007
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE sqlMapConfig
+ PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
+ "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
+
+<sqlMapConfig>
+
+ <!-- Configure a built-in transaction manager. If you're using an
+ app server, you probably want to use its transaction manager
+ and a managed datasource -->
+ <transactionManager type="JDBC" commitRequired="false">
+ <dataSource type="SIMPLE">
+ <property name="JDBC.Driver" value="org.hsqldb.jdbcDriver"/>
+ <property name="JDBC.ConnectionURL" value="jdbc:hsqldb:mem:camel_ibatis"/>
+ <property name="JDBC.Username" value="sa"/>
+ <property name="JDBC.Password" value=""/>
+ </dataSource>
+ </transactionManager>
+
+ <!-- List the SQL Map XML files. They can be loaded from the
+ classpath, as they are here (com.domain.data...) -->
+
+ <sqlMap resource="org/apache/camel/component/ibatis/Account.xml"/>
+
+ <!-- List more here...
+ <sqlMap resource="com/mydomain/data/Order.xml"/>
+ <sqlMap resource="com/mydomain/data/Documents.xml"/>
+ -->
+
+</sqlMapConfig>
Propchange: activemq/camel/trunk/components/camel-ibatis/src/test/resources/SqlMapConfig.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties Fri Sep 7 12:59:10 2007
@@ -0,0 +1,32 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following to enable debug of Camel
+log4j.logger.org.apache.camel=DEBUG
+
+#log4j.logger.org.apache.activemq=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
Propchange: activemq/camel/trunk/components/camel-ibatis/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml?rev=573683&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml (added)
+++ activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml Fri Sep 7 12:59:10 2007
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE sqlMap
+ PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
+ "http://ibatis.apache.org/dtd/sql-map-2.dtd">
+
+<sqlMap namespace="Account">
+
+ <!-- Use type aliases to avoid typing the full classname every time. -->
+ <typeAlias alias="Account" type="org.apache.camel.component.ibatis.Account"/>
+
+ <!-- Result maps describe the mapping between the columns returned
+ from a query, and the class properties. A result map isn't
+ necessary if the columns (or aliases) match to the properties
+ exactly. -->
+ <resultMap id="AccountResult" class="Account">
+ <result property="id" column="ACC_ID"/>
+ <result property="firstName" column="ACC_FIRST_NAME"/>
+ <result property="lastName" column="ACC_LAST_NAME"/>
+ <result property="emailAddress" column="ACC_EMAIL"/>
+ </resultMap>
+
+ <!-- Select with no parameters using the result map for Account class. -->
+ <select id="selectAllAccounts" resultMap="AccountResult">
+ select * from ACCOUNT
+ </select>
+
+ <!-- A simpler select example without the result map. Note the
+ aliases to match the properties of the target result class. -->
+ <select id="selectAccountById" parameterClass="int" resultClass="Account">
+ select
+ ACC_ID as id,
+ ACC_FIRST_NAME as firstName,
+ ACC_LAST_NAME as lastName,
+ ACC_EMAIL as emailAddress
+ from ACCOUNT
+ where ACC_ID = #id#
+ </select>
+
+ <!-- Insert example, using the Account parameter class -->
+ <insert id="insertAccount" parameterClass="Account">
+ insert into ACCOUNT (
+ ACC_ID,
+ ACC_FIRST_NAME,
+ ACC_LAST_NAME,
+ ACC_EMAIL
+ )
+ values (
+ #id#, #firstName#, #lastName#, #emailAddress#
+ )
+ </insert>
+
+ <!-- Update example, using the Account parameter class -->
+ <update id="updateAccount" parameterClass="Account">
+ update ACCOUNT set
+ ACC_FIRST_NAME = #firstName#,
+ ACC_LAST_NAME = #lastName#,
+ ACC_EMAIL = #emailAddress#
+ where
+ ACC_ID = #id#
+ </update>
+
+ <!-- Delete example, using an integer as the parameter class -->
+ <delete id="deleteAccountById" parameterClass="int">
+ delete from ACCOUNT where ACC_ID = #id#
+ </delete>
+
+</sqlMap>
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-ibatis/src/test/resources/org/apache/camel/component/ibatis/Account.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?rev=573683&r1=573682&r2=573683&view=diff
==============================================================================
--- activemq/camel/trunk/components/pom.xml (original)
+++ activemq/camel/trunk/components/pom.xml Fri Sep 7 12:59:10 2007
@@ -58,6 +58,7 @@
<module>camel-saxon</module>
<module>camel-script</module>
<module>camel-spring</module>
+ <module>camel-xmlbeans</module>
<module>camel-xmpp</module>
</modules>