fixes null pointer

This commit is contained in:
Alex Huang 2013-06-17 16:06:04 -07:00
parent fa525a7d38
commit 6adf761848
4 changed files with 20 additions and 8 deletions

View File

@ -161,7 +161,7 @@ public class AsyncJobDaoImpl extends GenericDaoBase<AsyncJobVO, Long> implements
public List<AsyncJobVO> getExpiredUnfinishedJobs(Date cutTime, int limit) {
SearchCriteria<AsyncJobVO> sc = expiringUnfinishedAsyncJobSearch.create();
sc.setParameters("created", cutTime);
sc.setParameters("jobStatus", 0);
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
Filter filter = new Filter(AsyncJobVO.class, "created", true, 0L, (long)limit);
return listIncludingRemovedBy(sc, filter);
}
@ -170,7 +170,7 @@ public class AsyncJobDaoImpl extends GenericDaoBase<AsyncJobVO, Long> implements
public List<AsyncJobVO> getExpiredCompletedJobs(Date cutTime, int limit) {
SearchCriteria<AsyncJobVO> sc = expiringCompletedAsyncJobSearch.create();
sc.setParameters("created", cutTime);
sc.setParameters("jobStatus", 0);
sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
Filter filter = new Filter(AsyncJobVO.class, "created", true, 0L, (long)limit);
return listIncludingRemovedBy(sc, filter);
}
@ -178,8 +178,9 @@ public class AsyncJobDaoImpl extends GenericDaoBase<AsyncJobVO, Long> implements
@Override
@DB
public void resetJobProcess(long msid, int jobResultCode, String jobResultMessage) {
String sql = "UPDATE async_job SET job_status=" + JobInfo.Status.FAILED + ", job_result_code=" + jobResultCode
+ ", job_result='" + jobResultMessage + "' where job_status=0 AND (job_complete_msid=? OR (job_complete_msid IS NULL AND job_init_msid=?))";
String sql = "UPDATE async_job SET job_status=" + JobInfo.Status.FAILED.ordinal() + ", job_result_code=" + jobResultCode
+ ", job_result='" + jobResultMessage + "' where job_status=" + JobInfo.Status.IN_PROGRESS.ordinal()
+ " AND (job_complete_msid=? OR (job_complete_msid IS NULL AND job_init_msid=?))";
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;

View File

@ -133,6 +133,7 @@ public class AsyncJobVO implements AsyncJob, JobInfo {
public AsyncJobVO() {
uuid = UUID.randomUUID().toString();
related = UUID.randomUUID().toString();
status = Status.IN_PROGRESS;
}
public AsyncJobVO(String related, long userId, long accountId, String cmd, String cmdInfo, Long instanceId, String instanceType) {
@ -144,6 +145,7 @@ public class AsyncJobVO implements AsyncJob, JobInfo {
this.related = related;
this.instanceId = instanceId;
this.instanceType = instanceType;
status = Status.IN_PROGRESS;
}
@Override

View File

@ -1485,7 +1485,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
if (type == EnumType.STRING) {
pstmt.setString(j, value == null ? null : value.toString());
} else if (type == EnumType.ORDINAL) {
pstmt.setInt(j, value == null ? null : ((Enum<?>)value).ordinal());
if (value == null) {
pstmt.setObject(j, null);
} else {
pstmt.setInt(j, ((Enum<?>)value).ordinal());
}
}
} else if (attr.field.getType() == URI.class) {
pstmt.setString(j, value == null ? null : value.toString());
@ -1499,7 +1503,11 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
if (type == EnumType.STRING) {
pstmt.setString(j, value == null ? null : value.toString());
} else if (type == EnumType.ORDINAL) {
pstmt.setLong(j, value == null ? null : (value instanceof Ip) ? ((Ip)value).longValue() : NetUtils.ip2Long((String)value));
if (value == null) {
pstmt.setObject(j, null);
} else {
pstmt.setLong(j, (value instanceof Ip) ? ((Ip)value).longValue() : NetUtils.ip2Long((String)value));
}
}
} else {
pstmt.setObject(j, value);

View File

@ -49,7 +49,7 @@ public class ConfigValue<T> {
@SuppressWarnings("unchecked")
public T value() {
if (_config.isDynamic()) {
if (_value == null || _config.isDynamic()) {
Configuration vo = _entityMgr.findById(Configuration.class, _config.key());
String value = vo != null ? vo.getValue() : _config.defaultValue();
@ -66,8 +66,9 @@ public class ConfigValue<T> {
_value = (T)value;
} else if (type.isAssignableFrom(Float.class)) {
_value = (T)new Float(Float.parseFloat(value) * _multiplier.floatValue());
} else {
throw new CloudRuntimeException("Unsupported data type for config values: " + type);
}
throw new CloudRuntimeException("Unsupported data type for config values: " + type);
}
return _value;