View Javadoc

1   /*
2    ORDI - Ontology Repository and Data Integration
3   
4    Copyright (c) 2004-2007, OntoText Lab. / SIRMA
5   
6    This library is free software; you can redistribute it and/or modify it under
7    the terms of the GNU Lesser General Public License as published by the Free
8    Software Foundation; either version 2.1 of the License, or (at your option)
9    any later version.
10   This library is distributed in the hope that it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13   details.
14   You should have received a copy of the GNU Lesser General Public License along
15   with this library; if not, write to the Free Software Foundation, Inc.,
16   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17   */
18  package com.ontotext.ordi.rdbms;
19  
20  import java.util.ArrayList;
21  
22  import org.openrdf.model.Resource;
23  import org.openrdf.model.URI;
24  import org.openrdf.model.Value;
25  
26  import com.ontotext.ordi.exception.ORDIException;
27  import com.ontotext.ordi.exception.ORDIReadOnlyException;
28  import com.ontotext.ordi.iterator.CloseableIterator;
29  import com.ontotext.ordi.iterator.CloseableIteratorImpl;
30  import com.ontotext.ordi.tripleset.TStatement;
31  import com.ontotext.ordi.tripleset.impl.TQueryConnectionImpl;
32  import com.ontotext.ordi.mapper.processor.Processor;
33  import com.ontotext.ordi.mapper.model.RDFResultSet;
34  
35  public class RDBMSConnection extends TQueryConnectionImpl {
36  
37      private static final String READ_ONLY_ERROR = "The source does not support write operations!";
38      private Processor processor;
39      private RDBMSAdapter source;
40  
41      public RDBMSConnection(RDBMSAdapter source, Processor processor) {
42          super(source);
43          if (processor == null) {
44              throw new IllegalArgumentException();
45          }
46          this.processor = processor;
47          this.source = source;
48      }
49  
50      public TStatement addStatement(Resource subj, URI pred, Value obj,
51              URI namedGraph) throws ORDIException {
52          throw new ORDIReadOnlyException(READ_ONLY_ERROR);
53      }
54  
55      public TStatement addStatement(Resource subj, URI pred, Value obj,
56              URI namedGraph, URI... ts) throws ORDIException {
57          throw new ORDIReadOnlyException(READ_ONLY_ERROR);
58      }
59  
60      public int associateTripleset(Resource subj, URI pred, Value obj,
61              URI namedGraph, URI... ts) {
62          return 0;
63      }
64  
65      public int deassociateTripleset(Resource subj, URI pred, Value obj,
66              URI namedGraph, URI... ts) {
67          return 0;
68      }
69  
70      public CloseableIterator<? extends Value> getValuesOfType(URI uri)
71              throws ORDIException {
72          return new CloseableIteratorImpl<Value>(new ArrayList<Value>()
73                  .iterator());
74      }
75  
76      public int removeStatement(Resource subj, URI pred, Value obj,
77              URI namedGraph) throws ORDIException {
78          throw new ORDIReadOnlyException(READ_ONLY_ERROR);
79      }
80  
81      public CloseableIterator<? extends TStatement> search(Resource subj,
82              URI pred, Value obj, URI namedGraph, URI ts) throws ORDIException {
83          RDFResultSet resultSet = processor
84                  .evaluate(subj, pred, obj, namedGraph);
85          RDBMSCloseableIterator iterator = new RDBMSCloseableIterator(resultSet,
86                  source.getTriplesetFactory());
87          return iterator;
88      }
89  
90      public boolean isOpen() {
91          return true;
92      }
93  
94      public boolean isReadOnly() {
95          return true;
96      }
97  }