@Override protected ValueFactory getValueFactory() { return yard.getValueFactory(); } @Override
@Override public ValueFactory getValueFactory() { return yard.getValueFactory(); }
@Override public ValueFactory getValueFactory() { return yard.getValueFactory(); }
protected Representation create(String id, boolean store) throws YardException { Representation r; if (store) { r = getYard().create(id); } else if (id != null && !id.isEmpty()) { r = getYard().getValueFactory().createRepresentation(id); } else { throw new IllegalArgumentException("If store is FALSE the id MUST NOT be NULL nor EMPTY!"); } representationIds.add(r.getId()); return r; }
@Test public void testGetValueFactory() { assertNotNull("The ValueFactory MUST NOT be NULL", getYard().getValueFactory()); }
/** * Applies the mappings defined by the {@link #baseMapper} and the {@link #additionalMapper} * to the parsed Representation. * * @param yard The yard (local reference to avoid syncronization) * @param representation The representation to map * @return the mapped representation */ private Representation applyCacheMappings(Yard yard, Representation representation) { long start = System.currentTimeMillis(); Representation mapped = null; ValueFactory valueFactory = getValueFactory(); if (baseMapper != null) { mapped = yard.getValueFactory().createRepresentation(representation.getId()); baseMapper.applyMappings(representation, mapped,valueFactory); } if (additionalMapper != null) { if (mapped == null) { mapped = yard.getValueFactory().createRepresentation(representation.getId()); } additionalMapper.applyMappings(representation, mapped,valueFactory); } log.info(" -- applied mappings in " + (System.currentTimeMillis() - start) + "ms"); return mapped != null ? mapped : representation; }
/** * Applies the mappings defined by the {@link #baseMapper} and the {@link #additionalMapper} * to the parsed Representation. * * @param yard The yard (local reference to avoid syncronization) * @param representation The representation to map * @return the mapped representation */ private Representation applyCacheMappings(Yard yard, Representation representation) { long start = System.currentTimeMillis(); Representation mapped = null; ValueFactory valueFactory = getValueFactory(); if (baseMapper != null) { mapped = yard.getValueFactory().createRepresentation(representation.getId()); baseMapper.applyMappings(representation, mapped,valueFactory); } if (additionalMapper != null) { if (mapped == null) { mapped = yard.getValueFactory().createRepresentation(representation.getId()); } additionalMapper.applyMappings(representation, mapped,valueFactory); } log.info(" -- applied mappings in " + (System.currentTimeMillis() - start) + "ms"); return mapped != null ? mapped : representation; }
@Override public void initialise() { //override the ldpath instance used for the initialisation with //the one using the IndexingDestination //this is OK, because parsing ldpath programs anyway does only need //the "value factory" role of the RDFBackend and does not actually //access any data. Yard yard = indexingConfig.getIndexingDestination().getYard(); YardBackend backend = new YardBackend(yard); this.ldPath = new EntityhubLDPath(backend,yard.getValueFactory()); }
@Override public void initialise() { //override the ldpath instance used for the initialisation with //the one using the IndexingDestination //this is OK, because parsing ldpath programs anyway does only need //the "value factory" role of the RDFBackend and does not actually //access any data. Yard yard = indexingConfig.getIndexingDestination().getYard(); YardBackend backend = new YardBackend(yard); this.ldPath = new EntityhubLDPath(backend,yard.getValueFactory()); }
/** * Stores the baseMappings to the {@link Yard}. This may cause unexpected * behaviour for subsequest calls of the stored configuration does not * correspond with the actual data stored within the cache.<p> * Typically this is only used at the start or end of the creation of a * full Cache ({@link CacheStrategy#all}) of an referenced site (entity source).<p> * Note also that if the {@link #baseMapper} is <code>null</code> this * method removes any existing configuration from the yard. * @throws YardException an any error while storing the config to the yard. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ public static void storeBaseMappingsConfiguration(Yard yard,FieldMapper baseMapper) throws YardException,IllegalArgumentException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } if(baseMapper == null){ yard.remove(Cache.BASE_CONFIGURATION_URI); } else { Representation config = yard.getValueFactory().createRepresentation(Cache.BASE_CONFIGURATION_URI); writeFieldConfig(config,baseMapper); yard.store(config); } } /**
/** * Stores the current configuration used for caching documents back to the * {@link Yard}. This configuration is present in the {@link #additionalMapper}). * If this field is <code>null</code> than any existing configuration is * removed form the index. * @throws YardException on any error while changing the configuration in the * yard. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ protected static void storeAdditionalMappingsConfiguration(Yard yard,FieldMapper additionalMapper) throws YardException,IllegalArgumentException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } if(additionalMapper == null){ yard.remove(Cache.ADDITIONAL_CONFIGURATION_URI); } else { Representation config = yard.getValueFactory().createRepresentation(Cache.ADDITIONAL_CONFIGURATION_URI); writeFieldConfig(config,additionalMapper); yard.store(config); } } /**
/** * Stores the baseMappings to the {@link Yard}. This may cause unexpected * behaviour for subsequest calls of the stored configuration does not * correspond with the actual data stored within the cache.<p> * Typically this is only used at the start or end of the creation of a * full Cache ({@link CacheStrategy#all}) of an referenced site (entity source).<p> * Note also that if the {@link #baseMapper} is <code>null</code> this * method removes any existing configuration from the yard. * @throws YardException an any error while storing the config to the yard. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ public static void storeBaseMappingsConfiguration(Yard yard,FieldMapper baseMapper) throws YardException,IllegalArgumentException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } if(baseMapper == null){ yard.remove(Cache.BASE_CONFIGURATION_URI); } else { Representation config = yard.getValueFactory().createRepresentation(Cache.BASE_CONFIGURATION_URI); writeFieldConfig(config,baseMapper); yard.store(config); } } /**
/** * Stores the current configuration used for caching documents back to the * {@link Yard}. This configuration is present in the {@link #additionalMapper}). * If this field is <code>null</code> than any existing configuration is * removed form the index. * @throws YardException on any error while changing the configuration in the * yard. * @throws IllegalArgumentException if <code>null</code> is parsed as {@link Yard}. */ protected static void storeAdditionalMappingsConfiguration(Yard yard,FieldMapper additionalMapper) throws YardException,IllegalArgumentException { if(yard == null){ throw new IllegalArgumentException("The parsed Yard MUST NOT be NULL!"); } if(additionalMapper == null){ yard.remove(Cache.ADDITIONAL_CONFIGURATION_URI); } else { Representation config = yard.getValueFactory().createRepresentation(Cache.ADDITIONAL_CONFIGURATION_URI); writeFieldConfig(config,additionalMapper); yard.store(config); } } /**
try { Yard yard = getYard(); final ValueFactory vf = yard.getValueFactory(); yard.store(new Iterable<Representation>() { @Override
/** * Stores the parsed representation to the Yard and also applies the * configured {@link #getFieldMapper() FieldMappings}. * @param The representation to store */ @Override public void store(Representation representation) throws ManagedSiteException { try { Yard yard = getYard(); fieldMapper.applyMappings(representation, representation, yard.getValueFactory()); yard.store(representation); } catch (YardException e) { throw new ManagedSiteException(e.getMessage(), e); } } /**
return null; ValueFactory valueFactory = entityhubYard.getValueFactory();
return null; ValueFactory valueFactory = entityhubYard.getValueFactory();
/** * Tests that multiple Representations are removed. * * @throws YardException */ @Test public void testRemoveRepresentations() throws YardException { // NOTE: This test needs not to use the create(..) method, because we // remove the created representation form the store anyway as part of the // test String id = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id1"; String id2 = "urn:yard.test.testRemoveRepresentationsWithNullValue:representation.id2"; String field = "urn:the.field:used.for.this.Test"; String testValue = "This is a test"; Yard yard = getYard(); // use both ways to add the two Representations (should make no differences, // but one never can know ... Representation test1 = yard.create(id); // create and add Representation test2 = yard.getValueFactory().createRepresentation(id2); // create test2.add(field, testValue); // add value yard.store(test2);// store assertTrue(yard.isRepresentation(test1.getId())); // test if stored assertTrue(yard.isRepresentation(test2.getId())); yard.remove(Arrays.asList(test1.getId(), test2.getId())); // remove assertFalse(yard.isRepresentation(test1.getId())); // test if removed assertFalse(yard.isRepresentation(test2.getId())); } /**
String testValue = "This is a test"; Yard yard = getYard(); Representation test = yard.getValueFactory().createRepresentation(id); test.add(field, testValue);
Representation test2 = yard.getValueFactory().createRepresentation(id2); // create