@Test public void getColumn() throws Exception { SwiftMetaData meta = mock(SwiftMetaData.class); when(meta.getColumnId("c")).thenReturn("cId"); CacheColumnSegment seg = spy(new CacheColumnSegment(new ResourceLocation("/"), meta)); Column column = mock(Column.class); doReturn(column).when(seg, "newColumn", any(), any()); Assert.assertEquals(column, seg.getColumn(new ColumnKey("c"))); Assert.assertEquals(seg.getColumn(new ColumnKey("c")), seg.getColumn(new ColumnKey("c"))); when(meta.getColumnId("d")).thenThrow(Exception.class); assertNull(seg.getColumn(new ColumnKey("d"))); }
@Override public <T> Column<T> getColumn(ColumnKey key) { try { String name = key.getName(); String columnId = meta.getColumnId(name); if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } synchronized (columns) { if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } IResourceLocation child = location.buildChildLocation(columnId); Column<?> column = newColumn(child, ColumnTypeUtils.getClassType(meta.getColumn(name))); columns.put(key, column); return (Column<T>) column; } } catch (SwiftMetaDataColumnAbsentException e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } catch (Exception e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } }
CacheColumnSegment extends BaseSegment { @Override public <T> Column<T> getColumn(ColumnKey key) { try { String name = key.getName(); String columnId = meta.getColumnId(name); if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } synchronized (columns) { if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } IResourceLocation child = location.buildChildLocation(columnId); Column<?> column = newColumn(child, ColumnTypeUtils.getClassType(meta.getColumn(name))); columns.put(key, column); return (Column<T>) column; } } catch (SwiftMetaDataColumnAbsentException e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } catch (Exception e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } } }
CacheColumnSegment extends BaseSegment { @Override public <T> Column<T> getColumn(ColumnKey key) { try { String name = key.getName(); String columnId = meta.getColumnId(name); if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } synchronized (columns) { if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } IResourceLocation child = location.buildChildLocation(columnId); Column<?> column = newColumn(child, ColumnTypeUtils.getClassType(meta.getColumn(name))); columns.put(key, column); return (Column<T>) column; } } catch (SwiftMetaDataColumnAbsentException e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } catch (Exception e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } } CacheColumnSegment(IResourceLocation location, SwiftMetaData meta); }
CacheColumnSegment extends BaseSegment { @Override public <T> Column<T> getColumn(ColumnKey key) { try { String name = key.getName(); String columnId = meta.getColumnId(name); if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } synchronized (columns) { if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } IResourceLocation child = location.buildChildLocation(columnId); Column<?> column = newColumn(child, ColumnTypeUtils.getClassType(meta.getColumn(name))); columns.put(key, column); return (Column<T>) column; } } catch (SwiftMetaDataColumnAbsentException e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } catch (Exception e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } } CacheColumnSegment(IResourceLocation location, SwiftMetaData meta); @Override Column<T> getColumn(ColumnKey key); @Override void release(); }
CacheColumnSegment extends BaseSegment { @Override public <T> Column<T> getColumn(ColumnKey key) { try { String name = key.getName(); String columnId = meta.getColumnId(name); if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } synchronized (columns) { if (columns.containsKey(key)) { return (Column<T>) columns.get(key); } IResourceLocation child = location.buildChildLocation(columnId); Column<?> column = newColumn(child, ColumnTypeUtils.getClassType(meta.getColumn(name))); columns.put(key, column); return (Column<T>) column; } } catch (SwiftMetaDataColumnAbsentException e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } catch (Exception e) { SwiftLoggers.getLogger().error("getColumn failed", e); return null; } } CacheColumnSegment(IResourceLocation location, SwiftMetaData meta); @Override Column<T> getColumn(ColumnKey key); @Override void release();  }