Package de.fuberlin.wiwiss.d2rq

Examples of de.fuberlin.wiwiss.d2rq.D2RQException


 
  public void assertNoUndefinedTerms(Model model,
      int undefinedPropertyErrorCode, int undefinedClassErrorCode) {
    Collection<Property> unknownProperties = getUndefinedProperties(model);
    if (!unknownProperties.isEmpty()) {
      throw new D2RQException(
          "Unknown property " + PrettyPrinter.toString(
              unknownProperties.iterator().next()) + ", maybe a typo?",
          undefinedPropertyErrorCode);
    }
    Collection<Resource> unknownClasses = getUndefinedClasses(model);
    if (!unknownClasses.isEmpty()) {
      throw new D2RQException(
          "Unknown class " + PrettyPrinter.toString(
              unknownClasses.iterator().next()) + ", maybe a typo?",
          undefinedClassErrorCode);
    }
  }
View Full Code Here


*/
public class D2RQAssembler extends AssemblerBase {

  public Object open(Assembler ignore, Resource description, Mode ignore2) {
    if (!description.hasProperty(D2RQ.mappingFile)) {
      throw new D2RQException("Error in assembler specification " + description + ": missing property d2rq:mappingFile");
    }
    if (!description.getProperty(D2RQ.mappingFile).getObject().isURIResource()) {
      throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:mappingFile must be a URI");
    }
    String mappingFileURI = ((Resource) description.getProperty(D2RQ.mappingFile).getObject()).getURI();
    String resourceBaseURI = null;
    Statement stmt = description.getProperty(D2RQ.resourceBaseURI);
    if (stmt != null) {
      if (!stmt.getObject().isURIResource()) {
        throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:resourceBaseURI must be a URI");
      }
      resourceBaseURI = ((Resource) stmt.getObject()).getURI();
    }
    return new ModelD2RQ(mappingFileURI, null, resourceBaseURI);
  }
View Full Code Here

    return fetchSize;
  }

  private void connect() {
    if (jdbcURL != null && !jdbcURL.toLowerCase().startsWith("jdbc:")) {
      throw new D2RQException("Not a JDBC URL: " + jdbcURL, D2RQException.D2RQ_DB_CONNECTION_FAILED);
    }
    try {
      log.info("Establishing JDBC connection to " + jdbcURL);
      this.connection = DriverManager.getConnection(this.jdbcURL, getConnectionProperties());
    } catch (SQLException ex) {
      close();
      throw new D2RQException(
          "Database connection to " + jdbcURL + " failed " +
          "(user: " + username + "): " + ex.getMessage(),
          D2RQException.D2RQ_DB_CONNECTION_FAILED);
    }
    // Database-dependent initialization
    try {
      vendor().initializeConnection(connection);
    } catch (SQLException ex) {
      close();
      throw new D2RQException(
          "Database initialization failed: " + ex.getMessage(),
          D2RQException.D2RQ_DB_CONNECTION_FAILED);
    }
  }
View Full Code Here

      } else {
        this.vendor = Vendor.SQL92;
      }
      log.info("Using vendor class: " + vendor.getClass().getName());
    } catch (SQLException ex) {
      throw new D2RQException("Database exception", ex);
    }
  }
View Full Code Here

  public static void registerJDBCDriver(String driverClassName) {
    if (driverClassName == null) return;
    try {
      Class.forName(driverClassName);
    } catch (ClassNotFoundException ex) {
      throw new D2RQException("Database driver class not found: " + driverClassName,
          D2RQException.DATABASE_JDBCDRIVER_CLASS_NOT_FOUND);
    }
  }
View Full Code Here

  public TranslationTableParser(String url) {
    try {
      this.url = new IRIResolver().resolve(url);;
      this.reader = new BufferedReader(new FileReader(new File(new URI(this.url))));
    } catch (FileNotFoundException fnfex) {
      throw new D2RQException("File not found at URL: " + this.url);
    } catch (URISyntaxException usynex) {
      throw new D2RQException("Malformed URI: " + this.url);
    }
  }
View Full Code Here

        }
        result.add(new Translation(fields[0], fields[1]));
      }
      return result;
    } catch (IOException iex) {
      throw new D2RQException(iex);
    }
  }
View Full Code Here

            writer.setProperty("xmlbase", loader.getResourceBaseURI());
          }
        }
        writer.write(d2rqModel, new OutputStreamWriter(out, "utf-8"), loader.getResourceBaseURI());
      } catch (NoWriterForLangException ex) {
        throw new D2RQException("Unknown format '" + format + "'", D2RQException.STARTUP_UNKNOWN_FORMAT);
      } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException("Can't happen -- utf-8 is always supported");
      }
    } finally {
      out.close();
View Full Code Here

    double timeout = -1;
    if (cmd.hasArg(timeoutArg)) {
      try {
        timeout = Double.parseDouble(cmd.getArg(timeoutArg).getValue());
      } catch (NumberFormatException ex) {
        throw new D2RQException("Timeout must be a number in seconds: '"
            + cmd.getArg(timeoutArg).getValue() + "'", D2RQException.MUST_BE_NUMERIC);
      }
    }
   
    loader.setFastMode(true);
    ModelD2RQ d2rqModel = loader.getModelD2RQ();

    String prefixes = "";
    for (String prefix: d2rqModel.getNsPrefixMap().keySet()) {
      prefixes += "PREFIX " + prefix + ": <" + d2rqModel.getNsPrefixURI(prefix) + ">\n";
    }
    query = prefixes + query;
    log.info("Query:\n" + query);
   
    try {
      QueryEngineD2RQ.register();
      Query q = QueryFactory.create(query, loader.getResourceBaseURI());
      QueryExecution qe = QueryExecutionFactory.create(q, d2rqModel);
      if (timeout > 0) {
        qe.setTimeout(Math.round(timeout * 1000));
      }
      QueryExecUtils.executeQuery(q, qe, ResultsFormat.lookup(format));
    } catch(QueryCancelledException ex) {
      throw new D2RQException("Query timeout", ex, D2RQException.QUERY_TIMEOUT);
    } finally {
      d2rqModel.close();
    }
  }
View Full Code Here

TOP

Related Classes of de.fuberlin.wiwiss.d2rq.D2RQException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.