AccumuloTemporalIndexer extends AbstractAccumuloIndexer implements TemporalIndexer { private void storeStatement(final Statement statement) throws IOException, IllegalArgumentException { Objects.requireNonNull(temporalIndexBatchWriter,"This is not initialized for writing. Must call setMultiTableBatchWriter() and init()."); final boolean isValidPredicate = validPredicates == null || validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate()); if (!isValidPredicate || !(statement.getObject() instanceof Literal)) { return; } final DateTime[] indexDateTimes = new DateTime[2]; extractDateTime(statement, indexDateTimes); if (indexDateTimes[0]==null) { return; } if (!this.isInit) throw new RuntimeException("Method .init() was not called (or failed) before attempting to store statements."); try { if (indexDateTimes[1] != null) { final TemporalInterval interval = new TemporalInterval(new TemporalInstantRfc3339(indexDateTimes[0]), new TemporalInstantRfc3339(indexDateTimes[1])); addInterval(temporalIndexBatchWriter, interval, statement); } else { final TemporalInstant instant = new TemporalInstantRfc3339(indexDateTimes[0]); addInstant(temporalIndexBatchWriter, instant, statement); } } catch (final MutationsRejectedException e) { throw new IOException("While adding interval/instant for statement =" + statement, e); } }  @Override void init(); @Override void setConf(final Configuration conf); @Override Configuration getConf(); @Override void storeStatement(final RyaStatement statement); void removeInterval(final BatchWriter writer, final TemporalInterval interval, final Statement statement); void removeInstant(final BatchWriter writer, final TemporalInstant instant, final Statement statement); void addInterval(final BatchWriter writer, final TemporalInterval interval, final Statement statement); void addInstant(final BatchWriter writer, final TemporalInstant instant, final Statement statement); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantEqualsInstant(
            final TemporalInstant queryInstant, final StatementConstraints constraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantBeforeInstant(
            final TemporalInstant queryInstant, final StatementConstraints constraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantAfterInstant(
            final TemporalInstant queryInstant, final StatementConstraints constraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantBeforeInterval(
            final TemporalInterval givenInterval, final StatementConstraints contraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantAfterInterval(
            final TemporalInterval givenInterval, final StatementConstraints contraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantInsideInterval(
            final TemporalInterval queryInterval, final StatementConstraints constraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantHasBeginningInterval(
            final TemporalInterval queryInterval, final StatementConstraints contraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryInstantHasEndInterval(
            final TemporalInterval queryInterval, final StatementConstraints contraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryIntervalEquals(
            final TemporalInterval query, final StatementConstraints contraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryIntervalBefore(
            final TemporalInterval queryInterval, final StatementConstraints constraints); @Override CloseableIteration<Statement, QueryEvaluationException> queryIntervalAfter(
            final TemporalInterval queryInterval, final StatementConstraints constraints); @Override Set<IRI> getIndexablePredicates(); @Override void flush(); @Override void close(); @Override String getTableName(); static String makeTableName(final String ryaInstanceName); @Override void deleteStatement(final RyaStatement statement); @Override void setConnector(final Connector connector); @Override void destroy(); @Override void purge(final RdfCloudTripleStoreConfiguration configuration); @Override void dropAndDestroy(); @Override void setMultiTableBatchWriter(MultiTableBatchWriter writer);  }
@Test public void testStoreStatement() throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException { int rowsStoredExpected = 0; ValueFactory vf = SimpleValueFactory.getInstance(); IRI pred1_atTime = vf.createIRI(URI_PROPERTY_AT_TIME); IRI pred2_circa = vf.createIRI(URI_PROPERTY_CIRCA); String validDateStringWithThirteens = "1313-12-13T13:13:13Z"; tIndexer.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj1"), RDFS.LABEL, vf.createLiteral(validDateStringWithThirteens)))); final String invalidDateString = "ThisIsAnInvalidDate"; tIndexer.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj2"), pred1_atTime, vf.createLiteral(invalidDateString)))); final String testDate2014InBRST = "2014-12-31T23:59:59-02:00"; final String testDate2016InET = "2016-12-31T20:59:59-05:00"; Statement s3 = vf.createStatement(vf.createIRI("foo:subj3"), pred1_atTime, vf.createLiteral(testDate2014InBRST)); Statement s4 = vf.createStatement(vf.createIRI("foo:subj4"), pred2_circa, vf.createLiteral(testDate2016InET)); tIndexer.storeStatement(convertStatement(s3)); rowsStoredExpected++; tIndexer.storeStatement(convertStatement(s4)); rowsStoredExpected++; tIndexer.storeStatement(convertStatement(vf.createStatement(vf.createIRI("foo:subj5"), pred1_atTime, vf.createIRI("in:valid")))); tIndexer.flush(); int rowsStoredActual = printTables("junit testing: Temporal entities stored in testStoreStatement", null, null); assertEquals("Number of rows stored.", rowsStoredExpected*4, rowsStoredActual); }
@Test public void testStoreStatementWithInterestingLiterals() throws Exception { ValueFactory vf = SimpleValueFactory.getInstance(); IRI pred1_atTime = vf.createIRI(URI_PROPERTY_AT_TIME); tIndexer.storeStatement(convertStatement(vf.createStatement( vf.createIRI("foo:subj2"), pred1_atTime, vf.createLiteral("A number of organizations located, gathered, or classed together. [Derived from Concise Oxford English Dictionary, 11th Edition, 2008]")))); int rowsStoredActual = printTables("junit testing: Temporal entities stored in testStoreStatement", null, null); Assert.assertEquals("Number of rows stored.", 0, rowsStoredActual); }
@Test public void testStoreStatementsSameTime() throws IOException, NoSuchAlgorithmException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException { ValueFactory vf = SimpleValueFactory.getInstance(); IRI pred1_atTime = vf.createIRI(URI_PROPERTY_AT_TIME); IRI pred2_circa = vf.createIRI(URI_PROPERTY_CIRCA); final String ZONETestDateInBRST = "2014-12-31T23:59:59-02:00"; final String ZONETestDateInZulu = "2015-01-01T01:59:59Z"; final String ZONETestDateInET = "2014-12-31T20:59:59-05:00"; Statement s1 = vf.createStatement(vf.createIRI("foo:subj1"), pred2_circa, vf.createLiteral(ZONETestDateInET)); Statement s2 = vf.createStatement(vf.createIRI("foo:subj2"), pred1_atTime, vf.createLiteral(ZONETestDateInZulu)); Statement s3 = vf.createStatement(vf.createIRI("foo:subj3"), pred1_atTime, vf.createLiteral(ZONETestDateInBRST)); int rowsStoredExpected = 0; tIndexer.storeStatement(convertStatement(s1)); rowsStoredExpected++; tIndexer.storeStatement(convertStatement(s2)); rowsStoredExpected++; tIndexer.storeStatement(convertStatement(s3)); rowsStoredExpected++; int rowsStoredActual = printTables("junit testing: Duplicate times stored", null , null); Assert.assertEquals("Number of Duplicate times stored, 1 means duplicates not handled correctly.", rowsStoredExpected*4, rowsStoredActual); }