public Object getObject(ExecutionContext ec, ResultSet resultSet, int[] exprIndex) { if (exprIndex == null) { return null; } Object datastoreValue = getDatastoreMapping(0).getObject(resultSet, exprIndex[0]); if (datastoreValue == null) { return null; } if (datastoreValue instanceof String) { TypeConverter conv = ec.getNucleusContext() .getTypeManager() .getTypeConverterForType(LocalTime.class, String.class); if (conv != null) { return conv.toMemberType(datastoreValue); } else { throw new NucleusUserException("This type doesn't support persistence as a String"); } } else if (datastoreValue instanceof Time) { Time time = (Time) datastoreValue; Calendar cal = Calendar.getInstance(); cal.setTime(time); LocalTime localTime = LocalTime.of( cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND), cal.get(Calendar.MILLISECOND) * 1000000); return localTime; } else { return null; } }
public void setObject(ExecutionContext ec, PreparedStatement ps, int[] exprIndex, Object value) { if (value == null) { getDatastoreMapping(0).setObject(ps, exprIndex[0], null); } else if (datastoreMappings != null && datastoreMappings.length > 0 && datastoreMappings[0].isStringBased()) { TypeConverter conv = ec.getNucleusContext() .getTypeManager() .getTypeConverterForType(LocalTime.class, String.class); if (conv != null) { Object obj = conv.toDatastoreType(value); getDatastoreMapping(0).setObject(ps, exprIndex[0], obj); } else { throw new NucleusUserException("This type doesn't support persistence as a String"); } } else { LocalTime val = (LocalTime) value; Calendar cal = Calendar.getInstance(); cal.set(0, 0, 0, val.getHour(), val.getMinute(), val.getSecond()); getDatastoreMapping(0).setObject(ps, exprIndex[0], cal); } }