@Override public URI apply(final Record record) { return record.getID(); }
@Override public void store(final URI type, final Record record) throws IOException, IllegalStateException { Preconditions.checkState(this.changes != null, "Read-only DataTransaction"); registerChange(type, record.getID(), record); }
@Override public void handle(final Record record) throws Throwable { if (record != null) { writer.write(record.getID().stringValue()); writer.write("\n"); } }
@Override public void store(final URI type, final Record record) throws IOException, IllegalStateException { Preconditions.checkState(!this.ended); Preconditions.checkState(!this.readOnly); Preconditions.checkArgument(record.getID() != null); final Map<URI, Record> table = this.getTable(type); table.put(record.getID(), Record.create(record, true)); }
@Override public void handle(final Record axiom) throws Throwable { if (axiom == null) { flush(true); } else { this.buffer.put(axiom.getID(), axiom); if (this.buffer.size() == BUFFER_SIZE) { flush(false); } } }
@Override public void store(URI type, Record record) throws IOException, IllegalStateException { writingOperations.get(type).incrementAndGet(); IndexWriter indexWriter = writers.get(type); String uri; try { uri = record.getID().toString(); } catch (NullPointerException e) { throw new IOException(e); } logger.debug(String.format("Inserting %s", uri)); Document doc = new Document(); doc.add(new Field(KEY_NAME, uri, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.add(new Field(VALUE_NAME, serializeRecord(record, serializer), Field.Store.YES)); // use "update" instead of "add" to avoid duplicates indexWriter.updateDocument(new Term(KEY_NAME, uri), doc); }
@Override public void store(URI type, Record record) throws IOException, IllegalStateException { // String tableName = getTableName(type); // String query = insertQuery.replace("$tableName", tableName); String uri; try { uri = record.getID().toString(); } catch (NullPointerException e) { throw new IOException(e); } logger.debug(String.format("Inserting %s", uri)); try { // PreparedStatement stmt = con.prepareStatement(query); // stmt.setString(1, uri); // stmt.setBytes(2, serializeRecord(record)); // stmt.executeUpdate(); insertBatchStatements.get(type).setString(1, uri); insertBatchStatements.get(type).setBytes(2, serializeRecord(record)); insertBatchStatements.get(type).addBatch(); } catch (SQLException e) { throw new IOException(e); } }
@Override public synchronized void init() throws IOException, IllegalStateException { Preconditions.checkState(!this.initialized && !this.closed); this.initialized = true; InputStream stream = null; try { if (this.fileSystem.exists(this.filePath)) { stream = Files.readWithBackup(this.fileSystem, this.filePath); final RDFFormat format = RDFFormat.forFileName(this.filePath.getName()); final List<Record> records = Record.decode( RDFUtil.readRDF(stream, format, null, null, false), ImmutableSet.of(KS.RESOURCE, KS.MENTION, KS.ENTITY, KS.CONTEXT), false) .toList(); for (final Record record : records) { final URI id = Preconditions.checkNotNull(record.getID()); final URI type = Preconditions.checkNotNull(record.getSystemType()); MemoryDataStore.this.tables.get(type).put(id, record); } MemoryDataStore.LOGGER.info("{} initialized, {} records loaded", this.getClass() .getSimpleName(), records.size()); } else { MemoryDataStore.LOGGER.info("{} initialized, no record loaded", this.getClass() .getSimpleName()); } } finally { Util.closeQuietly(stream); } }
@Override public void handle(final Record record) throws Throwable { if (record == null || this.records > 0 && this.records % 1000 == 0) { LOGGER.info(this.records + " records, " + this.triples + " triples processed"); } if (record != null) { final List<Statement> statements = Record.encode(Stream.create(record), ImmutableSet.of()).toList(); writer.handleComment(record.getID().toString()); for (final Statement statement : statements) { writer.handleStatement(statement); } ++this.records; this.triples += statements.size(); } }
@Override public void store(final URI type, final Record record) throws IOException, IllegalStateException { // Delete existing data for the record URI delete(type, record.getID()); // Add statements final List<Statement> statements = Record.encode(Stream.create(record), ImmutableList.of(type)).toList(); this.transaction.add(statements); }
private Map<URI, Record> extractRelated(final Record record) throws Throwable { // TODO: this has to be done better using some Schema object final URI id = record.getID(); final URI type = record.getSystemType(); final Map<URI, Record> map = Maps.newHashMap(); if (type.equals(KS.RESOURCE)) { for (final URI mentionID : record.get(KS.HAS_MENTION, URI.class)) { map.put(mentionID, Record.create(mentionID, KS.MENTION).add(KS.MENTION_OF, id)); } } else if (type.equals(KS.MENTION)) { final URI resourceID = record.getUnique(KS.MENTION_OF, URI.class); if (resourceID != null) { map.put(resourceID, Record.create(resourceID, KS.RESOURCE).add(KS.HAS_MENTION, id)); } } else { // TODO: handle entities, axioms and contexts throw new Error("Unexpected type: " + type); } return map; }
private Object encodeRecord(final Record record, @Nullable final Set<URI> propertiesToEncode) { final URI id = record.getID(); final Object encodedID = id == null ? null : encodeIdentifier(id); final List<Object> props = Lists.newArrayList(); for (final URI property : record.getProperties()) { if (propertiesToEncode == null || propertiesToEncode.contains(property)) { ensureInDictionary(property); final List<? extends Object> nodes = record.get(property); if (property.equals(RDF.TYPE)) { for (final Object value : nodes) { if (value instanceof URI) { ensureInDictionary((URI) value); } } } final GenericData.Record prop = new GenericData.Record(Schemas.PROPERTY); prop.put("propertyURI", encodeIdentifier(property)); prop.put("propertyValue", encodeNodes(nodes)); props.add(prop); } } return SerializerAvro.newGenericRecord(Schemas.RECORD, encodedID, props); }
} else { final Record record = (Record) input; ids.add(record.getID()); suppliedRecords.add(record);
transaction.delete(record.getSystemType(), record.getID());
final Representation representation = Representation.create(stream); final Record meta = representation.getMetadata(); meta.setID(metadata.getID()); meta.set(NIE.MIME_TYPE, transformToType); meta.set(NFO.FILE_NAME, name); representation.getMetadata().setID(metadata.getID()); for (final URI property : metadata.getProperties()) { representation.getMetadata().set(property, metadata.get(property));