use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class UpdateTest method testUpdateDateTime.
/**
* Executes the following query:
* update item set created_datetime=to_date('2003-10-10', 'yyyy-MM-dd') where item_id='Z-TESTITEM-01'
* It then ensures that the record was properly updated and then resets it back to the original value
*/
public void testUpdateDateTime() {
try {
Criteria c = new Criteria();
c.setTable(ItemMeta.getName());
c.addCriteria(ItemMeta.ITEM_ID, "Z-TESTITEM-01");
Iterator i = m_uow.query(c).iterator();
Item item = (Item) i.next();
DateTime originalCreatedDatetime = item.getCreatedDatetime();
DateTime newCreatedDatetime = new DateTime(2003, DateTime.OCTOBER, 10);
item.updateCreatedDatetime(newCreatedDatetime);
m_uow.update(item);
m_uow.commit();
// Now ensure that the record got updated
m_uow = new UOW();
c = new Criteria();
c.setTable(ItemMeta.getName());
c.addCriteria(ItemMeta.ITEM_ID, "Z-TESTITEM-01");
i = m_uow.query(c).iterator();
item = (Item) i.next();
assertEquals(newCreatedDatetime, item.getCreatedDatetime());
// Now reset to the original value
item.updateCreatedDatetime(originalCreatedDatetime);
m_uow.update(item);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class GridForm method createNewTreeModel.
private GridModel createNewTreeModel() {
GridModel model = new GridModel();
GridModelRow row;
// Root Node 1
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
// Root Node 2
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(1));
row.addElement("field1", new EditBoxModel("Field11Value"));
row.addElement("field2", new EditBoxModel("Field12Value"));
row.addElement("field3", new DateTimeModel());
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value1"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field21Value"));
row.addElement("field2", new EditBoxModel("Field22Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field23Value"));
row.addElement("field2", new EditBoxModel("Field24Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(3));
row.addElement("field1", new EditBoxModel("Field31Value"));
row.addElement("field2", new EditBoxModel("Field32Value"));
row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value3"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(2));
row.addElement("field1", new EditBoxModel("Field43Value"));
row.addElement("field2", new EditBoxModel("Field44Value"));
row.addElement("field3", new DateTimeModel(new DateTime()));
row.addElement("field4", new CheckBoxModel(false));
row.addElement("field6", new DropDownModel("Value2"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(3));
row.addElement("field1", new EditBoxModel("Field51Value"));
row.addElement("field2", new EditBoxModel("Field52Value"));
row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value3"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(4));
row.addElement("field1", new EditBoxModel("Field61Value"));
row.addElement("field2", new EditBoxModel("Field62Value"));
row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value3"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("level", new Integer(5));
row.addElement("field1", new EditBoxModel("Field71Value"));
row.addElement("field2", new EditBoxModel("Field72Value"));
row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value3"));
row = model.newRow();
row.addElement("isExpanded", new Boolean(false));
row.addElement("isTarget", new Boolean(false));
row.addElement("isParent", new Boolean(true));
row.addElement("level", new Integer(3));
row.addElement("field1", new EditBoxModel("Field81Value"));
row.addElement("field2", new EditBoxModel("Field82Value"));
row.addElement("field3", new DateTimeModel(DateTime.addMonth(new DateTime(), 1)));
row.addElement("field4", new CheckBoxModel(true));
row.addElement("field6", new DropDownModel("Value3"));
return model;
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class PersistenceLoggingTest method testLogging.
public void testLogging() throws Exception {
UOW uow = null;
try {
// Specify the IPersistenceLoggingPlugin. This should ideally be mentioned in ApplicationRules.global
ContextManagerFactory.instance().setThreadContext(null);
ContextManagerFactory.instance().setProperty("jaffa.persistence.IPersistenceLoggingPlugin", "org.jaffa.persistence.blackboxtests.logging.DemoLogger");
// Create some Items
uow = new UOW();
for (int i = 0; i < ITEM_COUNT; i++) {
Item obj = new Item();
obj.setItemId("Z-TESTLOG-" + i);
obj.setKeyRef("KR" + i);
obj.setCreatedDatetime(new DateTime(2000, DateTime.JANUARY, 15, (i + 1), 30, 40, 0));
obj.setPrice(new Double(i * 10.5));
obj.setQty(new Long(i * 10));
uow.add(obj);
}
uow.commit();
// Delete the Items
uow = new UOW();
for (int i = 0; i < ITEM_COUNT; i++) {
Item obj = Item.findByPK(uow, "Z-TESTLOG-" + i);
assertNotNull("Item having id " + "Z-TESTLOG-" + i + " should have been retrieved", obj);
uow.delete(obj);
}
uow.commit();
// Unmarshal the serialized objects to java
uow = new UOW();
for (String s : DemoLogger.c_addedSerializedObjects) {
JAXBContext jc = JAXBContext.newInstance(new Class[] { Item.class });
Unmarshaller unmarshaller = jc.createUnmarshaller();
Object obj = unmarshaller.unmarshal(new StringReader(s));
uow.addSpecial(obj);
}
DemoLogger.c_addedSerializedObjects.clear();
uow.commit();
// Delete the Items
uow = new UOW();
for (int i = 0; i < ITEM_COUNT; i++) {
Item obj = Item.findByPK(uow, "Z-TESTLOG-" + i);
assertNotNull("Item having id " + "Z-TESTLOG-" + i + " should have been retrieved", obj);
assertEquals("KR" + i, obj.getKeyRef());
assertEquals(new DateTime(2000, DateTime.JANUARY, 15, (i + 1), 30, 40, 0), obj.getCreatedDatetime());
assertEquals(new Double(i * 10.5), obj.getPrice());
assertEquals(new Long(i * 10), obj.getQty());
uow.delete(obj);
}
uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class DateConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
@Override
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
// Error out if an unsupported class is passed
if (paramType != Date.class && paramType != java.sql.Date.class && paramType != Time.class && paramType != Timestamp.class && paramType != Calendar.class) {
log.warn("Unsupported input. Class=" + paramType);
throw new MarshallException(paramType);
}
// invoke the base routine, which will convert the input to a DateTime after taking timezone differences into consideration
DateTime dt = (DateTime) super.convertInbound(DateTime.class, iv, inctx);
// now convert DateTime to the desired type
Object output = null;
if (dt != null) {
if (paramType == Date.class)
output = dt.getUtilDate();
else if (paramType == java.sql.Date.class)
output = dt.sqlDate();
else if (paramType == Time.class)
output = dt.sqlTime();
else if (paramType == Timestamp.class)
output = dt.timestamp();
else if (paramType == Calendar.class)
output = dt.calendar();
}
if (log.isDebugEnabled())
log.debug("Inbound '" + iv.getValue() + "' converted to '" + output + '\'');
return output;
}
use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.
the class JaffaDateConverter method convertInbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
*/
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException {
// Error out if an unsupported class is passed
if (paramType != DateOnly.class && paramType != DateTime.class) {
log.warn("Unsupported input. Class=" + paramType);
throw new MarshallException(paramType);
}
// Extract Char Encoding from the Web Context
String charEncoding = null;
WebContext context = WebContextFactory.get();
if (context != null) {
HttpServletRequest req = context.getHttpServletRequest();
if (req != null)
charEncoding = req.getCharacterEncoding();
}
if (charEncoding == null)
charEncoding = CHAR_ENCODER;
String value = iv.getValue();
// If the text is null then the whole bean is null
if (value.trim().equals(ProtocolConstants.INBOUND_NULL))
return null;
Object output;
try {
// Handle a millisecond input
long millis = 0;
if (value.length() > 0)
millis = Long.parseLong(value);
// DWR returns null dates as '0', so we must return a null in this case
if (millis == 0)
return null;
Boolean useServerTime = Parser.parseBoolean((String) ContextManagerFactory.instance().getProperty(RULE_NAME_USE_SERVER_TIME));
if (useServerTime != null && useServerTime) {
if (log.isInfoEnabled())
log.info("A String representation of a date should be posted by the client, since the application rule '" + RULE_NAME_USE_SERVER_TIME + "' is set");
}
output = paramType == DateOnly.class ? new DateOnly(millis) : new DateTime(millis);
} catch (NumberFormatException e) {
try {
// Handle a String input
if (log.isDebugEnabled())
log.debug("Error in parsing '" + value + "' as milliseconds since 1970. Will attempt to parse it as a String representation of a date");
output = paramType == DateOnly.class ? DateTime.toDateOnly(Parser.parseDateTime(URLDecoder.decode(value, charEncoding), FORMAT_DATE_TIME)) : Parser.parseDateTime(URLDecoder.decode(value, charEncoding), FORMAT_DATE_TIME);
} catch (FormatDateTimeException e1) {
if (log.isDebugEnabled())
log.debug("Error in parsing Date '" + value + "' using the format '" + FORMAT_DATE_TIME + '\'', e1);
throw new MarshallException(DateOnly.class, e1);
} catch (UnsupportedEncodingException e1) {
if (log.isDebugEnabled())
log.debug("Error in encoding Date '" + value + "' using the format '" + charEncoding + '\'', e1);
throw new MarshallException(DateOnly.class, e1);
}
}
if (log.isDebugEnabled())
log.debug("Inbound '" + value + "' converted to '" + output + '\'');
return output;
}
Aggregations