java 字符串拼出hibernate xml

package com.kongjs.dbmo.jdbc;

import org.springframework.util.StringUtils;


public final class HBM {
    public static String toMappingString(String s) {
        String str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<!DOCTYPE hibernate-mapping PUBLIC\n" +
                "        \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" +
                "        \"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">";
        return str + "<hibernate-mapping>" + s + "</hibernate-mapping>";
    }

    public static String toEntityString(String table, String s, String comment) {
        if (StringUtils.hasLength(comment)) {
            s += " <comment>" + comment + "</comment> ";
        }
        return " <class entity-name=\"" + table + "\" table=\"" + table + "\">" + s + "</class> ";
    }

    public static String toCompositeIdString(String s) {
        return " <composite-id>" + s + "</composite-id> ";
    }

    public static String toColumnString(String name, String length, String precision, String scale, Boolean notNull, Boolean unique, String sqlType, String index, Boolean check, String defaultVal, String comment, String javaTypeName) {
        String s = "";
        s += " <column";
        if (StringUtils.hasLength(name)) {
            s += " name=\"" + name + "\"";
        }
        if (StringUtils.hasLength(length)) {
            s += " length=\"" + length + "\"";
        }
        if (StringUtils.hasLength(precision)) {
            s += " precision=\"" + precision + "\"";
        }
        if (StringUtils.hasLength(scale)) {
            s += " scale=\"" + scale + "\"";
        }
        if (notNull != null && notNull) {
            s += " not-null=\"" + notNull + "\"";
        }
        if (unique != null && unique) {
            s += " unique=\"" + unique + "\"";
        }
        if (StringUtils.hasLength(sqlType)) {
            s += " sql-type=\"" + sqlType + "\"";
        }
        if (StringUtils.hasLength(index)) {
            s += " index=\"" + index + "\"";
        }
        if (check != null && check) {
            s += " check=\"" + check + "\"";
        }
        if (StringUtils.hasLength(defaultVal)) {
            s += " default=\"" + defaultVal + "\"";
        }
        s += ">";
        if (StringUtils.hasLength(comment)) {
            s += " <comment>" + comment + "</comment>";
        }
        s += " </column>";
        if (StringUtils.hasLength(javaTypeName)) {
            s += " <type name=\"" + javaTypeName + "\"/> ";
        }
        return s;
    }

    public static String toPropertyString(String name, String length, String precision, String scale, Boolean notNull, Boolean unique, String sqlType, String index, Boolean check, String defaultVal, String comment, String javaTypeName) {
        return " <property name=\"" + name + "\">" + toColumnString(name, length, precision, scale, notNull, unique, sqlType, index, check, defaultVal, comment, javaTypeName) + "</property> ";
    }

    public static String toKeyPropertyString(String name, String length, String precision, String scale, Boolean notNull, Boolean unique, String sqlType, String index, Boolean check, String defaultVal, String comment, String javaTypeName) {
        return " <key-property name=\"" + name + "\">" + toColumnString(name, length, precision, scale, notNull, unique, sqlType, index, check, defaultVal, comment, javaTypeName) + "</key-property> ";
    }

    public static String toIdString(String name, String length, String precision, String scale, Boolean notNull, Boolean unique, String sqlType, String index, Boolean check, String defaultVal, String comment, String javaTypeName) {
        return " <id name=\"" + name + "\">" + toColumnString(name, length, precision, scale, notNull, unique, sqlType, index, check, defaultVal, comment, javaTypeName) + "</id> ";
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值