/** * 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 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); }
ClobAccess clob = new ClobAccess(os, new Clob(Integer.parseInt(parts[0]))); if (parts.length >= 3) { int offset = Integer.parseInt(parts[1]);
ClobAccess clob = new ClobAccess(os, new Clob(Integer.parseInt(parts[0]))); if (parts.length >= 3) { int offset = Integer.parseInt(parts[1]);
/** * 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)); } } } }
/** * 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)); } } } }
@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()); }