Пример #1
0
        public static HcSQLInfo CreateProduct(string schema, string name, string key, string sql)
        {
            var sqlInfo = new HcSQLInfo();
            if (HcMySQLToolContext.IsConnected)
            {
                sqlInfo.Name = name;
                sqlInfo.Key = key;
                sqlInfo.SQL = sql;
                sqlInfo.Columns = HcColumnInfo.CreateColumns(schema, sqlInfo.Name);
            }

            return sqlInfo;
        }
Пример #2
0
        private void createSqlJava(string folder, HcSQLInfo sqlInfo)
        {
            DirectoryInfo newFolder;
            if (Directory.Exists(folder + @"\src\" + Constants.Package.Replace(@".", @"\") + @"\main\db\sql"))
            {
                newFolder = new DirectoryInfo(folder + @"\src\" + Constants.Package.Replace(@".", @"\") + @"\main\db\sql");
            }
            else
            {
                newFolder = Directory.CreateDirectory(folder + @"\src\" + Constants.Package.Replace(@".", @"\") + @"\main\db\sql");
            }

            writeSqlSupportJava(newFolder.FullName, sqlInfo);
            writeSqlJava(newFolder.FullName, sqlInfo);
        }
Пример #3
0
        private void createMybatisCustomXML(string folder, HcSQLInfo sqlInfo)
        {
            DirectoryInfo newFolder;
            if (Directory.Exists(folder + @"\src\sql\cmt"))
            {
                newFolder = new DirectoryInfo(folder + @"\src\sql\cmt");
            }
            else
            {
                newFolder = Directory.CreateDirectory(folder + @"\src\sql\cmt");
            }

            var file = new FileStream(string.Format(@"{0}\custom.xml", newFolder.FullName), FileMode.Create, FileAccess.Write);
            using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8))
            {
                writer.WriteLine(@"<?xml version=""1.0"" encoding=""UTF-8"" ?>");
                writer.WriteLine(@"<!DOCTYPE mapper PUBLIC ""-//mybatis.org//DTD Mapper 3.0//EN"" ""http://mybatis.org/dtd/mybatis-3-mapper.dtd"">");
                writer.WriteLine(@"");
                writer.WriteLine(@"<mapper namespace=""custom"">");
                writer.WriteLine(@"");
                writer.WriteLine(@"	<select id=""{0}"" resultType=""{1}.main.db.sql.{2}DTO"">", sqlInfo.Key, Constants.Package, sqlInfo.Name.ToTitleCase());
                writer.WriteLine(@"		{0}", sqlInfo.SQL);
                writer.WriteLine(@"	</select>");
                writer.WriteLine(@"</mapper>");
            }
        }
Пример #4
0
 public void WriteServiceDBSql(string path, HcSQLInfo sqlInfo)
 {
     DirectoryInfo dir;
     if (Directory.Exists(path + @"\" + Constants.Package + @".main.db"))
     {
         dir = new DirectoryInfo(path + @"\" + Constants.Package + @".main.db");
     }
     else
     {
         dir = Directory.CreateDirectory(path + @"\" + Constants.Package + @".main.db");
     }
     createMybatisCustomXML(dir.FullName, sqlInfo);
     createSqlJava(dir.FullName, sqlInfo);
 }
Пример #5
0
        private void writeSqlSupportJava(string path, HcSQLInfo sqlInfo)
        {
            var newFolder = Directory.CreateDirectory(path + @"\support");
            var file = File.Create(string.Format(@"{0}\{1}DTOSupport.java", newFolder.FullName, sqlInfo.Name.ToTitleCase()));
            using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8))
            {
                writer.WriteLine(@"/*");
                writer.WriteLine(@" * {0}", ToolLibrary.Constants.ProjectName);
                writer.WriteLine(@" * {0}", ToolLibrary.Constants.CompanyName);
                writer.WriteLine(@" */");
                writer.WriteLine(@"package " + Constants.Package + @".main.db.sql.support;");
                writer.WriteLine(@"");
                if (sqlInfo.Columns.FindAll(d => d.DataType == MySqlDbType.VarChar).Count > 0)
                {
                    writer.WriteLine(@"import " + Constants.Package + @".fw.core.util.StringUtil;");
                }
                if (sqlInfo.Columns.FindAll(d => d.DataType == MySqlDbType.Date || d.DataType == MySqlDbType.Time).Count > 0)
                {
                    writer.WriteLine(@"import " + Constants.Package + @".fw.core.util.DateUtil;");
                }
                if (sqlInfo.Columns.FindAll(d => d.DataType == MySqlDbType.Blob).Count > 0)
                {
                    writer.WriteLine(@"import " + Constants.Package + @".fw.core.sql.CISBlob;");
                }
                writer.WriteLine(@"import " + Constants.Package + @".main.db.base.BaseTableDTO;");
                writer.WriteLine(@"import " + Constants.Package + @".main.db.sql.{0}DTO;", sqlInfo.Name.ToTitleCase());
                writer.WriteLine(@"");
                writer.WriteLine(@"/**");
                writer.WriteLine(@" *Service DB Support DTO");
                writer.WriteLine(@" *");
                writer.WriteLine(@" * History");
                writer.WriteLine(@" * REV.         Updated Date           Updater              Infomation");
                writer.WriteLine(@" * -------      ---------------        ----------------     ------------------");
                writer.WriteLine(@" * 1.0          {0}             TOOL                 Create", DateTime.Now.ToString("yyyy/MM/dd"));
                writer.WriteLine(@"*");
                writer.WriteLine(@" */");
                writer.WriteLine(@"public abstract class {0}DTOSupport extends BaseTableDTO {{", sqlInfo.Name.ToTitleCase());
                writer.WriteLine(@"");

                foreach (var column in sqlInfo.Columns)
                {
                    writer.WriteLine(@"");
                    writer.WriteLine(@"	public static final String COLUMN_{0} = ""{0}"";", column.ColumnName.ToUpper());
                }

                writer.WriteLine(@"");
                writer.WriteLine(@"	public static final String SQL_NAME = ""{0}"";", sqlInfo.Key);

                writer.WriteLine(@"");
                writer.WriteLine(@"	public static {0}DTO setDefaultValue() {{", sqlInfo.Name.ToTitleCase());
                writer.WriteLine(@"		{0}DTO defaultDTO = new {0}DTO();", sqlInfo.Name.ToTitleCase());

                foreach (var column in sqlInfo.Columns)
                {
                    writer.WriteLine(@"");
                    writer.WriteLine(@"		defaultDTO.set{0}({1});", column.ColumnName.ToPublicDefinition(), getDefaultValue(column.DataType));
                }

                writer.WriteLine(@"");
                writer.WriteLine(@"		return defaultDTO;");
                writer.WriteLine(@"	}");
                writer.WriteLine(@"}");
            }
        }
Пример #6
0
        private void writeSqlJava(string newFolder, HcSQLInfo sqlInfo)
        {
            var file = new FileStream(string.Format(@"{0}\{1}DTO.java", newFolder, sqlInfo.Name.ToTitleCase()), FileMode.Create, FileAccess.Write);
            using (StreamWriter writer = new StreamWriter(file, System.Text.Encoding.UTF8))
            {
                writer.WriteLine(@"/*");
                writer.WriteLine(@" * {0}", ToolLibrary.Constants.ProjectName);
                writer.WriteLine(@" * {0}", ToolLibrary.Constants.CompanyName);
                writer.WriteLine(@" */");
                writer.WriteLine(@"package " + Constants.Package + @".main.db.sql;");
                writer.WriteLine(@"");
                writer.WriteLine(@"import " + Constants.Package + @".main.db.sql.support.{0}DTOSupport;", sqlInfo.Name.ToTitleCase());
                writer.WriteLine(@"");
                writer.WriteLine(@"/**");
                writer.WriteLine(@" *Service DB DTO");
                writer.WriteLine(@" *");
                writer.WriteLine(@" * History");
                writer.WriteLine(@" * REV.         Updated Date           Updater              Infomation");
                writer.WriteLine(@" * -------      ---------------        ----------------     ------------------");
                writer.WriteLine(@" * 1.0          {0}             TOOL                 Create", DateTime.Now.ToString("yyyy/MM/dd"));
                writer.WriteLine(@"*");
                writer.WriteLine(@" */");
                writer.WriteLine(@"@" + Constants.Package + @".fw.core.type.Alias(""{0}"")", sqlInfo.Name.ToUpper());
                writer.WriteLine(@"@" + Constants.Package + @".fw.core.type.AliasKanJi("""")");
                writer.WriteLine(@"public class {0}DTO extends {0}DTOSupport implements java.io.Serializable, Comparable<{0}DTO> {{", sqlInfo.Name.ToTitleCase());
                writer.WriteLine(@"");
                writer.WriteLine(@"	private static final long serialVersionUID = 1L;");

                var i = 0;
                foreach (var column in sqlInfo.Columns)
                {
                    writer.WriteLine(@"");
                    writer.WriteLine(@"	@" + Constants.Package + @".fw.core.type.Alias(""{0}"")", column.ColumnName.ToUpper());
                    writer.WriteLine(@"	@" + Constants.Package + @".fw.core.type.Index({0})", i);
                    writer.WriteLine(@"	@" + Constants.Package + @".fw.core.type.DataType(""{0}"")", column.DataTypeName);
                    if (column.IsNullAble == false)
                    {
                        writer.WriteLine(@"	@" + Constants.Package + @".fw.core.type.NotNull");
                    }
                    if (column.DataType == MySqlDbType.VarChar || column.DataType == MySqlDbType.Blob)
                    {
                        writer.WriteLine(@"	@" + Constants.Package + @".fw.core.type.Length(min = {0}, max = {0})", column.Character_Maximum_Length);
                    }
                    if (column.ColumnKey == true)
                    {
                        writer.WriteLine(@"	@" + Constants.Package + @".fw.core.type.IsPK");
                    }
                    writer.WriteLine(@"	private {0} {1} = null;", getJavaTypeString(column.DataType), column.ColumnName.ToPrivateDefinition());
                    i++;
                }

                foreach (var column in sqlInfo.Columns)
                {
                    writer.WriteLine(@"");
                    writer.WriteLine(@"	public {0} get{1}() {{", getJavaTypeString(column.DataType), column.ColumnName.ToPublicDefinition());
                    writer.WriteLine(@"		return this.{0};", column.ColumnName.ToPrivateDefinition());
                    writer.WriteLine(@"	}");
                    writer.WriteLine(@"");
                    writer.WriteLine(@"	public void set{0}(", column.ColumnName.ToPublicDefinition());
                    writer.WriteLine(@"			{0} {1}) {{", getJavaTypeString(column.DataType), column.ColumnName.ToPrivateDefinition());
                    writer.WriteLine(@"		this.{0} = {0};", column.ColumnName.ToPrivateDefinition());
                    writer.WriteLine(@"	}");
                }
                writer.WriteLine(@"");
                writer.WriteLine(@"  	/* (non-Javadoc)");
                writer.WriteLine(@"     * @see java.lang.Comparable#compareTo(java.lang.Object)");
                writer.WriteLine(@"     */");
                writer.WriteLine(@"    @Override");
                writer.WriteLine(@"    public int compareTo(");
                writer.WriteLine(@"			{0}DTO compareToDTO) {{", sqlInfo.Name.ToTitleCase());
                writer.WriteLine(@"        return this.equals(compareToDTO) ? 0 : -1;");
                writer.WriteLine(@"    }");
                writer.WriteLine(@"}");
                writer.WriteLine(@"");
            }
        }