Java Code Examples for com.bigdata.rdf.store.AbstractTripleStore#commit()

The following examples show how to use com.bigdata.rdf.store.AbstractTripleStore#commit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMultiInlineURIHandlersSingleNamespace.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void test_TestVocabularyInlineValues() {

		final Properties properties = getProperties();

		AbstractTripleStore store = getStore(properties);

		try {

			final BigdataValueFactory vf = store.getValueFactory();

			final StatementBuffer<BigdataStatement> sb = new StatementBuffer<BigdataStatement>(
					store, 4 /* capacity */);

			BigdataURI pred = vf
					.createURI("http://blazegraph.com/Position#hasMarketValue");
			BigdataValue obj = vf.createLiteral("100.00");

			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E
			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_TaxCost
			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_UnrealizedGain
			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_WashSale

			final BigdataURI[] uris = new BigdataURI[] {
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_TaxCost"),
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_UnrealizedGain"),
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E"),
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_WashSale") };

			final String[] localNames = new String[] {
					"Position_010072F0000038090100000000D56C9E_TaxCost",
					"Position_010072F0000038090100000000D56C9E_UnrealizedGain",
					"Position_010072F0000038090100000000D56C9E",
					"Position_010072F0000038090100000000D56C9E_WashSale" };


			for (int i = 0; i < uris.length; i++) {
				sb.add(uris[i], pred, obj);
			}

			sb.flush();
			store.commit();

			if (log.isDebugEnabled())
				log.debug(store.dumpStore());

			for (int i = 0; i < uris.length; i++) {

				final BigdataURI uri = uris[i];

				if (log.isDebugEnabled()) {
					log.debug("Checking " + uri.getNamespace() + " "
							+ uri.getLocalName() + " inline: "
							+ uri.getIV().isInline());
					log.debug(localNames[i] + " : " + uri.getLocalName());
				}

				//Check it is inlined
				assertTrue(uri.getIV().isInline());

				//Check the local names are correct
				assertTrue(localNames[i].equals(uri.getLocalName()));
			}

		} finally {
			store.__tearDownUnitTest();
		}

	}
 
Example 2
Source File: TestAddTerms.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Unit test for addTerms() when the {@link BigdataValue}[] contains
 * distinct instances of {@link BigdataValue}s which are equals().
 */
public void test_duplicates_distinct_references() {

    final Properties properties = getProperties();
    
    // test w/o predefined vocab.
    properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
            .getName());

    // test w/o axioms - they imply a predefined vocab.
    properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
    
    // test w/o the full text index.
    properties.setProperty(Options.TEXT_INDEX, "false");

    // test w/o xsd inlining
    properties.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false");

    AbstractTripleStore store = getStore(properties);
    
    try {

        // Note: List allows duplicates!
        final Collection<BigdataValue> terms = new LinkedList<BigdataValue>();

        // lookup/add some values.
        final BigdataValueFactory f = store.getValueFactory();

        // Add two distinct instances of the same Value.
        terms.add(f.asValue(RDF.TYPE));
        terms.add(f.asValue(RDF.TYPE));
        assertEquals(2,terms.size());
        
        // Add two distinct instances of the same Value.
        terms.add(f.createURI(getVeryLargeURI()));
        terms.add(f.createURI(getVeryLargeURI()));
        assertEquals(4,terms.size());

        // Add two distinct instances of the same Value.
        terms.add(f.createLiteral("test"));
        terms.add(f.createLiteral("test"));
        terms.add(f.createLiteral("test","en"));
        terms.add(f.createLiteral("test","en"));
        terms.add(f.createLiteral(getVeryLargeLiteral()));
        terms.add(f.createLiteral(getVeryLargeLiteral()));
        assertEquals(10,terms.size());

        if (store.getLexiconRelation().isStoreBlankNodes()) {

            /*
             * Note: Blank nodes will not round trip through the lexicon unless
             * the "told bnodes" is enabled.
             */

            // Add two distinct instances of the same Value.
            terms.add(f.createBNode());
            terms.add(f.createBNode());
            terms.add(f.createBNode("a"));
            terms.add(f.createBNode("a"));
            terms.add(f.createBNode(getVeryLargeLiteral()));
            terms.add(f.createBNode(getVeryLargeLiteral()));
            assertEquals(16,terms.size());

        }

        final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

        if (store.isStable()) {

            store.commit();

            store = reopenStore(store);

            // verify same reverse mappings.

            final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                    .getTerms(ids.keySet());

            assertEquals(ids.size(), ids2.size());

            for (Map.Entry<IV<?,?>, BigdataValue> e : ids2.entrySet()) {

                final IV<?,?> id = e.getKey();
                
                assertEquals("Id mapped to a different term? : termId="
                        + id, ids.get(id), ids2.get(id));

            }

        }

    } finally {
        
        store.__tearDownUnitTest();
        
    }

}
 
Example 3
Source File: AbstractRIOTestCase.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Test loads an RDF/XML resource into a database and then verifies by
 * re-parse that all expected statements were made persistent in the
 * database.
 * 
 * @param resource
 * 
 * @throws Exception
 */
protected void doLoadAndVerifyTest(final String resource,
        final boolean parallel) throws Exception {

    AbstractTripleStore store = getStore();

    try {

        doLoad(store, resource, parallel);

        store.commit();

        if (store.isStable()) {

            store = reopenStore(store);

        }

        doVerify(store, resource, parallel);

    } finally {

        store.__tearDownUnitTest();

    }

}
 
Example 4
Source File: TestInlining.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
     * Unsigned numerics should not be inlined at this time.
     */
    public void test_unsigned() {

        final Properties properties = getProperties();
        
        // test w/o predefined vocab.
        properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
                .getName());

        // test w/o axioms - they imply a predefined vocab.
        properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
        
        // test w/o the full text index.
        properties.setProperty(Options.TEXT_INDEX, "false");

        AbstractTripleStore store = getStore(properties);
        
        try {

            final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

            // lookup/add some values, ensure range is beyond max signed values.
            final BigdataValueFactory f = store.getValueFactory();
            
            terms.add(f.createLiteral("135", f
                    .createURI(XSD.UNSIGNED_BYTE.toString())));

            terms.add(f.createLiteral(""+ (10L + Integer.MAX_VALUE), f
                    .createURI(XSD.UNSIGNED_INT.toString())));

            terms.add(f.createLiteral("" + (Short.MAX_VALUE + 10), f
                    .createURI(XSD.UNSIGNED_SHORT.toString())));

            terms.add(f.createLiteral(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(10)).toString(), f
                    .createURI(XSD.UNSIGNED_LONG.toString())));

            /*
             * Note: Blank nodes will not round trip through the lexicon unless
             * the "told bnodes" is enabled.
             */
