/** * Read a KiWiDateLiteral serialized with writeDateLiteral from a DataInput source * * @param input the source * @return the de-serialized KiWiDateLiteral * @throws IOException */ public static KiWiDateLiteral readDateLiteral(DataInput input) throws IOException { long id = input.readLong(); if(id == -1) { return null; } else { DateTime content = new DateTime(input.readLong(), DateTimeZone.forOffsetMillis(input.readInt())); KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created); r.setId(id); return r; } }
/** * Efficiently serialize a KiWiDateLiteral to a DataOutput destination. * * @param out the destination * @param literal the KiWiDateLiteral to serialize * @throws IOException */ public static void writeDateLiteral(DataOutput out, KiWiDateLiteral literal) throws IOException { if(literal == null) { out.writeLong(-1L); } else { out.writeLong(literal.getId()); out.writeLong(literal.getDateContent().getMillis()); out.writeInt(literal.getDateContent().getZone().getOffset(literal.getDateContent())); writeURI(out, literal.getType()); out.writeLong(literal.getCreated().getTime()); } }
/** * Gets the label of this literal. * * @return The literal's label. */ @Override public String getLabel() { return getContent(); }
/** * A separate equalsContent method for checking whether literals are equal in their content; we cannot override * the .equals function with this because it would break the system in cases where the same content is used in * different literals. * * @param o * @return */ @Override public boolean equals(Object o) { if (this == o) return true; if(o instanceof Literal) { Literal that = (Literal)o; if(!(this.getDatatype().equals(that.getDatatype()))) return false; return calendarValue().toGregorianCalendar().getTime().getTime() == that.calendarValue().toGregorianCalendar().getTime().getTime(); } return false; }
} else if(n instanceof KiWiDateLiteral) { KiWiDateLiteral l = (KiWiDateLiteral)n; createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, l.getDateContent(), l.getDateContent().getZone().getOffset(l.getDateContent()) / 1000, null, l.getDatatype(), l.getLocale(), l.getCreated()); } else if(n instanceof KiWiStringLiteral) { KiWiStringLiteral l = (KiWiStringLiteral)n;
KiWiDateLiteral literal = new KiWiDateLiteral(value, uri); connection.storeNode(literal); Assert.assertTrue(literal.getId() >= 0); KiWiNode testLiteral1 = connection.loadNodeById(literal.getId()); KiWiNode testLiteral2 = connection.loadNodeById(literal.getId()); KiWiNode testLiteral3 = connection.loadLiteral(literal.stringValue(),null,uri); KiWiNode testLiteral4 = connection.loadNodeById(literal.getId()); KiWiNode testLiteral5 = connection.loadLiteral(literal.stringValue(),null,uri); Assert.assertEquals((long) literal.getId(), result.getLong("id")); Assert.assertEquals(literal.stringValue(),result.getString("svalue")); Assert.assertEquals(value.getMillis(), result.getTimestamp("tvalue", Calendar.getInstance(TimeZone.getTimeZone("UTC"))).getTime()); Assert.assertEquals("date",result.getString("ntype"));
KiWiDateLiteral result = new KiWiDateLiteral(); result.setCreated(new Date(row.getTimestamp(11, calendarUTC).getTime())); result.setType((KiWiUriResource) loadNodeById(row.getLong(10))); result.setId(id); result.setDateContent(dvalue);
insertNode.setString(2, dateLiteral.stringValue()); insertNode.setTimestamp(3, new Timestamp(dateLiteral.getDateContent().getMillis()), calendarUTC); insertNode.setInt(4, dateLiteral.getDateContent().getZone().getOffset(dateLiteral.getDateContent())/1000); if (dateLiteral.getType() != null) insertNode.setLong(5,dateLiteral.getType().getId()); else throw new IllegalStateException("a date literal must have a datatype"); insertNode.setTimestamp(6, new Timestamp(dateLiteral.getCreated().getTime()), calendarUTC);
result= new KiWiDateLiteral(dvalue, rtype);
public void setDateContent(DateTime dateContent) { this.dateContent = dateContent.withMillisOfSecond(0); if(XSD.DateTime.equals(getDatatype())) { this.content = DateUtils.getXMLCalendar(this.dateContent).toXMLFormat(); } else if(XSD.Date.equals(getDatatype())) { this.content = ISODateTimeFormat.date().print(dateContent); } else if(XSD.Time.equals(getDatatype())) { this.content = ISODateTimeFormat.time().print(dateContent); } }
} else if(n instanceof KiWiDateLiteral) { KiWiDateLiteral l = (KiWiDateLiteral)n; createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, l.getDateContent(), l.getDateContent().getZone().getOffset(l.getDateContent()) / 1000, null, l.getDatatype(), l.getLocale(), l.getCreated()); } else if(n instanceof KiWiStringLiteral) { KiWiStringLiteral l = (KiWiStringLiteral)n;
KiWiDateLiteral result = new KiWiDateLiteral(); result.setCreated(new Date(row.getTimestamp(11, calendarUTC).getTime())); result.setType((KiWiUriResource) loadNodeById(row.getLong(10))); result.setId(id); result.setDateContent(dvalue);
insertNode.setString(2, dateLiteral.stringValue()); insertNode.setTimestamp(3, new Timestamp(dateLiteral.getDateContent().getMillis()), calendarUTC); insertNode.setInt(4, dateLiteral.getDateContent().getZone().getOffset(dateLiteral.getDateContent())/1000); if (dateLiteral.getType() != null) insertNode.setLong(5,dateLiteral.getType().getId()); else throw new IllegalStateException("a date literal must have a datatype"); insertNode.setTimestamp(6, new Timestamp(dateLiteral.getCreated().getTime()), calendarUTC);
result= new KiWiDateLiteral(dvalue, rtype);
/** * A separate equalsContent method for checking whether literals are equal in their content; we cannot override * the .equals function with this because it would break the system in cases where the same content is used in * different literals. * * @param o * @return */ @Override public boolean equals(Object o) { if (this == o) return true; if(o instanceof Literal) { Literal that = (Literal)o; if(!(this.getDatatype().equals(that.getDatatype()))) return false; return calendarValue().toGregorianCalendar().getTime().getTime() == that.calendarValue().toGregorianCalendar().getTime().getTime(); } return false; }
public void setDateContent(DateTime dateContent) { this.dateContent = dateContent.withMillisOfSecond(0); if(XSD.DateTime.equals(getDatatype())) { this.content = DateUtils.getXMLCalendar(this.dateContent).toXMLFormat(); } else if(XSD.Date.equals(getDatatype())) { this.content = ISODateTimeFormat.date().print(dateContent); } else if(XSD.Time.equals(getDatatype())) { this.content = ISODateTimeFormat.time().print(dateContent); } }
} else if(n instanceof KiWiDateLiteral) { KiWiDateLiteral l = (KiWiDateLiteral)n; createNodeList(rowArray, l.getId(), l.getClass(), l.getContent(), null, null, l.getDateContent(), l.getDateContent().getZone().getOffset(l.getDateContent()) / 1000, null, l.getDatatype(), l.getLocale(), l.getCreated()); } else if(n instanceof KiWiStringLiteral) { KiWiStringLiteral l = (KiWiStringLiteral)n;
/** * Efficiently serialize a KiWiDateLiteral to a DataOutput destination. * * @param out the destination * @param literal the KiWiDateLiteral to serialize * @throws IOException */ public static void writeDateLiteral(DataOutput out, KiWiDateLiteral literal) throws IOException { if(literal == null) { out.writeLong(-1L); } else { out.writeLong(literal.getId()); out.writeLong(literal.getDateContent().getMillis()); out.writeInt(literal.getDateContent().getZone().getOffset(literal.getDateContent())); writeURI(out, literal.getType()); out.writeLong(literal.getCreated().getTime()); } }
/** * Creates a new literal representing the specified calendar that is typed * using the appropriate XML Schema date/time datatype. * * @param calendar The value for the literal. * @return An typed literal for the specified calendar. */ @Override public Literal createLiteral(XMLGregorianCalendar calendar) { KiWiLiteral l = new KiWiDateLiteral(new DateTime(calendar.toGregorianCalendar()), (KiWiUriResource) createURI(LiteralCommons.getXSDType(Date.class)), new Date()); l.setId(idGenerator.getId()); return l; }
/** * Read a KiWiDateLiteral serialized with writeDateLiteral from a DataInput source * * @param input the source * @return the de-serialized KiWiDateLiteral * @throws IOException */ public static KiWiDateLiteral readDateLiteral(DataInput input) throws IOException { long id = input.readLong(); if(id == -1) { return null; } else { DateTime content = new DateTime(input.readLong(), DateTimeZone.forOffsetMillis(input.readInt())); KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiDateLiteral r = new KiWiDateLiteral(content, dtype, created); r.setId(id); return r; } }