@Test public void testInlining() throws Exception{ BufferManager buffMgr = BufferManagerFactory.getStandaloneBufferManager(); FileStore fs = buffMgr.createFileStore("temp"); ClobType clob = new ClobType(new ClobImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ReaderInputStream(new StringReader("small"), Charset.forName(Streamable.ENCODING)); } }, 5)); assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob)); LobManager lobManager = new LobManager(new int[] {0}, fs); lobManager.updateReferences(Arrays.asList(clob), ReferenceMode.CREATE); assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob)); }
@SuppressWarnings("unchecked") public void updateReferences(List<?> tuple, ReferenceMode mode) throws TeiidComponentException { for (int i = 0; i < lobIndexes.length; i++) { Object anObj = tuple.get(lobIndexes[i]); if (!(anObj instanceof Streamable<?>)) { continue; } Streamable lob = (Streamable) anObj; String id = lob.getReferenceStreamId(); LobHolder lobHolder = this.lobReferences.get(id); switch (mode) { case REMOVE: if (lobHolder != null) { lobHolder.referenceCount--; if (lobHolder.referenceCount < 1) { this.lobReferences.remove(id); } } break; case ATTACH: if (lob.getReference() == null) { if (lobHolder == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30033, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30033)); } lob.setReference(lobHolder.lob.getReference()); } break; case CREATE: try { StorageMode storageMode = InputStreamFactory.getStorageMode(lob); if (id == null || (inlineLobs && (storageMode == StorageMode.MEMORY || (storageMode != StorageMode.FREE && lob.length()*(lob instanceof BaseClobType?2:1) <= maxMemoryBytes)))) { lob.setReferenceStreamId(null); if (inlineLobs && storageMode == StorageMode.OTHER) { persistLob(lob, null, null, true, maxMemoryBytes); } else { saveTemporaryLob(lob); } continue; } } catch (SQLException e) { } if (lob.getReference() == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30034, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30034)); } if (lobHolder == null) { saveTemporaryLob(lob); this.lobReferences.put(id, new LobHolder(lob)); } else { lobHolder.referenceCount++; } break; } } }
LobManager { @SuppressWarnings("unchecked") public void updateReferences(List<?> tuple, ReferenceMode mode) throws TeiidComponentException { for (int i = 0; i < lobIndexes.length; i++) { Object anObj = tuple.get(lobIndexes[i]); if (!(anObj instanceof Streamable<?>)) { continue; } Streamable lob = (Streamable) anObj; String id = lob.getReferenceStreamId(); LobHolder lobHolder = this.lobReferences.get(id); switch (mode) { case REMOVE: if (lobHolder != null) { lobHolder.referenceCount--; if (lobHolder.referenceCount < 1) { this.lobReferences.remove(id); } } break; case ATTACH: if (lob.getReference() == null) { if (lobHolder == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30033, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30033)); } lob.setReference(lobHolder.lob.getReference()); } break; case CREATE: try { StorageMode storageMode = InputStreamFactory.getStorageMode(lob); if (id == null || (inlineLobs && (storageMode == StorageMode.MEMORY || (storageMode != StorageMode.FREE && lob.length()*(lob instanceof BaseClobType?2:1) <= maxMemoryBytes)))) { lob.setReferenceStreamId(null); if (inlineLobs && storageMode == StorageMode.OTHER) { persistLob(lob, null, null, true, maxMemoryBytes); } else { saveTemporaryLob(lob); } continue; } } catch (SQLException e) { } if (lob.getReference() == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30034, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30034)); } if (lobHolder == null) { saveTemporaryLob(lob); this.lobReferences.put(id, new LobHolder(lob)); } else { lobHolder.referenceCount++; } break; } } } }
LobManager { @SuppressWarnings("unchecked") public void updateReferences(List<?> tuple, ReferenceMode mode) throws TeiidComponentException { for (int i = 0; i < lobIndexes.length; i++) { Object anObj = tuple.get(lobIndexes[i]); if (!(anObj instanceof Streamable<?>)) { continue; } Streamable lob = (Streamable) anObj; String id = lob.getReferenceStreamId(); LobHolder lobHolder = this.lobReferences.get(id); switch (mode) { case REMOVE: if (lobHolder != null) { lobHolder.referenceCount--; if (lobHolder.referenceCount < 1) { this.lobReferences.remove(id); } } break; case ATTACH: if (lob.getReference() == null) { if (lobHolder == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30033, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30033)); } lob.setReference(lobHolder.lob.getReference()); } break; case CREATE: try { StorageMode storageMode = InputStreamFactory.getStorageMode(lob); if (id == null || (inlineLobs && (storageMode == StorageMode.MEMORY || (storageMode != StorageMode.FREE && lob.length()*(lob instanceof BaseClobType?2:1) <= maxMemoryBytes)))) { lob.setReferenceStreamId(null); if (inlineLobs && storageMode == StorageMode.OTHER) { persistLob(lob, null, null, true, maxMemoryBytes); } else { saveTemporaryLob(lob); } continue; } } catch (SQLException e) { } if (lob.getReference() == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30034, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30034)); } if (lobHolder == null) { saveTemporaryLob(lob); this.lobReferences.put(id, new LobHolder(lob)); } else { lobHolder.referenceCount++; } break; } } } LobManager(int[] lobIndexes, FileStore lobStore); }
LobManager { @SuppressWarnings("unchecked") public void updateReferences(List<?> tuple, ReferenceMode mode) throws TeiidComponentException { for (int i = 0; i < lobIndexes.length; i++) { Object anObj = tuple.get(lobIndexes[i]); if (!(anObj instanceof Streamable<?>)) { continue; } Streamable lob = (Streamable) anObj; String id = lob.getReferenceStreamId(); LobHolder lobHolder = this.lobReferences.get(id); switch (mode) { case REMOVE: if (lobHolder != null) { lobHolder.referenceCount--; if (lobHolder.referenceCount < 1) { this.lobReferences.remove(id); } } break; case ATTACH: if (lob.getReference() == null) { if (lobHolder == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30033, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30033)); } lob.setReference(lobHolder.lob.getReference()); } break; case CREATE: try { StorageMode storageMode = InputStreamFactory.getStorageMode(lob); if (id == null || (inlineLobs && (storageMode == StorageMode.MEMORY || (storageMode != StorageMode.FREE && lob.length()*(lob instanceof BaseClobType?2:1) <= maxMemoryBytes)))) { lob.setReferenceStreamId(null); if (inlineLobs && storageMode == StorageMode.OTHER) { persistLob(lob, null, null, true, maxMemoryBytes); } else { saveTemporaryLob(lob); } continue; } } catch (SQLException e) { } if (lob.getReference() == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30034, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30034)); } if (lobHolder == null) { saveTemporaryLob(lob); this.lobReferences.put(id, new LobHolder(lob)); } else { lobHolder.referenceCount++; } break; } } } LobManager(int[] lobIndexes, FileStore lobStore); LobManager clone(); void setInlineLobs(boolean trackMemoryLobs); void setMaxMemoryBytes(int maxMemoryBytes); @SuppressWarnings("unchecked") void updateReferences(List<?> tuple, ReferenceMode mode); Streamable<?> getLobReference(String id); static int[] getLobIndexes(List<? extends Expression> expressions); void persist(); void detachLob(final Streamable<?> lob, final FileStore store, byte[] bytes); static void persistLob(final Streamable<?> lob,
            final FileStore store, byte[] bytes, boolean inlineLobs, int maxMemoryBytes); int getLobCount(); void remove(); void setSaveTemporary(boolean b); }
LobManager { @SuppressWarnings("unchecked") public void updateReferences(List<?> tuple, ReferenceMode mode) throws TeiidComponentException { for (int i = 0; i < lobIndexes.length; i++) { Object anObj = tuple.get(lobIndexes[i]); if (!(anObj instanceof Streamable<?>)) { continue; } Streamable lob = (Streamable) anObj; String id = lob.getReferenceStreamId(); LobHolder lobHolder = this.lobReferences.get(id); switch (mode) { case REMOVE: if (lobHolder != null) { lobHolder.referenceCount--; if (lobHolder.referenceCount < 1) { this.lobReferences.remove(id); } } break; case ATTACH: if (lob.getReference() == null) { if (lobHolder == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30033, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30033)); } lob.setReference(lobHolder.lob.getReference()); } break; case CREATE: try { StorageMode storageMode = InputStreamFactory.getStorageMode(lob); if (id == null || (inlineLobs && (storageMode == StorageMode.MEMORY || (storageMode != StorageMode.FREE && lob.length()*(lob instanceof BaseClobType?2:1) <= maxMemoryBytes)))) { lob.setReferenceStreamId(null); if (inlineLobs && storageMode == StorageMode.OTHER) { persistLob(lob, null, null, true, maxMemoryBytes); } else { saveTemporaryLob(lob); } continue; } } catch (SQLException e) { } if (lob.getReference() == null) { throw new TeiidComponentException(QueryPlugin.Event.TEIID30034, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30034)); } if (lobHolder == null) { saveTemporaryLob(lob); this.lobReferences.put(id, new LobHolder(lob)); } else { lobHolder.referenceCount++; } break; } } } LobManager(int[] lobIndexes, FileStore lobStore); LobManager clone(); void setInlineLobs(boolean trackMemoryLobs); void setMaxMemoryBytes(int maxMemoryBytes); @SuppressWarnings("unchecked") void updateReferences(List<?> tuple, ReferenceMode mode); Streamable<?> getLobReference(String id); static int[] getLobIndexes(List<? extends Expression> expressions); void persist(); void detachLob(final Streamable<?> lob, final FileStore store, byte[] bytes); static void persistLob(final Streamable<?> lob,
            final FileStore store, byte[] bytes, boolean inlineLobs, int maxMemoryBytes); int getLobCount(); void remove(); void setSaveTemporary(boolean b);  }