org.mybatis.generator.config.PluginConfiguration Java Examples
The following examples show how to use
org.mybatis.generator.config.PluginConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyBatisGeneratorConfigurationParser.java From mapper-generator-javafx with Apache License 2.0 | 6 votes |
private void parsePlugin(Context context, Node node) { PluginConfiguration pluginConfiguration = new PluginConfiguration(); context.addPluginConfiguration(pluginConfiguration); Properties attributes = parseAttributes(node); String type = attributes.getProperty("type"); pluginConfiguration.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())) { parseProperty(pluginConfiguration, childNode); } } }
Example #2
Source File: IbatorConfigurationParser.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
private void parseIbatorPlugin(Context context, Node node) { PluginConfiguration pluginConfiguration = new PluginConfiguration(); context.addPluginConfiguration(pluginConfiguration); Properties attributes = parseAttributes(node); String type = attributes.getProperty("type"); //$NON-NLS-1$ pluginConfiguration.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(pluginConfiguration, childNode); } } }
Example #3
Source File: MyBatisGeneratorConfigurationParser.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
private void parsePlugin(Context context, Node node) { PluginConfiguration pluginConfiguration = new PluginConfiguration(); context.addPluginConfiguration(pluginConfiguration); Properties attributes = parseAttributes(node); String type = attributes.getProperty("type"); //$NON-NLS-1$ pluginConfiguration.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(pluginConfiguration, childNode); } } }
Example #4
Source File: IbatorConfigurationParser.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
private void parseIbatorPlugin(Context context, Node node) { PluginConfiguration pluginConfiguration = new PluginConfiguration(); context.addPluginConfiguration(pluginConfiguration); Properties attributes = parseAttributes(node); String type = attributes.getProperty("type"); //$NON-NLS-1$ pluginConfiguration.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(pluginConfiguration, childNode); } } }
Example #5
Source File: MyBatisGeneratorConfigurationParser.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
private void parsePlugin(Context context, Node node) { PluginConfiguration pluginConfiguration = new PluginConfiguration(); context.addPluginConfiguration(pluginConfiguration); Properties attributes = parseAttributes(node); String type = attributes.getProperty("type"); //$NON-NLS-1$ pluginConfiguration.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(pluginConfiguration, childNode); } } }
Example #6
Source File: PluginTools.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 获取插件所在位置 * @param context 上下文 * @param plugin 插件 * @return -1:未找到 */ public static int getPluginIndex(Context context, Class plugin) { List<PluginConfiguration> list = getConfigPlugins(context); // 检查是否配置了ModelColumnPlugin插件 for (int i = 0; i < list.size(); i++) { PluginConfiguration config = list.get(i); if (plugin.getName().equals(config.getConfigurationType())) { return i; } } return -1; }
Example #7
Source File: PluginTools.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 获取插件列表 * @param ctx 上下文 * @return */ public static List<PluginConfiguration> getConfigPlugins(Context ctx) { try { // 利用反射获取pluginConfigurations属性 return (List<PluginConfiguration>) BeanUtils.getProperty(ctx, "pluginConfigurations"); } catch (Exception e) { logger.error("插件检查反射异常", e); } return new ArrayList<>(); }
Example #8
Source File: PluginTools.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 获取插件配置 * @param context 上下文 * @param plugin 插件 * @return */ public static PluginConfiguration getPluginConfiguration(Context context, Class plugin) { int index = getPluginIndex(context, plugin); if (index > -1) { return getConfigPlugins(context).get(index); } return null; }
Example #9
Source File: BasePlugin.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * Set the context under which this plugin is running. * @param context the new context */ @Override public void setContext(Context context) { super.setContext(context); // 添加插件 HookAggregator.getInstance().setContext(context); // 配置插件使用的模板引擎 PluginConfiguration cfg = PluginTools.getPluginConfiguration(context, CommentPlugin.class); if (cfg == null || cfg.getProperty(CommentPlugin.PRO_TEMPLATE) == null) { commentGenerator = context.getCommentGenerator(); } else { TemplateCommentGenerator templateCommentGenerator = new TemplateCommentGenerator(context, cfg.getProperty(CommentPlugin.PRO_TEMPLATE)); // ITFSW 插件使用的注释生成器 commentGenerator = templateCommentGenerator; // 修正系统插件 try { // 先执行一次生成CommentGenerator操作,然后再替换 context.getCommentGenerator(); BeanUtils.setProperty(context, "commentGenerator", templateCommentGenerator); } catch (Exception e) { logger.error("反射异常", e); } } // mybatis版本 if (StringUtility.stringHasValue(context.getProperty(PRO_MYBATIS_VERSION))) { this.mybatisVersion = context.getProperty(PRO_MYBATIS_VERSION); } }
Example #10
Source File: IntrospectedTableTools.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 设置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); } }
Example #11
Source File: ObjectFactory.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public static Plugin createPlugin(Context context, PluginConfiguration pluginConfiguration) { Plugin plugin = (Plugin) createInternalObject(pluginConfiguration .getConfigurationType()); plugin.setContext(context); plugin.setProperties(pluginConfiguration.getProperties()); return plugin; }
Example #12
Source File: XmbgMojoUnitTest.java From dolphin with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected boolean checkPlugin(Class<?> clazz, Context context){ Field field = FieldUtils.getDeclaredField(Context.class,"pluginConfigurations",true); try { List<PluginConfiguration> pluginConfigurations = (List<PluginConfiguration>) field.get(context); for(PluginConfiguration pluginConfiguration : pluginConfigurations){ if(pluginConfiguration.getConfigurationType().equals(clazz.getTypeName())){ return true; } } } catch (IllegalAccessException e) { e.printStackTrace(); } return false; }
Example #13
Source File: LombokPlugin.java From mybatis-generator-plugin with Apache License 2.0 | 4 votes |
/** * 添加注解 * @param topLevelClass * @param introspectedTable * @param modelType */ private void addAnnotations(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, EnumModelType modelType) { for (String annotation : this.annotations) { // @Data if (annotation.startsWith("@Data")) { this.addAnnotation(topLevelClass, annotation); if (topLevelClass.getSuperClass() != null) { this.addAnnotation(topLevelClass, "@EqualsAndHashCode(callSuper = true)"); this.addAnnotation(topLevelClass, "@ToString(callSuper = true)"); } } else if (annotation.startsWith("@Builder")) { // TODO 配合IncrementsPlugin,以后删除 boolean checkIncrementsPlugin = true; if (!this.suportSuperBuilderForIdea) { switch (modelType) { case MODEL_PRIMARY_KEY: checkIncrementsPlugin = PluginTools.getHook(ILombokPluginHook.class).modelPrimaryKeyBuilderClassGenerated(topLevelClass, introspectedTable); break; case MODEL_BASE_RECORD: checkIncrementsPlugin = PluginTools.getHook(ILombokPluginHook.class).modelBaseRecordBuilderClassGenerated(topLevelClass, introspectedTable); break; case MODEL_RECORD_WITH_BLOBS: checkIncrementsPlugin = PluginTools.getHook(ILombokPluginHook.class).modelRecordWithBLOBsBuilderClassGenerated(topLevelClass, introspectedTable); break; } } if (checkIncrementsPlugin) { // 有子类或者父类 int count = 0; if (introspectedTable.getRules().generatePrimaryKeyClass()) { count++; } if (introspectedTable.getRules().generateBaseRecordClass()) { count++; } if (introspectedTable.getRules().generateRecordWithBLOBsClass()) { count++; } if (topLevelClass.getSuperClass() != null || count >= 2) { if (this.suportSuperBuilderForIdea) { // TODO 兼容老版本 PluginConfiguration configuration = new PluginConfiguration(); configuration.setConfigurationType(ModelBuilderPlugin.class.getTypeName()); ModelBuilderPlugin modelBuilderPlugin = (ModelBuilderPlugin) ObjectFactory.createPlugin(this.context, configuration); switch (modelType) { case MODEL_PRIMARY_KEY: modelBuilderPlugin.modelPrimaryKeyBuilderClassGenerated(topLevelClass, introspectedTable); break; case MODEL_BASE_RECORD: modelBuilderPlugin.modelBaseRecordBuilderClassGenerated(topLevelClass, introspectedTable); break; case MODEL_RECORD_WITH_BLOBS: modelBuilderPlugin.modelRecordWithBLOBsBuilderClassGenerated(topLevelClass, introspectedTable); break; } } else { this.addAnnotation(topLevelClass, "@SuperBuilder"); } } else { this.addAnnotation(topLevelClass, annotation); } } } else { this.addAnnotation(topLevelClass, annotation); } } }
Example #14
Source File: ObjectFactory.java From mybatis-generator-core-fix with Apache License 2.0 | 3 votes |
/** * Creates a new Object object. * * @param context * the context * @param pluginConfiguration * the plugin configuration * @return the plugin */ public static Plugin createPlugin(Context context, PluginConfiguration pluginConfiguration) { Plugin plugin = (Plugin) createInternalObject(pluginConfiguration .getConfigurationType()); plugin.setContext(context); plugin.setProperties(pluginConfiguration.getProperties()); return plugin; }