Example #1
0
 def QueryCondition(self):
     self.WriteMsg('\t<sql id="queryCondition%s">' % self.mEntityTableName)
     self.WriteMsg('\t\t<dynamic prepend="where">')
     for i in self.mColumnNameList:
         self.WriteMsg(
             '\t\t\t<isNotNull prepend="and" property="%s"> %s = #%s# </isNotNull>'
             % (utils.convertJavaName(i), i, utils.convertJavaName(i)))
     self.WriteMsg('\t\t</dynamic>')
     self.WriteMsg('\t</sql>\n')
Example #2
0
 def Update(self):
     self.WriteMsg('\t<update id="update%s" parameterClass="%s.%s">' %
                   (self.mEntityTableName, self.cfg["package"],
                    self.mEntityTableName))
     self.WriteMsg('\t\tupdate %s' % self.mTableName)
     self.WriteMsg('\t\t<dynamic prepend="set">')
     for i in self.mColumnNameList:
         self.WriteMsg(
             '\t\t\t<isNotNull prepend="," property="%s"> %s = #%s# </isNotNull>'
             % (utils.convertJavaName(i), i, utils.convertJavaName(i)))
     self.WriteMsg('\t\t</dynamic>')
     self.WriteMsg('\t\t<include refid="queryByKey%s"/>' %
                   self.mClassTableName)
     self.WriteMsg('\t</update>\n')
Example #3
0
 def QueryByKey(self):
     if self.mPrimaryKey:
         self.WriteMsg('\t<sql id="queryByKey%s">' % self.mClassTableName)
         self.WriteMsg(
             '\t\twhere %s = #%s#' %
             (self.mPrimaryKey, utils.convertJavaName(self.mPrimaryKey)))
         self.WriteMsg('\t</sql>\n')
Example #4
0
 def ResultMap(self):
     self.WriteMsg(
         '\t<resultMap id="%s" class="%s.%s" > ' %
         (self.mResultMapName, self.cfg["package"], self.mEntityTableName))
     for i in self.mColumnNameList:
         self.WriteMsg('\t\t<result property="%s" column="%s"/>' %
                       (utils.convertJavaName(i), i))
     self.WriteMsg("\t</resultMap>\n")
Example #5
0
 def InsertEntity(self):
     self.WriteMsg('\t<insert id="insert%s" parameterClass="%s.%s">' %
                   (self.mEntityTableName, self.cfg["package"],
                    self.mEntityTableName))
     self.WriteMsg('\t\tinsert into %s(' % self.mTableName)
     first = True
     for i in self.mColumnNameList:
         self.WriteMsg(
             '\t\t<isNotNull prepend="%s" property="%s"> %s </isNotNull>' %
             ("" if first else ",", utils.convertJavaName(i), i))
         first = False
     self.WriteMsg('\t\t)\n\t\tvalues(')
     first = True
     for i in self.mColumnNameList:
         ni = utils.convertJavaName(i)
         self.WriteMsg(
             '\t\t<isNotNull prepend="%s" property="%s"> #%s# </isNotNull>'
             % ("" if first else ",", ni, ni))
         first = False
     self.WriteMsg('\t\t)')
     self.WriteMsg('\t</insert>\n')
Example #6
0
    def TryEntity(self):
        dirs = self.CheckDirectory("entity")
        fd = os.path.join(dirs, self.cfg["entity"] + ".java")
        with open(fd, "w", encoding="utf8") as of:
            self.mOutPutFileStream = of
            self.WriteMsg(const.JAVA_ENTITY_HEADER %
                          (const.PACKAGE_NAME, self.cfg["dirname"]))
            self.WriteMsg('@Table(name = "%s")' % self.cfg["table"])
            self.WriteMsg(
                'public class %s  extends AbsVersion implements Serializable, IEntity {\n'
                % self.mEntityTableName)
            pkVarType = "Integer"
            if self.mPrimaryKey:
                self.WriteMsg("\t@Primary")
                self.WriteMsg(
                    '\t@Column(name = "%s", sort = 0, isNotNull = true)' %
                    self.mPrimaryKey)
                for i in self.mDatas:
                    if i[1] == self.mPrimaryKey:
                        pkVarType = self.GetVarType(i[3])
                self.WriteMsg(
                    '\tprivate %s %s;' %
                    (pkVarType, utils.convertJavaName(self.mPrimaryKey)))
            idx = 1
            for i in self.mDatas:
                if i[1] == self.mPrimaryKey: continue
                self.WriteMsg(
                    '\t@Column(name = "%s", isNotNull = %s, comment = "%s", sort = %d)'
                    % (i[1], "false" if i[4] == "YES" else "true", i[5], idx))
                self.WriteMsg(
                    '\tprivate %s %s;' %
                    (self.GetVarType(i[3]), utils.convertJavaName(i[1])))
                idx += 1
            self.WriteMsg('\n')

            for i in self.mDatas:
                self.WriteMsg(
                    '\tpublic %s get%s() {' %
                    (self.GetVarType(i[3]), utils.convertClassName(i[1])))
                self.WriteMsg('\t\treturn %s;' % utils.convertJavaName(i[1]))
                self.WriteMsg('\t}\n')
                self.WriteMsg(
                    '\tpublic void set%s(%s %s) {' %
                    (utils.convertClassName(i[1]), self.GetVarType(
                        i[3]), utils.convertJavaName(i[1])))
                self.WriteMsg(
                    '\t\tthis.%s = %s;' %
                    (utils.convertJavaName(i[1]), utils.convertJavaName(i[1])))
                self.WriteMsg('\t}\n')

            self.WriteMsg("\t@Override")
            self.WriteMsg("\tpublic String getPirmaryKeyName() {")
            self.WriteMsg('\t\treturn "%s";' %
                          utils.convertJavaName(self.mPrimaryKey))
            self.WriteMsg("\t}\n")
            self.WriteMsg("\t@Override")
            self.WriteMsg('\tpublic %s getPrimaryKeyValue() {' % pkVarType)
            self.WriteMsg('\t\treturn this.%s;' %
                          utils.convertJavaName(self.mPrimaryKey))
            self.WriteMsg("\t}\n")
            self.WriteMsg("\t@Override")
            self.WriteMsg('\tpublic IEntity copy() {')
            self.WriteMsg('\t\t%s entity = new %s();' %
                          (self.mEntityTableName, self.mEntityTableName))
            for i in self.mDatas:
                clsi1 = utils.convertClassName(i[1])
                self.WriteMsg('\t\tentity.set%s(get%s());' % (clsi1, clsi1))
            self.WriteMsg('\t\treturn entity;')
            self.WriteMsg("\t}\n")
            self.WriteMsg("\t@Override")
            self.WriteMsg('\tpublic %s getWebUrlId() {' % pkVarType)
            self.WriteMsg('\t\treturn this.%s;' %
                          utils.convertJavaName(self.mPrimaryKey))
            self.WriteMsg("\t}\n")
            self.WriteMsg("}\n")