Source Code Cross Referenced for LUBMRepository.java in  » RSS-RDF » sesame » org » openrdf » sail » lubm » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » sesame » org.openrdf.sail.lubm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.sail.lubm;
007:
008:        import java.io.File;
009:        import java.io.FilenameFilter;
010:        import java.net.URL;
011:
012:        import edu.lehigh.swat.bench.ubt.api.Query;
013:        import edu.lehigh.swat.bench.ubt.api.QueryResult;
014:
015:        import org.openrdf.query.MalformedQueryException;
016:        import org.openrdf.query.QueryEvaluationException;
017:        import org.openrdf.query.QueryLanguage;
018:        import org.openrdf.query.TupleQueryResult;
019:        import org.openrdf.query.UnsupportedQueryLanguageException;
020:        import org.openrdf.repository.Repository;
021:        import org.openrdf.repository.RepositoryConnection;
022:        import org.openrdf.repository.RepositoryException;
023:        import org.openrdf.repository.sail.SailRepository;
024:        import org.openrdf.rio.RDFFormat;
025:        import org.openrdf.rio.RDFParseException;
026:        import org.openrdf.rio.UnsupportedRDFormatException;
027:        import org.openrdf.sail.Sail;
028:
029:        public abstract class LUBMRepository implements 
030:                edu.lehigh.swat.bench.ubt.api.Repository {
031:
032:            private Repository repository;
033:
034:            private String ontologyURL;
035:
036:            public LUBMRepository() {
037:            }
038:
039:            // implements edu.lehigh.swat.bench.ubt.api.Repository.open(...)
040:            public void open(String database) {
041:                try {
042:                    repository = new SailRepository(createSail(database));
043:                    repository.initialize();
044:                } catch (RepositoryException e) {
045:                    throw new RuntimeException(e);
046:                }
047:            }
048:
049:            /**
050:             * Creates the (stack of) Sails that is subject to testing.
051:             * 
052:             * @param database
053:             *        A identifier for the database that is to be tested, for example a
054:             *        JDBC-URL or a data directory.
055:             * @return An uninitialized Sail object for the specified 'database'.
056:             */
057:            public abstract Sail createSail(String database);
058:
059:            // implements edu.lehigh.swat.bench.ubt.api.Repository.close()
060:            public void close() {
061:                try {
062:                    repository.shutDown();
063:                } catch (RepositoryException e) {
064:                    throw new RuntimeException(e);
065:                }
066:            }
067:
068:            // implements edu.lehigh.swat.bench.ubt.api.Repository.setOntology(...)
069:            public void setOntology(String ontology) {
070:                ontologyURL = ontology;
071:            }
072:
073:            // implements edu.lehigh.swat.bench.ubt.api.Repository.load(...)
074:            public boolean load(String dataDir) {
075:                try {
076:                    RepositoryConnection con = repository.getConnection();
077:
078:                    // load ontology first
079:                    System.out.println("Loading ontology");
080:                    con
081:                            .add(new URL(ontologyURL), ontologyURL,
082:                                    RDFFormat.RDFXML);
083:
084:                    File dir = new File(dataDir);
085:                    File[] fileList = dir.listFiles(new FilenameFilter() {
086:
087:                        public boolean accept(File dir, String name) {
088:                            return name.endsWith(".owl");
089:                        }
090:                    });
091:
092:                    if (fileList == null) {
093:                        System.err
094:                                .println("Invalid data directory: " + dataDir);
095:                        return false;
096:                    }
097:                    for (int i = 0; i < fileList.length; i++) {
098:                        System.out.println("Loading " + fileList[i]);
099:                        con.add(fileList[i], fileList[i].getPath(),
100:                                RDFFormat.RDFXML);
101:                    }
102:
103:                    // System.out.println("Commiting transaction");
104:                    // txn.commit();
105:
106:                    System.out.println("Done loading");
107:                    con.close();
108:
109:                    return true;
110:                } catch (RDFParseException e) {
111:                    e.printStackTrace();
112:                } catch (RepositoryException e) {
113:                    e.printStackTrace();
114:                } catch (java.io.IOException e) {
115:                    e.printStackTrace();
116:                } catch (UnsupportedRDFormatException e) {
117:                    e.printStackTrace();
118:                }
119:
120:                return false;
121:            }
122:
123:            // implements edu.lehigh.swat.bench.ubt.api.Repository.issueQuery(...)
124:            public QueryResult issueQuery(Query query) {
125:
126:                try {
127:                    RepositoryConnection con = repository.getConnection();
128:                    TupleQueryResult queryResult = con.prepareTupleQuery(
129:                            QueryLanguage.SERQL, query.getString()).evaluate();
130:                    con.close();
131:
132:                    return new LUBMQueryResult(queryResult);
133:                } catch (MalformedQueryException e) {
134:                    e.printStackTrace();
135:                } catch (RepositoryException e) {
136:                    e.printStackTrace();
137:                } catch (UnsupportedQueryLanguageException e) {
138:                    e.printStackTrace();
139:                } catch (QueryEvaluationException e) {
140:                    e.printStackTrace();
141:                }
142:
143:                return null;
144:            }
145:
146:            // implements edu.lehigh.swat.bench.ubt.api.Repository.clear()
147:            public void clear() {
148:                try {
149:                    RepositoryConnection con = repository.getConnection();
150:                    con.clear();
151:                    con.close();
152:                } catch (RepositoryException e) {
153:                    throw new RuntimeException(e);
154:                }
155:            }
156:
157:            private static class LUBMQueryResult implements  QueryResult {
158:
159:                private int num;
160:
161:                private TupleQueryResult queryResult;
162:
163:                public LUBMQueryResult(TupleQueryResult queryResult) {
164:                    this .queryResult = queryResult;
165:                }
166:
167:                public long getNum() {
168:                    return num;
169:                }
170:
171:                public boolean next() {
172:                    try {
173:                        if (queryResult.hasNext()) {
174:                            queryResult.next();
175:                            num++;
176:                            return true;
177:                        } else {
178:                            queryResult.close();
179:                            return false;
180:                        }
181:                    } catch (QueryEvaluationException e) {
182:                        e.printStackTrace();
183:                        return false;
184:                    }
185:                }
186:
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.