org.apache.ibatis.session.Configuration.getTypeAliasRegistry()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中org.apache.ibatis.session.Configuration.getTypeAliasRegistry()方法的一些代码示例,展示了Configuration.getTypeAliasRegistry()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getTypeAliasRegistry()方法的具体详情如下:
包路径:org.apache.ibatis.session.Configuration
类名称:Configuration
方法名:getTypeAliasRegistry

Configuration.getTypeAliasRegistry介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

void loadAlias(String alias, Class dtoClass) {
 conf.getTypeAliasRegistry().registerAlias(alias, dtoClass);
}

代码示例来源:origin: baomidou/mybatis-plus

private void typeAliasesElement(XNode parent) {
  if (parent != null) {
    for (XNode child : parent.getChildren()) {
      if ("package".equals(child.getName())) {
        String typeAliasPackage = child.getStringAttribute("name");
        configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
      } else {
        String alias = child.getStringAttribute("alias");
        String type = child.getStringAttribute("type");
        try {
          Class<?> clazz = Resources.classForName(type);
          if (alias == null) {
            typeAliasRegistry.registerAlias(clazz);
          } else {
            typeAliasRegistry.registerAlias(alias, clazz);
          }
        } catch (ClassNotFoundException e) {
          throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
        }
      }
    }
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public BaseBuilder(Configuration configuration) {
 this.configuration = configuration;
 this.typeAliasRegistry = this.configuration.getTypeAliasRegistry();
 this.typeHandlerRegistry = this.configuration.getTypeHandlerRegistry();
}

代码示例来源:origin: org.mybatis/mybatis

public BaseBuilder(Configuration configuration) {
 this.configuration = configuration;
 this.typeAliasRegistry = this.configuration.getTypeAliasRegistry();
 this.typeHandlerRegistry = this.configuration.getTypeHandlerRegistry();
}

代码示例来源:origin: camunda/camunda-bpm-platform

private void typeAliasesElement(XNode parent) {
 if (parent != null) {
  for (XNode child : parent.getChildren()) {
   if ("package".equals(child.getName())) {
    String typeAliasPackage = child.getStringAttribute("name");
    configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
   } else {
    String alias = child.getStringAttribute("alias");
    String type = child.getStringAttribute("type");
    try {
     Class<?> clazz = Resources.classForName(type);
     if (alias == null) {
      typeAliasRegistry.registerAlias(clazz);
     } else {
      typeAliasRegistry.registerAlias(alias, clazz);
     }
    } catch (ClassNotFoundException e) {
     throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
    }
   }
  }
 }
}

代码示例来源:origin: org.mybatis/mybatis

private void typeAliasesElement(XNode parent) {
 if (parent != null) {
  for (XNode child : parent.getChildren()) {
   if ("package".equals(child.getName())) {
    String typeAliasPackage = child.getStringAttribute("name");
    configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
   } else {
    String alias = child.getStringAttribute("alias");
    String type = child.getStringAttribute("type");
    try {
     Class<?> clazz = Resources.classForName(type);
     if (alias == null) {
      typeAliasRegistry.registerAlias(clazz);
     } else {
      typeAliasRegistry.registerAlias(alias, clazz);
     }
    } catch (ClassNotFoundException e) {
     throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
    }
   }
  }
 }
}

代码示例来源:origin: org.apache.ibatis/ibatis-core

public BaseBuilder(Configuration configuration) {
 this.configuration = configuration;
 this.typeAliasRegistry = this.configuration.getTypeAliasRegistry();
 this.typeHandlerRegistry = this.configuration.getTypeHandlerRegistry();
}

代码示例来源:origin: mybatis-book/book

public static void main(String[] args) throws IOException {
  UnpooledDataSource dataSource = new UnpooledDataSource(
      "com.mysql.jdbc.Driver", 
      "jdbc:mysql://localhost:3306/mybatis", 
      "root", 
      "");
  TransactionFactory transactionFactory = new JdbcTransactionFactory();
  Environment environment = new Environment("Java", transactionFactory, dataSource);
  
  Configuration configuration = new Configuration(environment);
  configuration.getTypeAliasRegistry().registerAliases("tk.mybatis.simple.model");
  configuration.setLogImpl(Log4jImpl.class);
  
  InputStream inputStream = Resources.getResourceAsStream("tk/mybatis/simple/mapper/CountryMapper.xml");
  XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, "tk/mybatis/simple/mapper/CountryMapper.xml", configuration.getSqlFragments());
  mapperParser.parse();
  
  SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    List<Country> countryList = sqlSession.selectList("selectAll");
    printCountryList(countryList);
  } finally {
    sqlSession.close();
  }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db

public void loadAlias(String alias, Class dtoClass) {
 conf.getTypeAliasRegistry().registerAlias(alias, dtoClass);
}

代码示例来源:origin: com.intoverflow.booster/booster-config

private void addRegistry(@Autowired SqlSessionFactory sqlSessionFactory) {
    org.apache.ibatis.session.Configuration configuration = sqlSessionFactory.getConfiguration();
    configuration.getLanguageRegistry().register(VelocityLangDriver.class);
    configuration.getTypeAliasRegistry().registerAlias(VelocityLangDriver.class);
    configuration.getTypeAliasRegistry().registerAlias(BlankableEnumTypeHandler.class);
    configuration.getTypeAliasRegistry().registerAlias(BlankableEnumOrdinalTypeHandler.class);

    /*TypeHandlerRegistry typeHandlerRegistry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry();
    typeHandlerRegistry.register(BigDecimalArrayTypeHandler.class);
    typeHandlerRegistry.register(BooleanArrayTypeHandler.class);
    typeHandlerRegistry.register(CharacterArrayTypeHandler.class);
    typeHandlerRegistry.register(FloatArrayTypeHandler.class);
    typeHandlerRegistry.register(IntegerArrayTypeHandler.class);
    typeHandlerRegistry.register(LongArrayTypeHandler.class);
    typeHandlerRegistry.register(ShortArrayTypeHandler.class);
    typeHandlerRegistry.register(StringArrayTypeHandler.class);*/
  }
}

代码示例来源:origin: snakerflow/snakerflow

/**
 * 使用DataSource初始化SqlSessionFactory
 * @param ds 数据源
 */
public static void initialize(DataSource ds) {
  TransactionFactory transactionFactory = new MybatisTransactionFactory();
  Environment environment = new Environment("snaker", transactionFactory, ds);
  Configuration configuration = new Configuration(environment);
  configuration.getTypeAliasRegistry().registerAliases(SCAN_PACKAGE, Object.class);
  if (log.isInfoEnabled()) {
    Map<String, Class<?>> typeAliases = configuration.getTypeAliasRegistry().getTypeAliases();
    for(Entry<String, Class<?>> entry : typeAliases.entrySet()) {
      log.info("Scanned class:[name=" + entry.getKey() + ",class=" + entry.getValue().getName() + "]");
    }
  }
  try {
    for(String resource : resources) {
      InputStream in = Resources.getResourceAsStream(resource);
      XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, resource, configuration.getSqlFragments());
      xmlMapperBuilder.parse();
    }
  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    ErrorContext.instance().reset();
  }
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}

代码示例来源:origin: org.flowable/flowable-engine-common

public Configuration parseMybatisConfiguration(XMLConfigBuilder parser) {
  Configuration configuration = parser.parse();
  if (dependentEngineMybatisTypeAliasConfigs != null) {
    for (MybatisTypeAliasConfigurator typeAliasConfig : dependentEngineMybatisTypeAliasConfigs) {
      typeAliasConfig.configure(configuration.getTypeAliasRegistry());
    }
  }
  if (dependentEngineMybatisTypeHandlerConfigs != null) {
    for (MybatisTypeHandlerConfigurator typeHandlerConfig : dependentEngineMybatisTypeHandlerConfigs) {
      typeHandlerConfig.configure(configuration.getTypeHandlerRegistry());
    }
  }
  parseDependentEngineMybatisXMLMappers(configuration);
  parseCustomMybatisXMLMappers(configuration);
  return configuration;
}

代码示例来源:origin: sivaprasadreddy/Java-Persistence-with-MyBatis3

public static SqlSessionFactory getSqlSessionFactoryUsingJavaAPI()
{
  if(javaSqlSessionFactory==null) 
  {
    try
    {
      DataSource dataSource = DataSourceFactory.getDataSource();
      TransactionFactory transactionFactory = new JdbcTransactionFactory();
      Environment environment = new Environment("development", transactionFactory, dataSource);
      Configuration configuration = new Configuration(environment);
      configuration.getTypeAliasRegistry().registerAlias("student", Student.class);
      configuration.getTypeHandlerRegistry().register(PhoneTypeHandler.class);
      configuration.addMapper(StudentMapper.class);
      javaSqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
      
    }catch (Exception e)
    {
      throw new RuntimeException(e);
    }
  }
  return javaSqlSessionFactory;
}

代码示例来源:origin: org.alfresco/alfresco-repository

