1 5 package org.h2.fulltext; 6 7 import java.sql.Connection ; 8 import java.sql.PreparedStatement ; 9 import java.sql.ResultSet ; 10 import java.sql.SQLException ; 11 import java.sql.Statement ; 12 import java.util.HashMap ; 13 import java.util.HashSet ; 14 15 public class FullTextSettings { 16 17 private static HashMap settings = new HashMap (); 18 19 private HashSet ignoreList = new HashSet (); 20 private HashMap words = new HashMap (); 21 private HashMap indexes = new HashMap (); 22 private PreparedStatement prepSelectMapByWordId; 23 private PreparedStatement prepSelectRowById; 24 25 private FullTextSettings() { 26 } 27 28 HashSet getIgnoreList() { 29 return ignoreList; 30 } 31 32 public HashMap getWordList() { 33 return words; 34 } 35 36 IndexInfo getIndexInfo(long indexId) { 37 return (IndexInfo) indexes.get(new Long (indexId)); 38 } 39 40 void addIndexInfo(IndexInfo index) { 41 indexes.put(new Long (index.id), index); 42 } 43 44 public String convertWord(String word) { 45 word = word.toUpperCase(); 47 if(ignoreList.contains(word)) { 48 return null; 49 } 50 return word; 51 } 52 53 static FullTextSettings getInstance(Connection conn) throws SQLException { 54 String path = getIndexPath(conn); 55 FullTextSettings setting = (FullTextSettings) settings.get(path); 56 if(setting == null) { 57 setting = new FullTextSettings(); 58 settings.put(path, setting); 59 } 60 return setting; 61 } 62 63 private static String getIndexPath(Connection conn) throws SQLException { 64 Statement stat = conn.createStatement(); 65 ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()"); 66 rs.next(); 67 String path = rs.getString(1); 68 if (path == null) { 69 throw new SQLException ("FULLTEXT", "Fulltext search for in-memory databases is not supported."); 70 } 71 rs.close(); 72 return path; 73 } 74 75 public PreparedStatement getPrepSelectMapByWordId() { 76 return prepSelectMapByWordId; 77 } 78 79 public void setPrepSelectMapByWordId(PreparedStatement prepSelectMapByWordId) { 80 this.prepSelectMapByWordId = prepSelectMapByWordId; 81 } 82 83 public PreparedStatement getPrepSelectRowById() { 84 return prepSelectRowById; 85 } 86 87 public void setPrepSelectRowById(PreparedStatement prepSelectRowById) { 88 this.prepSelectRowById = prepSelectRowById; 89 } 90 91 } 92 | Popular Tags |