//            terms.add(f.createBNode());
//            terms.add(f.createBNode("a"));

            final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

            if (store.isStable()) {
                
                store.commit();
                
                store = reopenStore(store);

                // verify same reverse mappings.

                final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                        .getTerms(ids.keySet());

                assertEquals(ids.size(),ids2.size());
                
                for (Map.Entry<IV<?, ?>, BigdataValue> e : ids.entrySet()) {

                    final IV<?, ?> id = e.getKey();

                    // Should be inlined
                    assertTrue(store.isInlineLiterals() == id.isInline());
                    
                    assertEquals("Id mapped to a different term? : termId="
                            + id, ids.get(id), ids2.get(id));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }
 
Example 5
Source File: TestInlining.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
     * Unsigned numerics should not be inlined at this time.
     */
    public void test_badrangeUnsigned() {

        final Properties properties = getProperties();
        
        // test w/o predefined vocab.
        properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
                .getName());

        // test w/o axioms - they imply a predefined vocab.
        properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
        
        // test w/o the full text index.
        properties.setProperty(Options.TEXT_INDEX, "false");

        AbstractTripleStore store = getStore(properties);
        
        try {

            final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

            // lookup/add some values, ensure range is beyond max signed values.
            final BigdataValueFactory f = store.getValueFactory();
            
            // Out of range values cannot be inlined
            terms.add(f.createLiteral("-12", f
                    .createURI(XSD.UNSIGNED_BYTE.toString())));

            terms.add(f.createLiteral("1024", f
                    .createURI(XSD.UNSIGNED_BYTE.toString())));

            terms.add(f.createLiteral("" + Integer.MAX_VALUE, f
                    .createURI(XSD.UNSIGNED_SHORT.toString())));

           terms.add(f.createLiteral(""+ Long.MAX_VALUE, f
                    .createURI(XSD.UNSIGNED_INT.toString())));

            terms.add(f.createLiteral(BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(10)).toString(), f
                    .createURI(XSD.UNSIGNED_LONG.toString())));

            /*
             * Note: Blank nodes will not round trip through the lexicon unless
             * the "told bnodes" is enabled.
             */
//            terms.add(f.createBNode());
//            terms.add(f.createBNode("a"));

            final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

            if (store.isStable()) {
                
                store.commit();
                
                store = reopenStore(store);

                // verify same reverse mappings.

                final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                        .getTerms(ids.keySet());

                assertEquals(ids.size(),ids2.size());
                
                for (Map.Entry<IV<?, ?>, BigdataValue> e : ids.entrySet()) {

                    final IV<?, ?> id = e.getKey();

                    // Should be inlined
                    assertFalse(id.isInline());
                    
                    assertEquals("Id mapped to a different term? : termId="
                            + id, ids.get(id), ids2.get(id));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }
 
Example 6
Source File: TestInlining.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public void test_epoch() {

        final Properties properties = getProperties();
        
        // test w/o predefined vocab.
        properties.setProperty(Options.VOCABULARY_CLASS, MyVocabulary.class
                .getName());

        // test w/o axioms - they imply a predefined vocab.
        properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
        
        // test w/o the full text index.
        properties.setProperty(Options.TEXT_INDEX, "false");

        // do not inline unicode data.
        properties.setProperty(Options.MAX_INLINE_TEXT_LENGTH, "0");

        // test with the sample extension factory
        properties.setProperty(Options.EXTENSION_FACTORY_CLASS, 
                SampleExtensionFactory.class.getName());

        AbstractTripleStore store = getStore(properties);
        
        try {

            if (!store.isStable()) {

                /*
                 * We need a restart safe store to test this since otherwise a
                 * term cache could give us a false positive.
                 */

                return;
                
            }

            final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

            // lookup/add some values.
            final BigdataValueFactory f = store.getValueFactory();

            final BigdataLiteral l1 = f.createLiteral("1", EpochExtension.EPOCH);
            final BigdataLiteral l2 = f.createLiteral(String.valueOf(System.currentTimeMillis()), EpochExtension.EPOCH);
//            final BigdataLiteral l3 = f.createLiteral("-100", EpochExtension.EPOCH);
            final BigdataURI datatype = f.createURI(EpochExtension.EPOCH.stringValue());

            terms.add(l1);
            terms.add(l2);
//            terms.add(l3);
            terms.add(datatype);

            final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

            assertTrue(l1.getIV().isInline());
            assertTrue(l2.getIV().isInline());
//            assertFalse(l3.getIV().isInline());
            
            final LiteralExtensionIV iv1 = (LiteralExtensionIV) l1.getIV();
            final LiteralExtensionIV iv2 = (LiteralExtensionIV) l2.getIV();
            
			assertEquals(iv1.getExtensionIV(), datatype.getIV());
			assertEquals(iv2.getExtensionIV(), datatype.getIV());

            if (store.isStable()) {
                
                store.commit();
                
                store = reopenStore(store);

                // verify same reverse mappings.

                final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                        .getTerms(ids.keySet());

                assertEquals(ids.size(),ids2.size());
                
                for (Map.Entry<IV<?, ?>, BigdataValue> e : ids.entrySet()) {

                    final IV<?, ?> iv = e.getKey();

                    if(log.isInfoEnabled()) log.info(iv);
                    
                    assertEquals("Id mapped to a different term? : iv="
                            + iv, ids.get(iv), ids2.get(iv));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }
 
Example 7
Source File: TestAddTerms.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public void test_addTerms() {

        final Properties properties = getProperties();
        
        // test w/o predefined vocab.
        properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
                .getName());

        // test w/o axioms - they imply a predefined vocab.
        properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
        
        // test w/o the full text index.
        properties.setProperty(Options.TEXT_INDEX, "false");

        // test w/o inlining
        properties.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false");

        AbstractTripleStore store = getStore(properties);
        
        try {

            final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

            // lookup/add some values.
            final BigdataValueFactory f = store.getValueFactory();

            terms.add(f.asValue(RDF.TYPE));
            terms.add(f.asValue(RDF.PROPERTY));
            terms.add(f.createURI(getVeryLargeURI()));
            
            terms.add(f.createLiteral("test"));
            terms.add(f.createLiteral("test", "en"));
            terms.add(f.createLiteral(getVeryLargeLiteral()));

            terms.add(f.createLiteral("10", f
                    .createURI("http://www.w3.org/2001/XMLSchema#int")));

            terms.add(f.createLiteral("12", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

            terms.add(f.createLiteral("12.", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

            terms.add(f.createLiteral("12.0", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

            terms.add(f.createLiteral("12.00", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

			if (store.getLexiconRelation().isStoreBlankNodes()) {
	            /*
	             * Note: Blank nodes will not round trip through the lexicon unless
	             * the "told bnodes" is enabled.
	             */
				terms.add(f.createBNode());
				terms.add(f.createBNode("a"));
	            terms.add(f.createBNode(getVeryLargeLiteral()));

			}

			final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

			if (store.isStable()) {

				store.commit();

				store = reopenStore(store);

				// verify same reverse mappings.

                final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                        .getTerms(ids.keySet());

                assertEquals(ids.size(), ids2.size());

                for (Map.Entry<IV<?,?>, BigdataValue> e : ids2.entrySet()) {

                    final IV<?,?> id = e.getKey();
                    
                    assertEquals("Id mapped to a different term? : termId="
                            + id, ids.get(id), ids2.get(id));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }
 
Example 8
Source File: TestAddTerms.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * The "told bnodes" mode uses the blank node ID as specified rather than
 * assigning one based on a UUID. For this case, we need to store the blank
 * nodes in the reverse index (T2ID) so we can translate a blank node back
 * to a specific identifier.
 */
public void test_toldBNodes() {

    final Properties properties = getProperties();
    
    // test w/o predefined vocab.
    properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
            .getName());

    // test w/o axioms - they imply a predefined vocab.
    properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
    
    // test w/o the full text index.
    properties.setProperty(Options.TEXT_INDEX, "false");

    // this is the "told bnodes" mode.
    properties.setProperty(Options.STORE_BLANK_NODES, "true");

    AbstractTripleStore store = getStore(properties);
    
    try {

        if (!store.isStable()) {

            /*
             * We need a restart safe store to test this since otherwise a
             * term cache could give us a false positive.
             */

            return;
            
        }

        final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

        // lookup/add some values.
        final BigdataValueFactory f = store.getValueFactory();

        terms.add(f.createBNode());
        terms.add(f.createBNode("a"));

        final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

        if (store.isStable()) {
            
            store.commit();
            
            store = reopenStore(store);

            // verify same reverse mappings.

            final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                    .getTerms(ids.keySet());

            assertEquals(ids.size(),ids2.size());
            
            for (Map.Entry<IV<?, ?>, BigdataValue> e : ids.entrySet()) {

                final IV<?, ?> id = e.getKey();

                assertEquals("Id mapped to a different term? : termId="
                        + id, ids.get(id), ids2.get(id));

            }

        }

    } finally {
        
        store.__tearDownUnitTest();
        
    }

}