Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Hashtable<Character, List<String>> DictMap_Products = new Hashtable<Character, List<String>>();
- public static StorEntry[] Products = new StorEntry[]{};
- public static StorEntry[] Cities = new StorEntry[]{};
- @Override
- public void run()
- {
- while( true ) {
- try {
- long now = System.currentTimeMillis();
- try {
- Class.forName( "com.mysql.jdbc.Driver" );
- Connection myconn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/redeeman", "redeeman", "redeeman" );
- PreparedStatement stmt = myconn.prepareStatement( "SELECT String, Type, (LENGTH(`String`)-LENGTH(REPLACE(`String`,' ', ''))) AS NumSpaces FROM `stringsforlinks` ORDER BY NumSpaces DESC" );
- ResultSet resset = stmt.executeQuery();
- // TODO: consider changing to a SELECT COUNT(String) FROM stringsforlinks GROUP BY Type..
- resset.last();
- int numrows = resset.getRow();
- resset.beforeFirst();
- ArrayList<StorEntry> prodpattarr = new ArrayList<StorEntry>( numrows+1 );
- ArrayList<StorEntry> citypattarr = new ArrayList<StorEntry>( numrows+1 );
- DictMap_Products.clear();
- while( resset.next() ) {
- String str = resset.getString( "String" );
- String type = resset.getString( "Type" );
- Pattern p = Pattern.compile( "\\s(" + Pattern.quote( str ) + ").?\\s", Pattern.CASE_INSENSITIVE );
- if( type.equals( "product" ) ) {
- prodpattarr.add( new StorEntry( p.matcher( "" ), str ) );
- List<String> d = DictMap_Products.get( Character.toLowerCase( str.charAt( 0 ) ) );
- if( null == d )
- d = new ArrayList<String>();
- d.add( str );
- DictMap_Products.put( Character.toLowerCase( str.charAt( 0 ) ), d );
- } else if( type.equals( "city" ) )
- citypattarr.add( new StorEntry( p.matcher( "" ), str ) );
- }
- Products = prodpattarr.toArray( Products );
- Cities = citypattarr.toArray( Cities );
- stmt.close();
- myconn.close();
- } catch( Exception e ) {
- e.printStackTrace();
- }
- System.out.println( "Refreshing data, time: " + (System.currentTimeMillis()-now) + "ms" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement