ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbe...@apache.org
Subject svn commit: r744613 - in /ibatis/trunk/java/ibatis-3: ./ ibatis-3-core/src/main/java/org/apache/ibatis/api/ ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/ ibatis-3-core/src/main/java/org/apache/ibatis/api/defaults/ ibatis-3-core/src/mai...
Date Sun, 15 Feb 2009 06:30:10 GMT
Author: cbegin
Date: Sun Feb 15 06:30:10 2009
New Revision: 744613

URL: http://svn.apache.org/viewvc?rev=744613&view=rev
Log:
Added mapper interface binding and annotations (currently annotations are unused)

Added:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/CacheNamespace.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collection.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collections.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Delete.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Insert.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Param.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/QueryMethod.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Result.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/ResultClass.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Results.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Select.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Undefined.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Update.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/BindingException.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperFactory.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethodType.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/AuthorMapper.java
Modified:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/SqlSession.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/defaults/DefaultSqlSession.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
    ibatis/trunk/java/ibatis-3/version.properties

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/SqlSession.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/SqlSession.java?rev=744613&r1=744612&r2=744613&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/SqlSession.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/SqlSession.java
Sun Feb 15 06:30:10 2009
@@ -1,6 +1,7 @@
 package org.apache.ibatis.api;
 
 import org.apache.ibatis.executor.result.ResultHandler;
+import org.apache.ibatis.mapping.Configuration;
 
 import java.util.List;
 
@@ -42,4 +43,8 @@
 
   void close();
 
