ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/fulltext/FullTextSettings.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/fulltext/FullTextSettings.java
Status
scanned
Type
file
Name
FullTextSettings.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
6976 (6.8 KB)
MD5
543f7a35d83674ad94142f2544ad2a2c
SHA1
059de14b60145cc48a9c15405645cf510ee03149
SHA256
a8094ca0c3a086fd1096000867311189ca63f53153609f22734a43410e7ddde1
SHA512

      
    
SHA1_git
b12ecd8a8f8576f882c4ae5316bd0064bad1f738
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
FullTextSettings.java | 6.8 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.fulltext; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.HashMap; import java.util.HashSet; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import org.h2.util.SoftValuesHashMap; /** * The global settings of a full text search. */ final class FullTextSettings { /** * The settings of open indexes. */ private static final HashMap<String, FullTextSettings> SETTINGS = new HashMap<>(); /** * Whether this instance has been initialized. */ private boolean initialized; /** * The set of words not to index (stop words). */ private final HashSet<String> ignoreList = new HashSet<>(); /** * The set of words / terms. */ private final HashMap<String, Integer> words = new HashMap<>(); /** * The set of indexes in this database. */ private final ConcurrentHashMap<Integer, IndexInfo> indexes = new ConcurrentHashMap<>(); /** * The prepared statement cache. */ private final WeakHashMap<Connection, SoftValuesHashMap<String, PreparedStatement>> cache = new WeakHashMap<>(); /** * The whitespace characters. */ private String whitespaceChars = " \f+\"*%&/()=?'!,.;:-_#@|^~`{}[]<>\\"; /** * Create a new instance. */ private FullTextSettings() { // don't allow construction } /** * Clear set of ignored words */ public void clearIgnored() { synchronized (ignoreList) { ignoreList.clear(); } } /** * Amend set of ignored words * @param words to add */ public void addIgnored(Iterable<String> words) { synchronized (ignoreList) { for (String word : words) { word = normalizeWord(word); ignoreList.add(word); } } } /** * Clear set of searchable words */ public void clearWordList() { synchronized (words) { words.clear(); } } /** * Get id for a searchable word * @param word to find id for * @return Integer id or null if word is not found */ public Integer getWordId(String word) { synchronized (words) { return words.get(word); } } /** * Register searchable word * @param word to register * @param id to register with */ public void addWord(String word, Integer id) { synchronized (words) { words.putIfAbsent(word, id); } } /** * Get the index information for the given index id. * * @param indexId the index id * @return the index info */ IndexInfo getIndexInfo(int indexId) { return indexes.get(indexId); } /** * Add an index. * * @param index the index */ void addIndexInfo(IndexInfo index) { indexes.put(index.id, index); } /** * Convert a word to uppercase. This method returns null if the word is in * the ignore list. * * @param word the word to convert and check * @return the uppercase version of the word or null */ String convertWord(String word) { word = normalizeWord(word); synchronized (ignoreList) { if (ignoreList.contains(word)) { return null; } } return word; } /** * Get or create the fulltext settings for this database. * * @param conn the connection * @return the settings * @throws SQLException on failure */ static FullTextSettings getInstance(Connection conn) throws SQLException { String path = getIndexPath(conn); FullTextSettings setting; synchronized (SETTINGS) { setting = SETTINGS.get(path); if (setting == null) { setting = new FullTextSettings(); SETTINGS.put(path, setting); } } return setting; } /** * Get the file system path. * * @param conn the connection * @return the file system path */ private static String getIndexPath(Connection conn) throws SQLException { Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery( "CALL COALESCE(DATABASE_PATH(), 'MEM:' || DATABASE())"); rs.next(); String path = rs.getString(1); if ("MEM:UNNAMED".equals(path)) { throw FullText.throwException( "Fulltext search for private (unnamed) " + "in-memory databases is not supported."); } rs.close(); return path; } /** * Prepare a statement. The statement is cached in a soft reference cache. * * @param conn the connection * @param sql the statement * @return the prepared statement * @throws SQLException on failure */ synchronized PreparedStatement prepare(Connection conn, String sql) throws SQLException { SoftValuesHashMap<String, PreparedStatement> c = cache.get(conn); if (c == null) { c = new SoftValuesHashMap<>(); cache.put(conn, c); } PreparedStatement prep = c.get(sql); if (prep != null && prep.getConnection().isClosed()) { prep = null; } if (prep == null) { prep = conn.prepareStatement(sql); c.put(sql, prep); } return prep; } /** * Remove all indexes from the settings. */ void removeAllIndexes() { indexes.clear(); } /** * Remove an index from the settings. * * @param index the index to remove */ void removeIndexInfo(IndexInfo index) { indexes.remove(index.id); } /** * Set the initialized flag. * * @param b the new value */ void setInitialized(boolean b) { this.initialized = b; } /** * Get the initialized flag. * * @return whether this instance is initialized */ boolean isInitialized() { return initialized; } /** * Close all fulltext settings, freeing up memory. */ static void closeAll() { synchronized (SETTINGS) { SETTINGS.clear(); } } void setWhitespaceChars(String whitespaceChars) { this.whitespaceChars = whitespaceChars; } String getWhitespaceChars() { return whitespaceChars; } private static String normalizeWord(String word) { // TODO this is locale specific, document return word.toUpperCase(); } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
1.64
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License expression License clue details
(mpl-2.0 OR epl-1.0) AND proprietary-license {'score': 20.37, 'matcher': '3-seq', 'end_line': 3, 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'from_file': None, 'start_line': 2, 'matched_text': ' * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,\n * and the EPL 1.0 (https://h2database.com/html/license.html).', 'match_coverage': 20.37, 'matched_length': 11, 'rule_relevance': 100, 'rule_identifier': 'mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'license_expression': '(mpl-2.0 OR epl-1.0) AND proprietary-license', 'license_expression_spdx': '(MPL-2.0 OR EPL-1.0) AND LicenseRef-scancode-proprietary-license'}
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220