summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.xml6
-rw-r--r--src/YalpInputs/YalpPGSqlInput/YalpInputPluginImpl.java211
-rw-r--r--src/YalpInputs/YalpPGSqlInput/db-design-backup.sql139
-rw-r--r--src/YalpServer/InputPluginHandler.java2
4 files changed, 219 insertions, 139 deletions
diff --git a/build.xml b/build.xml
index 149a99f..e92dd67 100644
--- a/build.xml
+++ b/build.xml
@@ -23,7 +23,7 @@
<property name="build" value="build/"/>
<property name="lib" value="lib/"/>
- <property name="serverLibs" value="lib/log4j-1.2.15.jar"/>
+ <property name="log4jLibs" value="lib/log4j-1.2.15.jar"/>
<property name="vlctelnetLibs" value="lib/commons-net-1.4.1.jar"/>
<property name="swtLibs" value="lib/swt.jar"/>
<property name="dbLibs" value="lib/postgresql-8.1-404.jdbc3.jar"/>
@@ -59,7 +59,7 @@
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="YalpServer.YalpServer"/>
- <attribute name="Class-Path" value="${serverLibs}"/>
+ <attribute name="Class-Path" value="${log4jLibs}"/>
</manifest>
</jar>
</target>
@@ -99,7 +99,7 @@
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="YalpInputs.YalpPGSqlInput.YalpPGSqlInput"/>
- <attribute name="Class-Path" value="${dbLibs}"/>
+ <attribute name="Class-Path" value="${dbLibs} ${log4jLibs}"/>
</manifest>
</jar>
</target>
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
diff --git a/src/YalpInputs/YalpPGSqlInput/db-design-backup.sql b/src/YalpInputs/YalpPGSqlInput/db-design-backup.sql
index 0ab8d4d..bbdd0d9 100644
--- a/src/YalpInputs/YalpPGSqlInput/db-design-backup.sql
+++ b/src/YalpInputs/YalpPGSqlInput/db-design-backup.sql
@@ -2,14 +2,14 @@
-- PostgreSQL database dump
--
--- Started on 2008-09-23 20:48:41 CEST
+-- Started on 2008-09-25 00:44:25 CEST
SET client_encoding = 'UNICODE';
SET check_function_bodies = false;
SET client_min_messages = warning;
--
--- TOC entry 1518 (class 0 OID 0)
+-- TOC entry 1520 (class 0 OID 0)
-- Dependencies: 5
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
--
@@ -24,14 +24,14 @@ SET default_tablespace = '';
SET default_with_oids = false;
--
--- TOC entry 1170 (class 1259 OID 17306)
--- Dependencies: 1491 5
+-- TOC entry 1172 (class 1259 OID 17306)
+-- Dependencies: 1493 5
-- Name: IntProperties; Type: TABLE; Schema: public; Owner: yalp; Tablespace:
--
CREATE TABLE "IntProperties" (
id bigserial NOT NULL,
- description "char",
+ description text,
value integer
);
@@ -39,8 +39,8 @@ CREATE TABLE "IntProperties" (
ALTER TABLE public."IntProperties" OWNER TO yalp;
--
--- TOC entry 1520 (class 0 OID 0)
--- Dependencies: 1169
+-- TOC entry 1522 (class 0 OID 0)
+-- Dependencies: 1171
-- Name: IntProperties_id_seq; Type: SEQUENCE SET; Schema: public; Owner: yalp
--
@@ -48,35 +48,36 @@ SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('"IntProperties"', 'i
--
--- TOC entry 1172 (class 1259 OID 17313)
--- Dependencies: 1492 5
+-- TOC entry 1174 (class 1259 OID 17313)
+-- Dependencies: 1494 5
-- Name: Medias; Type: TABLE; Schema: public; Owner: yalp; Tablespace:
--
CREATE TABLE "Medias" (
id bigserial NOT NULL,
"type" character(1),
- path "char",
- "fileName" "char",
- tags "char"[],
- duration "char"
+ path text,
+ "fileName" text,
+ duration text,
+ name text,
+ tags text
);
ALTER TABLE public."Medias" OWNER TO yalp;
--
--- TOC entry 1521 (class 0 OID 0)
--- Dependencies: 1171
+-- TOC entry 1523 (class 0 OID 0)
+-- Dependencies: 1173
-- Name: Medias_id_seq; Type: SEQUENCE SET; Schema: public; Owner: yalp
--
-SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('"Medias"', 'id'), 1, false);
+SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('"Medias"', 'id'), 2, true);
--
--- TOC entry 1174 (class 1259 OID 17323)
--- Dependencies: 1493 1494 1495 5
+-- TOC entry 1176 (class 1259 OID 17323)
+-- Dependencies: 1495 1496 1497 5
-- Name: PropertyConnector; Type: TABLE; Schema: public; Owner: yalp; Tablespace:
--
@@ -91,23 +92,23 @@ CREATE TABLE "PropertyConnector" (
ALTER TABLE public."PropertyConnector" OWNER TO yalp;
--
--- TOC entry 1168 (class 1259 OID 17294)
--- Dependencies: 1490 5
+-- TOC entry 1170 (class 1259 OID 17294)
+-- Dependencies: 1492 5
-- Name: StringProperties; Type: TABLE; Schema: public; Owner: yalp; Tablespace:
--
CREATE TABLE "StringProperties" (
id bigserial NOT NULL,
- description "char",
- value "char"
+ description text,
+ value text
);
ALTER TABLE public."StringProperties" OWNER TO yalp;
--
--- TOC entry 1522 (class 0 OID 0)
--- Dependencies: 1167
+-- TOC entry 1524 (class 0 OID 0)
+-- Dependencies: 1169
-- Name: StringProperties_id_seq; Type: SEQUENCE SET; Schema: public; Owner: yalp
--
@@ -115,24 +116,24 @@ SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('"StringProperties"',
--
--- TOC entry 1165 (class 1259 OID 17269)
--- Dependencies: 1488 1489 5
+-- TOC entry 1167 (class 1259 OID 17269)
+-- Dependencies: 1490 1491 5
-- Name: Users; Type: TABLE; Schema: public; Owner: yalp; Tablespace:
--
CREATE TABLE "Users" (
- name "char"[] NOT NULL,
- "realName" name[],
"level" integer DEFAULT 1 NOT NULL,
- id bigserial NOT NULL
+ id bigserial NOT NULL,
+ name text NOT NULL,
+ "realName" text
);
ALTER TABLE public."Users" OWNER TO yalp;
--
--- TOC entry 1523 (class 0 OID 0)
--- Dependencies: 1166
+-- TOC entry 1525 (class 0 OID 0)
+-- Dependencies: 1168
-- Name: Users_id_seq; Type: SEQUENCE SET; Schema: public; Owner: yalp
--
@@ -140,8 +141,8 @@ SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('"Users"', 'id'), 1,
--
--- TOC entry 1524 (class 0 OID 0)
--- Dependencies: 1173
+-- TOC entry 1526 (class 0 OID 0)
+-- Dependencies: 1175
-- Name: propertyConnector_id_seq; Type: SEQUENCE SET; Schema: public; Owner: yalp
--
@@ -149,8 +150,8 @@ SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('"PropertyConnector"'
--
--- TOC entry 1513 (class 0 OID 17306)
--- Dependencies: 1170
+-- TOC entry 1515 (class 0 OID 17306)
+-- Dependencies: 1172
-- Data for Name: IntProperties; Type: TABLE DATA; Schema: public; Owner: yalp
--
@@ -159,18 +160,20 @@ COPY "IntProperties" (id, description, value) FROM stdin;
--
--- TOC entry 1514 (class 0 OID 17313)
--- Dependencies: 1172
+-- TOC entry 1516 (class 0 OID 17313)
+-- Dependencies: 1174
-- Data for Name: Medias; Type: TABLE DATA; Schema: public; Owner: yalp
--
-COPY "Medias" (id, "type", path, "fileName", tags, duration) FROM stdin;
+COPY "Medias" (id, "type", path, "fileName", duration, name, tags) FROM stdin;
+1 v /home/manut test.avi 5:55 huhu hihi
+2 s /home/manut test.mp3 2:22 chavenger - jung und frech live, hiltensweiler, hihi
\.
--
--- TOC entry 1515 (class 0 OID 17323)
--- Dependencies: 1174
+-- TOC entry 1517 (class 0 OID 17323)
+-- Dependencies: 1176
-- Data for Name: PropertyConnector; Type: TABLE DATA; Schema: public; Owner: yalp
--
@@ -179,8 +182,8 @@ COPY "PropertyConnector" ("mediaId", "stringPropertyId", "intPropertyId", id) FR
--
--- TOC entry 1512 (class 0 OID 17294)
--- Dependencies: 1168
+-- TOC entry 1514 (class 0 OID 17294)
+-- Dependencies: 1170
-- Data for Name: StringProperties; Type: TABLE DATA; Schema: public; Owner: yalp
--
@@ -189,18 +192,18 @@ COPY "StringProperties" (id, description, value) FROM stdin;
--
--- TOC entry 1511 (class 0 OID 17269)
--- Dependencies: 1165
+-- TOC entry 1513 (class 0 OID 17269)
+-- Dependencies: 1167
-- Data for Name: Users; Type: TABLE DATA; Schema: public; Owner: yalp
--
-COPY "Users" (name, "realName", "level", id) FROM stdin;
+COPY "Users" ("level", id, name, "realName") FROM stdin;
\.
--
--- TOC entry 1507 (class 16386 OID 17329)
--- Dependencies: 1174 1174
+-- TOC entry 1509 (class 16386 OID 17329)
+-- Dependencies: 1176 1176
-- Name: key_id_con; Type: CONSTRAINT; Schema: public; Owner: yalp; Tablespace:
--
@@ -211,8 +214,8 @@ ALTER TABLE ONLY "PropertyConnector"
ALTER INDEX public.key_id_con OWNER TO yalp;
--
--- TOC entry 1497 (class 16386 OID 17291)
--- Dependencies: 1165 1165
+-- TOC entry 1499 (class 16386 OID 17291)
+-- Dependencies: 1167 1167
-- Name: key_is_id; Type: CONSTRAINT; Schema: public; Owner: yalp; Tablespace:
--
@@ -223,8 +226,8 @@ ALTER TABLE ONLY "Users"
ALTER INDEX public.key_is_id OWNER TO yalp;
--
--- TOC entry 1501 (class 16386 OID 17298)
--- Dependencies: 1168 1168
+-- TOC entry 1503 (class 16386 OID 17298)
+-- Dependencies: 1170 1170
-- Name: prim_key_id; Type: CONSTRAINT; Schema: public; Owner: yalp; Tablespace:
--
@@ -235,8 +238,8 @@ ALTER TABLE ONLY "StringProperties"
ALTER INDEX public.prim_key_id OWNER TO yalp;
--
--- TOC entry 1503 (class 16386 OID 17310)
--- Dependencies: 1170 1170
+-- TOC entry 1505 (class 16386 OID 17310)
+-- Dependencies: 1172 1172
-- Name: prim_key_int_id; Type: CONSTRAINT; Schema: public; Owner: yalp; Tablespace:
--
@@ -247,8 +250,8 @@ ALTER TABLE ONLY "IntProperties"
ALTER INDEX public.prim_key_int_id OWNER TO yalp;
--
--- TOC entry 1505 (class 16386 OID 17320)
--- Dependencies: 1172 1172
+-- TOC entry 1507 (class 16386 OID 17320)
+-- Dependencies: 1174 1174
-- Name: prim_key_m_id; Type: CONSTRAINT; Schema: public; Owner: yalp; Tablespace:
--
@@ -259,20 +262,20 @@ ALTER TABLE ONLY "Medias"
ALTER INDEX public.prim_key_m_id OWNER TO yalp;
--
--- TOC entry 1499 (class 16386 OID 17278)
--- Dependencies: 1165 1165
--- Name: user_name_unique; Type: CONSTRAINT; Schema: public; Owner: yalp; Tablespace:
+-- TOC entry 1501 (class 16386 OID 17405)
+-- Dependencies: 1167 1167
+-- Name: username_is_unique; Type: CONSTRAINT; Schema: public; Owner: yalp; Tablespace:
--
ALTER TABLE ONLY "Users"
- ADD CONSTRAINT user_name_unique UNIQUE (name);
+ ADD CONSTRAINT username_is_unique UNIQUE (name);
-ALTER INDEX public.user_name_unique OWNER TO yalp;
+ALTER INDEX public.username_is_unique OWNER TO yalp;
--
--- TOC entry 1509 (class 16386 OID 17334)
--- Dependencies: 1174 1170 1502
+-- TOC entry 1511 (class 16386 OID 17334)
+-- Dependencies: 1176 1172 1504
-- Name: int_prop; Type: FK CONSTRAINT; Schema: public; Owner: yalp
--
@@ -281,8 +284,8 @@ ALTER TABLE ONLY "PropertyConnector"
--
--- TOC entry 1508 (class 16386 OID 17330)
--- Dependencies: 1174 1172 1504
+-- TOC entry 1510 (class 16386 OID 17330)
+-- Dependencies: 1176 1174 1506
-- Name: media_prop; Type: FK CONSTRAINT; Schema: public; Owner: yalp
--
@@ -291,8 +294,8 @@ ALTER TABLE ONLY "PropertyConnector"
--
--- TOC entry 1510 (class 16386 OID 17338)
--- Dependencies: 1174 1168 1500
+-- TOC entry 1512 (class 16386 OID 17338)
+-- Dependencies: 1176 1170 1502
-- Name: string_prop; Type: FK CONSTRAINT; Schema: public; Owner: yalp
--
@@ -301,7 +304,7 @@ ALTER TABLE ONLY "PropertyConnector"
--
--- TOC entry 1519 (class 0 OID 0)
+-- TOC entry 1521 (class 0 OID 0)
-- Dependencies: 5
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--
@@ -313,7 +316,7 @@ GRANT ALL ON SCHEMA public TO yalp;
GRANT ALL ON SCHEMA public TO PUBLIC;
--- Completed on 2008-09-23 20:48:41 CEST
+-- Completed on 2008-09-25 00:44:25 CEST
--
-- PostgreSQL database dump complete
diff --git a/src/YalpServer/InputPluginHandler.java b/src/YalpServer/InputPluginHandler.java
index 746204a..40c6208 100644
--- a/src/YalpServer/InputPluginHandler.java
+++ b/src/YalpServer/InputPluginHandler.java
@@ -32,6 +32,8 @@ public class InputPluginHandler {
}
/*
+ * @todo sort / priorization of search results
+ *
* @todo maybe each request in own thread
* timeouts, maximum number of results ...
*/