@Override public String toString() { if (map != null) { return map.toString(); } else { return "[LAZY node " + identifier + "]"; } }
@Override public boolean containsKey(Object key) { if (JdbcIndexDefinition.this.identifier.equals(key)) return true; if (keys.containsKey(key)) return true; check(); return map.containsKey(key); }
@Override public String get(Object key) { if (JdbcIndexDefinition.this.identifier.equals(key)) return identifier; if (keys.containsKey(key)) return keys.get(key); check(); return map.get(key); }
@Override public void configure(DocumentReader reader, Element element) { bitrates.clear(); try { for (Element bitrate : DocumentReader.getChildElements(reader.getElementByPath(element, CONFIG_TAG))) { BitrateInfo bri = new BitrateInfo(bitrate); log.debug("Adding BitrateInfo " + bri); bitrates.put(bri.getName(), bri); } } catch (Exception ex) { log.error("Error in filter.xml:" + ex, ex); } log.info("Configured bit rate labeler " + bitrates); FilterUtils.propertiesConfigure(this, reader, element); }
@Override public org.mmbase.bridge.Node getNode(final Cloud userCloud, final Document doc) { String docId = doc.get("number"); if (docId == null) { throw new IllegalArgumentException("No number found in " + doc); } LazyMap m = nodeCache.get(docId); // if (m == null) { Map<String, String> keys = new HashMap<String, String>(); for (String keyWord : keyWords) { keys.put(keyWord, doc.get(keyWord)); } m = new LazyMap(docId, keys); nodeCache.put(docId, m); } org.mmbase.bridge.Node node = new MapNode<String>( m, new MapNodeManager(userCloud, m) { @Override public boolean hasField(String name) { if (JdbcIndexDefinition.this.key.equals(name)) return true; return super.hasField(name); } @Override public org.mmbase.bridge.Field getField(String name) { if (map == null && JdbcIndexDefinition.this.key.equals(name)) { org.mmbase.core.CoreField fd = org.mmbase.core.util.Fields.createField( name, org.mmbase.core.util.Fields.classToType(Object.class), org.mmbase.bridge.Field.TYPE_UNKNOWN, org.mmbase.bridge.Field.STATE_VIRTUAL, null); return new org.mmbase.bridge.implementation.BasicField(fd, this); } else { return super.getField(name); } } }); if (log.isDebugEnabled()) { log.debug("Returning node for " + node); } return node; }
JdbcIndexDefinition( DataSource ds, Element element, Set allIndexedFields, boolean storeText, boolean mergeText, Analyzer a, boolean isSub) { this.dataSource = ds; indexSql = element.getAttribute("sql"); key = element.getAttribute("key"); String elementId = element.getAttribute("identifier"); identifier = "".equals(elementId) ? key : elementId; findSql = element.getAttribute("find"); NodeList childNodes = element.getChildNodes(); for (int k = 0; k < childNodes.getLength(); k++) { if (childNodes.item(k) instanceof Element) { Element childElement = (Element) childNodes.item(k); if ("field".equals(childElement.getLocalName())) { if (childElement.getAttribute("keyword").equals("true")) { keyWords.add(childElement.getAttribute("name")); } String m = childElement.getAttribute("multiple"); if ("".equals(m)) m = "add"; if (!m.equals("add")) { nonDefaultMultiples.put( childElement.getAttribute("name"), Indexer.Multiple.valueOf(m.toUpperCase())); } String b = childElement.getAttribute("boost"); if (!b.equals("")) { boosts.put(childElement.getAttribute("name"), Float.valueOf(b)); } } else if ("related".equals(childElement.getLocalName())) { subQueries.add( new JdbcIndexDefinition( ds, childElement, allIndexedFields, storeText, mergeText, a, true)); } } } this.analyzer = a; this.isSub = isSub; assert !isSub || "".equals(findSql); }
@Override protected void label(URLComposer uc) { for (Map.Entry<String, BitrateInfo> entry : bitrates.entrySet()) { int bitrate = uc.getSource().getIntValue("bitrate"); if (entry.getValue().matches(bitrate)) { log.debug("" + bitrate + " matched " + entry); if (overwrite || !uc.getInfo().containsKey(key)) { uc.getInfo().put(key, entry.getKey()); } } } }
protected void check() { if (map == null) { Connection connection = null; Statement statement = null; ResultSet results = null; try { connection = dataSource.getConnection(); statement = connection.createStatement(); long start = System.currentTimeMillis(); String s = getFindSql(identifier); if (log.isTraceEnabled()) { log.trace("About to execute " + s + " because ", new Exception()); } results = statement.executeQuery(s); ResultSetMetaData meta = results.getMetaData(); map = new HashMap<String, String>(); if (results.next()) { for (int i = 1; i <= meta.getColumnCount(); i++) { String value = org.mmbase.util.Casting.toString(results.getString(i)); map.put(meta.getColumnName(i).toLowerCase(), value); } } long duration = (System.currentTimeMillis() - start); if (duration > 500) { log.warn("Executed " + s + " in " + duration + " ms"); } else if (duration > 100) { log.debug("Executed " + s + " in " + duration + " ms"); } else { log.trace("Executed " + s + " in " + duration + " ms"); } } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } finally { if (results != null) try { results.close(); } catch (Exception e) { } if (statement != null) try { statement.close(); } catch (Exception e) { } if (connection != null) try { connection.close(); } catch (Exception e) { } } } }
@Override public Set<K> keySet() { return backing.keySet(); }
@Override public void clear() { backing.clear(); }
@Override public void putAll(Map<? extends K, ? extends V> map) { backing.putAll(map); }
@Override @SuppressWarnings("element-type-mismatch") public V remove(Object key) { return backing.remove(key); }
@Override public V put(K key, V value) { return backing.put(key, value); }
@Override @SuppressWarnings("element-type-mismatch") public boolean containsValue(Object value) { return backing.containsValue(value); }
@Override @SuppressWarnings("element-type-mismatch") public boolean containsKey(Object key) { return backing.containsKey(key); }
@Override public boolean isEmpty() { return backing.isEmpty(); }
@Override public Set<Map.Entry<K, V>> entrySet() { return backing.entrySet(); }
@Override public Set<Map.Entry<String, String>> entrySet() { check(); return map.entrySet(); }
@Override public int size() { check(); return map.size(); }
@Override public Collection<V> values() { return backing.values(); }
// wrapping for synchronization @Override public int size() { return backing.size(); }