Source Code Cross Referenced for RepositoryConfigUtil.java in  » RSS-RDF » sesame » org » openrdf » repository » config » 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.repository.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.repository.config;
007:
008:        import static org.openrdf.repository.config.RepositoryConfigSchema.REPOSITORYID;
009:        import static org.openrdf.repository.config.RepositoryConfigSchema.REPOSITORY_CONTEXT;
010:
011:        import java.util.LinkedHashSet;
012:        import java.util.List;
013:        import java.util.Set;
014:
015:        import org.openrdf.model.Graph;
016:        import org.openrdf.model.Literal;
017:        import org.openrdf.model.Resource;
018:        import org.openrdf.model.Statement;
019:        import org.openrdf.model.ValueFactory;
020:        import org.openrdf.model.impl.GraphImpl;
021:        import org.openrdf.model.vocabulary.RDF;
022:        import org.openrdf.repository.Repository;
023:        import org.openrdf.repository.RepositoryConnection;
024:        import org.openrdf.repository.RepositoryException;
025:        import org.openrdf.repository.RepositoryResult;
026:
027:        public class RepositoryConfigUtil {
028:
029:            public static Set<String> getRepositoryIDs(Repository repository)
030:                    throws RepositoryException {
031:                RepositoryConnection con = repository.getConnection();
032:                try {
033:                    Set<String> idSet = new LinkedHashSet<String>();
034:
035:                    RepositoryResult<Statement> idStatementIter = con
036:                            .getStatements(null, REPOSITORYID, null, true);
037:                    try {
038:                        while (idStatementIter.hasNext()) {
039:                            Statement idStatement = idStatementIter.next();
040:
041:                            if (idStatement.getObject() instanceof  Literal) {
042:                                Literal idLiteral = (Literal) idStatement
043:                                        .getObject();
044:                                idSet.add(idLiteral.getLabel());
045:                            }
046:                        }
047:                    } finally {
048:                        idStatementIter.close();
049:                    }
050:
051:                    return idSet;
052:                } finally {
053:                    con.close();
054:                }
055:            }
056:
057:            /**
058:             * Is configuration information for the specified repository ID present in
059:             * the (system) repository?
060:             * 
061:             * @param repository
062:             *        the repository to look in
063:             * @param repositoryID
064:             *        the repositoryID to look for
065:             * @return true if configurion information for the specified repository ID
066:             *         was found, false otherwise
067:             * @throws RepositoryException
068:             *         if an error occurred while trying to retrieve information from the
069:             *         (system) repository
070:             * @throws RepositoryConfigException
071:             */
072:            public static boolean hasRepositoryConfig(Repository repository,
073:                    String repositoryID) throws RepositoryException,
074:                    RepositoryConfigException {
075:                RepositoryConnection con = repository.getConnection();
076:                try {
077:                    return getIDStatement(con, repositoryID) != null;
078:                } finally {
079:                    con.close();
080:                }
081:            }
082:
083:            public static RepositoryConfig getRepositoryConfig(
084:                    Repository repository, String repositoryID)
085:                    throws RepositoryConfigException, RepositoryException {
086:                RepositoryConnection con = repository.getConnection();
087:                try {
088:                    Statement idStatement = getIDStatement(con, repositoryID);
089:                    if (idStatement == null) {
090:                        // No such config
091:                        return null;
092:                    }
093:
094:                    Resource repositoryNode = idStatement.getSubject();
095:                    Resource context = idStatement.getContext();
096:
097:                    if (context == null) {
098:                        throw new RepositoryException(
099:                                "No configuration context for repository "
100:                                        + repositoryID);
101:                    }
102:
103:                    Graph contextGraph = new GraphImpl();
104:                    con.getStatements(null, null, null, true, context).addTo(
105:                            contextGraph);
106:
107:                    return RepositoryConfig
108:                            .create(contextGraph, repositoryNode);
109:                } finally {
110:                    con.close();
111:                }
112:            }
113:
114:            /**
115:             * Update the specified Repository with the specified set of
116:             * RepositoryConfigs. This will overwrite all existing configurations in the
117:             * Repository that have a Repository ID occurring in these RepositoryConfigs.
118:             * 
119:             * @param repository
120:             *        The Repository whose contents will be modified.
121:             * @param configs
122:             *        The RepositoryConfigs that should be added to or updated in the
123:             *        Repository. The RepositoryConfig's ID may already occur in the
124:             *        Repository, in which case all previous configuration data for that
125:             *        Repository will be cleared before the RepositoryConfig is added.
126:             * @throws RepositoryException
127:             *         When access to the Repository's RepositoryConnection causes a
128:             *         RepositoryException.
129:             * @throws RepositoryConfigException
130:             */
131:            public static void updateRepositoryConfigs(Repository repository,
132:                    RepositoryConfig... configs) throws RepositoryException,
133:                    RepositoryConfigException {
134:                RepositoryConnection con = repository.getConnection();
135:
136:                try {
137:                    updateRepositoryConfigs(con, configs);
138:                } finally {
139:                    con.close();
140:                }
141:            }
142:
143:            /**
144:             * Update the specified RepositoryConnection with the specified set of
145:             * RepositoryConfigs. This will overwrite all existing configurations in the
146:             * Repository that have a Repository ID occurring in these RepositoryConfigs.
147:             * 
148:             * Note: this method does NOT commit the updates on the connection.
149:             * 
150:             * @param con
151:             *        the repository connection to perform the update on
152:             * @param configs
153:             *        The RepositoryConfigs that should be added to or updated in the
154:             *        Repository. The RepositoryConfig's ID may already occur in the
155:             *        Repository, in which case all previous configuration data for that
156:             *        Repository will be cleared before the RepositoryConfig is added.
157:             * 
158:             * @throws RepositoryException
159:             * @throws RepositoryConfigException
160:             */
161:            public static void updateRepositoryConfigs(
162:                    RepositoryConnection con, RepositoryConfig... configs)
163:                    throws RepositoryException, RepositoryConfigException {
164:                ValueFactory vf = con.getRepository().getValueFactory();
165:
166:                boolean wasAutoCommit = con.isAutoCommit();
167:                con.setAutoCommit(false);
168:
169:                for (RepositoryConfig config : configs) {
170:                    Resource context = getContext(con, config.getID());
171:
172:                    if (context != null) {
173:                        con.clear(context);
174:                    } else {
175:                        context = vf.createBNode();
176:                    }
177:
178:                    con.add(context, RDF.TYPE, REPOSITORY_CONTEXT);
179:
180:                    Graph graph = new GraphImpl(vf);
181:                    config.export(graph);
182:                    con.add(graph, context);
183:                }
184:
185:                con.setAutoCommit(wasAutoCommit);
186:            }
187:
188:            /**
189:             * Removes one or more Repository configurations from a Repository. Nothing
190:             * happens when this Repository does not contain configurations for these
191:             * Repository IDs.
192:             * 
193:             * @param repository
194:             *        The Repository to remove the configurations from.
195:             * @param repositoryIDs
196:             *        The IDs of the Repositories whose configurations need to be
197:             *        removed.
198:             * @throws RepositoryException
199:             *         Whenever access to the Repository's RepositoryConnection causes a
200:             *         RepositoryException.
201:             * @throws RepositoryConfigException
202:             */
203:            public static boolean removeRepositoryConfigs(
204:                    Repository repository, String... repositoryIDs)
205:                    throws RepositoryException, RepositoryConfigException {
206:                boolean changed = false;
207:
208:                RepositoryConnection con = repository.getConnection();
209:                try {
210:                    con.setAutoCommit(false);
211:
212:                    for (String id : repositoryIDs) {
213:                        Resource context = getContext(con, id);
214:                        if (context != null) {
215:                            con.clear(context);
216:                            con.remove(context, RDF.TYPE, REPOSITORY_CONTEXT);
217:                            changed = true;
218:                        }
219:                    }
220:
221:                    con.commit();
222:                } finally {
223:                    con.close();
224:                }
225:
226:                return changed;
227:            }
228:
229:            public static Resource getContext(RepositoryConnection con,
230:                    String repositoryID) throws RepositoryException,
231:                    RepositoryConfigException {
232:                Resource context = null;
233:
234:                Statement idStatement = getIDStatement(con, repositoryID);
235:                if (idStatement != null) {
236:                    context = idStatement.getContext();
237:                }
238:
239:                return context;
240:            }
241:
242:            private static Statement getIDStatement(RepositoryConnection con,
243:                    String repositoryID) throws RepositoryException,
244:                    RepositoryConfigException {
245:                Literal idLiteral = con.getRepository().getValueFactory()
246:                        .createLiteral(repositoryID);
247:                List<Statement> idStatementList = con.getStatements(null,
248:                        REPOSITORYID, idLiteral, true).asList();
249:
250:                if (idStatementList.size() == 1) {
251:                    return idStatementList.get(0);
252:                } else if (idStatementList.isEmpty()) {
253:                    return null;
254:                } else {
255:                    throw new RepositoryConfigException(
256:                            "Multiple ID-statements for repository ID "
257:                                    + repositoryID);
258:                }
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.