示例#1
0
 private void TryToAddDuplicate(TokenRegistry tokenCache)
 {
     try
     {
         tokenCache.Put(new NamedToken(INBOUND1_TYPE, 3));
     }
     catch (NonUniqueTokenException)
     {
     }
 }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void addTokenWithDuplicatedNotAllowed()
        public virtual void AddTokenWithDuplicatedNotAllowed()
        {
            TokenRegistry tokenCache = CreateTokenCache();

            tokenCache.Put(new NamedToken(INBOUND1_TYPE, 1));
            tokenCache.Put(new NamedToken(INBOUND2_TYPE, 2));

            ExpectedException.expect(typeof(NonUniqueTokenException));
            ExpectedException.expectMessage("The testType \"inbound1\" is not unique");

            tokenCache.Put(new NamedToken(INBOUND1_TYPE, 3));
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void keepOriginalTokenWhenAddDuplicate()
        public virtual void KeepOriginalTokenWhenAddDuplicate()
        {
            TokenRegistry tokenCache = CreateTokenCache();

            tokenCache.Put(new NamedToken(INBOUND1_TYPE, 1));
            tokenCache.Put(new NamedToken(INBOUND2_TYPE, 2));

            TryToAddDuplicate(tokenCache);

            assertEquals(1, tokenCache.GetId(INBOUND1_TYPE).Value);
            assertEquals(2, tokenCache.GetId(INBOUND2_TYPE).Value);
            assertNull(tokenCache.GetToken(3));
        }
示例#4
0
        private void CreateMissingTokens(string[] names, int[] ids)
        {
            lock (this)
            {
                // We redo the resolving under the lock, to make sure that these ids are really missing, and won't be
                // created concurrently with us.
                MutableIntSet unresolvedIndexes = new IntHashSet();
                ResolveIds(names, ids, i => !unresolvedIndexes.add(i));
                if (!unresolvedIndexes.Empty)
                {
                    // We still have unresolved ids to create.
                    ObjectIntHashMap <string> createdTokens     = CreateUnresolvedTokens(unresolvedIndexes, names, ids);
                    IList <NamedToken>        createdTokensList = new List <NamedToken>(createdTokens.size());
                    createdTokens.forEachKeyValue((name, index) => createdTokensList.Add(new NamedToken(name, ids[index])));

                    TokenRegistry.putAll(createdTokensList);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Create and put new token in cache.
        /// </summary>
        /// <param name="name"> token name </param>
        /// <returns> newly created token id </returns>
        /// <exception cref="KernelException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected synchronized int createToken(String name) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        protected internal override int CreateToken(string name)
        {
            lock (this)
            {
                int?id = TokenRegistry.getId(name);
                if (id != null)
                {
                    return(id.Value);
                }

                id = _tokenCreator.createToken(name);
                try
                {
                    TokenRegistry.put(new NamedToken(name, id.Value));
                }
                catch (NonUniqueTokenException e)
                {
                    throw new System.InvalidOperationException("Newly created token should be unique.", e);
                }
                return(id.Value);
            }
        }
 public AbstractTokenHolderBase(TokenRegistry tokenRegistry)
 {
     this.TokenRegistry = tokenRegistry;
 }