field.set(entity, null);
} else {
field.set(entity, rs.getLong(index));
}
} else if (type.isEnum()) {
final Enumerated enumerated = field.getAnnotation(Enumerated.class);
final EnumType enumType = (enumerated == null) ? EnumType.STRING : enumerated.value();
final Enum<?>[] enums = (Enum<?>[])field.getType().getEnumConstants();
for (final Enum<?> e : enums) {
if ((enumType == EnumType.STRING && e.name().equalsIgnoreCase(rs.getString(index))) ||
(enumType == EnumType.ORDINAL && e.ordinal() == rs.getInt(index))) {
field.set(entity, e);
return;
}
}
} else if (type == int.class) {
field.set(entity, rs.getInt(index));
} else if (type == Integer.class) {
if (rs.getObject(index) == null) {
field.set(entity, null);
} else {
field.set(entity, rs.getInt(index));
}
} else if (type == Date.class) {
final Object data = rs.getDate(index);
if (data == null) {
field.set(entity, null);
return;
}
field.set(entity, DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)));
} else if (type == Calendar.class) {
final Object data = rs.getDate(index);
if (data == null) {
field.set(entity, null);
return;
}
final Calendar cal = Calendar.getInstance();
cal.setTime(DateUtil.parseDateString(s_gmtTimeZone, rs.getString(index)));
field.set(entity, cal);
} else if (type == boolean.class) {
field.setBoolean(entity, rs.getBoolean(index));
} else if (type == Boolean.class) {
if (rs.getObject(index) == null) {
field.set(entity, null);
} else {
field.set(entity, rs.getBoolean(index));
}
} else if (type == URI.class) {
try {
String str = rs.getString(index);
field.set(entity, str == null ? null : new URI(str));
} catch (URISyntaxException e) {
throw new CloudRuntimeException("Invalid URI: " + rs.getString(index), e);
}
} else if (type == URL.class) {
try {
String str = rs.getString(index);
field.set(entity, str != null ? new URL(str) : null);
} catch (MalformedURLException e) {
throw new CloudRuntimeException("Invalid URL: " + rs.getString(index), e);
}
} else if (type == Ip.class) {
final Enumerated enumerated = field.getAnnotation(Enumerated.class);
final EnumType enumType = (enumerated == null) ? EnumType.STRING : enumerated.value();
Ip ip = null;
if (enumType == EnumType.STRING) {
String s = rs.getString(index);
ip = s == null ? null : new Ip(NetUtils.ip2Long(s));