/** * Copies all of the mappings from the specified map to this one. * These mappings replace any mappings that this map had for any of the * keys currently in the specified map. * * @param m mappings to be stored in this map */ @Override public void putAll(Map<? extends K, ? extends V> m) { for ( Map.Entry<? extends K, ? extends V> e : m.entrySet() ) { put( e.getKey(), e.getValue() ); } }
/** * Creates a new connection using the supplied configuration. * * @param config * {@link Configuration} instance, may not be null. */ public SqlServerConnection(Configuration config) { super(config, FACTORY); lsnToInstantCache = new BoundedConcurrentHashMap<>(100); realDatabaseName = retrieveRealDatabaseName(); }
@Override public String topicNameFor(I id, String prefix, String delimiter) { return topicNames.computeIfAbsent(id, i -> delegate.topicNameFor(i, prefix, delimiter)); } }
/** * {@inheritDoc} * * @throws NullPointerException if any of the arguments are null */ @Override public boolean replace(K key, V oldValue, V newValue) { if ( oldValue == null || newValue == null ) { throw new NullPointerException(); } int hash = hash( key.hashCode() ); return segmentFor( hash ).replace( key, hash, oldValue, newValue ); }
/** * Map a commit LSN to a point in time when the commit happened. * * @param lsn - LSN of the commit * @return time when the commit was recorded into the database log * @throws SQLException */ public Instant timestampOfLsn(Lsn lsn) throws SQLException { final String query = LSN_TO_TIMESTAMP; if (lsn.getBinary() == null) { return null; } Instant cachedInstant = lsnToInstantCache.get(lsn); if (cachedInstant != null) { return cachedInstant; } return prepareQueryAndMap(query, statement -> { statement.setBytes(1, lsn.getBinary()); }, singleResultMapper(rs -> { final Timestamp ts = rs.getTimestamp(1); final Instant ret = (ts == null) ? null : ts.toInstant(); LOGGER.trace("Timestamp of lsn {} is {}", lsn, ret); if (ret != null) { lsnToInstantCache.put(lsn, ret); } return ret; }, "LSN to timestamp query must return exactly one value")); }
/** * Legacy method testing if some key maps into the specified value * in this table. This method is identical in functionality to * {@link #containsValue}, and exists solely to ensure * full compatibility with class {@link java.util.Hashtable}, * which supported this method prior to introduction of the * Java Collections framework. * * @param value a value to search for * * @return <tt>true</tt> if and only if some key maps to the * <tt>value</tt> argument in this table as * determined by the <tt>equals</tt> method; * <tt>false</tt> otherwise * * @throws NullPointerException if the specified value is null */ public boolean contains(Object value) { return containsValue( value ); }
/** * {@inheritDoc} * * @throws NullPointerException if the specified key is null */ @Override public boolean remove(Object key, Object value) { int hash = hash( key.hashCode() ); if ( value == null ) { return false; } return segmentFor( hash ).remove( key, hash, value ) != null; }
/** * Legacy method testing if some key maps into the specified value * in this table. This method is identical in functionality to * {@link #containsValue}, and exists solely to ensure * full compatibility with class {@link java.util.Hashtable}, * which supported this method prior to introduction of the * Java Collections framework. * * @param value a value to search for * * @return <tt>true</tt> if and only if some key maps to the * <tt>value</tt> argument in this table as * determined by the <tt>equals</tt> method; * <tt>false</tt> otherwise * * @throws NullPointerException if the specified value is null */ public boolean contains(Object value) { return containsValue( value ); }
/** * Removes the key (and its corresponding value) from this map. * This method does nothing if the key is not in the map. * * @param key the key that needs to be removed * * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt> * * @throws NullPointerException if the specified key is null */ @Override public V remove(Object key) { int hash = hash( key.hashCode() ); return segmentFor( hash ).remove( key, hash, null ); }
/** * Reconstitute the <tt>ConcurrentHashMap</tt> instance from a * stream (i.e., deserialize it). * * @param s the stream */ @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Initialize each segment to be minimally sized, and let grow. for ( int i = 0; i < segments.length; ++i ) { segments[i].setTable( new HashEntry[1] ); } // Read the keys and values, and put the mappings in the table for (; ; ) { K key = (K) s.readObject(); V value = (V) s.readObject(); if ( key == null ) { break; } put( key, value ); } } }
@Override public String topicNameFor(I id, String prefix, String delimiter) { return topicNames.computeIfAbsent(id, i -> delegate.topicNameFor(i, prefix, delimiter)); } }
/** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. * <p/> * <p>More formally, if this map contains a mapping from a key * {@code k} to a value {@code v} such that {@code key.equals(k)}, * then this method returns {@code v}; otherwise it returns * {@code null}. (There can be at most one such mapping.) * * @throws NullPointerException if the specified key is null */ @Override public V get(Object key) { int hash = hash( key.hashCode() ); return segmentFor( hash ).get( key, hash ); }
/** * Copies all of the mappings from the specified map to this one. * These mappings replace any mappings that this map had for any of the * keys currently in the specified map. * * @param m mappings to be stored in this map */ @Override public void putAll(Map<? extends K, ? extends V> m) { for ( Map.Entry<? extends K, ? extends V> e : m.entrySet() ) { put( e.getKey(), e.getValue() ); } }
/** * Tests if the specified object is a key in this table. * * @param key possible key * * @return <tt>true</tt> if and only if the specified object * is a key in this table, as determined by the * <tt>equals</tt> method; <tt>false</tt> otherwise. * * @throws NullPointerException if the specified key is null */ @Override public boolean containsKey(Object key) { int hash = hash( key.hashCode() ); return segmentFor( hash ).containsKey( key, hash ); }
/** * Reconstitute the <tt>ConcurrentHashMap</tt> instance from a * stream (i.e., deserialize it). * * @param s the stream */ @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Initialize each segment to be minimally sized, and let grow. for ( int i = 0; i < segments.length; ++i ) { segments[i].setTable( new HashEntry[1] ); } // Read the keys and values, and put the mappings in the table for (; ; ) { K key = (K) s.readObject(); V value = (V) s.readObject(); if ( key == null ) { break; } put( key, value ); } } }
/** * {@inheritDoc} * * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * * @throws NullPointerException if the specified key or value is null */ @Override public V replace(K key, V value) { if ( value == null ) { throw new NullPointerException(); } int hash = hash( key.hashCode() ); return segmentFor( hash ).replace( key, hash, value ); }
/** * {@inheritDoc} * * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * * @throws NullPointerException if the specified key or value is null */ @Override public V putIfAbsent(K key, V value) { if ( value == null ) { throw new NullPointerException(); } int hash = hash( key.hashCode() ); return segmentFor( hash ).put( key, hash, value, true ); }
/** * Maps the specified key to the specified value in this table. * Neither the key nor the value can be null. * <p/> * <p> The value can be retrieved by calling the <tt>get</tt> method * with a key that is equal to the original key. * * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt> * * @throws NullPointerException if the specified key or value is null */ @Override public V put(K key, V value) { if ( value == null ) { throw new NullPointerException(); } int hash = hash( key.hashCode() ); return segmentFor( hash ).put( key, hash, value, false ); }
/** * {@inheritDoc} * * @throws NullPointerException if the specified key is null */ @Override public boolean remove(Object key, Object value) { int hash = hash( key.hashCode() ); if ( value == null ) { return false; } return segmentFor( hash ).remove( key, hash, value ) != null; }
/** * {@inheritDoc} * * @throws NullPointerException if any of the arguments are null */ @Override public boolean replace(K key, V oldValue, V newValue) { if ( oldValue == null || newValue == null ) { throw new NullPointerException(); } int hash = hash( key.hashCode() ); return segmentFor( hash ).replace( key, hash, oldValue, newValue ); }