Exemplo n.º 1
0
  @Override
  public String getText(BinaryValue binary) throws BinaryStoreException {

    if (binary instanceof InMemoryBinaryValue) {
      if (extractors == null || !extractors.extractionEnabled()) {
        return null;
      }

      // The extracted text will never be stored, so try directly using the text extractors ...
      return extractors.extract((InMemoryBinaryValue) binary, new TextExtractorContext(detector));
    }

    Iterator<Map.Entry<String, BinaryStore>> it = getNamedStoreIterator();

    while (it.hasNext()) {
      Map.Entry<String, BinaryStore> entry = it.next();

      final String binaryStoreKey = entry.getKey();
      BinaryStore bs = entry.getValue();
      try {
        if (bs.hasBinary(binary.getKey())) {
          return bs.getText(binary);
        }
      } catch (BinaryStoreException e) {
        logger.debug(e, "The named store " + binaryStoreKey + " raised exception");
        if (!it.hasNext()) {
          throw e;
        }
      }
    }

    throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(binary.getKey(), this));
  }
Exemplo n.º 2
0
  @Override
  public String getMimeType(BinaryValue binary, String name)
      throws IOException, RepositoryException {
    if (detector == null) {
      return null;
    }

    String detectedMimeType = detector.mimeTypeOf(name, binary);
    if (binary instanceof InMemoryBinaryValue) {
      return detectedMimeType;
    }

    Iterator<Map.Entry<String, BinaryStore>> it = getNamedStoreIterator();

    while (it.hasNext()) {
      Map.Entry<String, BinaryStore> entry = it.next();

      final String binaryStoreKey = entry.getKey();
      BinaryStore bs = entry.getValue();

      try {
        if (bs.hasBinary(binary.getKey())) {
          return bs.getMimeType(binary, name);
        }
      } catch (BinaryStoreException e) {
        logger.debug(e, "The named store " + binaryStoreKey + " raised exception");
        if (!it.hasNext()) {
          throw e;
        }
      }
    }

    throw new BinaryStoreException(JcrI18n.unableToFindBinaryValue.text(binary.getKey(), this));
  }
Exemplo n.º 3
0
 @Override
 public BinaryValue storeValue(InputStream stream, String hint) throws BinaryStoreException {
   BinaryStore binaryStore = selectBinaryStore(hint);
   BinaryValue bv = binaryStore.storeValue(stream);
   logger.debug("Stored binary " + bv.getKey() + " into binary store " + binaryStore);
   return bv;
 }
Exemplo n.º 4
0
 @Override
 public void addRecords(JournalRecord... records) {
   if (stopped) {
     return;
   }
   RW_LOCK.writeLock().lock();
   try {
     LOGGER.debug("Adding {0} records", records.length);
     for (JournalRecord record : records) {
       if (record.getTimeBasedKey() < 0) {
         // generate a unique timestamp only if there isn't one. In some scenarios (i.e. running in
         // a cluster) we
         // always want to keep the original TS because otherwise it would be impossible to have a
         // correct order
         // and therefore search
         long createTimeMillisUTC = TIME_BASED_KEYS.nextKey();
         record.withTimeBasedKey(createTimeMillisUTC);
       }
       this.records.put(record.getTimeBasedKey(), record);
     }
     this.journalDB.commit();
   } finally {
     RW_LOCK.writeLock().unlock();
   }
 }
Exemplo n.º 5
0
 /**
  * Create a cache container using the supplied configurations.
  *
  * @param globalConfiguration the global configuration
  * @param configuration the default cache configuration
  * @return the cache container
  * @deprecated use {@link #createContainer(GlobalConfigurationBuilder, ConfigurationBuilder)}
  *     instead
  */
 @Deprecated
 protected CacheContainer createContainer(
     GlobalConfiguration globalConfiguration, Configuration configuration) {
   logger.debug(
       "Starting cache manager with global configuration \n{0}\nand default configuration:\n{1}",
       globalConfiguration, configuration);
   return new DefaultCacheManager(globalConfiguration, configuration);
 }
 @Override
 public Connection createConnection(DriverInfo info) throws SQLException {
   logger.debug("Creating connection for RepositoryDelegte");
   if (this.repository == null) {
     retrieveRepository();
   }
   return new JcrConnection(this, info);
 }
Exemplo n.º 7
0
  @Override
  public void start() {
    cluster = Cluster.builder().addContactPoint(address).build();
    Metadata metadata = cluster.getMetadata();
    LOGGER.debug("Connected to cluster: {0}", metadata.getClusterName());
    for (Host host : metadata.getAllHosts()) {
      LOGGER.debug(
          "Datacenter: {0}; Host: {1}; Rack: {2}",
          host.getDatacenter(), host.getAddress(), host.getRack());
    }

    session = cluster.connect();
    try {
      session.execute(
          "CREATE KEYSPACE modeshape WITH replication "
              + "= {'class':'SimpleStrategy', 'replication_factor':3};");
    } catch (AlreadyExistsException e) {
    }

    session.execute("USE modeshape;");

    try {
      session.execute(
          "CREATE TABLE modeshape.binary("
              + "cid text PRIMARY KEY,"
              + "mime_type text,"
              + "ext_text text,"
              + "usage int,"
              + "usage_time timestamp,"
              + "payload blob)");
    } catch (AlreadyExistsException e) {
    }

    try {
      session.execute("CREATE INDEX USAGE_IDX ON modeshape.binary (usage);");
    } catch (InvalidQueryException e) {
      // exists
    }

    try {
      session.execute("CREATE INDEX EXPIRE_IDX ON modeshape.binary (usage_time);");
    } catch (InvalidQueryException e) {
      // exists
    }
  }
Exemplo n.º 8
0
 /**
  * Create a cache container using the supplied configurations.
  *
  * @param globalConfigurationBuilder the global configuration builder
  * @param configurationBuilder the default cache configuration builder
  * @return the cache container
  */
 protected CacheContainer createContainer(
     GlobalConfigurationBuilder globalConfigurationBuilder,
     ConfigurationBuilder configurationBuilder) {
   GlobalConfiguration globalConfiguration = globalConfigurationBuilder.build();
   Configuration configuration = configurationBuilder.build();
   logger.debug(
       "Starting cache manager with global configuration \n{0}\nand default configuration:\n{1}",
       globalConfiguration, configuration);
   return new DefaultCacheManager(globalConfiguration, configuration);
 }
Exemplo n.º 9
0
 protected synchronized void removeRecordsOlderThan(long millisInUtc) {
   RW_LOCK.writeLock().lock();
   try {
     if (millisInUtc <= 0 || stopped) {
       return;
     }
     long searchBound = TIME_BASED_KEYS.getCounterEndingAt(millisInUtc);
     LOGGER.debug("Removing records older than " + searchBound);
     NavigableMap<Long, JournalRecord> toRemove = this.records.headMap(searchBound);
     toRemove.clear();
     journalDB.commit();
     journalDB.compact();
   } finally {
     RW_LOCK.writeLock().unlock();
   }
 }
Exemplo n.º 10
0
  @SuppressWarnings("unused")
  @Override
  public void markAsUnused(Iterable<BinaryKey> keys) throws BinaryStoreException {
    Iterator<Map.Entry<String, BinaryStore>> it = getNamedStoreIterator();

    while (it.hasNext()) {
      Map.Entry<String, BinaryStore> entry = it.next();

      final String binaryStoreKey = entry.getKey();
      BinaryStore bs = entry.getValue();

      try {
        bs.markAsUnused(keys);
      } catch (BinaryStoreException e) {
        logger.debug(e, "The named store " + binaryStoreKey + " raised exception");
      }
    }
  }
Exemplo n.º 11
0
  @SuppressWarnings("unused")
  @Override
  public void removeValuesUnusedLongerThan(long minimumAge, TimeUnit unit)
      throws BinaryStoreException {
    Iterator<Map.Entry<String, BinaryStore>> it = getNamedStoreIterator();

    while (it.hasNext()) {
      Map.Entry<String, BinaryStore> entry = it.next();

      final String binaryStoreKey = entry.getKey();
      BinaryStore bs = entry.getValue();

      try {
        bs.removeValuesUnusedLongerThan(minimumAge, unit);
      } catch (BinaryStoreException e) {
        logger.debug(e, "The named store " + binaryStoreKey + " raised exception");
      }
    }
  }
  /**
   * @param xmiUuid the UUID of the model object whose node has not been created (cannot be <code>
   *     null</code>)
   * @return the unresolved reference (never <code>null</code>)
   * @throws Exception if a node for the specified UUID does exist
   */
  public UnresolvedReference addUnresolvedReference(String xmiUuid) throws Exception {
    CheckArg.isNotEmpty(xmiUuid, "xmiUuid");

    xmiUuid = resolveInternalReference(xmiUuid);

    if (this.uuidToNode.containsKey(xmiUuid)) {
      throw new Exception(TeiidI18n.illegalUnresolvedReference.text(xmiUuid));
    }

    // see if already unresolved
    UnresolvedReference unresolved = this.unresolved.get(xmiUuid);

    // create unresolved if necessary
    if (unresolved == null) {
      unresolved = new UnresolvedReference(xmiUuid);
      this.unresolved.put(xmiUuid, unresolved);
      LOGGER.debug("added '{0}' to the list of unresolved references", xmiUuid);
    }

    return unresolved;
  }
  /**
   * Initialize the supplied provider.
   *
   * @param provider the provider; may not be null
   * @throws RepositoryException if there is a problem initializing the provider
   */
  protected void doInitialize(IndexProvider provider) throws RepositoryException {

    // Set the execution context instance ...
    Reflection.setValue(provider, "context", repository.context());

    // Set the environment
    Reflection.setValue(provider, "environment", repository.environment());

    provider.initialize();

    // If successful, call the 'postInitialize' method reflectively (due to inability to call
    // directly) ...
    Method postInitialize = Reflection.findMethod(IndexProvider.class, "postInitialize");
    Reflection.invokeAccessibly(provider, postInitialize, new Object[] {});

    if (logger.isDebugEnabled()) {
      logger.debug(
          "Successfully initialized index provider '{0}' in repository '{1}'",
          provider.getName(), repository.name());
    }
  }
Exemplo n.º 14
0
 protected CacheContainer createContainer(String configFile) throws IOException, NamingException {
   CacheContainer container = null;
   // First try finding the cache configuration ...
   if (configFile != null && !configFile.equals(DEFAULT_CONFIGURATION_NAME)) {
     configFile = configFile.trim();
     try {
       logger.debug("Starting cache manager using configuration at '{0}'", configFile);
       container = new DefaultCacheManager(configFile);
     } catch (FileNotFoundException e) {
       // Configuration file was not found, so try JNDI using configFileName as JNDI name...
       container = (CacheContainer) jndiContext().lookup(configFile);
     }
   }
   if (container == null) {
     // The default Infinispan configuration is in-memory, local and non-clustered.
     // But we need a transaction manager, so use the generic TM which is a good default ...
     ConfigurationBuilder config = createDefaultConfigurationBuilder();
     GlobalConfigurationBuilder global = createGlobalConfigurationBuilder();
     container = createContainer(global, config);
   }
   return container;
 }
 /**
  * @param unresolved the unresolved reference being marked as resolved (cannot be <code>null
  *     </code>)
  */
 public void resolved(final UnresolvedReference unresolved) {
   CheckArg.isNotNull(unresolved, "unresolved");
   final UnresolvedReference resolved = this.unresolved.remove(unresolved.getUuid());
   assert (unresolved == resolved);
   LOGGER.debug("UUID '{0}' has been resolved", unresolved.getUuid());
 }
  /**
   * Allows the collection of node types to be unregistered if they are not referenced by other node
   * types as supertypes, default primary types of child nodes, or required primary types of child
   * nodes.
   *
   * @param nodeTypeNames the names of the node types to be unregistered
   * @param failIfNodeTypesAreUsed true if this method should fail to unregister the named node
   *     types if any of the node types are still in use by nodes, or false if this method should
   *     not perform such a check
   * @throws NoSuchNodeTypeException if any of the node type names do not correspond to a registered
   *     node type
   * @throws InvalidNodeTypeDefinitionException if any of the node types with the given names cannot
   *     be unregistered because they are the supertype, one of the required primary types, or a
   *     default primary type of a node type that is not being unregistered.
   * @throws RepositoryException if any other error occurs
   */
  void unregisterNodeType(Collection<Name> nodeTypeNames, boolean failIfNodeTypesAreUsed)
      throws NoSuchNodeTypeException, InvalidNodeTypeDefinitionException, RepositoryException {
    CheckArg.isNotNull(nodeTypeNames, "nodeTypeNames");
    if (nodeTypeNames.isEmpty()) return;

    if (failIfNodeTypesAreUsed) {
      long start = System.nanoTime();
      // Search the content graph to make sure that this type isn't being used
      for (Name nodeTypeName : nodeTypeNames) {
        if (isNodeTypeInUse(nodeTypeName)) {
          String name = nodeTypeName.getString(context.getNamespaceRegistry());
          throw new InvalidNodeTypeDefinitionException(
              JcrI18n.cannotUnregisterInUseType.text(name));
        }
      }
      long time =
          TimeUnit.MILLISECONDS.convert(Math.abs(System.nanoTime() - start), TimeUnit.NANOSECONDS);
      logger.debug(
          "{0} milliseconds to check if any of these node types are unused before unregistering them: {1}",
          time, nodeTypeNames);
    }

    try {
      /*
       * Grab an exclusive lock on this data to keep other nodes from being added/saved while the unregistration checks are occurring
       */
      List<JcrNodeType> removedNodeTypes = new ArrayList<JcrNodeType>(nodeTypeNames.size());
      nodeTypesLock.writeLock().lock();
      final NodeTypes nodeTypes = this.nodeTypesCache;

      for (Name nodeTypeName : nodeTypeNames) {
        /*
         * Check that the type names are valid
         */
        if (nodeTypeName == null) {
          throw new NoSuchNodeTypeException(JcrI18n.invalidNodeTypeName.text());
        }
        String name = nodeTypeName.getString(context.getNamespaceRegistry());

        JcrNodeType foundNodeType = nodeTypes.getNodeType(nodeTypeName);
        if (foundNodeType == null) {
          throw new NoSuchNodeTypeException(JcrI18n.noSuchNodeType.text(name));
        }
        removedNodeTypes.add(foundNodeType);

        /*
         * Check that no other node definitions have dependencies on any of the named types
         */
        for (JcrNodeType nodeType : nodeTypes.getAllNodeTypes()) {
          // If this node is also being unregistered, don't run checks against it
          if (nodeTypeNames.contains(nodeType.getInternalName())) {
            continue;
          }

          for (JcrNodeType supertype : nodeType.supertypes()) {
            if (nodeTypeName.equals(supertype.getInternalName())) {
              throw new InvalidNodeTypeDefinitionException(
                  JcrI18n.cannotUnregisterSupertype.text(name, supertype.getName()));
            }
          }

          for (JcrNodeDefinition childNode : nodeType.childNodeDefinitions()) {
            NodeType defaultPrimaryType = childNode.getDefaultPrimaryType();
            if (defaultPrimaryType != null && name.equals(defaultPrimaryType.getName())) {
              throw new InvalidNodeTypeDefinitionException(
                  JcrI18n.cannotUnregisterDefaultPrimaryType.text(
                      name, nodeType.getName(), childNode.getName()));
            }
            if (childNode.requiredPrimaryTypeNameSet().contains(nodeTypeName)) {
              throw new InvalidNodeTypeDefinitionException(
                  JcrI18n.cannotUnregisterRequiredPrimaryType.text(
                      name, nodeType.getName(), childNode.getName()));
            }
          }
        }
      }

      // Create the new cache ...
      NodeTypes newNodeTypes = nodeTypes.without(removedNodeTypes);

      // Remove the node types from persistent storage ...
      SessionCache system = repository.createSystemSession(context, false);
      SystemContent systemContent = new SystemContent(system);
      systemContent.unregisterNodeTypes(
          removedNodeTypes.toArray(new JcrNodeType[removedNodeTypes.size()]));
      systemContent.save();

      // Now change the cache ...
      this.nodeTypesCache = newNodeTypes;
      this.schemata = null;
    } finally {
      nodeTypesLock.writeLock().unlock();
    }
  }