package com.cmb.ccrm.mng;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import org.junit.Test;
import com.cmb.ccrm.base.BaseTest;
import com.google.common.base.CaseFormat;
public class test extends BaseTest {
@Test public void 生成实体类() throws Exception {
String tableName = "s51_tsk_rel_cust";
Connection conn = connection.getConnection();
DatabaseMetaData databaseMetaData = conn.getMetaData();
ResultSet tableRet = databaseMetaData.getTables(null, "%", tableName, new String[] { "TABLE" });
while (tableRet.next()) {
String columnName; String columnType;
ResultSet colRet = databaseMetaData.getColumns(null, "%", tableName, "%");
while (colRet.next()) { columnName = colRet.getString("COLUMN_NAME");
columnType = colRet.getString("TYPE_NAME").toLowerCase();
String remarks = colRet.getString("REMARKS");
String columType = "";
switch (columnType) {
case "varchar":
columType = "String";
break;
case "int":
columType = "int"; break;
default:
columType = "String";
}
System.out.println("/**");
System.out.println("*" + remarks);
System.out.println("*/"); // System.out.println(CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, "test-data")); // System.out.println(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "test_data")); // System.out.println(CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, "test_data")); // // System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "testdata")); // System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, "TestData")); // System.out.println(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, "testData"));
System.out.println("private " + columType + "\t" + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, columnName) + ";");
System.out.println();
}
}
}
}