package net.northking.cctp.maven.plugin;

import net.northking.cctp.maven.analyse.entity.TableRef;
import net.northking.cctp.maven.gen.CCTPGenerator;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

/**
 * 数据库实体类Maven插件
 *
 * @author xiusong.xie
 * @since 1.0
 */
@Mojo(name = "mybatis-service", threadSafe = true)
public class MybatisServiceMojo extends AbsDatabaseLoadMojo
{
  /**
   * Maven工程对象
   **/
  @Parameter(defaultValue = "${project}", readonly = true, required = true)
  private MavenProject project;


  /**
   * basePackage
   */
  @Parameter(required = true)
  private String basePackage;

  /**
   * 生成数据库表的实体对象
   *
   * @throws MojoExecutionException 异常
   * @throws MojoFailureException   异常
   */
  public final void execute() throws MojoExecutionException, MojoFailureException
  {
    CCTPGenerator generator = new CCTPGenerator(project.getBasedir(), basePackage);
    for (TableRef tableRef : loadTables())
    {
      generator.genMybatisService(tableRef);
    }

  }

}
