import java.util.*;
import mir.entity.*;
import mir.storage.*;
+import mir.util.*;
public class EntityAdapterDefinition {
Map calculatedFields;
calculatedFields.put(aFieldName, aField);
}
- public void addDateField(String aDestinationFieldName, String aSourceFieldName) {
- addCalculatedField(aDestinationFieldName, new DateField(aSourceFieldName));
+ public void addMirDateField(String aDestinationFieldName, String aSourceFieldName) {
+ addCalculatedField(aDestinationFieldName, new MirDateField(aSourceFieldName));
+ }
+
+ public void addDBDateField(String aDestinationFieldName, String aSourceFieldName) {
+ addCalculatedField(aDestinationFieldName, new DBDateField(aSourceFieldName));
}
public interface CalculatedField {
public Object getValue(EntityAdapter anEntityAdapter);
}
- private class DateField implements CalculatedField {
+ private class MirDateField implements CalculatedField {
private String fieldName;
- public DateField(String aFieldName) {
+ public MirDateField(String aFieldName) {
fieldName = aFieldName;
}
public Object getValue(EntityAdapter anEntityAdapter) {
+
Map result = new HashMap();
String textValue = anEntityAdapter.getEntity().getValue(fieldName);
Calendar calendar = GregorianCalendar.getInstance();
month = Integer.parseInt(textValue.substring(4,6));
day = Integer.parseInt(textValue.substring(6,8));
- calendar.set(year, month, day);
+ calendar.set(year, month-1, day);
+ date = calendar.getTime();
+ ;
+
+ result.put("date", date);
+ result.put("formatted", new DateToMapAdapter(date));
+
+ }
+ catch (Throwable t) {
+ result=null;
+ }
+ }
+
+ return result;
+
+ }
+
+ }
+
+ private class DBDateField implements CalculatedField {
+ private String fieldName;
+
+ public DBDateField(String aFieldName) {
+ fieldName = aFieldName;
+ }
+
+ public Object getValue(EntityAdapter anEntityAdapter) {
+
+ Map result = new HashMap();
+ String textValue = anEntityAdapter.getEntity().getValue(fieldName);
+ Calendar calendar = GregorianCalendar.getInstance();
+ int year;
+ int month;
+ int day;
+ int hours;
+ int minutes;
+
+ Date date;
+
+ if (textValue!=null) {
+ try {
+ year = Integer.parseInt(textValue.substring(0,4));
+ month = Integer.parseInt(textValue.substring(5,7));
+ day = Integer.parseInt(textValue.substring(8,10));
+ hours = Integer.parseInt(textValue.substring(11,13));
+ minutes = Integer.parseInt(textValue.substring(14,16));
+
+ calendar.set(year, month-1, day, hours, minutes);
date = calendar.getTime();
result.put("date", date);
- result.put("year", textValue.substring(0,4));
- result.put("month", textValue.substring(4,6));
- result.put("day", textValue.substring(6,8));
+ result.put("formatted", new DateToMapAdapter(date));
+ result.put("raw", textValue);
}
catch (Throwable t) {
- result.put("date", null);
- result.put("year", null);
- result.put("month", null);
- result.put("day", null);
+ result=null;
}
}
return result;
+
}
+
}
static protected Object getRelation(StorageObject aStorageObject, String aWhereClause, String anOrderByClause, EntityAdapterDefinition aDefinition) {
try {
return
- new EntityIteratorAdapter(
+ new CachingRewindableIterator( new EntityIteratorAdapter(
new EntityBrowser( aStorageObject, aWhereClause, anOrderByClause, -1),
- aDefinition);
+ aDefinition));
}
catch (Throwable t) {
throw new RuntimeException(t.getMessage());