Author: cbegin
Date: Mon Aug 14 23:15:42 2006
New Revision: 431539
URL: http://svn.apache.org/viewvc?rev=431539&view=rev
Log:
Added simple example to docs.
Added:
ibatis/trunk/java/mapper/mapper2/doc/simple_example/
ibatis/trunk/java/mapper/mapper2/doc/simple_example/README.TXT
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/Account.xml
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SimpleExample.java
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SqlMapConfig.xml
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/domain/
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/domain/Account.java
Modified:
ibatis/trunk/java/mapper/mapper2/build/build.xml
ibatis/trunk/java/mapper/mapper2/build/version.properties
Modified: ibatis/trunk/java/mapper/mapper2/build/build.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/build/build.xml?rev=431539&r1=431538&r2=431539&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/build/build.xml (original)
+++ ibatis/trunk/java/mapper/mapper2/build/build.xml Mon Aug 14 23:15:42 2006
@@ -72,6 +72,7 @@
<copy todir="${deploy.path}">
<fileset dir="${res.txt}">
<include name="**/*.txt"/>
+ <include name="simple_example/**/*"/>
</fileset>
</copy>
<propertyfile file="version.properties" comment="Build version info">
Modified: ibatis/trunk/java/mapper/mapper2/build/version.properties
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/build/version.properties?rev=431539&r1=431538&r2=431539&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/build/version.properties (original)
+++ ibatis/trunk/java/mapper/mapper2/build/version.properties Mon Aug 14
23:15:42 2006
@@ -1,5 +1,5 @@
#Build version info
-#Mon Aug 14 12:30:47 CDT 2006
+#Tue Aug 15 00:05:31 MDT 2006
version=2.1.7
-buildDate=2006/08/14 12\:30
-buildNum=631
+buildDate=2006/08/15 00\:05
+buildNum=634
Added: ibatis/trunk/java/mapper/mapper2/doc/simple_example/README.TXT
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/doc/simple_example/README.TXT?rev=431539&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/doc/simple_example/README.TXT (added)
+++ ibatis/trunk/java/mapper/mapper2/doc/simple_example/README.TXT Mon Aug 14
23:15:42 2006
@@ -0,0 +1,16 @@
+Welcome!
+
+This classpath contains a VERY simple example of how iBATIS can be
+configured and used. It is NOT a best practices example, instead
+it shows you the basics of iBATIS in the simplest form possible
+(i.e. lots of static methods ;-)
+
+Browse through it, get a feel for it. If you like, you can copy
+the XML files to your own project to use as a starting point.
+
+For a more complete example - and best practices - please see
+the JPetStore example application at http://www.ibatis.com
+
+Best regards,
+
+Clinton Begin
\ No newline at end of file
Added:
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/Account.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/Account.xml?rev=431539&view=auto
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/Account.xml
(added)
+++
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/Account.xml
Mon Aug 14 23:15:42 2006
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!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="com.mydomain.domain.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
Added:
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SimpleExample.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SimpleExample.java?rev=431539&view=auto
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SimpleExample.java
(added)
+++
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SimpleExample.java
Mon Aug 14 23:15:42 2006
@@ -0,0 +1,61 @@
+package com.mydomain.data;
+
+import com.ibatis.sqlmap.client.SqlMapClient;
+import com.ibatis.sqlmap.client.SqlMapClientBuilder;
+import com.ibatis.common.resources.Resources;
+import com.mydomain.domain.Account;
+
+import java.io.Reader;
+import java.io.IOException;
+import java.util.List;
+import java.sql.SQLException;
+
+/**
+ * This is not a best practices class. It's just an example
+ * to give you an idea of how iBATIS works. For a more complete
+ * example, see JPetStore 5.0 at http://www.ibatis.com.
+ */
+public class SimpleExample {
+
+ /**
+ * SqlMapClient instances are thread safe, so you only need one.
+ * In this case, we'll use a static singleton. So sue me. ;-)
+ */
+ private static SqlMapClient sqlMapper;
+
+ /**
+ * It's not a good idea to put code that can fail in a class initializer,
+ * but for sake of argument, here's how you configure an SQL Map.
+ */
+ static {
+ try {
+ Reader reader =
Resources.getResourceAsReader("com/mydomain/data/SqlMapConfig.xml");
+ sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
+ reader.close();
+ } catch (IOException e) {
+ // Fail fast.
+ throw new RuntimeException("Something bad happened while building the
SqlMapClient instance." + e, e);
+ }
+ }
+
+ public static List selectAllAccounts () throws SQLException {
+ return sqlMapper.queryForList("selectAllAccounts");
+ }
+
+ public static Account selectAccountById (int id) throws SQLException {
+ return (Account) sqlMapper.queryForObject("selectAccountById", id);
+ }
+
+ public static void insertAccount (Account account) throws SQLException {
+ sqlMapper.insert("insertAccount", account);
+ }
+
+ public static void updateAccount (Account account) throws SQLException {
+ sqlMapper.update("updateAccount", account);
+ }
+
+ public static void deleteAccount (int id) throws SQLException {
+ sqlMapper.delete("deleteAccount", id);
+ }
+
+}
Added:
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SqlMapConfig.xml
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SqlMapConfig.xml?rev=431539&view=auto
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SqlMapConfig.xml
(added)
+++
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/data/SqlMapConfig.xml
Mon Aug 14 23:15:42 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!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:."/>
+ <property name="JDBC.Username" value="sa"/>
+ <property name="JDBC.Password" value="sa"/>
+ </dataSource>
+ </transactionManager>
+
+ <!-- List the SQL Map XML files. They can be loaded from the
+ classpath, as they are here (com.domain.data...) -->
+ <sqlMap resource="com/mydomain/data/Account.xml"/>
+ <!-- List more here...
+ <sqlMap resource="com/mydomain/data/Order.xml"/>
+ <sqlMap resource="com/mydomain/data/Documents.xml"/>
+ -->
+
+</sqlMapConfig>
Added:
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/domain/Account.java
URL:
http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/domain/Account.java?rev=431539&view=auto
==============================================================================
---
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/domain/Account.java
(added)
+++
ibatis/trunk/java/mapper/mapper2/doc/simple_example/com/mydomain/domain/Account.java
Mon Aug 14 23:15:42 2006
@@ -0,0 +1,42 @@
+package com.mydomain.domain;
+
+public class Account {
+
+ private int id;
+ private String firstName;
+ private String lastName;
+ private String 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;
+ }
+
+}