ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbe...@apache.org
Subject svn commit: r703566 - in /ibatis/trunk/java/ibatis-3: ./ ibatis-3-core/src/main/java/org/apache/ibatis/mapping/ ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/ ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/environment/
Date Fri, 10 Oct 2008 19:49:04 GMT
Author: cbegin
Date: Fri Oct 10 12:49:04 2008
New Revision: 703566

URL: http://svn.apache.org/viewvc?rev=703566&view=rev
Log:
moved environment to core

Added:
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Environment.java
      - copied, changed from r702695, ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/environment/Environment.java
Removed:
    ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/environment/
Modified:
    ibatis/trunk/java/ibatis-3/TODO
    ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
    ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MapperConfigParser.java
    ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MonarchConfiguration.java

Modified: ibatis/trunk/java/ibatis-3/TODO
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/TODO?rev=703566&r1=703565&r2=703566&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/TODO (original)
+++ ibatis/trunk/java/ibatis-3/TODO Fri Oct 10 12:49:04 2008
@@ -2,11 +2,10 @@
  * Improved Error Messages
 
 Monarch XML
- * DTD / Schema
  * Named parameter parsing/merging
  * Loosely bound cache id to instance
    - (perhaps use late-binding lookup proxies for all config elements?)
-mvn 
+
 Monarch API
  * Transaction Manager
  * Mapper Interface Binding

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java?rev=703566&r1=703565&r2=703566&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Configuration.java
Fri Oct 10 12:49:04 2008
@@ -15,6 +15,8 @@
 
 public class Configuration {
 
+  private Environment environment;
+
   private boolean lazyLoadingEnabled = true;
   private boolean enhancementEnabled = false;
   private boolean multipleResultSetsEnabled = true;
@@ -35,6 +37,14 @@
   private final Map<String, ResultMap> resultMaps = new HashMap<String, ResultMap>();
   private final Map<String, ParameterMap> parameterMaps = new HashMap<String, ParameterMap>();
 
+  public Environment getEnvironment() {
+    return environment;
+  }
+
+  public void setEnvironment(Environment environment) {
+    this.environment = environment;
+  }
+
   public boolean isLazyLoadingEnabled() {
     return lazyLoadingEnabled;
   }

Copied: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Environment.java
(from r702695, ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/environment/Environment.java)
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Environment.java?p2=ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Environment.java&p1=ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/environment/Environment.java&r1=702695&r2=703566&rev=703566&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/environment/Environment.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/main/java/org/apache/ibatis/mapping/Environment.java
Fri Oct 10 12:49:04 2008
@@ -1,4 +1,4 @@
-package org.apache.ibatis.monarch.environment;
+package org.apache.ibatis.mapping;
 
 import org.apache.ibatis.transaction.TransactionManager;
 
@@ -13,8 +13,10 @@
 
   public static class Builder {
     private Environment environment = new Environment();
-    public Builder(String id) {
+    public Builder(String id, TransactionManager transactionManager, DataSource dataSource)
{
       environment.id = id;
+      environment.transactionManager = transactionManager;
+      environment.dataSource = dataSource;
     }
     public Builder transactionManager(TransactionManager transactionManager) {
       environment.transactionManager = transactionManager;
@@ -24,9 +26,14 @@
       environment.dataSource = dataSource;
       return this;
     }
+    public String id() {
+      return environment.id;
+    }
+
     public Environment build() {
       return environment;
     }
+
   }
 
   public String getId() {

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MapperConfigParser.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MapperConfigParser.java?rev=703566&r1=703565&r2=703566&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MapperConfigParser.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MapperConfigParser.java
Fri Oct 10 12:49:04 2008
@@ -6,7 +6,7 @@
 import org.apache.ibatis.plugin.Interceptor;
 import org.apache.ibatis.reflection.*;
 import org.apache.ibatis.io.Resources;
-import org.apache.ibatis.monarch.environment.Environment;
+import org.apache.ibatis.mapping.Environment;
 import org.apache.ibatis.transaction.TransactionManagerFactory;
 import org.apache.ibatis.datasource.DataSourceFactory;
 
@@ -15,9 +15,11 @@
 
 public class MapperConfigParser extends BaseParser {
 
+
   protected Reader reader;
   protected NodeletParser parser;
 
+  private String environment;
   private Environment.Builder environmentBuilder;
 
   public MapperConfigParser(Reader reader, Properties props) {
@@ -72,7 +74,7 @@
   public void objectFactoryElement(NodeletContext context) throws Exception {
     String type = context.getStringAttribute("type");
     Properties properties = context.getChildrenAsProperties();
-    ObjectFactory factory = (ObjectFactory)resolveClass(type).newInstance();
+    ObjectFactory factory = (ObjectFactory) resolveClass(type).newInstance();
     factory.setProperties(properties);
     configuration.setObjectFactory(factory);
   }
@@ -89,7 +91,7 @@
     }
     if (resource != null) {
       defaults.putAll(Resources.getResourceAsProperties(resource));
-    } else if (url != null){
+    } else if (url != null) {
       defaults.putAll(Resources.getUrlAsProperties(url));
     }
     Properties vars = configuration.getVariables();
@@ -107,64 +109,71 @@
     // Check that all settings are known to the configuration class
     for (Map.Entry entry : props.entrySet()) {
       MetaClass metaConfig = MetaClass.forClass(Configuration.class);
-      if (!metaConfig.hasSetter((String)entry.getKey())) {
+      if (!metaConfig.hasSetter((String) entry.getKey())) {
         throw new BuilderException("The setting " + entry.getKey() + " is not known.  Make
sure you spelled it correctly (case sensitive).");
       }
     }
-    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"),true));
-    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"),true));
-    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"),true));
-    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"),true));
-    configuration.setEnhancementEnabled(booleanValueOf(props.getProperty("enhancementEnabled"),false));
-    configuration.setGeneratedKeysEnabled(booleanValueOf(props.getProperty("generatedKeysEnabled"),false));
-    configuration.setDefaultExecutorType(ExecutorType.valueOf(stringValueOf(props.getProperty("defaultExecutorType"),"SIMPLE")));
-    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"),null));
+    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
+    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"),
true));
+    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"),
true));
+    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
+    configuration.setEnhancementEnabled(booleanValueOf(props.getProperty("enhancementEnabled"),
false));
+    configuration.setGeneratedKeysEnabled(booleanValueOf(props.getProperty("generatedKeysEnabled"),
false));
+    configuration.setDefaultExecutorType(ExecutorType.valueOf(stringValueOf(props.getProperty("defaultExecutorType"),
"SIMPLE")));
+    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"),
null));
   }
 
   //  <environments default="development">
   @Nodelet("/configuration/environments")
   public void environmentsElement(NodeletContext context) throws Exception {
-    String defaultEnv = context.getStringAttribute("default","default");
-    configuration.setDefaultEnvironment(defaultEnv);
+    if (environment == null) {
+      environment = context.getStringAttribute("default");
+    }
   }
 
   //  <environment id="development">
   @Nodelet("/configuration/environments/environment")
   public void environmentElement(NodeletContext context) throws Exception {
-    String id = context.getStringAttribute("id","default");
-    environmentBuilder = new Environment.Builder(id);
+    String id = context.getStringAttribute("id");
+    environmentBuilder = new Environment.Builder(id, null, null);
   }
 
   //  <transactionManager type="JDBC|JTA|EXTERNAL">
   //    <property name="" value=""/>
   @Nodelet("/configuration/environments/environment/transactionManager")
   public void transactionManagerElement(NodeletContext context) throws Exception {
-    String type = context.getStringAttribute("type");
-    Properties props = context.getChildrenAsProperties();
+    if (isSpecifiedEnvironment()) {
+      String type = context.getStringAttribute("type");
+      Properties props = context.getChildrenAsProperties();
 
-    TransactionManagerFactory factory = (TransactionManagerFactory) resolveClass(type).newInstance();
-    factory.setProperties(props);
+      TransactionManagerFactory factory = (TransactionManagerFactory) resolveClass(type).newInstance();
+      factory.setProperties(props);
 
-    environmentBuilder.transactionManager(factory.getTransactionManager());
+      environmentBuilder.transactionManager(factory.getTransactionManager());
+    }
   }
 
   //  <dataSource type="POOLED|UNPOOLED|JNDI">
   //    <property name="" value=""/>
   @Nodelet("/configuration/environments/environment/dataSource")
   public void dataSourceElement(NodeletContext context) throws Exception {
-    String type = context.getStringAttribute("type");
-    Properties props = context.getChildrenAsProperties();
+    if (isSpecifiedEnvironment()) {
+      String type = context.getStringAttribute("type");
+      Properties props = context.getChildrenAsProperties();
 
-    DataSourceFactory factory = (DataSourceFactory) resolveClass(type).newInstance();
-    factory.setProperties(props);
+      DataSourceFactory factory = (DataSourceFactory) resolveClass(type).newInstance();
+      factory.setProperties(props);
 
-    environmentBuilder.dataSource(factory.getDataSource());
+      environmentBuilder.dataSource(factory.getDataSource());
+    }
   }
 
   //  </environment>
   @Nodelet("/configuration/environments/environment/end()")
