Package com.eatle.persistent.generator

Source Code of com.eatle.persistent.generator.RenameSlectByExamplePlugin

package com.eatle.persistent.generator;

import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
import static org.mybatis.generator.internal.util.messages.Messages.getString;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.IntrospectedTable;

/**
*@Description: 重命名 selectByExample
*/
public class RenameSlectByExamplePlugin extends PluginAdapter
{
  private String searchString;

  private String replaceString;

  private Pattern pattern;

  /**
     *
     */
  public RenameSlectByExamplePlugin()
  {
  }

  public boolean validate(List<String> warnings)
  {

    searchString = properties.getProperty("searchString"); //$NON-NLS-1$
    replaceString = properties.getProperty("replaceString"); //$NON-NLS-1$

    boolean valid = stringHasValue(searchString)
        && stringHasValue(replaceString);

    if (valid)
    {
      pattern = Pattern.compile(searchString);
    }
    else
    {
      if (!stringHasValue(searchString))
      {
        warnings.add(getString("ValidationError.18", //$NON-NLS-1$
            "RenameExampleClassPlugin", //$NON-NLS-1$
            "searchString")); //$NON-NLS-1$
      }
      if (!stringHasValue(replaceString))
      {
        warnings.add(getString("ValidationError.18", //$NON-NLS-1$
            "RenameExampleClassPlugin", //$NON-NLS-1$
            "replaceString")); //$NON-NLS-1$
      }
    }

    return valid;
  }

  @Override
  public void initialized(IntrospectedTable introspectedTable)
  {
    String oldType = introspectedTable.getSelectByExampleStatementId();
    Matcher matcher = pattern.matcher(oldType);
    oldType = matcher.replaceAll(replaceString);

    introspectedTable.setSelectByExampleStatementId(oldType);
  }
}
TOP

Related Classes of com.eatle.persistent.generator.RenameSlectByExamplePlugin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.