无论使用哪个 DBMS,我都为 Paging 数据列表创建了PageFactory类。
但我不确定这是有效的工厂模式还是有问题。
如果有更好的方法,你能告诉我吗?
package com.tource.cms.common.database.paging;
import com.tource.cms.common.environment.EnvironmentVariables;
public class PageFactory {
private static final String DEFAULT_DATABASE_TYPE = getDefaultDatabaseType();
public static Page createPage(int totalRow, int currPage, int blockRow, int blockPage) {
if("mysql".equals(DEFAULT_DATABASE_TYPE))
return new MysqlPageCalculator(totalRow, currPage, blockRow, blockPage).getPage();
else if("oracle".equals(DEFAULT_DATABASE_TYPE))
return new OraclePageCalculator(totalRow, currPage, blockRow, blockPage).getPage();
else {
try {
throw new UnsupportedDatabaseException();
} catch (UnsupportedDatabaseException e) {
e.printStackTrace();
return null;
}
}
}
/** getting DBMS type from cached Memory */
private static String getDefaultDatabaseType() {
return EnvironmentVariables.get("cms.jdbc.databaseType").toLowerCase();
}
}