private static void writeUpdate(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <update id=""{0}_UPDATE"" parameterType=""" + Constants.Package + @".main.db.tbl.{1}DTO"">", info.Name.ToUpper(), info.Name.ToTitleCase()); writer.WriteLine(@" UPDATE {0}", info.Name.ToUpper()); writer.WriteLine(@" <set>"); foreach (var column in info.Columns.FindAll(d => d.ColumnKey == false)) { writer.WriteLine(@" <if test=""{0}!=null"">{1} = {2},</if>", column.ColumnName.ToPrivateDefinition(), column.ColumnName.ToUpper(), getUpdateDataTime(column.ColumnName.ToPrivateDefinition())); } writer.WriteLine(@" </set>"); var lst = info.Columns.FindAll(d => d.ColumnKey == true); if (lst.Count > 0) { writer.WriteLine(@" WHERE"); var writeLine = string.Empty; foreach (var column in lst) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0}AND", writeLine); } writeLine = string.Format(@" {0} = #{{{1}}} ", column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(writeLine); } writer.WriteLine(@" </update>"); }
private static void writeLikeSearchOr(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <!-- Search LIKE(OR) -->"); if (info.GetType() == typeof(HcTableInfo)) { writer.WriteLine(@" <select id=""{0}_LIKE_SEARCH_OR"" resultType=""" + Constants.Package + @".main.db.tbl.{1}DTO"">", info.Name.ToUpper(), info.Name.ToTitleCase()); } else if (info.GetType() == typeof(HcViewInfo)) { writer.WriteLine(@" <select id=""{0}_LIKE_SEARCH_OR"" resultType=""" + Constants.Package + @".main.db.view.{1}DTO"">", info.Name.ToUpper(), info.Name.ToTitleCase()); } writer.WriteLine(@" SELECT"); var writeLine = string.Empty; foreach (var column in info.Columns) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0},", writeLine); writeLine = string.Empty; } writeLine = string.Format(@" {0} AS ""{1}"" ", column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(writeLine); writer.WriteLine(@" FROM {0}", info.Name.ToUpper()); writer.WriteLine(@" <where>"); foreach (var column in info.Columns) { writer.WriteLine(@" <if test=""{0} != null"">OR {1} LIKE '%'|| #{{{2}}} ||'%'</if>", column.ColumnName.ToPrivateDefinition(), column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(@" </where>"); writeLine = string.Empty; foreach (var column in info.Columns.FindAll(d => d.ColumnKey == true)) { if (!string.IsNullOrEmpty(writeLine)) { writeLine = string.Format("{0},", writeLine); } writeLine = string.Format(@"{0} {1}", writeLine, column.ColumnName.ToUpper()); } if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine(@" <if test=""_orderByCondition == null"">ORDER BY{0}</if>", writeLine); } writer.WriteLine(@" <if test=""_orderByCondition != null"">ORDER BY ${_orderByCondition}</if>"); writer.WriteLine(@" <if test=""_fetchFirstCondition != null"">FETCH FIRST ${_fetchFirstCondition} ROWS ONLY</if>"); writer.WriteLine(@" <if test=""_limitCondition != null"">LIMIT ${_limitCondition}</if>"); writer.WriteLine(@" <if test=""_offsetCondition != null"">OFFSET ${_offsetCondition}</if>"); writer.WriteLine(@" </select>"); }
private static void writeSQLSearch(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <!-- Customize Search -->"); if (info.GetType() == typeof(HcTableInfo)) { writer.WriteLine(@" <select id=""{0}_SQL_SEARCH"" resultType=""" + Constants.Package + @".main.db.tbl.{1}DTO"" parameterType=""java.util.Map"">", info.Name.ToUpper(), info.Name.ToTitleCase()); } else if (info.GetType() == typeof(HcViewInfo)) { writer.WriteLine(@" <select id=""{0}_SQL_SEARCH"" resultType=""" + Constants.Package + @".main.db.view.{1}DTO"" parameterType=""java.util.Map"">", info.Name.ToUpper(), info.Name.ToTitleCase()); } writer.WriteLine(@" SELECT"); var writeLine = string.Empty; foreach (var column in info.Columns) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0},", writeLine); writeLine = string.Empty; } writeLine = string.Format(@" {0} AS ""{1}"" ", column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(writeLine); writer.WriteLine(@" FROM {0}", info.Name.ToUpper()); writer.WriteLine(@" <if test=""_dynamicWhereCondition != null"">WHERE ${_dynamicWhereCondition}</if>"); writeLine = string.Empty; foreach (var column in info.Columns.FindAll(d => d.ColumnKey == true)) { if (!string.IsNullOrEmpty(writeLine)) { writeLine = string.Format("{0},", writeLine); } writeLine = string.Format(@"{0} {1}", writeLine, column.ColumnName.ToUpper()); } if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine(@" <if test=""_orderByCondition == null"">ORDER BY{0}</if>", writeLine); } writer.WriteLine(@" <if test=""_orderByCondition != null"">ORDER BY ${_orderByCondition}</if>"); writer.WriteLine(@" <if test=""_fetchFirstCondition != null"">FETCH FIRST ${_fetchFirstCondition} ROWS ONLY</if>"); writer.WriteLine(@" <if test=""_limitCondition != null"">LIMIT ${_limitCondition}</if>"); writer.WriteLine(@" <if test=""_offsetCondition != null"">OFFSET ${_offsetCondition}</if>"); writer.WriteLine(@" </select>"); }
private static void writeInsert(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <!-- Table Insert -->"); writer.WriteLine(@" <insert id=""{0}_INSERT"" parameterType=""" + Constants.Package + @".main.db.tbl.{1}DTO"">", info.Name.ToUpper(), info.Name.ToTitleCase()); writer.WriteLine(@" INSERT INTO {0} (", info.Name.ToUpper()); var writeLine = string.Empty; foreach (var column in info.Columns.FindAll(d => d.AutoIncrement == false)) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0},", writeLine); } writeLine = string.Format(@" {0} ", column.ColumnName.ToUpper()); } writer.WriteLine(writeLine); writer.WriteLine(@" ) VALUES ("); writeLine = string.Empty; foreach (var column in info.Columns.FindAll(d => d.AutoIncrement == false)) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0},", writeLine); } writeLine = string.Format(@" {0} ", getUpdateDataTime(column.ColumnName.ToPrivateDefinition())); } writer.WriteLine(writeLine); writer.WriteLine(@" )"); var keys = info.Columns.FindAll(d => d.ColumnKey == true && d.AutoIncrement == true); if (keys.Count > 0) { writer.WriteLine(@" <selectKey resultType=""java.lang.{0}"" order=""AFTER"" keyProperty = ""{1}"">", getJavaTypeString(keys[0].DataType), keys[0].ColumnName.ToPrivateDefinition()); writer.WriteLine(@" SELECT LAST_INSERT_ID() AS ID"); writer.WriteLine(@" </selectKey>"); } writer.WriteLine(@" </insert>"); }
private static void writeFindForUpdate(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <!-- Key Search(For Update) -->"); writer.WriteLine(@" <select id=""{0}_FIND_FOR_UPDATE"" resultType=""" + Constants.Package + @".main.db.tbl.{1}DTO"">", info.Name.ToUpper(), info.Name.ToTitleCase()); writer.WriteLine(@" SELECT"); var writeLine = string.Empty; foreach (var column in info.Columns) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0},", writeLine); writeLine = string.Empty; } writeLine = string.Format(@" {0} AS ""{1}"" ", column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(writeLine); writer.WriteLine(@" FROM {0}", info.Name.ToUpper()); var lst = info.Columns.FindAll(d => d.ColumnKey == true); if (lst.Count > 0) { writer.WriteLine(@" WHERE"); writeLine = string.Empty; foreach (var column in lst) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0}AND", writeLine); } writeLine = string.Format(@" {0} = #{{{1}}} ", column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(writeLine); writer.WriteLine(@" FOR UPDATE"); } writer.WriteLine(@" </select>"); }
private static void writeDelete(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <!-- Key Delete -->"); writer.WriteLine(@" <delete id=""{0}_DELETE"" parameterType=""" + Constants.Package + @".main.db.tbl.{1}DTO"">", info.Name.ToUpper(), info.Name.ToTitleCase()); writer.WriteLine(@" DELETE FROM {0}", info.Name.ToUpper()); var lst = info.Columns.FindAll(d => d.ColumnKey == true); if (lst.Count > 0) { writer.WriteLine(@" WHERE"); var writeLine = string.Empty; foreach (var column in lst) { if (!string.IsNullOrEmpty(writeLine)) { writer.WriteLine("{0}AND", writeLine); } writeLine = string.Format(@" {0} = #{{{1}}} ", column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(writeLine); } writer.WriteLine(@" </delete>"); }
private static void writeCountSearch(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <!-- Count Customize -->"); writer.WriteLine(@" <select id=""{0}_COUNT_SEARCH"" resultType=""java.lang.Integer"" parameterType=""java.util.Map"">", info.Name.ToUpper()); writer.WriteLine(@" SELECT count(*)"); writer.WriteLine(@" FROM {0}", info.Name.ToUpper()); writer.WriteLine(@" <if test=""_dynamicWhereCondition != null"">WHERE ${_dynamicWhereCondition}</if>"); writer.WriteLine(@" </select>"); }
private static void writeCountOR(HcDBBaseInfo info, StreamWriter writer) { writer.WriteLine(@" <!-- Count OR -->"); writer.WriteLine(@" <select id=""{0}_COUNT_OR"" resultType=""java.lang.Integer"">", info.Name.ToUpper()); writer.WriteLine(@" SELECT count(*)"); writer.WriteLine(@" FROM {0}", info.Name.ToUpper()); writer.WriteLine(@" <where>"); foreach (var column in info.Columns) { writer.WriteLine(@" <if test=""{0} != null"">OR {1} = #{{{2}}}</if>", column.ColumnName.ToPrivateDefinition(), column.ColumnName.ToUpper(), column.ColumnName.ToPrivateDefinition()); } writer.WriteLine(@" </where>"); writer.WriteLine(@" </select>"); }