wiki.xsx.jg.main.Generator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JG-All Show documentation
Show all versions of JG-All Show documentation
a generator, from the database tables convert to the Java classes or from the Java classes convert to the database tables.
support mysql, oracle and sqlserver.
The newest version!
package wiki.xsx.jg.main;
import wiki.xsx.jg.core.FileGenerator;
import wiki.xsx.jg.core.TableGenerator;
import wiki.xsx.jg.log.Logger;
/**
* 生成器类
*/
public class Generator {
/**
* 根据数据表生成Java文件
* @param tableNames 表名,多个逗号分隔
* @param driverClassName 数据库驱动名称
* @param dbUrl 数据库地址
* @param userName 数据库用户名
* @param password 数据库密码
* @param rootPath 包的根路径
* @param packageName 完整包名,如com.xsx.test
*/
public static void createFiles(
String tableNames,
String driverClassName,
String dbUrl,
String userName,
String password,
String rootPath,
String packageName){
long start = System.currentTimeMillis();
try {
Logger.info("****************************************************************");
Logger.info("Start running\n");
FileGenerator.run(tableNames, driverClassName, dbUrl, userName, password, rootPath, packageName);
Logger.nextLine();
Logger.info("Create success");
}catch (Exception e){
Logger.nextLine();
Logger.error("Create fail");
Logger.error("Caused by: " + e.toString());
}finally {
long end = System.currentTimeMillis();
Logger.info("Total time: " + (end-start)/1000.0 + " s");
Logger.info("Finish");
Logger.info("****************************************************************");
}
}
/**
* 生成Java文件(数据库中的全部表)
* @param driverClassName 数据库驱动名称
* @param dbUrl 数据库地址
* @param userName 数据库用户名
* @param password 数据库密码
* @param rootPath 包的根路径
* @param packageName 完整包名,如com.xsx.test
*/
public static void createFiles(
String driverClassName,
String dbUrl,
String userName,
String password,
String rootPath,
String packageName){
createFiles(null, driverClassName, dbUrl, userName, password, rootPath, packageName);
}
/**
* 根据Java类创建数据表
* @param classNames 类名称,多个逗号分隔
* @param driverClassName 数据库驱动名称
* @param dbUrl 数据库地址
* @param userName 数据库用户名
* @param password 数据库密码
* @param rootPath 包的根路径
* @param packageName 完整包名,如com.xsx.test
*/
public static void createTables(
String classNames,
String driverClassName,
String dbUrl,
String userName,
String password,
String rootPath,
String packageName){
long start = System.currentTimeMillis();
try {
Logger.info("****************************************************************");
Logger.info("Start running\n");
TableGenerator.run(classNames, driverClassName, dbUrl, userName, password, rootPath, packageName);
Logger.info("Create success");
}catch (Exception e){
Logger.error("Create fail");
Logger.error("Caused by: " + e.toString());
}finally {
long end = System.currentTimeMillis();
Logger.info("Total time: " + (end-start)/1000.0 + " s");
Logger.info("Finish");
Logger.info("****************************************************************");
}
}
/**
* 创建数据表(包下的所有Java类,不含子目录)
* @param driverClassName 数据库驱动名称
* @param dbUrl 数据库地址
* @param userName 数据库用户名
* @param password 数据库密码
* @param rootPath 包的根路径
* @param packageName 完整包名,如com.xsx.test
*/
public static void createTables(
String driverClassName,
String dbUrl,
String userName,
String password,
String rootPath,
String packageName){
createTables(null, driverClassName, dbUrl, userName, password, rootPath, packageName);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy