Exemplo n.º 1
0
  @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;
  }
Exemplo n.º 2
0
  /*
   * (non-Javadoc)
   * @see org.mmbase.module.core.MMObjectBuilder#notify(org.mmbase.core.event.NodeEvent)
   */
  @Override
  public void notify(NodeEvent event) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Changed "
              + event.getMachine()
              + " "
              + event.getNodeNumber()
              + " "
              + event.getBuilderName()
              + " "
              + NodeEvent.newTypeToOldType(event.getType()));
    }
    if (tableName.equals(event.getBuilderName())) {
      if (event.getType() == Event.TYPE_NEW) {
        MMObjectNode typeRelNode = getNode(event.getNodeNumber());
        if (typeRelNode != null) {
          Set<MMObjectNode> newTypeRels = addCacheEntry(typeRelNode, true);
          log.service("Added to typerelcache: " + newTypeRels);
        } else {
          log.warn("Could not found typerel node with number " + event.getNodeNumber());
        }

      } else {
        // something else changed in a typerel node? reread the complete typeRelNodes Set
        log.service(
            "Received '" + event + "' which is about typrels. Now re-reading the entire cache");
        readCache();
      }
      // also, clear all query-caches, because result may change by this. See MMB-348
      for (Cache qc : CacheManager.getMap().values()) {
        if (qc instanceof QueryResultCache) {
          qc.clear();
        }
      }
    }
    super.notify(event);
  }