fix bug 7180

This commit is contained in:
Kelven Yang 2010-11-15 11:43:09 -08:00
parent 5329a19c66
commit 42ee65fce3
1 changed files with 16 additions and 6 deletions

View File

@ -157,14 +157,24 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
ResultSet rs = stmt.executeQuery();
if(rs != null && rs.next()) {
returnValue = rs.getString(1);
} else {
stmtInsert = txn.prepareAutoCloseStatement("INSERT INTO configuration(instance, name, value, description) VALUES('DEFAULT', ?, ?, '')");
stmtInsert.setString(1, name);
stmtInsert.setString(2, initValue);
if(stmtInsert.executeUpdate() < 1) {
throw new CloudRuntimeException("Unable to init configuration variable: " + name);
if(returnValue != null) {
txn.commit();
return returnValue;
} else {
// restore init value
returnValue = initValue;
}
}
stmt.close();
stmtInsert = txn.prepareAutoCloseStatement(
"INSERT INTO configuration(instance, name, value, description) VALUES('DEFAULT', ?, ?, '') ON DUPLICATE KEY UPDATE value=?");
stmtInsert.setString(1, name);
stmtInsert.setString(2, initValue);
stmtInsert.setString(3, initValue);
if(stmtInsert.executeUpdate() < 1) {
throw new CloudRuntimeException("Unable to init configuration variable: " + name);
}
txn.commit();
return returnValue;
} catch (Exception e) {