本文整理汇总了Java中org.mybatis.generator.config.Configuration类的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于org.mybatis.generator.config包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseIbatorConfiguration
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
public Configuration parseIbatorConfiguration(Element rootNode)
throws XMLParserException {
Configuration configuration = new Configuration();
NodeList nodeList = rootNode.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("properties".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperties(configuration, childNode);
} else if ("classPathEntry".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseClassPathEntry(configuration, childNode);
} else if ("ibatorContext".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseIbatorContext(configuration, childNode);
}
}
return configuration;
}
示例2: parseConfiguration
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
public Configuration parseConfiguration(Element rootNode)
throws XMLParserException {
Configuration configuration = new Configuration();
NodeList nodeList = rootNode.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("properties".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperties(configuration, childNode);
} else if ("classPathEntry".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseClassPathEntry(configuration, childNode);
} else if ("context".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseContext(configuration, childNode);
}
}
return configuration;
}
示例3: testGenerateMyBatis3WithInvalidConfig
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
@Test(expected=InvalidConfigurationException.class)
public void testGenerateMyBatis3WithInvalidConfig() throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3_badConfig.xml"));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, true);
} catch (InvalidConfigurationException e) {
assertEquals(2, e.getErrors().size());
throw e;
}
}
示例4: testGenerateIbatis2WithInvalidConfig
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
@Test(expected=InvalidConfigurationException.class)
public void testGenerateIbatis2WithInvalidConfig() throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigIbatis2_badConfig.xml"));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(1, e.getErrors().size());
throw e;
}
}
示例5: testGenerateInvalidConfigWithNoConnectionSources
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
@Test(expected=InvalidConfigurationException.class)
public void testGenerateInvalidConfigWithNoConnectionSources() throws Exception {
List<String> warnings = new ArrayList<String>();
Configuration config = new Configuration();
Context context = new Context(ModelType.HIERARCHICAL);
context.setId("MyContext");
config.addContext(context);
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(3, e.getErrors().size());
throw e;
}
}
示例6: testGenerateInvalidConfigWithTwoConnectionSources
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
@Test(expected=InvalidConfigurationException.class)
public void testGenerateInvalidConfigWithTwoConnectionSources() throws Exception {
List<String> warnings = new ArrayList<String>();
Configuration config = new Configuration();
Context context = new Context(ModelType.HIERARCHICAL);
context.setId("MyContext");
context.setConnectionFactoryConfiguration(new ConnectionFactoryConfiguration());
context.setJdbcConnectionConfiguration(new JDBCConnectionConfiguration());
config.addContext(context);
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(3, e.getErrors().size());
throw e;
}
}
示例7: testGenerateMyBatis3WithInvalidConfig
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
@Test(expected=InvalidConfigurationException.class)
public void testGenerateMyBatis3WithInvalidConfig() throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3_badConfig.xml"));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(2, e.getErrors().size());
throw e;
}
}
示例8: onOK
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
private void onOK() throws Exception {
Main.this.setTitle("正在运行...");
FileUtils.deleteDirectory( new File("src"));
File dir = new File("src");
if (!dir.exists()) {
dir.mkdir();
}
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
ConfigurationParser cp = new ConfigurationParser(warnings);
FileInputStream fileInputStream = new FileInputStream("generatorConfig.xml");
Configuration config = cp.parseConfiguration(fileInputStream);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
Main.this.setTitle("运行成功!");
}
示例9: getSqlSession
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
/**
* 获取SqlSession
* @return
* @throws IOException
*/
public SqlSession getSqlSession() throws IOException, ClassNotFoundException {
org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
config.setCallSettersOnNulls(true); // 设计null调用setter方法
config.setMapUnderscoreToCamelCase(true); // 驼峰命名支持
// 设置mapper
config.addMappers(targetPackage);
// 设置数据源,事务
PooledDataSourceFactory dataSourceFactory = new PooledDataSourceFactory();
dataSourceFactory.setProperties(DBHelper.properties);
DataSource dataSource = dataSourceFactory.getDataSource();
JdbcTransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("test", transactionFactory, dataSource);
config.setEnvironment(environment);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
return sqlSessionFactory.openSession(true);
}
示例10: generator
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
public static void generator(){
List<String> warnings=new ArrayList<String>();
try {
//specify the location of the config file to generator
File configFile=new File("./src/main/resources/mybatis/mybatis-generator/mybatis-generator.xml");
//parser the file
ConfigurationParser cp=new ConfigurationParser(warnings);
Configuration config=cp.parseConfiguration(configFile);
//set whether the file could be override
DefaultShellCallback dsc=new DefaultShellCallback(true);
MyBatisGenerator mg=new MyBatisGenerator(config, dsc, warnings);
mg.generate(null);
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: generator
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
public void generator() throws Exception{
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
//指定 逆向工程配置文件
File configFile = new File("generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
callback, warnings);
myBatisGenerator.generate(null);
}
示例12: MyBatisGenerator
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
/**
* Constructs a MyBatisGenerator object.
*
* @param configuration
* The configuration for this invocation
* @param shellCallback
* an instance of a ShellCallback interface. You may specify
* <code>null</code> in which case the DefaultShellCallback will
* be used.
* @param warnings
* Any warnings generated during execution will be added to this
* list. Warnings do not affect the running of the tool, but they
* may affect the results. A typical warning is an unsupported
* data type. In that case, the column will be ignored and
* generation will continue. You may specify <code>null</code> if
* you do not want warnings returned.
* @throws InvalidConfigurationException
* if the specified configuration is invalid
*/
public MyBatisGenerator(Configuration configuration, ShellCallback shellCallback,
List<String> warnings) throws InvalidConfigurationException {
super();
if (configuration == null) {
throw new IllegalArgumentException(getString("RuntimeError.2")); //$NON-NLS-1$
} else {
this.configuration = configuration;
}
if (shellCallback == null) {
this.shellCallback = new DefaultShellCallback(false);
} else {
this.shellCallback = shellCallback;
}
if (warnings == null) {
this.warnings = new ArrayList<String>();
} else {
this.warnings = warnings;
}
generatedJavaFiles = new ArrayList<GeneratedJavaFile>();
generatedXmlFiles = new ArrayList<GeneratedXmlFile>();
projects = new HashSet<String>();
this.configuration.validate();
}
示例13: generateJavaFiles
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
private static List<GeneratedJavaFile> generateJavaFiles(String configFile) throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(JavaCodeGenerationTest.class.getResourceAsStream(configFile));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
return myBatisGenerator.getGeneratedJavaFiles();
}
示例14: generateXmlFiles
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
private static List<GeneratedXmlFile> generateXmlFiles(String configFile) throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(JavaCodeGenerationTest.class.getResourceAsStream(configFile));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
return myBatisGenerator.getGeneratedXmlFiles();
}
示例15: main
import org.mybatis.generator.config.Configuration; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
List<String> warnings = new ArrayList<>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(
MapperGenerate.class.getResourceAsStream("/database/mybatis-generator-mapper-config.xml"));
DefaultShellCallback callback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}