private LobTypeMappings() { this.lobCodeByNonLobCode = new BoundedConcurrentHashMap<Integer, Integer>(); // BLOB mappings this.lobCodeByNonLobCode.put( Types.BLOB, Types.BLOB ); this.lobCodeByNonLobCode.put( Types.BINARY, Types.BLOB ); this.lobCodeByNonLobCode.put( Types.VARBINARY, Types.BLOB ); this.lobCodeByNonLobCode.put( Types.LONGVARBINARY, Types.BLOB ); // CLOB mappings this.lobCodeByNonLobCode.put( Types.CLOB, Types.CLOB ); this.lobCodeByNonLobCode.put( Types.CHAR, Types.CLOB ); this.lobCodeByNonLobCode.put( Types.VARCHAR, Types.CLOB ); this.lobCodeByNonLobCode.put( Types.LONGVARCHAR, Types.CLOB ); // NCLOB mappings this.lobCodeByNonLobCode.put( Types.NCLOB, Types.NCLOB ); this.lobCodeByNonLobCode.put( Types.NCHAR, Types.NCLOB ); this.lobCodeByNonLobCode.put( Types.NVARCHAR, Types.NCLOB ); this.lobCodeByNonLobCode.put( Types.LONGNVARCHAR, Types.NCLOB ); }
/** * Obtain the parameter metadata for given native-sql query. * <p/> * for native-sql queries, the param metadata is determined outside any relation to a query plan, because * query plan creation and/or retrieval for a native-sql query depends on all of the return types having been * set, which might not be the case up-front when param metadata would be most useful * * @param query The query * @return The parameter metadata */ public ParameterMetadata getSQLParameterMetadata(final String query, boolean isOrdinalParameterZeroBased) { final ParameterMetadataKey key = new ParameterMetadataKey( query, isOrdinalParameterZeroBased ); ParameterMetadataImpl value = parameterMetadataCache.get( key ); if ( value == null ) { value = nativeQueryInterpreter.getParameterMetadata( query ); parameterMetadataCache.putIfAbsent( key, value ); } return value; }
@Override public QueryStatisticsImpl getQueryStatistics(String queryString) { return queryStatsMap.computeIfAbsent( queryString, s -> new QueryStatisticsImpl( queryString ) ); }
/** * {@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; }
@Override public SelectQueryPlan getSelectQueryPlan(Key key) { // todo (6.0) : Log and stats, see HHH-12855 return (SelectQueryPlan) queryPlanCache.get( key ); }
@Override public void cacheSelectQueryPlan(Key key, SelectQueryPlan plan) { // todo (6.0) : LOG, see HHH-12855 queryPlanCache.putIfAbsent( key, plan ); }
/** * 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() ); } }
/** * Clean up the caches when the SessionFactory is closed. * <p> * Note that depending on the cache strategy implementation chosen, clearing the cache might not reclaim all the * memory. * <p> * Typically, when using LIRS, clearing the cache only invalidates the entries but the outdated entries are kept in * memory until they are replaced by others. It is not considered a memory leak as the cache is bounded. */ public void cleanup() { LOG.trace( "Cleaning QueryPlan Cache" ); queryPlanCache.clear(); parameterMetadataCache.clear(); }
@Override public String[] getQueries() { return ArrayHelper.toStringArray( queryStatsMap.keySet() ); }
/** * 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 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 ); }
@Override public SqmStatement getSqmStatement(String queryString) { return (SqmStatement) sqmStatementCache.get( queryString ); }
@Override public void cacheSqmStatement(String key, SqmStatement sqmStatement) { // todo (6.0) : Log and stats, see HHH-12855 sqmStatementCache.putIfAbsent( key, sqmStatement ); }
/** * 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 ); } } }
naturalIdQueryStatsMap.clear(); l2CacheStatsMap.clear(); queryStatsMap.clear(); deprecatedNaturalIdStatsMap.clear();
@Override public String[] getQueries() { return ArrayHelper.toStringArray( queryStatsMap.keySet() ); }
/** * 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 ); }
Map<String,Filter> enabledFilters) throws QueryException, MappingException { final FilterQueryPlanKey key = new FilterQueryPlanKey( filterString, collectionRole, shallow, enabledFilters ); FilterQueryPlan value = (FilterQueryPlan) queryPlanCache.get( key ); if ( value == null ) { LOG.tracev( ); value = new FilterQueryPlan( filterString, collectionRole, shallow, enabledFilters,factory ); queryPlanCache.putIfAbsent( key, value );
public StatisticsImpl(SessionFactoryImplementor sessionFactory) { this.sessionFactory = sessionFactory; this.queryStatsMap = new BoundedConcurrentHashMap( sessionFactory != null ? sessionFactory.getSessionFactoryOptions().getQueryStatisticsMaxSize() : Statistics.DEFAULT_QUERY_STATISTICS_MAX_SIZE, 20, BoundedConcurrentHashMap.Eviction.LRU ); clear(); }