📄 jdbcpropertydatabase.java
字号:
ps2.execute();
} finally {
ps2.releasePreparedStatement();
}
}
} finally {
rs.close();
ps.releasePreparedStatement();
}
}
return oldVal;
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#getPropertyProfiles(java.lang.String, boolean)
*/
public List getPropertyProfiles(String username, boolean includeGlobal) throws Exception {
JDBCPreparedStatement ps;
if (includeGlobal) {
ps = db.getStatement("select.global.profiles");
} else {
ps = db.getStatement("select.profiles");
}
try {
ps.setString(1, username == null ? "" : username);
ResultSet rs = ps.executeQuery();
try {
List v = new ArrayList();
while (rs.next()) {
v.add(buildPropertyProfile(rs));
}
return v;
} finally {
rs.close();
}
} finally {
ps.releasePreparedStatement();
}
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#getPropertyProfile(int)
*/
public PropertyProfile getPropertyProfile(int id) throws Exception {
JDBCPreparedStatement ps = db.getStatement("select.profile");
ResultSet rs = null;
try {
ps.setInt(1, id);
rs = ps.executeQuery();
if (rs.next()) {
return buildPropertyProfile(rs);
}
} finally {
if (rs != null)
rs.close();
ps.releasePreparedStatement();
}
return null;
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#createPropertyProfile(java.lang.String, java.lang.String, java.lang.String, int, int)
*/
public PropertyProfile createPropertyProfile(String username, String shortName, String description, int baseOn,
int parentResourcePermission) throws Exception {
JDBCPreparedStatement ps = db.getStatement("insert.profile");
Calendar c = Calendar.getInstance();
try {
ps.setString(1, username == null ? "" : username);
ps.setString(2, shortName);
ps.setString(3, description);
ps.setInt(4, parentResourcePermission);
ps.setString(5, db.formatTimestamp(c));
ps.setString(6, db.formatTimestamp(c));
ps.execute();
} finally {
ps.releasePreparedStatement();
}
int id = db.getLastInsertId(ps, "insert.profile.lastInsertId");
PropertyProfile profile = new DefaultPropertyProfile(id, username == null ? "" : username, shortName, description,
parentResourcePermission, c, c);
profile.setResourceName(shortName);
profile.setResourceDescription(description);
if (baseOn != -1) {
List propertyDefinitions = getPropertyDefinitions(username == null ? Constants.SCOPE_GLOBAL : Constants.SCOPE_PERSONAL);
for (Iterator i = propertyDefinitions.iterator(); i.hasNext();) {
PropertyDefinition def = (PropertyDefinition) i.next();
if (def.getVisibility() == PropertyDefinition.PROFILE) {
setProperty(profile.getResourceId(), username, def.getName(), getProperty(baseOn, username, def.getName()));
}
}
}
return profile;
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#updatePropertyProfile(int, java.lang.String, java.lang.String, int)
*/
public void updatePropertyProfile(int id, String shortName, String description, int parentResourcePermission) throws Exception {
JDBCPreparedStatement ps = db.getStatement("update.profile");
try {
ps.setString(1, shortName);
ps.setString(2, description);
ps.setInt(3, parentResourcePermission);
ps.setString(4, db.formatTimestamp(Calendar.getInstance()));
ps.setInt(5, id);
ps.execute();
} finally {
ps.releasePreparedStatement();
}
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#deletePropertyProfile(int)
*/
public PropertyProfile deletePropertyProfile(int id) throws Exception {
PropertyProfile prof = getPropertyProfile(id);
if(prof == null) {
throw new Exception("No property profile with " + id + ".");
}
propertyCache.clear();
JDBCPreparedStatement ps = db.getStatement("delete.profile.1");
ps.setInt(1, id);
try {
ps.execute();
} finally {
ps.releasePreparedStatement();
}
ps = db.getStatement("delete.profile.2");
ps.setInt(1, id);
try {
ps.execute();
} finally {
ps.releasePreparedStatement();
}
return prof;
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#getPropertyProfile(java.lang.String, java.lang.String)
*/
public PropertyProfile getPropertyProfile(String username, String name) throws Exception {
JDBCPreparedStatement ps = db.getStatement("select.profile.short");
ResultSet rs = null;
try {
ps.setString(1, username == null ? "" : username);
ps.setString(2, name);
rs = ps.executeQuery();
if (rs.next()) {
return buildPropertyProfile(rs);
}
return null;
} finally {
if (rs != null)
rs.close();
ps.releasePreparedStatement();
}
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#getPropertyInt(int, java.lang.String, java.lang.String)
*/
public int getPropertyInt(int profile, String username, String name) throws Exception {
try {
return Integer.parseInt(getProperty(profile, username, name));
} catch (NumberFormatException nfe) {
try {
return Integer.parseInt(getPropertyDefinition(name).getDefaultValue());
} catch (NumberFormatException nfe2) {
return 0;
}
}
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#getPropertyBoolean(int, java.lang.String, java.lang.String)
*/
public boolean getPropertyBoolean(int profile, String username, String name) throws Exception {
return "true".equals(getProperty(profile, username, name));
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.Database#cleanup()
*/
public void cleanup() throws Exception {
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#addPropertyDefinitionCategory(int, com.sslexplorer.boot.PropertyDefinitionCategory)
*/
public void addPropertyDefinitionCategory(int parentId, PropertyDefinitionCategory category) {
PropertyDefinitionCategory parent = parentId == -1 ? null : (PropertyDefinitionCategory) categoryMap.get(String
.valueOf(parentId));
if (parent != null) {
category.setParent(parent);
if(!parent.contains(category)) {
parent.addCategory(category);
}
} else {
if(!categories.contains(category)) {
categories.add(category);
}
}
categoryMap.put(String.valueOf(category.getId()), category);
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#removePropertyDefinitionCategory(int, com.sslexplorer.boot.PropertyDefinitionCategory)
*/
public void removePropertyDefinitionCategory(int parentId, PropertyDefinitionCategory category) {
PropertyDefinitionCategory parent = parentId == -1 ? null : (PropertyDefinitionCategory) categoryMap.get(String
.valueOf(parentId));
if (parent != null) {
parent.removeCategory(category);
}
}
/* (non-Javadoc)
* @see com.sslexplorer.boot.PropertyDatabase#getPropertyDefinitionCategory(int)
*/
public PropertyDefinitionCategory getPropertyDefinitionCategory(int id) {
return (PropertyDefinitionCategory) categoryMap.get(String.valueOf(id));
}
PropertyProfile buildPropertyProfile(ResultSet rs) throws SQLException {
String username = rs.getString("username");
Timestamp cd = rs.getTimestamp("date_created");
Calendar c = Calendar.getInstance();
c.setTimeInMillis(cd == null ? System.currentTimeMillis() : cd.getTime());
Timestamp ad = rs.getTimestamp("date_amended");
Calendar a = Calendar.getInstance();
a.setTimeInMillis(ad == null ? System.currentTimeMillis() : ad.getTime());
return new DefaultPropertyProfile(rs.getInt("id"), username.equals("") ? null : username, rs.getString("short_name"), rs
.getString("description"), rs.getInt("parent_resource_permission"), c, a);
}
void storeToCache(Serializable key, Serializable object) {
if (log.isDebugEnabled()) {
log.debug("Caching under " + key + ", ttl=" + CACHE_TTL + ", cost=" + CACHE_COST);
}
propertyCache.store(key, object, new Long(CACHE_TTL.longValue() + System.currentTimeMillis()), CACHE_COST);
if (log.isDebugEnabled()) {
log.debug("NUM_RETRIEVE_REQUESTED " + propertyCache.getStat(CacheStat.NUM_RETRIEVE_REQUESTED));
log.debug("NUM_RETRIEVE_FOUND " + propertyCache.getStat(CacheStat.NUM_RETRIEVE_FOUND));
log.debug("NUM_RETRIEVE_NOT_FOUND " + propertyCache.getStat(CacheStat.NUM_RETRIEVE_NOT_FOUND));
log.debug("NUM_STORE_REQUESTED " + propertyCache.getStat(CacheStat.NUM_STORE_REQUESTED));
log.debug("NUM_STORE_STORED " + propertyCache.getStat(CacheStat.NUM_STORE_STORED));
log.debug("NUM_STORE_NOT_STORED " + propertyCache.getStat(CacheStat.NUM_STORE_NOT_STORED));
log.debug("CUR_CAPACITY " + propertyCache.getStat(CacheStat.CUR_CAPACITY));
}
}
void loadPropertyDefinitions() throws Exception {
propertyDefinitions = new HashMap();
JDBCPreparedStatement ps = db.getStatement("load.properties");
ResultSet rs = ps.executeQuery();
try {
while (rs.next()) {
PropertyDefinition def = new DefaultPropertyDefinition(rs.getInt("type"), rs.getString("name"), rs
.getString("type_meta"), rs.getInt("category"), rs
.getString("default_value"), rs.getInt("visibility"), rs.getInt("sort_order"),
rs.getInt("hidden") == 1);
registerPropertyDefinition(def);
}
} finally {
rs.close();
ps.releasePreparedStatement();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -