コード例 #1
0
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
  private Pair<Map<String, String>, /*was it created now?*/ Boolean> getOrCreateIndexConfig(
      Class<? extends PropertyContainer> cls,
      String indexName,
      Map<String, String> suppliedConfig) {
    Pair<Map<String, String>, Boolean> result =
        findIndexConfig(cls, indexName, suppliedConfig, config.getParams());
    boolean createdNow = false;
    if (result.other()) { // Ok, we need to create this config
      synchronized (this) { // Were we the first ones to get here?
        Map<String, String> existing = indexStore.get(cls, indexName);
        if (existing != null) {
          // No, someone else made it before us, cool
          assertConfigMatches(
              getIndexProvider(existing.get(PROVIDER)), indexName, existing, result.first());
          return Pair.of(result.first(), false);
        }

        // We were the first one here, let's create this config
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        try {
          executorService.submit(new IndexCreatorJob(cls, indexName, result.first())).get();
          indexStore.set(cls, indexName, result.first());
          createdNow = true;
        } catch (ExecutionException ex) {
          throw new TransactionFailureException(
              "Index creation failed for " + indexName + ", " + result.first(), ex.getCause());
        } catch (InterruptedException ex) {
          Thread.interrupted();
        } finally {
          executorService.shutdownNow();
        }
      }
    }
    return Pair.of(result.first(), createdNow);
  }
コード例 #2
0
ファイル: InputRelationship.java プロジェクト: vimalaad/neo4j
 @Override
 protected void toStringFields(Collection<Pair<String, ?>> fields) {
   super.toStringFields(fields);
   fields.add(Pair.of("startNode", startNode));
   fields.add(Pair.of("endNode", endNode));
   if (hasTypeId()) {
     fields.add(Pair.of("typeId", typeId));
   } else {
     fields.add(Pair.of("type", type));
   }
 }
コード例 #3
0
ファイル: IndexManagerImpl.java プロジェクト: freeeve/neo4j
  private Pair<Map<String, String>, Boolean /*true=needs to be set*/> findIndexConfig(
      Class<? extends PropertyContainer> cls,
      String indexName,
      Map<String, String> suppliedConfig,
      Map<?, ?> dbConfig) {
    // Check stored config (has this index been created previously?)
    Map<String, String> storedConfig = indexStore.get(cls, indexName);
    if (storedConfig != null && suppliedConfig == null) {
      // Fill in "provider" if not already filled in, backwards compatibility issue
      Map<String, String> newConfig =
          injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig);
      if (newConfig != storedConfig) {
        indexStore.set(cls, indexName, newConfig);
      }
      return Pair.of(newConfig, Boolean.FALSE);
    }

    Map<String, String> configToUse = suppliedConfig;

    // Check db config properties for provider
    String provider = null;
    IndexImplementation indexProvider = null;
    if (configToUse == null) {
      provider = getDefaultProvider(indexName, dbConfig);
      configToUse = MapUtil.stringMap(PROVIDER, provider);
    } else {
      provider = configToUse.get(PROVIDER);
      provider = provider == null ? getDefaultProvider(indexName, dbConfig) : provider;
    }
    indexProvider = getIndexProvider(provider);
    configToUse = indexProvider.fillInDefaults(configToUse);
    configToUse = injectDefaultProviderIfMissing(cls, indexName, dbConfig, configToUse);

    // Do they match (stored vs. supplied)?
    if (storedConfig != null) {
      assertConfigMatches(indexProvider, indexName, storedConfig, suppliedConfig);
      // Fill in "provider" if not already filled in, backwards compatibility issue
      Map<String, String> newConfig =
          injectDefaultProviderIfMissing(cls, indexName, dbConfig, storedConfig);
      if (newConfig != storedConfig) {
        indexStore.set(cls, indexName, newConfig);
      }
      configToUse = newConfig;
    }

    boolean needsToBeSet = !indexStore.has(cls, indexName);
    return Pair.of(Collections.unmodifiableMap(configToUse), needsToBeSet);
  }
コード例 #4
0
  /**
   * Managing timeouts is trickier than putting all of them in a long list, like regular message
   * delivery. Timeouts are ordered and can be cancelled, so they need special treatment. Hence a
   * separate method for managing timeouts triggering.
   */
  private Pair<ClusterAction, ClusterState> performNextTimeoutFrom(ClusterInstance instance)
      throws Exception {
    ClusterState newState = snapshot();
    ClusterAction clusterAction = newState.instance(instance.uri().toASCIIString()).popTimeout();
    clusterAction.perform(newState);

    return Pair.of(clusterAction, newState);
  }
コード例 #5
0
ファイル: CypherDocIT.java プロジェクト: JohnPeng739/neo4j
  /** Cypher supports queries with parameters which are submitted as JSON. */
  @Test
  @Documented
  @Title("Use parameters")
  @Graph(
      value = {"I know you"},
      autoIndexNodes = true)
  public void send_queries_with_parameters() throws Exception {
    data.get();
    String script =
        "START x  = node:node_auto_index(name={startName}) MATCH path = (x-[r]-friend) WHERE friend"
            + ".name = {name} RETURN TYPE(r)";
    String response =
        cypherRestCall(script, Status.OK, Pair.of("startName", "I"), Pair.of("name", "you"));

    assertEquals(2, (jsonToMap(response)).size());
    assertTrue(response.contains("know"));
    assertTrue(response.contains("data"));
  }
コード例 #6
0
ファイル: CypherDocIT.java プロジェクト: JohnPeng739/neo4j
  /**
   * Sending a query with syntax errors will give a bad request (HTTP 400) response together with an
   * error message.
   */
  @Test
  @Documented
  @Title("Syntax errors")
  @Graph(
      value = {"I know you"},
      autoIndexNodes = true)
  public void send_queries_with_syntax_errors() throws Exception {
    data.get();
    String script =
        "START x  = node:node_auto_index(name={startName}) MATC path = (x-[r]-friend) WHERE friend"
            + ".name = {name} RETURN TYPE(r)";
    String response =
        cypherRestCall(
            script, Status.BAD_REQUEST, Pair.of("startName", "I"), Pair.of("name", "you"));

    Map<String, Object> output = jsonToMap(response);
    assertTrue(output.containsKey("message"));
    assertTrue(output.containsKey("stacktrace"));
  }
コード例 #7
0
ファイル: OnlineBackup.java プロジェクト: tinwelint/graphdb
 @SuppressWarnings("unchecked")
 private SlaveContext slaveContextOf(GraphDatabaseService graphDb) {
   XaDataSourceManager dsManager =
       ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
   List<Pair<String, Long>> txs = new ArrayList<Pair<String, Long>>();
   for (XaDataSource ds : dsManager.getAllRegisteredDataSources()) {
     txs.add(Pair.of(ds.getName(), ds.getLastCommittedTxId()));
   }
   return new SlaveContext(0, 0, txs.toArray(new Pair[0]));
 }
コード例 #8
0
ファイル: CypherDocIT.java プロジェクト: JohnPeng739/neo4j
  /** This example shows what happens if you misspell an identifier. */
  @Test
  @Documented
  @Title("Send queries with errors")
  @Graph(
      value = {"I know you"},
      autoIndexNodes = true)
  public void send_queries_with_errors() throws Exception {
    data.get();
    String script =
        "START x = node:node_auto_index(name={startName}) MATCH path = (x-[r]-friend) WHERE frien"
            + ".name = {name} RETURN type(r)";
    String response =
        cypherRestCall(
            script, Status.BAD_REQUEST, Pair.of("startName", "I"), Pair.of("name", "you"));

    Map<String, Object> responseMap = jsonToMap(response);
    assertEquals(4, responseMap.size());
    assertThat(response, containsString("message"));
    assertThat(((String) responseMap.get("message")), containsString("frien not defined"));
  }
コード例 #9
0
ファイル: CypherDocIT.java プロジェクト: JohnPeng739/neo4j
  /**
   * Create a node with a label and a property using Cypher. See the request for the parameter sent
   * with the query.
   */
  @Test
  @Documented
  @Title("Create a node")
  @Graph
  public void send_query_to_create_a_node() throws Exception {
    data.get();
    String script = "CREATE (n:Person { name : {name} }) RETURN n";
    String response = cypherRestCall(script, Status.OK, Pair.of("name", "Andres"));

    assertTrue(response.contains("name"));
    assertTrue(response.contains("Andres"));
  }
コード例 #10
0
 protected Pair<Integer, Node> getNode(Random random, boolean takeOut) {
   synchronized (nodes) {
     while (true) {
       int index = random.nextInt(nodes.length);
       Node node = nodes[index];
       if (null != node) {
         if (takeOut) nodes[index] = null;
         return Pair.of(index, node);
       }
     }
   }
 }
コード例 #11
0
ファイル: Server.java プロジェクト: Analect/neo4j
 protected ChannelBuffer mapSlave(Channel channel, RequestContext slave) {
   synchronized (connectedSlaveChannels) {
     // Checking for machineId -1 excludes the "empty" slave contexts
     // which some communication points pass in as context.
     if (slave != null && slave.machineId() != RequestContext.EMPTY.machineId()) {
       Pair<RequestContext, AtomicLong> previous = connectedSlaveChannels.get(channel);
       if (previous != null) {
         previous.other().set(System.currentTimeMillis());
       } else {
         connectedSlaveChannels.put(
             channel, Pair.of(slave, new AtomicLong(System.currentTimeMillis())));
       }
     }
   }
   return ChannelBuffers.dynamicBuffer();
 }
コード例 #12
0
ファイル: LegacyLogsTest.java プロジェクト: lassewesth/neo4j
  @Test
  public void shouldRewriteLogFiles() throws IOException {
    // given
    final IOCursor<LogEntry> cursor = mock(IOCursor.class);
    final LogVersionedStoreChannel writeChannel = mock(LogVersionedStoreChannel.class);
    final LogHeader header = new LogHeader(CURRENT_LOG_VERSION, 1, 42);
    when(fs.listFiles(storeDir, versionedLegacyLogFilesFilter))
        .thenReturn(new File[] {new File(getLegacyLogFilename(1))});
    when(reader.openReadableChannel(new File(getLegacyLogFilename(1))))
        .thenReturn(Pair.of(header, cursor));
    when(writer.openWritableChannel(new File(migrationDir, getLegacyLogFilename(1))))
        .thenReturn(writeChannel);

    // when
    new LegacyLogs(fs, reader, writer).migrateLogs(storeDir, migrationDir);

    // then
    verify(writer, times(1)).writeLogHeader(writeChannel, header);
    verify(writer, times(1)).writeAllLogEntries(writeChannel, cursor);
  }
コード例 #13
0
  public static Pair<byte[] /*header in the first record*/, byte[] /*all other bytes*/>
      readFullByteArray(
          long startRecord,
          Iterable<DynamicRecord> records,
          AbstractDynamicStore store,
          PropertyType propertyType) {
    long recordToFind = startRecord;
    Map<Long, DynamicRecord> recordsMap = new HashMap<Long, DynamicRecord>();
    for (DynamicRecord record : records) {
      recordsMap.put(record.getId(), record);
    }
    byte[] header = null;
    List<byte[]> byteList = new LinkedList<byte[]>();
    int totalSize = 0;
    while (recordToFind != Record.NO_NEXT_BLOCK.intValue()) {
      DynamicRecord record = recordsMap.get(recordToFind);
      if (record.isLight()) {
        store.makeHeavy(record);
      }

      int offset = 0;
      if (recordToFind == startRecord) { // This is the first one, read out the header separately
        header = propertyType.readDynamicRecordHeader(record.getData());
        offset = header.length;
      }

      byteList.add(record.getData());
      totalSize += (record.getData().length - offset);
      recordToFind = record.getNextBlock();
    }
    byte[] bArray = new byte[totalSize];
    int sourceOffset = header.length;
    int offset = 0;
    for (byte[] currentArray : byteList) {
      System.arraycopy(
          currentArray, sourceOffset, bArray, offset, currentArray.length - sourceOffset);
      offset += (currentArray.length - sourceOffset);
      sourceOffset = 0;
    }
    return Pair.of(header, bArray);
  }
コード例 #14
0
ファイル: PluginManager.java プロジェクト: nigelsmall/neo4j
 PluginManager(Config serverConfig, Iterable<ServerPlugin> plugins, LogProvider logProvider) {
   Map<String, Pair<ServerPlugin, ServerExtender>> extensions =
       new HashMap<String, Pair<ServerPlugin, ServerExtender>>();
   Log log = logProvider.getLog(getClass());
   for (ServerPlugin plugin : plugins) {
     PluginPointFactory factory = new PluginPointFactoryImpl();
     final ServerExtender extender = new ServerExtender(factory);
     try {
       plugin.loadServerExtender(extender);
     } catch (Exception ex) {
       log.warn("Failed to load plugin [%s]: %s", plugin.toString(), ex.getMessage());
       continue;
     } catch (LinkageError err) {
       log.warn("Failed to load plugin [%s]: %s", plugin.toString(), err.getMessage());
       continue;
     }
     Pair<ServerPlugin, ServerExtender> old =
         extensions.put(plugin.name, Pair.of(plugin, extender));
     if (old != null) {
       log.warn(
           String.format(
               "Extension naming conflict \"%s\" between \"%s\" and \"%s\"",
               plugin.name, old.first().getClass(), plugin.getClass()));
     }
   }
   for (Pair<ServerPlugin, ServerExtender> extension : extensions.values()) {
     log.info(String.format("Loaded server plugin \"%s\"", extension.first().name));
     for (PluginPoint point : extension.other().all()) {
       log.info(
           String.format(
               "  %s.%s: %s",
               point.forType().getSimpleName(), point.name(), point.getDescription()));
     }
     this.extensions.put(extension.first().name, extension.other());
   }
 }
コード例 #15
0
 private Pair<Integer, Object> extractValue(LegacyPropertyRecord propertyRecord) {
   int keyIndexId = propertyRecord.getKeyIndexId();
   Object value =
       propertyRecord.getType().getValue(propertyRecord, legacyStore.getDynamicRecordFetcher());
   return Pair.of(keyIndexId, value);
 }