ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbe...@apache.org
Subject svn commit: r746800 - in /ibatis/trunk/java/ibatis-3/ibatis-3-core/src: main/java/org/apache/ibatis/binding/ test/java/org/apache/ibatis/binding/
Date Sun, 22 Feb 2009 18:48:38 GMT
Author: cbegin
Date: Sun Feb 22 18:48:38 2009
New Revision: 746800

URL: http://svn.apache.org/viewvc?rev=746800&view=rev
Log:
CHanging computers... checking in half implemented code... broken test clearly points out
which code.

Added:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
Modified:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperRegistry.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/IbatisConfig.java

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperRegistry.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperRegistry.java?rev=746800&r1=746799&r2=746800&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperRegistry.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperRegistry.java
Sun Feb 22 18:48:38 2009
@@ -46,14 +46,23 @@
 
   private Cache parseCache(Class type) {
     CacheDomain cacheDomain = (CacheDomain) type.getAnnotation(CacheDomain.class);
+    CacheDomainRef cacheDomainRef = (CacheDomainRef) type.getAnnotation(CacheDomainRef.class);
     if (cacheDomain != null) {
-      CacheBuilder builder = new CacheBuilder(type.getName() + "-Cache");
+      String cacheId = type.getName() + "-BoundCache";
+      CacheBuilder builder = new CacheBuilder(cacheId);
       builder.clearInterval(cacheDomain.flushInterval());
       builder.size(cacheDomain.size());
       builder.readWrite(cacheDomain.readWrite());
       builder.implementation(cacheDomain.implementation());
       builder.addDecorator(cacheDomain.eviction());
       return builder.build();
+    } else if (cacheDomain != null) {
+      String cacheRefId = cacheDomainRef.value().getName();
+      Cache cache = config.getCache(cacheRefId);
+      if (cache == null) {
+        throw new BindingException("No cache exists in namespace "+ cacheRefId + ".  Be sure
to register the referenced cache namespace first when building mappers.");
+      }
+      return cache;
     }
     return null;
   }
@@ -89,6 +98,10 @@
 
   private void setResultMaps(Method method, final String mappedStatementId, MappedStatement.Builder
builder) {
     final Class returnType = getReturnType(method);
+
+    Results results = method.getAnnotation(Results.class);
+    
+
     builder.resultMaps(new ArrayList<ResultMap>() {{
       add(new ResultMap.Builder(
         config,

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java?rev=746800&r1=746799&r2=746800&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BindingTest.java
Sun Feb 22 18:48:38 2009
@@ -4,7 +4,9 @@
 import org.apache.ibatis.session.SqlSession;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import domain.blog.Blog;
+import static org.junit.Assert.*;
+
+import domain.blog.*;
 
 import java.util.List;
 
@@ -17,12 +19,12 @@
   }
 
   @Test
-  public void shouldExecuteBoundSelectListStatement() {
+  public void shouldExecuteBoundSelectListOfBlogsStatement() {
     SqlSession session = sqlSessionFactory.openSession();
     try {
       BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
       List<Blog> blogs = mapper.selectBlogs();
-      System.out.println(blogs.size());
+      assertEquals(2,blogs.size());
     } finally {
       session.close();
     }
@@ -30,16 +32,32 @@
   }
 
   @Test
-  public void shouldExecuteBoundSelectOneStatement() {
+  public void shouldExecuteBoundSelectOneBlogStatement() {
     SqlSession session = sqlSessionFactory.openSession();
     try {
       BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
-      Blog blogs = mapper.selectBlog(1);
-      System.out.println(blogs.getId());
+      Blog blog = mapper.selectBlog(1);
+      assertEquals(1,blog.getId());
+      assertEquals("Jim Business",blog.getTitle());
     } finally {
       session.close();
     }
+  }
 
+  @Test
+  public void shouldSelectOneAuthor() {
+    SqlSession session = sqlSessionFactory.openSession();
+    try {
+      BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
+      Author author = mapper.selectAuthor(101);
+      assertEquals(101,author.getId());
+      assertEquals("jim",author.getUsername());
+      assertEquals("********",author.getPassword());
+      assertEquals("jim@ibatis.apache.org",author.getEmail());
+      assertEquals("", author.getBio());
+    } finally {
+      session.close();
+    }
   }
 
 

Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java?rev=746800&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
(added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundAuthorMapper.java
Sun Feb 22 18:48:38 2009
@@ -0,0 +1,25 @@
+package org.apache.ibatis.binding;
+
+import static org.apache.ibatis.annotations.Annotations.*;
+import domain.blog.Author;
+
+public interface BoundAuthorMapper {
+
+  @Results({
+      @Result(property = "id",column = "AUTHOR_ID"),
+      @Result(property = "username",column = "AUTHOR_USERNAME"),
+      @Result(property = "password",column = "AUTHOR_PASSWORD"),
+      @Result(property = "email",column = "AUTHOR_EMAIL"),
+      @Result(property = "bio",column = "AUTHOR_BIO")
+      })
+  @Select({
+      "SELECT ",
+      "  ID as AUTHOR_ID,",
+      "  USERNAME as AUTHOR_USERNAME,",
+      "  PASSWORD as AUTHOR_PASSWORD,",
+      "  EMAIL as AUTHOR_EMAIL,",
+      "  BIO as AUTHOR_BIO",
+      "FROM AUTHOR WHERE ID = #{id}"})
+  Author selectAuthor(int id);
+
+}

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java?rev=746800&r1=746799&r2=746800&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/BoundBlogMapper.java
Sun Feb 22 18:48:38 2009
@@ -1,6 +1,6 @@
 package org.apache.ibatis.binding;
 
-import domain.blog.Blog;
+import domain.blog.*;
 import static org.apache.ibatis.annotations.Annotations.*;
 
 import java.util.List;

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/IbatisConfig.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/IbatisConfig.java?rev=746800&r1=746799&r2=746800&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/IbatisConfig.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/binding/IbatisConfig.java
Sun Feb 22 18:48:38 2009
@@ -18,6 +18,7 @@
       Environment environment = new Environment("Production", transactionFactory, dataSource);
       Configuration configuration = new Configuration(environment);
       configuration.addMapper(BoundBlogMapper.class);
+      configuration.addMapper(BoundAuthorMapper.class);
       return new DefaultSqlSessionFactory(configuration);
     } catch (Exception e) {
       throw new RuntimeException("Error initializing SqlSessionFactory. Cause: " + e, e);



Mime
View raw message