diff options
| author | guest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129> | 2008-09-24 21:58:16 +0000 |
|---|---|---|
| committer | guest <guest@f059d3a0-6783-47b7-97ff-1fe0bbf25129> | 2008-09-24 21:58:16 +0000 |
| commit | 1124d590a9db28e5a4088f8e84557469e7ee4bb2 (patch) | |
| tree | a61b20ed778ada22c475462587757098b098feab /src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java | |
| parent | ab841adc06acd2a6ff161ea866579674ce5ff99e (diff) | |
it's now possible to make a search request in the client, then the pgsqlinput plugin gets proper (incomplete) results out of the database, then everything crashes on the way back, cause the search result isn't yet set correctly
git-svn-id: http://manut.eu/svn/yalp/trunk@6 f059d3a0-6783-47b7-97ff-1fe0bbf25129
Diffstat (limited to 'src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java')
| -rw-r--r-- | src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java | 211 |
1 files changed, 143 insertions, 68 deletions
diff --git a/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java b/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java index 4d0a602..573c587 100644 --- a/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java +++ b/src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java @@ -60,6 +60,149 @@ public class YalpInputPluginImpl extends InputPluginInterfacePOA { } /* + * cuts Strings and returns an ArrayList of the cutted Strings + * + * @param str + * String to cut + * @return ArrayList<String> + * ArrayList with cutted Strings + */ + private ArrayList <String> stringCut (String str) { + + int i=0,j=0; + ArrayList<String> list= new ArrayList<String>(); + + while( j != -1 ) { + j=str.indexOf(" ", i); + if (j!=-1) { + list.add(new String (str.substring(i,j))); + i=j+1; + } else + list.add( new String( str.substring( i, str.length() ) ) ); + } + return list; + } + + public void search( String str, MediaType[] types, MediasHolder result, + YalpErrorHolder err) { + + logger.debug("search("+str+")"); + + ArrayList <String> searchWords = stringCut(str); + String query = new String(); + Boolean first, doIntersect, sound, video, image; + doIntersect = false; + sound = false; + video = false; + image = false; + + for( int i = 0; i < types.length; i++ ) + { + switch( types[i].value() ) + { + case MediaType._SOUND: + sound = true; + break; + case MediaType._VIDEO: + video = true; + break; + case MediaType._IMAGE: + image = true; + break; + } + } + + //for( int i = 0; i < searchWords.size(); i++ ) { + for( String pattern : searchWords ) { + first = true; + + if( doIntersect ) + query = query+") intersect "; + else + doIntersect = true; + + query += "select * from \"Medias\" where ("; + + if( sound ) { + first = false; + query += "\"type\" = 'a' "; + } + if( image ) { + if( first ) + first = false; + else + query += "or "; + query += "\"type\" = 'i' "; + } + if( video ) { + if( first ) + first = false; + else + query += "or "; + query += "\"type\" = 'v' "; + } + if( !first ) + query += ") and ("; + + query += "\"name\" Ilike '%"; + query += pattern; + query += "%' or \"tags\" Ilike '%"; + query += pattern; + /* + query += "%' or \"album\" Ilike '%"; + query += pattern; + query += "%'or \"year\" Ilike '%"; + query += pattern; + query += "%'or \"category\" Ilike '%"; + query += pattern; + */ + query += "%'"; + } + query += ")order by \"id\";"; + + logger.debug("sending SQL request: "+query); + + try { + + Statement stat = con.createStatement(); + ResultSet sqlResult = stat.executeQuery(query); + + System.out.println("found: "); + while( sqlResult.next() ) { + System.out.print(sqlResult.getString(3)+": "); + System.out.print(sqlResult.getString(4)+"\t| "); + System.out.println(sqlResult.getString(6)); + /* + result.add( + new Result( sqlResult.getInt(1), + sqlResult.getString(2), + ---> + result.getString(3), + result.getString(4), + result.getString(5), + result.getString(6), + result.getString(7), + result.getString(8), + result.getInt(9), + result.getInt(10), + result.getString(11), + result.getInt(12), + result.getString(13), + result.getString(14), + result.getString(15) ) ); + */ + } + System.out.println(); + + } catch( SQLException e ) { + System.out.println("Exception in PGSqlInput.search: "+e); + } + + } + +// == REIMPLEMENTATION NEEDED : == // + +/* * submits changes to yalpMediaDatabase * * @param change @@ -101,74 +244,6 @@ public class YalpInputPluginImpl extends InputPluginInterfacePOA { } /* - * returns an ArrayList of Results which are matching to the commited Find object - * - * @param media - * Object which describes search criterias - * @return ArrayList<Result> - * List with Results matching search criteria - */ - public void search(String str, MediaType[] types, MediasHolder result, YalpErrorHolder err) { - System.out.println("juhu: searching for: "+str); - /* t.b.d. alter this to new database design - try{ - ArrayList <String > searchWords=stringCut(media.str); - String query= new String(); - Boolean first; - for (int i=0;i<searchWords.size();i++){ - first=true; - if (i!=0)query = query+") intersect "; - query= query+"select * from \"medien\" where ("; - if (media.audio){ - first=false; - query=query+"\"type\" = 'audio' "; - } - if (media.video){ - if (first)first=false; - else query=query+"or "; - query=query+"\"type\" = 'video' "; - } - if (!first)query=query+") and ("; - query=query+"\"title\" Ilike '%"+searchWords.get(i)+"%' or \"author\" Ilike '%"+searchWords.get(i)+"%' or \"album\" Ilike '%"+searchWords.get(i)+"%'or \"year\" Ilike '%"+searchWords.get(i)+"%'or \"category\" Ilike '%"+searchWords.get(i)+"%'"; - } - query=query+")order by \"id\";"; - - ArrayList<Result> resultList=new ArrayList<Result>(); - Statement stat= con.createStatement(); - ResultSet result=stat.executeQuery(query); - while(result.next()){ - resultList.add( new Result(result.getInt(1),result.getString(2),result.getString(3),result.getString(4),result.getString(5),result.getString(6),result.getString(7),result.getString(8),result.getInt(9),result.getInt(10),result.getString(11),result.getInt(12),result.getString(13),result.getString(14),result.getString(15))); - } - return resultList; - }catch(SQLException e){ - System.out.println("Exception in PGSqlInput.search: "+e); - return new ArrayList<Result>(); - } - */ - } - -/* - * cuts Strings and returns an ArrayList of the cutted Strings - * - * @param str - * String to cut - * @return ArrayList<String> - * ArrayList with cutted Strings - */ - private ArrayList <String> stringCut (String str){ - int i=0,j=0; - ArrayList<String> list= new ArrayList<String>(); - while(j!=-1){ - j=str.indexOf(" ",i); - if (j!=-1){ - list.add(new String (str.substring(i,j))); - i=j+1; - } else list.add(new String (str.substring(i,str.length()))); - } - return list; - } - -/* * returns number of medias in database * * @return String |
