protected void setUp() throws java.lang.Exception {

    conn = TestConnection.makeAndCleanTestConnection();
    model = ModelRDB.createModel(conn, TestPackage.M_DB);

    model
        .createResource()
        .addProperty(RDF.type, RDFS.Resource)
        .addProperty(RDFS.label, "foo")
        .addProperty(RDF.value, "123");
    model
        .createResource()
        .addProperty(RDF.type, RDFS.Resource)
        .addProperty(RDFS.label, "bar")
        .addProperty(RDF.value, "123");
  }
Пример #2
0
  /**
   * Connect to a database.
   *
   * @param urlStr
   * @param dbUser
   * @param dbPassword
   * @param dbType
   * @param driverName Load this driver (if not null)
   * @return Model
   */
  public static Model connectToDB(
      String urlStr,
      String dbUser,
      String dbPassword,
      String modelName,
      String dbType,
      String driverName) {
    // Fragment ID is the model name.
    try {
      if (driverName != null) Class.forName(driverName).newInstance();
    } catch (Exception ex) {
    }

    try {
      IDBConnection conn =
          ModelFactory.createSimpleRDBConnection(urlStr, dbUser, dbPassword, dbType);
      return ModelRDB.open(conn, modelName);
    } catch (JenaException rdfEx) {
      LoggerFactory.getLogger(ModelLoader.class)
          .error("Failed to open SQL database: ModelLoader.connectToDB", rdfEx);
      throw rdfEx;
    }
  }