📄 databaseinfofactory.java
字号:
package com.sure.dataabstraction;
import java.util.Properties;
/**
* this is DatabaseInfoFactory which create DatabaseInfo from your property or
* create a defatul DatabaseInfo (DatabaseInfoDefatul) if you setup your
* DatabaseInfo implemention class name, it will create your DatabaseInfo you
* want.
*
*@author Mengzy
*@date 2002-8-16
*/
public class DatabaseInfoFactory {
//get default DatabaseInfo , this return DatabaseInfoDefault instance
/**
* Gets the defaultDatabaseInfo attribute of the DatabaseInfoFactory class
*
*@return The defaultDatabaseInfo value
*/
public static DatabaseInfo getDefaultDatabaseInfo() {
String className = null;
className = System.getProperty(CLASS_NAME);
if (className == null) {
DatabaseInfo info = null;
try {
info = new DatabaseInfoDefault();
} catch (Exception ex) {
System.err.println(ex);
throw new RuntimeException(ex.getMessage());
}
return info;
} else {
Properties pro = new Properties();
pro.setProperty(CLASS_NAME, className);
DatabaseInfo instance = null;
try {
instance = getDatabaseInfo(pro);
} catch (DBException e) {
instance = new DatabaseInfoDefault();
}
return instance;
}
}
/**
* Gets the databaseInfo attribute of the DatabaseInfoFactory class
*
*@param pro Description of the Parameter
*@return The databaseInfo value
*@exception DBException Description of the Exception
*/
public static DatabaseInfo getDatabaseInfo(Properties pro) throws DBException {
DatabaseInfo instance = null;
//get class name and this class must implements DatabaseInfo interface
String className = pro.getProperty(CLASS_NAME);
if (className == null) {
throw new DBException("Can not find " + CLASS_NAME + " property, set it first");
}
try {
//get it by class name , you must import this class in your project otherwise it
//throw a DBException class not found;
Class cl = Class.forName(className);
instance = (DatabaseInfo) cl.newInstance();
return instance;
} catch (Exception ce) {
throw new DBException(ce.getMessage());
}
}
//defatul property name , you can set System property by this name
private final static String CLASS_NAME = "com.sure.databaseInfo.class";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -