📄 repository.java
字号:
package com.doone.fj1w.fjmgr.repos.service;
import com.doone.data.DataRow;
import com.doone.data.DacClient;
import com.doone.data.DataTable;
import com.doone.util.FileLogger;
import com.doone.fj1w.fjmgr.repos.service.IRepositoryInfo;
import com.doone.uurm.StateEnum;
import java.util.Date;
/**
* Created by IntelliJ IDEA.
* User: lizhx
* Date: 2005-7-26
* Time: 21:23:20
* Email:lizx@doone.com.cn
*/
public class Repository implements IRepositoryInfo {
DataRow repositoryInfo;
private DacClient _dbClient;
// [start] 表结构初始化
private static DataTable repos_Struct;
static {
// 负责加载表结构信息,以便其它地方多次使用该表结构。而不需要手工重新构建。
loadTableStruct();
}
static void loadTableStruct() {
try {
// 通过查询数据表得到一个空数据的表结构。
String sql = "select REPOSITORYID,UPREPOSITORYID,TITLE,CONTENT,STARTTIME,ENDTIME, STATEMODIFYTIME,CITYCODE,ALTERSTATE,STATE from Td_Repository where 1=2";
DacClient dbClient = new DacClient();
repos_Struct = dbClient.executeQuery(sql);
} catch (Exception ex) {
FileLogger.getLogger().warn("加载表结构信息时出现异常:", ex);
}
}
// [end]
// [start] 知识库对象控制集。
public Repository() {
repositoryInfo = null;
_dbClient = null;
}
/**
* 构建知识库信息的结构,并创建一新的空行。
*
* @return 具有与数据库相同结构的新行。
*/
private DataRow buildStruct() {
if (repos_Struct == null)
loadTableStruct();
if (repos_Struct == null)
throw new RuntimeException("初始化数据结构时出错,程序不能完成初始化。");
DataTable dt = repos_Struct.copyStruct();
DataRow dr = dt.newRow();
dt.getRows().add(dr);
return dr;
}
/**
* 新建知识库实例,以便用于知识库的添加。
*
* @param dbClient
* 用于将信息更改存储到数据库中的数据库连接。
* @return 新建的知识库实现对象。
*/
public static Repository newInstance(DacClient dbClient) {
Repository ret = new Repository();
ret._dbClient = dbClient;
ret.repositoryInfo = ret.buildStruct();
try {
ret.setRepositoryId(new Long(dbClient.getSequence("SEQ_REPOSITORYID")));
ret.setStartTime(new Date());
ret.setTitle("");
ret.setEndTime(new Date());
ret.setStateModifyTime(new Date());
//ret.setContent("");
} catch (Exception ex) {
FileLogger.getLogger().warn("新建知识库实例时发生异常:", ex);
throw new RuntimeException(ex);
}
return ret;
}
/**
* 根据知识库标识获取知识库实例信息。
*
* @param dbClient
* 用于存储或获取数据库中信息的数据库连接。
* @param lRepositoryId
* 需要获取的知识库标识。
* @return 指定知识库的信息对象。
*/
public static Repository getInstance(DacClient dbClient, long lRepositoryId) {
Repository ret = new Repository();
ret._dbClient = dbClient;
try {
// 通过查询数据表得到一个空数据的表结构。
String sql = "select REPOSITORYID,UPREPOSITORYID,TITLE,CONTENT,STARTTIME,ENDTIME,STATEMODIFYTIME,CITYCODE,ALTERSTATE,STATE from Td_Repository where REPOSITORYID="
+ String.valueOf(lRepositoryId);
DataTable dt = dbClient.executeQuery(sql);
if (dt.getRows().getCount() == 1) {
ret.repositoryInfo = dt.getRow(0);
} else if (lRepositoryId == 0) {
// 如果要获取的知识库信息是空数据库,特殊处理。
ret.repositoryInfo = dt.newRow();
dt.getRows().add(ret.repositoryInfo);
ret.repositoryInfo.setValue("RepositoryId", new Long(0));
ret.repositoryInfo.setValue("content","");
//需要添加信息
} else if (dt.getRows().getCount() > 1)
throw new RuntimeException("获取知识库数据,指定的知识库标识在库中不存在。");
} catch (Exception ex) {
FileLogger.getLogger().warn("加载知识库信息时出现异常:", ex);
throw new RuntimeException(ex);
}
return ret;
}
/**
* 删除当前知识库对象(只做逻辑删除),它只有执行save方法后才能正式提交到数据库中。
*/
public void delete() {
setState(StateEnum.DISABLED);
}
/**
* 将当前知识库对象中所做的所有修改更新到数据库中。
*/
public void save() {
try {
// XXX 进行必要的数据有效性检查。
if (_dbClient == null)
_dbClient = new DacClient();
_dbClient.updateDataRow(repositoryInfo);
} catch (Exception ex) {
FileLogger.getLogger().warn("保存知识库信息时出现异常:", ex);
throw new RuntimeException(ex);
}
}
/** 是否有下一级子对象。 */
public boolean HasChild(String sCity) {
DataTable ret = null;
int iCount=0;
try {
StringBuffer sql = new StringBuffer();
sql.append("select ");
sql.append("count(*) COUNT ");
sql.append(" from Td_Repository");
sql.append(" where UPREPOSITORYID=?");
sql.append(" and CITYCODE=?");
Object[] aParam = new Object[2];
aParam[0] = this.getRepositoryId();
aParam[1] = sCity;
ret = _dbClient.executeQuery(sql.toString(), aParam);
iCount=ret.getRow(0).getInt("COUNT");
if(iCount==0) return false;
else return true;
}
catch (Exception ex) {
FileLogger.getLogger().warn("加载对象知识库信息时出现异常:", ex);
throw new RuntimeException(ex);
}
}
/**
* 通过知识库标识获取一个已经存在的对象知识库信息。
*
* @param dbClient 使用通用的数据库访问接口DacClient。
* @param repositoryId
*/
public static Repository getRepositoryByID(DacClient dbClient, long repositoryId,String sCity) {
Repository ret = new Repository();
ret._dbClient = dbClient;
try {
StringBuffer sql = new StringBuffer();
sql.append("select ");
sql.append("REPOSITORYID, ");
sql.append("UPREPOSITORYID, ");
sql.append("TITLE, ");
sql.append("CONTENT, ");
sql.append("STARTTIME, ");
sql.append("ENDTIME, ");
sql.append("STATEMODIFYTIME, ");
sql.append("ALTERSTATE, ");
sql.append("CITYCODE, ");
sql.append("STATE");
sql.append(" from Td_Repository");
sql.append(" where REPOSITORYID=?");
sql.append(" and CITYCODE=?");
Object[] aParam = new Object[2];
aParam[0] = new Long(repositoryId);
aParam[1] = sCity;
DataTable dt = dbClient.executeQuery(sql.toString(), aParam);
if (dt.getRows().getCount() == 1) {
ret._dbClient = dbClient;
ret.repositoryInfo= dt.getRow(0);
}
else if (repositoryId == 0) {
// 如果要获取的知识库信息是根节点,特殊处理。
ret._dbClient = dbClient;
ret.repositoryInfo = dt.newRow();
dt.getRows().add(ret.repositoryInfo);
ret.repositoryInfo.setValue("REPOSITORYID", new Long(0));
ret.setUpRepositoryId(new Long(0));
ret.setStartTime(new Date());
ret.setEndTime(new Date());
ret.setTitle("知识库根节点。");
ret.setState(StateEnum.DISABLED);
}
else {
throw new RuntimeException("找不到知识库标识:"
+ String.valueOf(repositoryId) + "对应的对象知识库。");
}
}
catch (Exception ex) {
FileLogger.getLogger().warn("获取对象知识库标识时出现异常:", ex);
throw new RuntimeException(ex);
}
return ret;
}
/** 获取所有下一级子对象。 */
public Repository[] getChilds(String sCity) {
Repository[] ret = null;
try {
DataTable dt = getChildList(sCity);
if (dt.getRows().getCount() > 0) {
ret = new Repository[dt.getRows().getCount()];
for (int i = 0; i < ret.length; i++) {
ret[i] = new Repository();
ret[i]._dbClient = _dbClient;
ret[i].repositoryInfo = dt.getRow(i);
}
}
}
catch (Exception ex) {
FileLogger.getLogger().warn("加载对象知识库信息时出现异常:", ex);
throw new RuntimeException(ex);
}
return ret;
}
/** 获取所有下一级子对象列表。 */
DataTable getChildList(String sCity) {
DataTable ret = null;
try {
StringBuffer sql = new StringBuffer();
sql.append("select ");
sql.append("REPOSITORYID, ");
sql.append("UPREPOSITORYID, ");
sql.append("TITLE, ");
sql.append("CONTENT, ");
sql.append("STARTTIME, ");
sql.append("ENDTIME, ");
sql.append("STATEMODIFYTIME, ");
sql.append("ALTERSTATE, ");
sql.append("CITYCODE, ");
sql.append("STATE");
sql.append(" from Td_Repository");
sql.append(" where UPREPOSITORYID=?");
sql.append(" and CITYCODE=?");
Object[] aParam = new Object[2];
aParam[0] = this.getRepositoryId();
aParam[1] = sCity;
ret = _dbClient.executeQuery(sql.toString(), aParam);
}
catch (Exception ex) {
FileLogger.getLogger().warn("加载对象知识库信息时出现异常:", ex);
throw new RuntimeException(ex);
}
return ret;
}
public Long getRepositoryId() {
return new Long(repositoryInfo.getLong("RepositoryId"));
}
public Long getUpRepositoryId() {
return new Long(repositoryInfo.getLong("UpRepositoryId"));
}
public String getTitle() {
return repositoryInfo.getString("Title");
}
public String getContent() {
return repositoryInfo.getString("Content");
}
public Date getStartTime() {
return repositoryInfo.getDate("StartTime");
}
public Date getEndTime() {
return repositoryInfo.getDate("EndTime");
}
public String getState() {
return repositoryInfo.getString("State");
}
public String getAlterState() {
return repositoryInfo.getString("AlterState");
}
public String getCityCode() {
return repositoryInfo.getString("CityCode");
}
public Date getStateModifyTime() {
return repositoryInfo.getDate("STATEMODIFYTIME");
}
public void setRepositoryId(Long newRepositoryId) {
repositoryInfo.setValue("RepositoryId", newRepositoryId);
}
public void setUpRepositoryId(Long newUpRepositoryId) {
repositoryInfo.setValue("UpRepositoryId", newUpRepositoryId);
}
public void setTitle(String newTitle) {
repositoryInfo.setValue("Title", newTitle);
}
public void setContent(String newContent) {
repositoryInfo.setValue("Content", newContent);
}
public void setStartTime(Date newStartTime) {
repositoryInfo.setValue("StartTime", newStartTime);
}
public void setEndTime(Date newEndTime) {
repositoryInfo.setValue("EndTime", newEndTime);
}
public void setState(String newState)
{
String tmp = newState.toUpperCase();
if (tmp.equals(StateEnum.ENABLED) || tmp.equals(StateEnum.DISABLED)) {
repositoryInfo.setValue("State", newState);
setStateModifyTime(new Date());
}
else throw new RuntimeException("状态设置错误,无效的新状态。");
}
public void setStateModifyTime(Date newStateModifyTime) {
repositoryInfo.setValue("STATEMODIFYTIME", newStateModifyTime);
}
public void setAlterState(String newAlterState) {
String tmp = newAlterState.toUpperCase();
if (tmp.equals(StateEnum.ENABLED) || tmp.equals(StateEnum.DISABLED)) {
repositoryInfo.setValue("AlterState", newAlterState);
setStateModifyTime(new Date());
}
else throw new RuntimeException("修改状态设置错误,无效的新状态。");
}
public void setCityCode(String newCityCode) {
repositoryInfo.setValue("CityCode", newCityCode);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -