public void setStatementMetadataProperties(final Set<RyaIRI> metadataProperties) { final String[] propArray = new String[metadataProperties.size()]; int i = 0; for(final RyaIRI uri: metadataProperties) { propArray[i] = uri.getData(); i++; } setStrings(CONF_STATEMENT_METADATA_PROPERTIES, propArray); }
@Override public RyaType newInstance() { return new RyaIRI(); } }
/** * Verify all of the patterns have predicates that match one of the Type's property names. * * @param type - The Type the patterns match. (not null) * @param patterns - The patterns to check. * @throws IllegalStateException If any of the non-type defining Statement Patterns * contain a predicate that does not match one of the Type's property names. */ private static void verifyAllPredicatesPartOfType(final Type type, final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(type); requireNonNull(patterns); for(final StatementPattern pattern : patterns) { // Skip TYPE patterns. final RyaIRI predicate = new RyaIRI( pattern.getPredicateVar().getValue().toString() ); if(predicate.equals(TYPE_ID_IRI)) { continue; } if(!type.getPropertyNames().contains(predicate)) { throw new IllegalStateException("The Predicate of a Statement Pattern must be a property name for the Type. " + "Type ID: '" + type.getId().getData() + "' Pattern: " + pattern); } } }
final RyaIRI predicate = new RyaIRI(pattern.getPredicateVar().getValue().toString()); if (predicate.equals(TYPE_ID_URI)) { final RyaIRI statementID = new RyaIRI(pattern.getObjectVar().getValue().stringValue()); if (statementID.equals(STATEMENT_ID_URI)) { statementFound = true; } else { if (predicate.equals(SUBJ_ID_URI)) { if (!subjFound) { subjFound = true; if (predicate.equals(PRED_ID_URI)) { if (!predFound) { predFound = true; if (predicate.equals(OBJ_ID_URI)) { if (!objFound) { objFound = true;
entitiesCursor = entities.search(Optional.of(new RyaIRI(subj)), type, properties); } else { entitiesCursor = entities.search(Optional.empty(), type, properties); final Optional<RyaType> prop = typedEntity.getPropertyValue(new RyaIRI(key.getData())); if(prop.isPresent()) { final RyaType type = prop.get();
@Override public void update(final Entity old, final Entity updated) throws StaleUpdateException, EntityStorageException { requireNonNull(old); requireNonNull(updated); // The updated entity must have the same Subject as the one it is replacing. if(!old.getSubject().equals(updated.getSubject())) { throw new EntityStorageException("The old Entity and the updated Entity must have the same Subject. " + "Old Subject: " + old.getSubject().getData() + ", Updated Subject: " + updated.getSubject().getData()); } // Make sure the updated Entity has a higher verison. if(old.getVersion() >= updated.getVersion()) { throw new EntityStorageException("The old Entity's version must be less than the updated Entity's version." + " Old version: " + old.getVersion() + " Updated version: " + updated.getVersion()); } final Set<Bson> filters = new HashSet<>(); // Must match the old entity's Subject. filters.add( makeSubjectFilter(old.getSubject()) ); // Must match the old entity's Version. filters.add( makeVersionFilter(old.getVersion()) ); // Do a find and replace. final Bson oldEntityFilter = Filters.and(filters); final Document updatedDoc = ENTITY_CONVERTER.toDocument(updated); final MongoCollection<Document> collection = mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME); if(collection.findOneAndReplace(oldEntityFilter, updatedDoc) == null) { throw new StaleUpdateException("Could not update the Entity with Subject '" + updated.getSubject().getData() + "."); } }
@Override public Tuple getNext() throws IOException { try { if (reader.nextKeyValue()) { Key key = reader.getCurrentKey(); org.apache.accumulo.core.data.Value value = reader.getCurrentValue(); ByteArrayDataInput input = ByteStreams.newDataInput(key.getRow().getBytes()); RyaStatement ryaStatement = ryaContext.deserializeTriple(layout, new TripleRow(key.getRow().getBytes(), key.getColumnFamily().getBytes(), key.getColumnQualifier().getBytes())); Tuple tuple = TupleFactory.getInstance().newTuple(7); tuple.set(0, ryaStatement.getSubject().getData()); tuple.set(1, ryaStatement.getPredicate().getData()); tuple.set(2, ryaStatement.getObject().getData()); tuple.set(3, (ryaStatement.getContext() != null) ? (ryaStatement.getContext().getData()) : (null)); tuple.set(4, ryaStatement.getSubject().getDataType()); tuple.set(5, ryaStatement.getPredicate().getDataType()); tuple.set(6, ryaStatement.getObject().getDataType()); return tuple; } } catch (Exception e) { throw new IOException(e); } return null; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; RyaIRIRange that = (RyaIRIRange) o; if (start != null ? !start.equals(that.start) : that.start != null) return false; if (stop != null ? !stop.equals(that.stop) : that.stop != null) return false; return true; }
private static IRI createTypePropertiesUri(final ImmutableMap<RyaIRI, ImmutableMap<RyaIRI, Property>> typeProperties) throws SmartUriException { final List<NameValuePair> nameValuePairs = new ArrayList<>(); for (final Entry<RyaIRI, ImmutableMap<RyaIRI, Property>> typeProperty : typeProperties.entrySet()) { final RyaIRI type = typeProperty.getKey(); final Map<RyaIRI, Property> propertyMap = typeProperty.getValue(); final IRI typeUri = createIndividualTypeWithPropertiesUri(type, propertyMap); final String keyString = type.getDataType().getLocalName(); final String valueString = typeUri.getLocalName(); nameValuePairs.add(new BasicNameValuePair(keyString, valueString)); } final URIBuilder uriBuilder = new URIBuilder(); uriBuilder.addParameters(nameValuePairs); String uriString; try { final java.net.URI uri = uriBuilder.build(); final String queryString = uri.getRawSchemeSpecificPart(); uriString = "urn:test" + queryString; } catch (final URISyntaxException e) { throw new SmartUriException("Unable to create type properties for the Smart URI", e); } return VF.createIRI(uriString); }
columnFamily = context; columnFamilySet = true; } else if (columnFamily != null && !columnFamily.equals(context)) { columnFamily = null; byte[] contextBytes = context.getData().getBytes("UTF-8"); rangeMapRange = range.bound(new Column(contextBytes, new byte[] { (byte) 0x00 }, new byte[] { (byte) 0x00 }), new Column(contextBytes, new byte[] { (byte) 0xff }, new byte[] { (byte) 0xff }));
final RyaIRI predicate = new RyaIRI(pattern.getPredicateVar().getValue().toString()); if (predicate.equals(SUBJ_ID_URI)) { sp.setContextVar(pattern.getContextVar()); sp.setSubjectVar(pattern.getObjectVar()); if (predicate.equals(PRED_ID_URI)) { sp.setPredicateVar(pattern.getObjectVar()); if (predicate.equals(OBJ_ID_URI)) { sp.setObjectVar(pattern.getObjectVar());
return false; if (context != null ? !context.equals(that.context) : that.context != null) { return false; return false; if (predicate != null ? !predicate.equals(that.predicate) : that.predicate != null) { return false; return false; if (subject != null ? !subject.equals(that.subject) : that.subject != null) { return false;
/** * Converts a {@link RyaIRI} to the contained data string. * @param namespace the namespace. * @param ryaIri the {@link RyaIRI} to convert. * @return the data value without the namespace. */ public static String convertRyaIriToString(final String namespace, final RyaIRI ryaIri) { return StringUtils.replaceOnce(ryaIri.getData(), namespace, ""); }
private static Set<RyaIRI> getPropURIFromStrings(final String... props) { final Set<RyaIRI> properties = new HashSet<>(); if (props != null) { for(final String prop : props) { if (StringUtils.isNotBlank(prop)) { properties.add(new RyaIRI(prop)); } } } return properties; }
public void testRegex() throws Exception { RyaIRI subj = new RyaIRI("urn:test#1234"); RyaIRI pred = new RyaIRI("urn:test#pred"); RyaIRI obj = new RyaIRI("urn:test#obj"); RyaStatement ryaStatement = new RyaStatement(subj, pred, obj); Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = new WholeRowHashedTripleResolver().serialize(ryaStatement); TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, pred.getData(), null, null, null); Pattern p = Pattern.compile(tripleRowRegex.getRow()); Matcher matcher = p.matcher(row); assertTrue(matcher.matches()); tripleRowRegex = spoStrategy.buildRegex(subj.getData(), null, null, null, null); p = Pattern.compile(tripleRowRegex.getRow()); matcher = p.matcher(row); assertTrue(matcher.matches()); tripleRowRegex = spoStrategy.buildRegex(null, null, obj.getData(), null, null); p = Pattern.compile(tripleRowRegex.getRow()); matcher = p.matcher(row); tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), null, null, null); p = Pattern.compile(tripleRowRegex.getRow()); matcher = p.matcher(row); assertTrue(matcher.matches()); tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), obj.getData(), null, null); p = Pattern.compile(tripleRowRegex.getRow()); matcher = p.matcher(row); assertTrue(matcher.matches());
/** * Verifies a single Statement Pattern defines the Type of Entity this query node matches. * * @param type - The expected Type. (not null) * @param patterns - The patterns to check. (not null) * @throws IllegalStateException No Type or the wrong Type is specified by the patterns. */ private static void verifyHasCorrectTypePattern(final Type type, final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(type); requireNonNull(patterns); boolean typeFound = false; for(final StatementPattern pattern : patterns) { final RyaIRI predicate = new RyaIRI(pattern.getPredicateVar().getValue().toString()); if(predicate.equals(TYPE_ID_IRI)) { final RyaIRI typeId = new RyaIRI( pattern.getObjectVar().getValue().stringValue() ); if(typeId.equals(type.getId())) { typeFound = true; } else { throw new IllegalStateException("Statement Pattern encountred for a Type that does not match the expected Type." + " Expected Type = '" + type.getId().getData() + "' Found Type = '" + typeId.getData() + "'"); } } } if(!typeFound) { throw new IllegalStateException("The collection of Statement Patterns that this node matches must define which Type they match."); } }
updated.setVersion(oldEntity.getVersion() + 1); if(TYPE_IRI.equals(statement.getPredicate())) { final RyaIRI typeId = new RyaIRI( statement.getObject().getData() ); if(!oldEntity.getExplicitTypeIds().contains(typeId)) { return Optional.empty(); for(final RyaIRI typeId : oldEntity.getProperties().keySet()) { for(final RyaIRI propertyName : oldEntity.getProperties().get(typeId).keySet()) { if(deletedPropertyName.equals(propertyName)) { propertyWasPresent = true; updated.unsetProperty(typeId, deletedPropertyName);
assertTrue(!subject.equals(subject2));
public String getPrefix() { String data = getStart().getData(); return data.substring(0, data.length() - 1); } }