本文整理汇总了Java中org.mybatis.generator.config.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于org.mybatis.generator.config包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseJavaTypeResolver
import org.mybatis.generator.config.Context; //导入依赖的package包/类
protected void parseJavaTypeResolver(Context context, Node node) {
JavaTypeResolverConfiguration javaTypeResolverConfiguration = new JavaTypeResolverConfiguration();
context.setJavaTypeResolverConfiguration(javaTypeResolverConfiguration);
Properties attributes = parseAttributes(node);
String type = attributes.getProperty("type"); //$NON-NLS-1$
if (stringHasValue(type)) {
javaTypeResolverConfiguration.setConfigurationType(type);
}
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperty(javaTypeResolverConfiguration, childNode);
}
}
}
开发者ID:xiachengwei5,项目名称:org.mybatis.generator.core-1.3.5,代码行数:26,代码来源:MyBatisGeneratorConfigurationParser.java
示例2: parseConnectionFactory
import org.mybatis.generator.config.Context; //导入依赖的package包/类
protected void parseConnectionFactory(Context context, Node node) {
ConnectionFactoryConfiguration connectionFactoryConfiguration = new ConnectionFactoryConfiguration();
context.setConnectionFactoryConfiguration(connectionFactoryConfiguration);
Properties attributes = parseAttributes(node);
String type = attributes.getProperty("type"); //$NON-NLS-1$
if (stringHasValue(type)) {
connectionFactoryConfiguration.setConfigurationType(type);
}
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperty(connectionFactoryConfiguration, childNode);
}
}
}
示例3: testGenerateInvalidConfigWithTwoConnectionSources
import org.mybatis.generator.config.Context; //导入依赖的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;
}
}
示例4: parseSqlMapGenerator
import org.mybatis.generator.config.Context; //导入依赖的package包/类
protected void parseSqlMapGenerator(Context context, Node node) {
SqlMapGeneratorConfiguration sqlMapGeneratorConfiguration = new SqlMapGeneratorConfiguration();
context.setSqlMapGeneratorConfiguration(sqlMapGeneratorConfiguration);
Properties attributes = parseAttributes(node);
String targetPackage = attributes.getProperty("targetPackage"); //$NON-NLS-1$
String targetProject = attributes.getProperty("targetProject"); //$NON-NLS-1$
sqlMapGeneratorConfiguration.setTargetPackage(targetPackage);
sqlMapGeneratorConfiguration.setTargetProject(targetProject);
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperty(sqlMapGeneratorConfiguration, childNode);
}
}
}
示例5: parseJavaModelGenerator
import org.mybatis.generator.config.Context; //导入依赖的package包/类
protected void parseJavaModelGenerator(Context context, Node node) {
JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = new JavaModelGeneratorConfiguration();
context
.setJavaModelGeneratorConfiguration(javaModelGeneratorConfiguration);
Properties attributes = parseAttributes(node);
String targetPackage = attributes.getProperty("targetPackage"); //$NON-NLS-1$
String targetProject = attributes.getProperty("targetProject"); //$NON-NLS-1$
javaModelGeneratorConfiguration.setTargetPackage(targetPackage);
javaModelGeneratorConfiguration.setTargetProject(targetProject);
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperty(javaModelGeneratorConfiguration, childNode);
}
}
}
示例6: getJavaBeansField
import org.mybatis.generator.config.Context; //导入依赖的package包/类
/**
* Gets the java beans field.
*
* @param introspectedColumn
* the introspected column
* @param context
* the context
* @param introspectedTable
* the introspected table
* @return the java beans field
*/
public static Field getJavaBeansField(IntrospectedColumn introspectedColumn,
Context context,
IntrospectedTable introspectedTable) {
FullyQualifiedJavaType fqjt = introspectedColumn
.getFullyQualifiedJavaType();
String property = introspectedColumn.getJavaProperty();
Field field = new Field();
field.setVisibility(JavaVisibility.PRIVATE);
field.setType(fqjt);
field.setName(property);
context.getCommentGenerator().addFieldComment(field,
introspectedTable, introspectedColumn);
return field;
}
示例7: testGenerateInvalidConfigWithNoConnectionSources
import org.mybatis.generator.config.Context; //导入依赖的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;
}
}
示例8: getJavaBeansGetter
import org.mybatis.generator.config.Context; //导入依赖的package包/类
/**
* Gets the java beans getter.
*
* @param introspectedColumn
* the introspected column
* @param context
* the context
* @param introspectedTable
* the introspected table
* @return the java beans getter
*/
public static Method getJavaBeansGetter(IntrospectedColumn introspectedColumn,
Context context,
IntrospectedTable introspectedTable) {
FullyQualifiedJavaType fqjt = introspectedColumn
.getFullyQualifiedJavaType();
String property = introspectedColumn.getJavaProperty();
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(fqjt);
method.setName(getGetterMethodName(property, fqjt));
context.getCommentGenerator().addGetterComment(method,
introspectedTable, introspectedColumn);
StringBuilder sb = new StringBuilder();
sb.append("return "); //$NON-NLS-1$
sb.append(property);
sb.append(';');
method.addBodyLine(sb.toString());
return method;
}
示例9: parseCommentGenerator
import org.mybatis.generator.config.Context; //导入依赖的package包/类
protected void parseCommentGenerator(Context context, Node node) {
CommentGeneratorConfiguration commentGeneratorConfiguration = new CommentGeneratorConfiguration();
context.setCommentGeneratorConfiguration(commentGeneratorConfiguration);
Properties attributes = parseAttributes(node);
String type = attributes.getProperty("type"); //$NON-NLS-1$
if (stringHasValue(type)) {
commentGeneratorConfiguration.setConfigurationType(type);
}
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperty(commentGeneratorConfiguration, childNode);
}
}
}
示例10: createIntrospectedTableForValidation
import org.mybatis.generator.config.Context; //导入依赖的package包/类
/**
* This method creates an introspected table implementation that is only usable for validation (i.e. for a context
* to determine if the target is ibatis2 or mybatis3).
*
*
* @param context
* the context
* @return the introspected table
*/
public static IntrospectedTable createIntrospectedTableForValidation(Context context) {
String type = context.getTargetRuntime();
if (!stringHasValue(type)) {
type = IntrospectedTableMyBatis3Impl.class.getName();
} else if ("Ibatis2Java2".equalsIgnoreCase(type)) { //$NON-NLS-1$
type = IntrospectedTableIbatis2Java2Impl.class.getName();
} else if ("Ibatis2Java5".equalsIgnoreCase(type)) { //$NON-NLS-1$
type = IntrospectedTableIbatis2Java5Impl.class.getName();
} else if ("Ibatis3".equalsIgnoreCase(type)) { //$NON-NLS-1$
type = IntrospectedTableMyBatis3Impl.class.getName();
} else if ("MyBatis3".equalsIgnoreCase(type)) { //$NON-NLS-1$
type = IntrospectedTableMyBatis3Impl.class.getName();
} else if ("MyBatis3Simple".equalsIgnoreCase(type)) { //$NON-NLS-1$
type = IntrospectedTableMyBatis3SimpleImpl.class.getName();
}
IntrospectedTable answer = (IntrospectedTable) createInternalObject(type);
answer.setContext(context);
return answer;
}
示例11: DatabaseIntrospector
import org.mybatis.generator.config.Context; //导入依赖的package包/类
/**
* Instantiates a new database introspector.
*
* @param context
* the context
* @param databaseMetaData
* the database meta data
* @param javaTypeResolver
* the java type resolver
* @param warnings
* the warnings
*/
public DatabaseIntrospector(Context context,
DatabaseMetaData databaseMetaData,
JavaTypeResolver javaTypeResolver, List<String> warnings) {
super();
this.context = context;
this.databaseMetaData = databaseMetaData;
this.javaTypeResolver = javaTypeResolver;
this.warnings = warnings;
logger = LogFactory.getLog(getClass());
//获取数据库的版本信息
try {
DatabaseMetaData md = databaseMetaData.getConnection().getMetaData();
databaseProductName = md.getDatabaseProductName().toUpperCase();
} catch (SQLException se) {
warnings.add("获取数据库版本失败:" + se.getMessage());
}
}
示例12: getJavaBeansSetter
import org.mybatis.generator.config.Context; //导入依赖的package包/类
/**
* Gets the java beans setter.
*
* @param introspectedColumn
* the introspected column
* @param context
* the context
* @param introspectedTable
* the introspected table
* @return the java beans setter
*/
public static Method getJavaBeansSetter(IntrospectedColumn introspectedColumn,
Context context,
IntrospectedTable introspectedTable) {
FullyQualifiedJavaType fqjt = introspectedColumn
.getFullyQualifiedJavaType();
String property = introspectedColumn.getJavaProperty();
Method method = new Method();
method.setVisibility(JavaVisibility.PUBLIC);
method.setName(getSetterMethodName(property));
method.addParameter(new Parameter(fqjt, property));
context.getCommentGenerator().addSetterComment(method,
introspectedTable, introspectedColumn);
StringBuilder sb = new StringBuilder();
if (introspectedColumn.isStringColumn() && isTrimStringsEnabled(introspectedColumn)) {
sb.append("this."); //$NON-NLS-1$
sb.append(property);
sb.append(" = "); //$NON-NLS-1$
sb.append(property);
sb.append(" == null ? null : "); //$NON-NLS-1$
sb.append(property);
sb.append(".trim();"); //$NON-NLS-1$
method.addBodyLine(sb.toString());
} else {
sb.append("this."); //$NON-NLS-1$
sb.append(property);
sb.append(" = "); //$NON-NLS-1$
sb.append(property);
sb.append(';');
method.addBodyLine(sb.toString());
}
return method;
}
示例13: setDomainObjectName
import org.mybatis.generator.config.Context; //导入依赖的package包/类
/**
* 设置DomainObjectName和MapperName
*
* @param introspectedTable
* @param context
* @param domainObjectName
*/
public static void setDomainObjectName(IntrospectedTable introspectedTable, Context context, String domainObjectName) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
// 配置信息(没啥用)
introspectedTable.getTableConfiguration().setDomainObjectName(domainObjectName);
// FullyQualifiedTable修正
Field domainObjectNameField = FullyQualifiedTable.class.getDeclaredField("domainObjectName");
domainObjectNameField.setAccessible(true);
domainObjectNameField.set(introspectedTable.getFullyQualifiedTable(), domainObjectName);
// 重新修正introspectedTable属性信息
Method calculateJavaClientAttributes = IntrospectedTable.class.getDeclaredMethod("calculateJavaClientAttributes");
calculateJavaClientAttributes.setAccessible(true);
calculateJavaClientAttributes.invoke(introspectedTable);
Method calculateModelAttributes = IntrospectedTable.class.getDeclaredMethod("calculateModelAttributes");
calculateModelAttributes.setAccessible(true);
calculateModelAttributes.invoke(introspectedTable);
Method calculateXmlAttributes = IntrospectedTable.class.getDeclaredMethod("calculateXmlAttributes");
calculateXmlAttributes.setAccessible(true);
calculateXmlAttributes.invoke(introspectedTable);
// 注意!! 如果配置了ExampleTargetPlugin插件,要修正Example 位置
PluginConfiguration configuration = PluginTools.getPluginConfiguration(context, ExampleTargetPlugin.class);
if (configuration != null && configuration.getProperty(ExampleTargetPlugin.PRO_TARGET_PACKAGE) != null) {
String exampleType = introspectedTable.getExampleType();
// 修改包名
JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = context.getJavaModelGeneratorConfiguration();
String targetPackage = javaModelGeneratorConfiguration.getTargetPackage();
String newExampleType = exampleType.replace(targetPackage, configuration.getProperty(ExampleTargetPlugin.PRO_TARGET_PACKAGE));
introspectedTable.setExampleType(newExampleType);
}
}
示例14: createJavaFormatter
import org.mybatis.generator.config.Context; //导入依赖的package包/类
/**
* Creates a new Object object.
*
* @param context
* the context
* @return the java formatter
*/
public static JavaFormatter createJavaFormatter(Context context) {
String type = context.getProperty(PropertyRegistry.CONTEXT_JAVA_FORMATTER);
if (!stringHasValue(type)) {
type = DefaultJavaFormatter.class.getName();
}
JavaFormatter answer = (JavaFormatter) createInternalObject(type);
answer.setContext(context);
return answer;
}
示例15: parseJavaClientGenerator
import org.mybatis.generator.config.Context; //导入依赖的package包/类
private void parseJavaClientGenerator(Context context, Node node) {
JavaClientGeneratorConfiguration javaClientGeneratorConfiguration = new JavaClientGeneratorConfiguration();
context.setJavaClientGeneratorConfiguration(javaClientGeneratorConfiguration);
Properties attributes = parseAttributes(node);
String type = attributes.getProperty("type"); //$NON-NLS-1$
String targetPackage = attributes.getProperty("targetPackage"); //$NON-NLS-1$
String targetProject = attributes.getProperty("targetProject"); //$NON-NLS-1$
String implementationPackage = attributes
.getProperty("implementationPackage"); //$NON-NLS-1$
javaClientGeneratorConfiguration.setConfigurationType(type);
javaClientGeneratorConfiguration.setTargetPackage(targetPackage);
javaClientGeneratorConfiguration.setTargetProject(targetProject);
javaClientGeneratorConfiguration
.setImplementationPackage(implementationPackage);
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
parseProperty(javaClientGeneratorConfiguration, childNode);
}
}
}