@Override public int getIdByName( String name ) { Integer id = tokenRegistry.getId( name ); if ( id == null ) { return NO_TOKEN; } return id; }
boolean resolveIds( String[] names, int[] ids, IntPredicate unresolvedIndexCheck ) { boolean foundUnresolvable = false; for ( int i = 0; i < ids.length; i++ ) { Integer id = tokenRegistry.getId( names[i] ); if ( id != null ) { ids[i] = id; } else { foundUnresolvable = true; if ( unresolvedIndexCheck.test( i ) ) { // If the check returns `true`, it's a signal that we should stop early. break; } } } return foundUnresolvable; } }
/** * Create and put new token in cache. * * @param name token name * @return newly created token id * @throws KernelException */ @Override protected synchronized int createToken( String name ) throws KernelException { Integer id = tokenRegistry.getId( name ); if ( id != null ) { return id; } id = tokenCreator.createToken( name ); try { tokenRegistry.put( new NamedToken( name, id ) ); } catch ( NonUniqueTokenException e ) { throw new IllegalStateException( "Newly created token should be unique.", e ); } return id; }
@Override public int getOrCreateId( String name ) { Integer id = tokenRegistry.getId( name ); if ( id != null ) { return id; } // Let's create it try { return createToken( name ); } catch ( ReadOnlyDbException e ) { throw new TransactionFailureException( e.getMessage(), e ); } catch ( Throwable e ) { throw new TransactionFailureException( "Could not create token.", e ); } }
@Test public 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 ).intValue() ); assertEquals( 2, tokenCache.getId( INBOUND2_TYPE ).intValue() ); assertNull( tokenCache.getToken( 3 ) ); }
@Override public int getIdByName( String name ) { Integer id = tokenRegistry.getId( name ); if ( id == null ) { return NO_TOKEN; } return id; }
boolean resolveIds( String[] names, int[] ids, IntPredicate unresolvedIndexCheck ) { boolean foundUnresolvable = false; for ( int i = 0; i < ids.length; i++ ) { Integer id = tokenRegistry.getId( names[i] ); if ( id != null ) { ids[i] = id; } else { foundUnresolvable = true; if ( unresolvedIndexCheck.test( i ) ) { // If the check returns `true`, it's a signal that we should stop early. break; } } } return foundUnresolvable; } }
/** * Create and put new token in cache. * * @param name token name * @return newly created token id * @throws KernelException */ @Override protected synchronized int createToken( String name ) throws KernelException { Integer id = tokenRegistry.getId( name ); if ( id != null ) { return id; } id = tokenCreator.createToken( name ); try { tokenRegistry.put( new NamedToken( name, id ) ); } catch ( NonUniqueTokenException e ) { throw new IllegalStateException( "Newly created token should be unique.", e ); } return id; }
@Override public int getOrCreateId( String name ) { Integer id = tokenRegistry.getId( name ); if ( id != null ) { return id; } // Let's create it try { return createToken( name ); } catch ( ReadOnlyDbException e ) { throw new TransactionFailureException( e.getMessage(), e ); } catch ( Throwable e ) { throw new TransactionFailureException( "Could not create token.", e ); } }