public String getPrefix() { String data = getStart().getData(); return data.substring(0, data.length() - 1); } }
/** * 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 RyaURI predicate = new RyaURI( pattern.getPredicateVar().getValue().toString() ); if(predicate.equals(TYPE_ID_URI)) { 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); } } }
@Override public RyaType newInstance() { return new RyaURI(); } }
entitiesCursor = entities.search(Optional.of(new RyaURI(subj)), type, properties); } else { entitiesCursor = entities.search(Optional.empty(), type, properties); final Optional<RyaType> prop = typedEntity.getPropertyValue(new RyaURI(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() + "."); } }
final RyaURI predicate = new RyaURI(pattern.getPredicateVar().getValue().toString()); if (predicate.equals(TYPE_ID_URI)) { final RyaURI statementID = new RyaURI(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;
@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; RyaURIRange that = (RyaURIRange) 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 URI createTypePropertiesUri(final ImmutableMap<RyaURI, ImmutableMap<RyaURI, Property>> typeProperties) throws SmartUriException { final List<NameValuePair> nameValuePairs = new ArrayList<>(); for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> typeProperty : typeProperties.entrySet()) { final RyaURI type = typeProperty.getKey(); final Map<RyaURI, Property> propertyMap = typeProperty.getValue(); final URI 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 new URIImpl(uriString); }
protected boolean check() throws RyaDAOException { if (!first.hasNext()) return false; first_subj = first.next().getSubject(); for (CloseableIteration<RyaStatement, RyaDAOException> iter : iters) { if (!iter.hasNext()) return false; //no more left to join RyaURI iter_subj = iter.next().getSubject(); while (first_subj.compareTo(iter_subj) < 0) { if (!first.hasNext()) return false; first_subj = first.next().getSubject(); } while (first_subj.compareTo(iter_subj) > 0) { if (!iter.hasNext()) return false; iter_subj = iter.next().getSubject(); } } return true; } };
private static Set<RyaURI> getPropURIFromStrings(final String... props) { final Set<RyaURI> properties = new HashSet<>(); if (props != null) { for(final String prop : props) { if (StringUtils.isNotBlank(prop)) { properties.add(new RyaURI(prop)); } } } return properties; }
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 RyaURI predicate = new RyaURI(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;
public void setStatementMetadataProperties(final Set<RyaURI> metadataProperties) { final String[] propArray = new String[metadataProperties.size()]; int i = 0; for(final RyaURI uri: metadataProperties) { propArray[i] = uri.getData(); i++; } setStrings(CONF_STATEMENT_METADATA_PROPERTIES, propArray); }
/** * 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 RyaURI predicate = new RyaURI(pattern.getPredicateVar().getValue().toString()); if(predicate.equals(TYPE_ID_URI)) { final RyaURI typeId = new RyaURI( 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."); } }
static void setUpRya() throws AccumuloException, AccumuloSecurityException, RyaDAOException { MockInstance mock = new MockInstance(INSTANCE_NAME); Connector conn = mock.getConnector(USERNAME, new PasswordToken(USERP)); AccumuloRyaDAO dao = new AccumuloRyaDAO(); dao.setConnector(conn); AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); conf.setTablePrefix(PREFIX); dao.setConf(conf); dao.init(); String ns = "http://example.com/"; dao.add(new RyaStatement(new RyaURI(ns+"s1"), new RyaURI(ns+"p1"), new RyaURI(ns+"o1"))); dao.add(new RyaStatement(new RyaURI(ns+"s1"), new RyaURI(ns+"p2"), new RyaURI(ns+"o2"))); dao.add(new RyaStatement(new RyaURI(ns+"s2"), new RyaURI(ns+"p1"), new RyaURI(ns+"o3"), new RyaURI(ns+"g1"))); dao.add(new RyaStatement(new RyaURI(ns+"s3"), new RyaURI(ns+"p3"), new RyaURI(ns+"o3"), new RyaURI(ns+"g2"))); dao.destroy(); }
updated.setVersion(oldEntity.getVersion() + 1); if(TYPE_URI.equals(statement.getPredicate())) { final RyaURI typeId = new RyaURI( statement.getObject().getData() ); if(!oldEntity.getExplicitTypeIds().contains(typeId)) { return Optional.empty(); for(final RyaURI typeId : oldEntity.getProperties().keySet()) { for(final RyaURI propertyName : oldEntity.getProperties().get(typeId).keySet()) { if(deletedPropertyName.equals(propertyName)) { propertyWasPresent = true; updated.unsetProperty(typeId, deletedPropertyName);
/** * Converts a {@link RyaURI} to the contained data string. * @param namespace the namespace. * @param the {@link RyaURI} to convert. * @return the data value without the namespace. */ public static String convertRyaUriToString(final String namespace, final RyaURI ryaUri) { return StringUtils.replaceOnce(ryaUri.getData(), namespace, ""); }