-  public void environmentClosingElement(NodeletContext context) throws Exception {
-    configuration.addEnvironment(environmentBuilder.build());
+  public void environmentElementEnd(NodeletContext context) throws Exception {
+    if (isSpecifiedEnvironment()) {
+      configuration.setEnvironment(environmentBuilder.build());
+    }
   }
 
   //  <typeHandler javaType="" jdbcType="" handler=""/>
@@ -197,8 +206,18 @@
     } else {
       throw new BuilderException("A mapper element may only specify a url or resource, but
not both.");
     }
-    MapperParser mapperParser = new MapperParser(reader,configuration);
+    MapperParser mapperParser = new MapperParser(reader, configuration);
     mapperParser.parse();
   }
 
+  private boolean isSpecifiedEnvironment() {
+    if (environment == null) {
+      throw new BuilderException("No environment specified.");
+    } else if (environmentBuilder.id() == null) {
+      throw new BuilderException("Environment requires an id attribute.");
+    } else if (environment.equals(environmentBuilder.id())) {
+      return true;
+    }
+    return false;
+  }
 }

Modified: ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MonarchConfiguration.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MonarchConfiguration.java?rev=703566&r1=703565&r2=703566&view=diff
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MonarchConfiguration.java
(original)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-monarch/src/main/java/org/apache/ibatis/monarch/builder/MonarchConfiguration.java
Fri Oct 10 12:49:04 2008
@@ -1,28 +1,11 @@
 package org.apache.ibatis.monarch.builder;
 
 import org.apache.ibatis.mapping.Configuration;
-import org.apache.ibatis.monarch.environment.Environment;
+import org.apache.ibatis.mapping.Environment;
 
 import java.util.*;
 
 public class MonarchConfiguration extends Configuration {
 
-  private String defaultEnvironment;
-  private Map<String,Environment> environmentMap = new HashMap<String,Environment>();
-
-  public String getDefaultEnvironment() {
-    return defaultEnvironment;
-  }
-
-  public void setDefaultEnvironment(String defaultEnvironment) {
-    this.defaultEnvironment = defaultEnvironment;
-  }
-
-  public void addEnvironment(Environment environment) {
-    if(environmentMap.containsKey(environment.getId())) {
-      throw new BuilderException("Duplicate environment ID detected: " + environment.getId()
+ ".  Environment ID must be unique.");
-    }
-    environmentMap.put(environment.getId(),environment);
-  }
 }
 



Mime
View raw message