public Revision getRevision ( final int articleID , final Timestamp time ) throws WikiApiException { try { PreparedStatement statement = null ; ResultSet result = null ; String fullRevisions ; String revisionCounters ; if ( articleID < 1 || time == null || time . getTime ( ) <= 0 ) { throw new IllegalArgumentException ( ) ; } int firstPK = - 1 , lastPK = - 1 ; try { statement = this . connection . prepareStatement ( "SELECT FullRevisionPKs, RevisionCounter," + " FirstAppearance " + "FROM index_articleID_rc_ts " + "WHERE ArticleID=? LIMIT 1" ) ; statement . setInt ( 1 , articleID ) ; result = statement . executeQuery ( ) ; if ( result . next ( ) ) { fullRevisions = result . getString ( 1 ) ; revisionCounters = result . getString ( 2 ) ; long firstDate = result . getLong ( 3 ) ; // Find first and last FullRevision PK int max = fullRevisions . length ( ) ; int index = fullRevisions . indexOf ( ' ' ) ; if ( index == - 1 ) { index = max ; } firstPK = Integer . parseInt ( fullRevisions . substring ( 0 , index ) ) ; index = revisionCounters . lastIndexOf ( ' ' ) + 1 ; lastPK = firstPK + Integer . parseInt ( revisionCounters . substring ( index , revisionCounters . length ( ) ) ) ; if ( time . getTime ( ) < firstDate ) { throw new WikiPageNotFoundException ( "No revision before the " + "specified date [" + time + "]" ) ; } } else { throw new WikiPageNotFoundException ( "The article with the ID " + articleID + " was not found." ) ; } } finally { if ( statement != null ) { statement . close ( ) ; } if ( result != null ) { result . close ( ) ; } } try { statement = this . connection . prepareStatement ( "SELECT RevisionCounter FROM revisions WHERE PrimaryKey >= ? AND PrimaryKey < ? AND Timestamp <= ? ORDER BY Timestamp DESC LIMIT 1" ) ; statement . setInt ( 1 , firstPK ) ; statement . setInt ( 2 , lastPK ) ; statement . setLong ( 3 , time . getTime ( ) ) ; result = statement . executeQuery ( ) ; if ( result . next ( ) ) { int revisionCount = result . getInt ( 1 ) ; return getReferencedRevision ( articleID , revisionCount , fullRevisions , revisionCounters ) ; } else { throw new WikiPageNotFoundException ( "The revision with the specified timestamp was not found." ) ; } } finally { if ( statement != null ) { statement . close ( ) ; } if ( result != null ) { result . close ( ) ; } } } catch ( WikiPageNotFoundException e ) { throw e ; } catch ( Exception e ) { throw new WikiApiException ( e ) ; } }
Returns the by the article ID and timestamp specified revision . Note that the timestamp is not an unique identifier of a revision related to an article . The returned revision should be the first revision that can be found inside the database .