+  Configuration getConfiguration();
+
+  <T> T getMapper(Class<T> type);
+
 }

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/CacheNamespace.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/CacheNamespace.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/CacheNamespace.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/CacheNamespace.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,16 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface CacheNamespace {
+
+  String[] value();
+
+}
+
+

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collection.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collection.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collection.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collection.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,17 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Collection {
+
+  Class type();
+  String property();
+  String groupBy() default "";
+  //Result[] nestedResults() default {};
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collections.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collections.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collections.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Collections.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,14 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Collections {
+
+  Collection[] value();
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Delete.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Delete.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Delete.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Delete.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,16 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Delete {
+
+  String[] value();
+
+}
+
+

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Insert.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Insert.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Insert.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Insert.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,16 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Insert {
+
+  String[] value();
+
+}
+
+

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Param.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Param.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Param.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Param.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,20 @@
+package org.apache.ibatis.api.annotations;
+
+import org.apache.ibatis.mapping.ParameterMode;
+import org.apache.ibatis.type.JdbcType;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
+public @interface Param {
+
+  String name();
+  ParameterMode mode() default ParameterMode.IN;
+  JdbcType jdbcType() default JdbcType.UNDEFINED;
+  Class typeHandler() default Undefined.class;
+  
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/QueryMethod.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/QueryMethod.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/QueryMethod.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/QueryMethod.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,16 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface QueryMethod {
+
+  Class type();
+  String methodName();
+  String parameters() default "";
+  
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Result.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Result.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Result.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Result.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,21 @@
+package org.apache.ibatis.api.annotations;
+
+import org.apache.ibatis.type.JdbcType;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Result {
+
+  String column() default "";
+  String property() default "";
+  String field() default "";
+  JdbcType jdbcType() default JdbcType.UNDEFINED;
+  Class typeHandler() default Undefined.class;
+  QueryMethod nestedQuery() default @QueryMethod(type= Undefined.class, methodName="", parameters="");
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/ResultClass.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/ResultClass.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/ResultClass.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/ResultClass.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,14 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ResultClass {
+
+  Class value();
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Results.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Results.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Results.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Results.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,14 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Results {
+
+  Result[] value();
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Select.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Select.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Select.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Select.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,16 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Select {
+
+  String[] value();
+
+}
+
+

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Undefined.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Undefined.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Undefined.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Undefined.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,4 @@
+package org.apache.ibatis.api.annotations;
+
+public @interface Undefined {
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Update.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Update.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Update.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/annotations/Update.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,16 @@
+package org.apache.ibatis.api.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface Update {
+
+  String[] value();
+
+}
+
+

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/defaults/DefaultSqlSession.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/defaults/DefaultSqlSession.java?rev=744613&r1=744612&r2=744613&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/defaults/DefaultSqlSession.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/api/defaults/DefaultSqlSession.java
Sun Feb 15 06:30:10 2009
@@ -7,11 +7,14 @@
 import org.apache.ibatis.executor.result.ResultHandler;
 import org.apache.ibatis.mapping.Configuration;
 import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.binding.MapperFactory;
 
 import java.util.List;
 
 public class DefaultSqlSession implements SqlSession {
 
+  private MapperFactory mapperFactory;
+
   private Configuration configuration;
   private Executor executor;
 
@@ -19,6 +22,7 @@
   private boolean dirty;
 
   public DefaultSqlSession(Configuration configuration, Executor executor, boolean autoCommit)
{
+    this.mapperFactory = new MapperFactory();
     this.configuration = configuration;
     this.executor = executor;
     this.autoCommit = autoCommit;
@@ -137,6 +141,14 @@
     }
   }
 
+  public Configuration getConfiguration() {
+    return configuration;
+  }
+
+  public <T> T getMapper(Class<T> type) {
+    return mapperFactory.getMapper(type, this);
+  }
+
   private boolean isCommitOrRollbackRequired(boolean force) {
     return (!autoCommit && dirty) || force;
   }

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/BindingException.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/BindingException.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/BindingException.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/BindingException.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,22 @@
+package org.apache.ibatis.binding;
+
+import org.apache.ibatis.mapping.SqlMapperException;
+
+public class BindingException extends SqlMapperException {
+
+  public BindingException() {
+    super();
+  }
+
+  public BindingException(String message) {
+    super(message);
+  }
+
+  public BindingException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+  public BindingException(Throwable cause) {
+    super(cause);
+  }
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperFactory.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperFactory.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperFactory.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperFactory.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,15 @@
+package org.apache.ibatis.binding;
+
+import org.apache.ibatis.api.SqlSession;
+
+public class MapperFactory {
+
+  public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
+    try {
+      return MapperProxy.newMapperProxy(type, sqlSession);
+    } catch (Exception e) {
+      throw new RuntimeException("Error getting mapper instance. Cause: " + e, e);
+    }
+  }
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethod.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,120 @@
+package org.apache.ibatis.binding;
+
+import org.apache.ibatis.api.SqlSession;
+import org.apache.ibatis.mapping.Configuration;
+
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+import java.util.List;
+
+public class MapperMethod {
+
+  private SqlSession sqlSession;
+  private Configuration config;
+
+  private MapperMethodType type;
+  private String commandName;
+
+  private Method method;
+  private int argCount;
+
+  private boolean returnsList;
+  private boolean hasListBounds;
+
+  public MapperMethod(Method method, SqlSession sqlSession) {
+
+    this.sqlSession = sqlSession;
+    this.method = method;
+    this.config = sqlSession.getConfiguration();
+
+    setupFields();
+    determineSelectMethod();
+    determineCommandType();
+    validateStatement();
+  }
+
+  public Object execute(Object[] args) throws SQLException {
+    Object result;
+    if (MapperMethodType.INSERT == type) {
+      Object param = getParam(args);
+      result = sqlSession.insert(commandName, param);
+    } else if (MapperMethodType.UPDATE == type) {
+      Object param = getParam(args);
+      result = sqlSession.update(commandName, param);
+    } else if (MapperMethodType.DELETE == type) {
+      Object param = getParam(args);
+      result = sqlSession.delete(commandName, param);
+    } else if (MapperMethodType.SELECT == type) {
+      if (returnsList) {
+        result = executeForList(args);
+      } else {
+        Object param = getParam(args);
+        result = sqlSession.selectOne(commandName, param);
+      }
+    } else {
+      throw new BindingException("Unkown execution method for: " + commandName);
+    }
+
+    return result;
+  }
+
+  private void setupFields() {
+    this.commandName = method.getDeclaringClass().getName() + "." + method.getName();
+    this.argCount = method.getParameterTypes().length;
+  }
+
+  private void determineSelectMethod() {
+    if (List.class.isAssignableFrom(method.getReturnType())) {
+      returnsList = true;
+      if (argCount == 2) {
+      } else if (argCount == 3) {
+        hasListBounds = true;
+      }
+    }
+  }
+
+  private void determineCommandType() {
+    String methodName = method.getName();
+    if (methodName.startsWith("insert") || methodName.startsWith("create")) {
+      type = MapperMethodType.INSERT;
+    } else if (methodName.startsWith("update") || methodName.startsWith("save")) {
+      type = MapperMethodType.UPDATE;
+    } else if (methodName.startsWith("delete") || methodName.startsWith("remove")) {
+      type = MapperMethodType.DELETE;
+    } else if (methodName.startsWith("select") || methodName.startsWith("find")) {
+      type = MapperMethodType.SELECT;
+    } else {
+      throw new BindingException("Unkown execution method for: " + commandName);      
+    }
+  }
+
+  private void validateStatement() {
+    try {
+      config.getMappedStatement(commandName);
+    } catch (Exception e) {
+      throw new BindingException("Invalid bound statement (not found): " + commandName);
+    }
+  }
+
+  private Object executeForList(Object[] args) throws SQLException {
+    Object result;
+    if (hasListBounds) {
+      Object param = getParam(args);
+      int skip = ((Integer) args[1]);
+      int max = ((Integer) args[2]);
+      result = sqlSession.selectList(commandName, param, skip, max);
+    } else {
+      Object param = getParam(args);
+      result = sqlSession.selectList(commandName, param);
+    }
+    return result;
+  }
+
+  private Object getParam(Object[] args) {
+    if (args == null) {
+      return null;
+    }
+    return args.length > 0 ? args[0] : null;
+  }
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethodType.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethodType.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethodType.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperMethodType.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,5 @@
+package org.apache.ibatis.binding;
+
+public enum MapperMethodType {
+  INSERT,UPDATE,DELETE,SELECT
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java
Sun Feb 15 06:30:10 2009
@@ -0,0 +1,28 @@
+package org.apache.ibatis.binding;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.apache.ibatis.api.SqlSession;
+
+public class MapperProxy implements InvocationHandler {
+
+  private SqlSession sqlSession;
+
+  private <T> MapperProxy(SqlSession sqlSession) {
+    this.sqlSession = sqlSession;
+  }
+
+  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+    return new MapperMethod(method, sqlSession).execute(args);
+  }
+
+  public static <T> T newMapperProxy (Class<T> mapperInterface, SqlSession sqlSession)
{
+    ClassLoader classLoader = mapperInterface.getClassLoader();
+    Class[] interfaces = new Class[]{mapperInterface};
+    MapperProxy proxy = new MapperProxy(sqlSession);
+    return (T)Proxy.newProxyInstance(classLoader, interfaces, proxy);
+  }
+
+}

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/AuthorMapper.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/AuthorMapper.java?rev=744613&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/AuthorMapper.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/com/domain/AuthorMapper.java Sun
Feb 15 06:30:10 2009
@@ -0,0 +1,18 @@
+package com.domain;
+
+import domain.blog.Author;
+
+import java.util.List;
+
+public interface AuthorMapper {
+
+  List selectAllAuthors ();
+  Author selectAuthor(int id);
+  void insertAuthor(Author author);
+  int deleteAuthor(int id);
+  int updateAuthor(Author author);
+
+}
+
+
+

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java?rev=744613&r1=744612&r2=744613&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/api/SqlSessionTest.java
Sun Feb 15 06:30:10 2009
@@ -11,6 +11,8 @@
 import java.io.Reader;
 import java.util.List;
 
+import com.domain.AuthorMapper;
+
 public class SqlSessionTest extends BaseDataTest {
   private static SqlSessionFactory sqlMapper;
 
@@ -287,4 +289,83 @@
     assertTrue(first != second);
   }
 
+  @Test
+  public void shouldSelectAuthorsUsingMapperClass() {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      AuthorMapper mapper = session.getMapper(AuthorMapper.class);
+      System.out.println(mapper.getClass());
+      List authors = mapper.selectAllAuthors();
+      assertEquals(2,authors.size());
+    } finally {
+      session.close();
+    }
+  }
+
+  @Test
+  public void shouldExecuteSelectOneAuthorUsingMapperClass() {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      AuthorMapper mapper = session.getMapper(AuthorMapper.class);
+      System.out.println(mapper.getClass());
+      Author author = mapper.selectAuthor(101);
+      assertEquals(101,author.getId());
+    } finally {
+      session.close();
+    }
+  }
+
+  @Test
+  public void shouldInsertAuthorUsingMapperClass() throws Exception {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      AuthorMapper mapper = session.getMapper(AuthorMapper.class);
+      Author expected = new Author(500, "cbegin", "******", "cbegin@somewhere.com", "Something...",
null);
+      mapper.insertAuthor(expected);
+      Author actual = mapper.selectAuthor(500);
+      assertNotNull(actual);
+      assertEquals(expected.getId(), actual.getId());
+      assertEquals(expected.getUsername(), actual.getUsername());
+      assertEquals(expected.getPassword(), actual.getPassword());
+      assertEquals(expected.getEmail(), actual.getEmail());
+      assertEquals(expected.getBio(), actual.getBio());
+    } finally {
+      session.close();
+    }
+  }
+
+  @Test
+  public void shouldDeleteAuthorUsingMapperClass() throws Exception {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      AuthorMapper mapper = session.getMapper(AuthorMapper.class);
+      int count = mapper.deleteAuthor(101);
+      assertEquals(count, 1);
+      try{
+        mapper.selectAuthor(101);
+        fail("Expected exception.");
+      } catch(Exception e) {
+        assertEquals(ApiException.class, e.getClass());
+      }
+    } finally {
+      session.close();
+    }
+  }
+
+  @Test
+  public void shouldUpdateAuthorUsingMapperClass() throws Exception {
+    SqlSession session = sqlMapper.openSession();
+    try {
+      AuthorMapper mapper = session.getMapper(AuthorMapper.class);
+      Author expected = mapper.selectAuthor(101);
+      expected.setUsername("NewUsername");
+      int count = mapper.updateAuthor(expected);
+      assertEquals(count, 1);
+      Author actual = mapper.selectAuthor(101);
+      assertEquals(expected.getUsername(), actual.getUsername());
+    } finally {
+      session.close();
+    }
+  }
+
 }

Modified: ibatis/trunk/java/ibatis-3/version.properties
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/version.properties?rev=744613&r1=744612&r2=744613&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/version.properties (original)
+++ ibatis/trunk/java/ibatis-3/version.properties Sun Feb 15 06:30:10 2009
@@ -1,5 +1,5 @@
 #Build version info
-#Thu Jan 22 22:47:43 MST 2009
+#Sat Feb 14 23:23:36 MST 2009
 version=3.0.0
-buildDate=2009/01/22 22\:47
-buildNum=114
+buildDate=2009/02/14 23\:23
+buildNum=119



Mime
View raw message