Example #1
0
 private void sqlElement(List<XNode> list, String requiredDatabaseId) throws Exception {
   for (XNode context : list) {
     String databaseId = context.getStringAttribute("databaseId");
     String id = context.getStringAttribute("id");
     id = builderAssistant.applyCurrentNamespace(id, false);
     if (databaseIdMatchesCurrent(id, databaseId, requiredDatabaseId))
       sqlFragments.put(id, context);
   }
 }
Example #2
0
 private void cacheElement(XNode context) throws Exception {
   if (context != null) {
     String type = context.getStringAttribute("type", "PERPETUAL");
     Class<? extends Cache> typeClass = typeAliasRegistry.resolveAlias(type);
     String eviction = context.getStringAttribute("eviction", "LRU");
     Class<? extends Cache> evictionClass = typeAliasRegistry.resolveAlias(eviction);
     Long flushInterval = context.getLongAttribute("flushInterval");
     Integer size = context.getIntAttribute("size");
     boolean readWrite = !context.getBooleanAttribute("readOnly", false);
     Properties props = context.getChildrenAsProperties();
     builderAssistant.useNewCache(typeClass, evictionClass, flushInterval, size, readWrite, props);
   }
 }
Example #3
0
 private void cacheRefElement(XNode context) {
   if (context != null) {
     configuration.addCacheRef(
         builderAssistant.getCurrentNamespace(), context.getStringAttribute("namespace"));
     CacheRefResolver cacheRefResolver =
         new CacheRefResolver(builderAssistant, context.getStringAttribute("namespace"));
     try {
       cacheRefResolver.resolveCacheRef();
     } catch (IncompleteElementException e) {
       configuration.addIncompleteCacheRef(cacheRefResolver);
     }
   }
 }
Example #4
0
 private void parameterMapElement(List<XNode> list) throws Exception {
   for (XNode parameterMapNode : list) {
     String id = parameterMapNode.getStringAttribute("id");
     String type = parameterMapNode.getStringAttribute("type");
     Class<?> parameterClass = resolveClass(type);
     List<XNode> parameterNodes = parameterMapNode.evalNodes("parameter");
     List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
     for (XNode parameterNode : parameterNodes) {
       String property = parameterNode.getStringAttribute("property");
       String javaType = parameterNode.getStringAttribute("javaType");
       String jdbcType = parameterNode.getStringAttribute("jdbcType");
       String resultMap = parameterNode.getStringAttribute("resultMap");
       String mode = parameterNode.getStringAttribute("mode");
       String typeHandler = parameterNode.getStringAttribute("typeHandler");
       Integer numericScale = parameterNode.getIntAttribute("numericScale");
       ParameterMode modeEnum = resolveParameterMode(mode);
       Class<?> javaTypeClass = resolveClass(javaType);
       JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
       @SuppressWarnings("unchecked")
       Class<? extends TypeHandler<?>> typeHandlerClass =
           (Class<? extends TypeHandler<?>>) resolveClass(typeHandler);
       ParameterMapping parameterMapping =
           builderAssistant.buildParameterMapping(
               parameterClass,
               property,
               javaTypeClass,
               jdbcTypeEnum,
               resultMap,
               modeEnum,
               typeHandlerClass,
               numericScale);
       parameterMappings.add(parameterMapping);
     }
     builderAssistant.addParameterMap(id, parameterClass, parameterMappings);
   }
 }
Example #5
0
 private void configurationElement(XNode context) {
   try {
     String namespace = context.getStringAttribute("namespace");
     if (namespace.equals("")) {
       throw new BuilderException("Mapper's namespace cannot be empty");
     }
     builderAssistant.setCurrentNamespace(namespace);
     cacheRefElement(context.evalNode("cache-ref"));
     cacheElement(context.evalNode("cache"));
     parameterMapElement(context.evalNodes("/mapper/parameterMap"));
     resultMapElements(context.evalNodes("/mapper/resultMap"));
     sqlElement(context.evalNodes("/mapper/sql"));
     buildStatementFromContext(context.evalNodes("select|insert|update|delete"));
   } catch (Exception e) {
     throw new BuilderException("Error parsing Mapper XML. Cause: " + e, e);
   }
 }
Example #6
0
 private ResultMapping buildResultMappingFromContext(
     XNode context, Class<?> resultType, ArrayList<ResultFlag> flags) throws Exception {
   String property = context.getStringAttribute("property");
   String column = context.getStringAttribute("column");
   String javaType = context.getStringAttribute("javaType");
   String jdbcType = context.getStringAttribute("jdbcType");
   String nestedSelect = context.getStringAttribute("select");
   String nestedResultMap =
       context.getStringAttribute(
           "resultMap",
           processNestedResultMappings(context, Collections.<ResultMapping>emptyList()));
   String notNullColumn = context.getStringAttribute("notNullColumn");
   String columnPrefix = context.getStringAttribute("columnPrefix");
   String typeHandler = context.getStringAttribute("typeHandler");
   String resulSet = context.getStringAttribute("resultSet");
   String foreignColumn = context.getStringAttribute("foreignColumn");
   boolean lazy =
       "lazy"
           .equals(
               context.getStringAttribute(
                   "fetchType", configuration.isLazyLoadingEnabled() ? "lazy" : "eager"));
   Class<?> javaTypeClass = resolveClass(javaType);
   @SuppressWarnings("unchecked")
   Class<? extends TypeHandler<?>> typeHandlerClass =
       (Class<? extends TypeHandler<?>>) resolveClass(typeHandler);
   JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
   return builderAssistant.buildResultMapping(
       resultType,
       property,
       column,
       javaTypeClass,
       jdbcTypeEnum,
       nestedSelect,
       nestedResultMap,
       notNullColumn,
       columnPrefix,
       typeHandlerClass,
       flags,
       resulSet,
       foreignColumn,
       lazy);
 }
Example #7
0
 private void bindMapperForNamespace() {
   String namespace = builderAssistant.getCurrentNamespace();
   if (namespace != null) {
     Class<?> boundType = null;
     try {
       boundType = Resources.classForName(namespace);
     } catch (ClassNotFoundException e) {
       // ignore, bound type is not required
     }
     if (boundType != null) {
       if (!configuration.hasMapper(boundType)) {
         // Spring may not know the real resource name so we set a
         // flag
         // to prevent loading again this resource from the mapper
         // interface
         // look at MapperAnnotationBuilder#loadXmlResource
         configuration.addLoadedResource("namespace:" + namespace);
         configuration.addMapper(boundType);
       }
     }
   }
 }
Example #8
0
 private Discriminator processDiscriminatorElement(
     XNode context, Class<?> resultType, List<ResultMapping> resultMappings) throws Exception {
   String column = context.getStringAttribute("column");
   String javaType = context.getStringAttribute("javaType");
   String jdbcType = context.getStringAttribute("jdbcType");
   String typeHandler = context.getStringAttribute("typeHandler");
   Class<?> javaTypeClass = resolveClass(javaType);
   @SuppressWarnings("unchecked")
   Class<? extends TypeHandler<?>> typeHandlerClass =
       (Class<? extends TypeHandler<?>>) resolveClass(typeHandler);
   JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
   Map<String, String> discriminatorMap = new HashMap<String, String>();
   for (XNode caseChild : context.getChildren()) {
     String value = caseChild.getStringAttribute("value");
     String resultMap =
         caseChild.getStringAttribute(
             "resultMap", processNestedResultMappings(caseChild, resultMappings));
     discriminatorMap.put(value, resultMap);
   }
   return builderAssistant.buildDiscriminator(
       resultType, column, javaTypeClass, jdbcTypeEnum, typeHandlerClass, discriminatorMap);
 }