Correct DAO usage in VmwareDatacenterVO, relax assertion conditions to work with stack calling frame that is not wrapped with @DB injection

This commit is contained in:
Kelven Yang 2013-07-30 18:05:01 -07:00
parent 57dc52bb6f
commit 249e2e8f59
4 changed files with 20 additions and 6 deletions

View File

@ -73,6 +73,7 @@ public class VersionDaoImpl extends GenericDaoBase<VersionVO, Long> implements V
} }
@Override @Override
@DB
public String getCurrentVersion() { public String getCurrentVersion() {
Connection conn = null; Connection conn = null;
try { try {

View File

@ -299,13 +299,19 @@ public class Transaction {
if (se == null) { if (se == null) {
return false; return false;
} }
StringBuffer sb = new StringBuffer();
for (; stack < stacks.length; stack++) { for (; stack < stacks.length; stack++) {
String methodName = stacks[stack].getMethodName(); String methodName = stacks[stack].getMethodName();
sb.append(" ").append(methodName);
if (methodName.equals(se.ref)){ if (methodName.equals(se.ref)){
return true; return true;
} }
} }
return false;
// relax stack structure for several places that @DB required injection is not in place
s_logger.warn("Non-standard stack context that Transaction context is manaully placed into the calling chain. Stack chain: " + sb);
return true;
} }
protected static String buildName() { protected static String buildName() {

View File

@ -49,7 +49,7 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
private String vmwareDatacenterName; private String vmwareDatacenterName;
@Column(name = "vcenter_host") @Column(name = "vcenter_host")
private String vCenterHost; private String vcenterHost;
@Column(name = "uuid") @Column(name = "uuid")
private String uuid; private String uuid;
@ -93,7 +93,7 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
@Override @Override
public String getVcenterHost() { public String getVcenterHost() {
return vCenterHost; return vcenterHost;
} }
public void setUuid(String uuid) { public void setUuid(String uuid) {
@ -109,7 +109,7 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
} }
public void setVcenterHost(String vCenterHost) { public void setVcenterHost(String vCenterHost) {
this.vCenterHost = vCenterHost; this.vcenterHost = vCenterHost;
} }
public void setUser(String user) { public void setUser(String user) {
@ -143,7 +143,7 @@ public class VmwareDatacenterVO implements VmwareDatacenter {
this.uuid = UUID.randomUUID().toString(); this.uuid = UUID.randomUUID().toString();
this.vmwareDatacenterName = name; this.vmwareDatacenterName = name;
this.guid = guid; this.guid = guid;
this.vCenterHost = vCenterHost; this.vcenterHost = vCenterHost;
this.user = user; this.user = user;
this.password = password; this.password = password;
} }

View File

@ -29,6 +29,7 @@ import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import com.cloud.utils.LogUtils; import com.cloud.utils.LogUtils;
import com.cloud.utils.SerialVersionUID; import com.cloud.utils.SerialVersionUID;
import com.cloud.utils.component.ComponentContext; import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.db.Transaction;
public class CloudStartupServlet extends HttpServlet { public class CloudStartupServlet extends HttpServlet {
public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName()); public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName());
@ -47,7 +48,13 @@ public class CloudStartupServlet extends HttpServlet {
public void run() { public void run() {
if(ComponentContext.getApplicationContext() != null) { if(ComponentContext.getApplicationContext() != null) {
_timer.cancel(); _timer.cancel();
ComponentContext.initComponentsLifeCycle();
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
ComponentContext.initComponentsLifeCycle();
} finally {
txn.close();
}
} }
} }
}, 0, 1000); }, 0, 1000);