oracle: 11gR2 ojdbc6
测试用例代码
@Test
public void save() {
GeneralStatDao dao = IocMaster.getInstance().get(GeneralStatDao.class);
GeneralStat bean = mockBean();
log.debug("bean: " + bean);
log.debug("bean.getTime().getTime(): " + bean.getTime().getTime());
GeneralStat base = dao.save(StatTableNameConst.STAT_BASE, bean);
log.debug("base: " + base);
log.debug("base.getTime().getTime(): " + base.getTime().getTime());
Assert.assertNotNull(base);
List<GeneralStat> list = dao.getByAllColums(StatTableNameConst.STAT_BASE, base);
for (GeneralStat gs : list) {
log.debug("gs = " + gs);
log.debug("gs.getTime().getTime() = " + gs.getTime().getTime());
}
}
private GeneralStat mockBean() {
GeneralStat gs = new GeneralStat();
gs.setCorpId("0300");
gs.setKpiId(StatKpiConst.MONITORING_COVERAGE);
gs.setDimension1(StatDataConst.DICT_TYPE_38_NETDEVICE_ROUTER);
gs.setDimension2("-1");
gs.setDimension3("-1");
gs.setDimension4("-1");
gs.setTime(new java.sql.Date(new Date().getTime())); //这是没有标准化的时间,为测试数据。真实数据应该是标准化的
gs.setValue("88");
gs.setFlag(0);
return gs;
}
DAO代码
public GeneralStat save(String tableName, GeneralStat gs) {
try {
TableName.set(tableName);
return dao.insert(gs);
} finally {
TableName.clear();
}
}
public List<GeneralStat> getByAllColums(String tableName, final GeneralStat gs) {
Condition cond = Cnd.where("corporationid", "=", gs.getCorpId()).and("kpiid", "=", gs.getKpiId());
try {
TableName.set(tableName);
return dao.query(GeneralStat.class, cond);
} finally {
TableName.clear();
}
}
PO代码
@Table("${stat_table_name}")
public class GeneralStat {
@Column("CORPORATIONID")
private String corpId;
@Column("KPIID")
private String kpiId;
@Column("TIME")
private java.sql.Date time;
.....
建表语句
-- Create table
create table STAT_BASE
(
corporationid VARCHAR2(10) not null,
kpiid VARCHAR2(5) not null,
time DATE not null,
dimension1 VARCHAR2(10) default -1 not null,
dimension2 VARCHAR2(10) default -1 not null,
dimension3 VARCHAR2(10) default -1 not null,
dimension4 VARCHAR2(10) default -1 not null,
value VARCHAR2(20),
flag NUMBER(1) default 0
)