use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.
the class ConfigDao method setConfig.
public void setConfig(ConfigModel config, Date until) throws DalException {
logger.info("[setConfig] {}: {}", config, until);
boolean insert = false;
try {
getKey(config.getKey());
} catch (DalException e) {
logger.info("[setKey][not exist, create]{}", e.getMessage());
insert = true;
}
ConfigTbl configTbl = new ConfigTbl();
configTbl.setKey(config.getKey());
configTbl.setValue(config.getVal());
if (config.getUpdateIP() != null) {
configTbl.setLatestUpdateIp(config.getUpdateIP());
}
if (config.getUpdateUser() != null) {
configTbl.setLatestUpdateUser(config.getUpdateUser());
}
if (until != null) {
configTbl.setUntil(until);
}
if (!insert) {
queryHandler.handleUpdate(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return configTblDao.updateValAndUntilByKey(configTbl, ConfigTblEntity.UPDATESET_FULL);
}
});
} else {
configTbl.setDesc("insert automatically");
queryHandler.handleInsert(new DalQuery<Integer>() {
@Override
public Integer doQuery() throws DalException {
return configTblDao.insert(configTbl);
}
});
}
logger.info("[setConfig] config update successfully, as {}", config.toString());
}
use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.
the class ConfigServiceImpl method getConfig.
@Override
public ConfigModel getConfig(String key) {
try {
ConfigTbl configTbl = configDao.getByKey(key);
ConfigModel config = new ConfigModel();
config.setKey(key);
config.setVal(configTbl.getValue());
config.setUpdateIP(configTbl.getLatestUpdateIp());
config.setUpdateUser(configTbl.getLatestUpdateUser());
return config;
} catch (DalException e) {
logger.error("[getConfig] {}", e);
return null;
}
}
use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.
the class ConfigDaoTest method testSetConfigAndUntil2.
@Test
public void testSetConfigAndUntil2() throws Exception {
String localKey = "config.dao.test";
String value = String.valueOf(true);
Date date = DateTimeUtils.getHoursLaterDate(1);
configDao.setKey(localKey, value);
value = String.valueOf(false);
ConfigModel model = new ConfigModel().setKey(localKey).setVal(value);
configDao.setConfigAndUntil(model, date);
ConfigTbl config = configDao.getByKey(localKey);
logger.info("config: {}", config);
Assert.assertEquals(value, config.getValue());
Assert.assertEquals(date, config.getUntil());
}
use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.
the class ConfigDaoTest method testSetKeyAndUntil.
@Test
public void testSetKeyAndUntil() throws Exception {
String localKey = "config.dao.test";
String value = String.valueOf(false);
Date date = DateTimeUtils.getHoursLaterDate(1);
ConfigModel model = new ConfigModel().setKey(localKey).setVal(value);
configDao.setConfigAndUntil(model, date);
ConfigTbl config = configDao.getByKey(localKey);
logger.info("config: {}", config);
Assert.assertEquals(value, config.getValue());
Assert.assertEquals(date, config.getUntil());
}
use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.
the class ConfigServiceImpl method getAndResetTrueIfExpired.
private boolean getAndResetTrueIfExpired(String key) {
try {
ConfigTbl config = configDao.getByKey(key);
boolean result = Boolean.valueOf(config.getValue());
if (!result) {
Date expireDate = config.getUntil();
Date currentDate = new Date();
ConfigModel configModel = new ConfigModel().setKey(key).setVal(String.valueOf(true)).setUpdateUser("System");
if (currentDate.after(expireDate)) {
logger.info("[getAndResetTrueIfExpired] Off time expired, reset to be true");
configDao.setConfig(configModel);
result = true;
}
}
return result;
} catch (Exception e) {
return true;
}
}
Aggregations