private void typeAliasesElement(XNode parent) {
  if (parent != null) {
    for (XNode child : parent.getChildren()) {
      if ("package".equals(child.getName())) {
        String typeAliasPackage = child.getStringAttribute("name");
        configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
      } else {
        String alias = child.getStringAttribute("alias");
        String type = child.getStringAttribute("type");
        try {
          Class<?> clazz = Resources.classForName(type);
          if (alias == null) {
            typeAliasRegistry.registerAlias(clazz);
          } else {
            typeAliasRegistry.registerAlias(alias, clazz);
          }
        } catch (ClassNotFoundException e) {
          throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
        }
      }
    }
  }
}

代码示例来源:origin: deas/alfresco

private void typeAliasesElement(XNode parent) {
  if (parent != null) {
    for (XNode child : parent.getChildren()) {
      if ("package".equals(child.getName())) {
        String typeAliasPackage = child.getStringAttribute("name");
        configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
      } else {
        String alias = child.getStringAttribute("alias");
        String type = child.getStringAttribute("type");
        try {
          Class<?> clazz = Resources.classForName(type);
          if (alias == null) {
            typeAliasRegistry.registerAlias(clazz);
          } else {
            typeAliasRegistry.registerAlias(alias, clazz);
          }
        } catch (ClassNotFoundException e) {
          throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
        }
      }
    }
  }
}

代码示例来源:origin: Alfresco/alfresco-repository

private void typeAliasesElement(XNode parent) {
  if (parent != null) {
    for (XNode child : parent.getChildren()) {
      if ("package".equals(child.getName())) {
        String typeAliasPackage = child.getStringAttribute("name");
        configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
      } else {
        String alias = child.getStringAttribute("alias");
        String type = child.getStringAttribute("type");
        try {
          Class<?> clazz = Resources.classForName(type);
          if (alias == null) {
            typeAliasRegistry.registerAlias(clazz);
          } else {
            typeAliasRegistry.registerAlias(alias, clazz);
          }
        } catch (ClassNotFoundException e) {
          throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
        }
      }
    }
  }
}

代码示例来源:origin: chanedi/QuickProject

private void typeAliasesElement(XNode parent) {
 if (parent != null) {
  for (XNode child : parent.getChildren()) {
   if ("package".equals(child.getName())) {
    String typeAliasPackage = child.getStringAttribute("name");
    configuration.getTypeAliasRegistry().registerAliases(typeAliasPackage);
   } else {
    String alias = child.getStringAttribute("alias");
    String type = child.getStringAttribute("type");
    try {
     Class<?> clazz = Resources.classForName(type);
     if (alias == null) {
      typeAliasRegistry.registerAlias(clazz);
     } else {
      typeAliasRegistry.registerAlias(alias, clazz);
     }
    } catch (ClassNotFoundException e) {
     throw new BuilderException("Error registering typeAlias for '" + alias + "'. Cause: " + e, e);
    }
   }
  }
 }
}

代码示例来源:origin: org.nanoframework/nano-orm-mybatis

final TypeAliasRegistry typeAliasRegistry = configuration.getTypeAliasRegistry();
for (final String pkg : typeAliasPackageName) {
  typeAliasRegistry.registerAliases(pkg);

代码示例来源:origin: org.ow2.petals.flowable/flowable-engine-common

public Configuration parseMybatisConfiguration(XMLConfigBuilder parser) {
  Configuration configuration = parser.parse();
  if (dependentEngineMybatisTypeAliasConfigs != null) {
    for (CustomMybatisTypeAliasConfig typeAliasConfig : dependentEngineMybatisTypeAliasConfigs) {
      configuration.getTypeAliasRegistry().registerAlias(typeAliasConfig.getAliasName(), typeAliasConfig.getTypeHandlerClass());
    }
  }
  if (dependentEngineMybatisTypeHandlerConfigs != null) {
    for (CustomMyBatisTypeHandlerConfig typeHandlerConfig : dependentEngineMybatisTypeHandlerConfigs) {
      configuration.getTypeHandlerRegistry().register(typeHandlerConfig.getJavaTypeClass(), typeHandlerConfig.getJdbcType(), typeHandlerConfig.getTypeHandlerClass());
    }
  }
  parseDependentEngineMybatisXMLMappers(configuration);
  parseCustomMybatisXMLMappers(configuration);
  return configuration;
}

代码示例来源:origin: org.alfresco/alfresco-repository

ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
for (String packageToScan : typeAliasPackageArray) {
  configuration.getTypeAliasRegistry().registerAliases(packageToScan,
      typeAliasesSuperType == null ? Object.class : typeAliasesSuperType);
  if (this.logger.isDebugEnabled()) {
  configuration.getTypeAliasRegistry().registerAlias(typeAlias);
  if (this.logger.isDebugEnabled()) {
    this.logger.debug("Registered type alias: '" + typeAlias + "'");

相关文章

Configuration类方法