/** * {@inheritDoc} */ @Override public String getDbDescription() { return super.getDbDescription() + "," + ClobAccessReverseComplement.class.getName(); }
residues = org.intermine.objectstore.query.ClobAccess.decodeDbDescription(os, notXml[i]); i++;
/** * {@inheritDoc} */ @Override public ClobAccessReverseComplement subSequence(int start, int end) { init(); ClobAccess sub = originalClobAccess.subSequence(length - end, length - start); return new ClobAccessReverseComplement(sub); }
/** * Returns a new CharSequence that is a subsequence of this sequence, from start (inclusive) to * end (exclusive). * * @param start the start index, inclusive * @param end the end index, exclusive * @return the specified sequence * @throws IndexOutOfBoundsException if the start or end are negative, if end is greater than * length(), or if start is greater than end */ @Override public ClobAccess subSequence(int start, int end) { init(); if (start < 0) { throw new IndexOutOfBoundsException("start is less than zero"); } if (end > length) { throw new IndexOutOfBoundsException("end is greater than the length of this Clob"); } if (end < start) { throw new IndexOutOfBoundsException("end is less than start"); } if ((start == 0) && (end == length)) { return this; } return new ClobAccess(results, clob, start + offset, end - start); }
@Test public void testClob() throws Exception { Clob clob = writer.createClob(); writer.replaceClob(clob, "Monkey"); ClobAccess ca = new ClobAccess(writer, clob); Assert.assertEquals("Monkey", ca.toString()); StringBuilder longString = new StringBuilder(); for (int i = 0; i < 10000; i++) { longString.append("Lots of monkeys. "); } writer.replaceClob(clob, longString.toString()); Assert.assertEquals("Monkey", ca.toString()); ca = new ClobAccess(writer, clob); Assert.assertEquals(170000, ca.length()); Assert.assertEquals(longString.toString(), ca.toString()); Assert.assertEquals('L', ca.charAt(1700)); Assert.assertEquals('L', ca.charAt(16983)); ClobAccess sub = ca.subSequence(85000, 85016); Assert.assertEquals("Lots of monkeys.", sub.toString()); Assert.assertEquals(16, sub.length()); }
ClobAccess clob = new ClobAccess(os, new Clob(Integer.parseInt(parts[0]))); if (parts.length >= 3) { int offset = Integer.parseInt(parts[1]); int length = Integer.parseInt(parts[2]); clob = clob.subSequence(offset, offset + length);
/** * Returns the length of this character sequence. * * @return the number of chars in this sequence */ @Override public int length() { init(); return length; }
/** * Returns a String that describes this object sufficiently for it to be recreated given an * ObjectStore. This format is stored in the database. * * @return a String */ public String getDbDescription() { if (subSequence) { return clob.getClobId() + "," + offset + "," + length(); } else { return clob.getClobId() + ""; } }
/** * Writes the contents of any pending Clobs to the database, and replaces them in the objects * with a real ClobAccess object. * * @param c a connection * @param o the object to transform * @throws ObjectStoreException if something goes wrong * @throws SQLException if something goes wrong * @throws IllegalAccessException if something goes wrong */ protected void writePendingClobs(Connection c, Object o) throws ObjectStoreException, SQLException, IllegalAccessException { for (Map.Entry<String, TypeUtil.FieldInfo> fieldEntry : TypeUtil.getFieldInfos(o.getClass()).entrySet()) { TypeUtil.FieldInfo fieldInfo = fieldEntry.getValue(); if (ClobAccess.class.isAssignableFrom(fieldInfo.getType())) { ClobAccess ca = (ClobAccess) TypeUtil.getFieldValue(o, fieldInfo.getName()); if (ca instanceof PendingClob) { // We can't call createClob here - we already have a connection, and // we must use that one. Clob clob = new Clob(getSerialWithConnection(c)); replaceClobWithConnection(c, clob, ((PendingClob) ca) .toString()); DynamicUtil.setFieldValue(o, fieldInfo.getName(), new ClobAccess(this, clob)); } } } }
if (!"id".equalsIgnoreCase(fieldname)) { if (value instanceof ClobAccess) { item.setAttribute(fieldname, ((ClobAccess) value).toString()); } else { item.setAttribute(fieldname, objectToString(value));
/** * {@inheritDoc} */ @Override public char charAt(int index) { init(); char originalChar = super.charAt(length - index - 1); return translate(originalChar); }
ClobAccess clob = new ClobAccess(os, new Clob(Integer.parseInt(parts[0]))); if (parts.length >= 3) { int offset = Integer.parseInt(parts[1]); int length = Integer.parseInt(parts[2]); clob = clob.subSequence(offset, offset + length);
/** * Returns a new CharSequence that is a subsequence of this sequence, from start (inclusive) to * end (exclusive). * * @param start the start index, inclusive * @param end the end index, exclusive * @return the specified sequence * @throws IndexOutOfBoundsException if the start or end are negative, if end is greater than * length(), or if start is greater than end */ @Override public ClobAccess subSequence(int start, int end) { init(); if (start < 0) { throw new IndexOutOfBoundsException("start is less than zero"); } if (end > length) { throw new IndexOutOfBoundsException("end is greater than the length of this Clob"); } if (end < start) { throw new IndexOutOfBoundsException("end is less than start"); } if ((start == 0) && (end == length)) { return this; } return new ClobAccess(results, clob, start + offset, end - start); }
/** * Returns the length of this character sequence. * * @return the number of chars in this sequence */ @Override public int length() { init(); return length; }
/** * Returns a String that describes this object sufficiently for it to be recreated given an * ObjectStore. This format is stored in the database. * * @return a String */ public String getDbDescription() { if (subSequence) { return clob.getClobId() + "," + offset + "," + length(); } else { return clob.getClobId() + ""; } }
/** * Writes the contents of any pending Clobs to the database, and replaces them in the objects * with a real ClobAccess object. * * @param c a connection * @param o the object to transform * @throws ObjectStoreException if something goes wrong * @throws SQLException if something goes wrong * @throws IllegalAccessException if something goes wrong */ protected void writePendingClobs(Connection c, Object o) throws ObjectStoreException, SQLException, IllegalAccessException { for (Map.Entry<String, TypeUtil.FieldInfo> fieldEntry : TypeUtil.getFieldInfos(o.getClass()).entrySet()) { TypeUtil.FieldInfo fieldInfo = fieldEntry.getValue(); if (ClobAccess.class.isAssignableFrom(fieldInfo.getType())) { ClobAccess ca = (ClobAccess) TypeUtil.getFieldValue(o, fieldInfo.getName()); if (ca instanceof PendingClob) { // We can't call createClob here - we already have a connection, and // we must use that one. Clob clob = new Clob(getSerialWithConnection(c)); replaceClobWithConnection(c, clob, ((PendingClob) ca) .toString()); DynamicUtil.setFieldValue(o, fieldInfo.getName(), new ClobAccess(this, clob)); } } } }
if (!"id".equalsIgnoreCase(fieldname)) { if (value instanceof ClobAccess) { item.setAttribute(fieldname, ((ClobAccess) value).toString()); } else { item.setAttribute(fieldname, objectToString(value));
/** * Returns a String for a given object * * @param value the value to convert * @return the string representation */ private static String objectToString(Object value) { if (value instanceof Date) { return "" + ((Date) value).getTime(); } else if (value instanceof ClobAccess) { return ((ClobAccess) value).getDbDescription(); } else { return value.toString(); } }
residues = org.intermine.objectstore.query.ClobAccess.decodeDbDescription(os, notXml[i]); i++;
/** * Sends the entire contents of the Clob into the given PrintStream. This method should be used * in preference to toString() in order to save memory with large Clobs. * * @param out a PrintStream to write the Clob value to */ public void drainToPrintStream(PrintStream out) { init(); int lowestPage = offset / CLOB_PAGE_SIZE; int highestPage = (offset + length - 1) / CLOB_PAGE_SIZE; for (int page = lowestPage; page <= highestPage; page++) { String pageText = (String) results.get(page); if (page == highestPage) { pageText = pageText.substring(0, offset + length - page * CLOB_PAGE_SIZE); } if (page == lowestPage) { pageText = pageText.substring(offset - page * CLOB_PAGE_SIZE, pageText.length()); } out.print(pageText); } }