⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 versioningrdbmssail.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      sc.repository = rc.getRepositoryId();      result = rc.getRepositoryId();    } catch (ConfigurationException e) {    	throw new SailInternalException(e);    } catch (SQLException e) {      throw new SailInternalException(e);    } catch (AccessDeniedException e){      throw new SailInternalException(e);    } catch (UnknownRepositoryException e){      throw new SailInternalException(e);    }    return result;  }  /**   * Retrive list of all labeled states of the repository.   * @return a list of Versin interfaces for each labeled state of the repository   */  public Iterator getVersions()  {    return new Iterator() {      // initialize      Connection con = null;      java.sql.Statement st = null;      ResultSet rs = null;      boolean hn =false;      {        try {          con = RDBMS().getConnection();          st = con.createStatement();          rs = st.executeQuery(              "SELECT vid, usid, uid, label FROM " + VERSION_TABLE);          hn = rs.next();          if (!hn)          {            rs.close();            st.close();            con.close();          }        } catch (SQLException ex) {          throw new SailInternalException(ex);        }      }      public boolean hasNext() {        return hn;      }      public Object next()      {        Object res = null;        if (hn) {          try {            int vid = rs.getInt(1);            int usid = rs.getInt(2);            int uid = rs.getInt(3);            String label = rs.getString(4);            res = new VersionOMM(vid, usid, uid, label);            hn = rs.next();            if (!hn)            {              rs.close();              st.close();              con.close();            }          } catch (SQLException ex) {            throw new SailInternalException(ex);          }        }        return res;      }      public void remove()          { }    };  }  /**   * Perform locking of statements in the repository   * @param statementsList - list of statemensts to lock   */  public void lockStatements(Iterator statementsList)  {    throw new RuntimeException( "lockStatements is not implemented" );  }  /**   * Perform unlocking of statements in the repository   * @param statementsList - list of statemensts to unlock   */  public void unlockStatements(Iterator statementsList)  {    throw new RuntimeException( "unlockStatements is not implemented" );  }  /**   * Stop the increment of the update counter. Usefull for a kind of batch updates   * or adding a distinct daml coinstructs at once.   */  public void pauseCounterIncrement()  {    SessionContext.getContext().bIncrementIsPaused = true;  }  /**   * Coninue with the normal increment of the update counter on each modification   * made in the repository.   */  public void continueCounterIncrement()  {    SessionContext.getContext().bIncrementIsPaused = false;  }  /**   * Check if the update couter ss paused   * @return true if the updateCouter is paused, flase otherwise   */  public boolean isPausedCounterIncrement()  {    return SessionContext.getContext().bIncrementIsPaused;  }  public static final String MADE_BY_URI = "http://www.ontotext.com/otk/2002/03/kcs.rdfs#madeBy";  public static final String USER_ID_URI = "http://www.ontotext.com/otk/2002/03/kcs.rdfs#userID";  public static final String VERSION_NAME_URI = "http://www.ontotext.com/otk/2002/03/kcs.rdfs#versionName";  public static final String VERSION_UPDATE_ID = "http://www.ontotext.com/otk/2002/03/kcs.rdfs#stateLabeled";  public static final String BORN_AT_URI = "http://www.ontotext.com/otk/2002/03/kcs.rdfs#bornAt";  public static final String DIED_AT_URI = "http://www.ontotext.com/otk/2002/03/kcs.rdfs#diedAt";  public static final String MADE_ON_URI = "http://www.ontotext.com/otk/2002/03/kcs.rdfs#madeOn";  public static final String EXPLICIT_KEY = "EXPLICIT";  public static final String KIND_KEY = "KIND";  /**   * Retrieves the meta info associated with a statement.   * @param subj the subject of the statement   * @param pred the predicate of the statement   * @param obj the object of the statement   * @return a map of meta info keys vs meta info values   */  public Map getMetaInfo(String subj, String pred, String obj) {    if (subj == null || pred == null || obj == null){      throw new SailInternalException("Cannot Retrieve MetaInfo for a statement"                                      +" that is not in the repository:\n"                                      +"<"+subj+","+pred+","+obj+">");    }    Map map = new HashMap();    Resource subjRes = new org.openrdf.model.impl.URIImpl(subj);    Resource predRes = new org.openrdf.model.impl.URIImpl(pred);    Resource objRes = null;    try {      objRes = new org.openrdf.model.impl.URIImpl(obj);    } catch (IllegalArgumentException e) {    }    // find subj pred obj ids    int subjId = _getResourceId(subjRes);    int predId = _getResourceId(predRes);    int objId = 0;    if (objRes != null)      objId = _getResourceId(objRes);    if ( objId == 0 ) {      Literal objLit = new org.openrdf.model.impl.LiteralImpl(obj);      objId = _getLiteralId(objLit);    }    if (subjId == 0 || objId == 0 || predId == 0) {      throw new SailInternalException("Cannot Retrieve MetaInfo for a statement"                                      +" that is not in the repository:\n"                                      +"<"+subj+","+pred+","+obj+">");    }    int bornAt;    int diedAt;    int statementId;    boolean explicit;    {//get all      Connection con = null;      java.sql.Statement st = null;      ResultSet rs = null;      try {        con = RDBMS().getConnection();        st = con.createStatement();        rs = st.executeQuery(            "SELECT id, explicit, BornAt, DiedAt FROM "+            TRIPLES_HIST_TABLE+            " WHERE subject="+subjId+            " AND predicate="+predId+            " AND object="+objId);        int countLifetime = 0;        while (rs.next()) {          String suffix = "";          if (countLifetime > 0)            suffix = suffix+countLifetime;          statementId = rs.getInt(1);          explicit = rs.getBoolean(2);          bornAt = rs.getInt(3);          diedAt = rs.getInt(4);          map.put(EXPLICIT_KEY+suffix,explicit?"true":"false");          map.put(BORN_AT_URI+suffix,new Integer(bornAt));          if (diedAt != 0 ) {            map.put(DIED_AT_URI+suffix,new Integer(diedAt));          }          countLifetime++;        }        rs.close();        st.close();        con.close();      } catch (SQLException ex) {        throw new SailInternalException(ex);      }    }    return map;  }  /**   * Retrieves the meta info associated with an update.   * @param updateId the id of the update   * @return a map of meta info keys vs meta info values   */  public Map getUpdateMetaInfo(String updateId) {    Map map = new HashMap();    Connection con = null;    java.sql.Statement st = null;    ResultSet rs = null;    try {      con = RDBMS().getConnection();      st = con.createStatement();      rs = st.executeQuery(          "SELECT uid, time, usid, kind FROM "          + UPDATES_TABLE          + " WHERE uid = " + updateId);      if (rs.next()) {        String time = rs.getString(2);        int usid = rs.getInt(3);        int kind = rs.getInt(4);        UserInfo ui = SesameServer.getSystemConfig().getUserInfo(usid);        if (ui != null)          map.put(MADE_BY_URI, ui.getFullName());        else          map.put(MADE_BY_URI, "unknown user");        map.put(USER_ID_URI, new Integer(usid));        map.put(MADE_ON_URI, time);        String updateKind = "";        switch (kind) {          case 1:            updateKind = "add";            break;          case 2:            updateKind = "remove";            break;          case 3:            updateKind = "add/remove";            break;          default:            updateKind = "UNKNOWN/BUG";            break;        }        map.put(KIND_KEY, updateKind);      }      rs.close();      st.close();      con.close();    } catch (SQLException ex) {      throw new SailInternalException(ex);    }    return map;  }  /**   * Retrieves the meta info associated with a version .   * @param versionId the id of the update   * @return a map of meta info keys vs meta info values   */  public Map getVersionMetaInfo(String versionId) {    Map map = new HashMap();    Connection con = null;    java.sql.Statement st = null;    ResultSet rs = null;    try {      con = RDBMS().getConnection();      st = con.createStatement();      rs = st.executeQuery(          "SELECT vid, usid, uid, label FROM "          + VERSION_TABLE          + " WHERE vid = " + versionId);      if (rs.next()) {        int vid = rs.getInt(1);        int usid = rs.getInt(2);        int uid = rs.getInt(3);        String label = rs.getString(4);        UserInfo ui = SesameServer.getSystemConfig().getUserInfo(usid);        map.put(USER_ID_URI,new Long(uid));        if (ui != null)          map.put(MADE_BY_URI, ui.getFullName());        else          map.put(MADE_BY_URI, "unknown user");        map.put(VERSION_UPDATE_ID, new Integer(uid));        map.put(VERSION_NAME_URI, label);      }      rs.close();      st.close();      con.close();    } catch (SQLException ex) {      throw new SailInternalException(ex);    }    return map;  } // getVersionMetaInfo()  /**   * Updates the inferred statements.   **/  protected void _processChangedTriples()          throws SQLException  {    try {      //_statementsRemoved || was in IF below      // create new update        if (((_statementsAdded) || (_statementsRemoved))&& !isPausedCounterIncrement())        {          int updateKind = 0;          if (_statementsAdded)            updateKind = updateKind+1;          if (_statementsRemoved)            updateKind = updateKind+2;          RDBMS().executeUpdate("INSERT into "+UPDATES_TABLE+                                " VALUES("+(getStateUid()+1)+", NULL, "+getCurrentUserID()+", "+                                updateKind+" , "+baseUrlIndex+")");          if (getStateUid() == 1)            labelCurrentState("Auto Version after the first Upload");        }        RDBMS().executeUpdate(                              " INSERT INTO " + TRIPLES_HIST_TABLE + " SELECT " +                              " t.id, t.subject, t.predicate, t.object, "+RDBMS().TRUE+", "+                              getStateUid() + ", " + 0 +                              " from "+NEW_TRIPLES_TABLE+" t"                              );    } catch (SQLException e) {      e.printStackTrace();    }    super._processChangedTriples();  }  //>-- VersionManagement interface}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -