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> ";
}
}
java 字符串拼出hibernate xml
最新推荐文章于 2024-09-27 00:45:01 发布