You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2017/10/03 19:34:07 UTC
[21/65] [abbrv] jena git commit: JENA-1397: Rename java packages
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTransactionLifecycle2.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTransactionLifecycle2.java b/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTransactionLifecycle2.java
deleted file mode 100644
index 72b732b..0000000
--- a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTransactionLifecycle2.java
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.transaction;
-
-import static org.junit.Assert.* ;
-
-import java.util.concurrent.atomic.AtomicReference ;
-
-import org.apache.jena.query.ReadWrite ;
-import org.junit.After ;
-import org.junit.Before ;
-import org.junit.Test ;
-import org.seaborne.dboe.base.file.Location ;
-import org.seaborne.dboe.migrate.L ;
-import org.seaborne.dboe.transaction.txn.Transaction ;
-import org.seaborne.dboe.transaction.txn.TransactionCoordinator ;
-import org.seaborne.dboe.transaction.txn.TransactionException ;
-import org.seaborne.dboe.transaction.txn.journal.Journal ;
-
-/**
- * Details tests of the transaction lifecycle in one JVM
- * including tests beyond the TransactionalComponentLifecycle
- *
- * Journal independent.
- */
-public class TestTransactionLifecycle2 {
- // org.junit.rules.ExternalResource ?
- protected TransactionCoordinator txnMgr ;
-// protected TransInteger counter1 = new TransInteger(0) ;
-// protected TransInteger counter2 = new TransInteger(0) ;
-// protected TransMonitor monitor = new TransMonitor() ;
-
- @Before public void setup() {
- Journal jrnl = Journal.create(Location.mem()) ;
- txnMgr = new TransactionCoordinator(jrnl) ;
- txnMgr.start() ;
- }
-
- @After public void clearup() {
- txnMgr.shutdown();
- }
-
- protected void checkClear() {
- assertEquals(0, txnMgr.countActive()) ;
- assertEquals(0, txnMgr.countBegin()-txnMgr.countFinished()) ;
- }
-
- @Test public void txn_direct_01() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- txn1.end();
- checkClear() ;
- }
-
- @Test(expected=TransactionException.class)
- public void txn_direct_02() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE) ;
- txn1.end();
- checkClear() ;
- }
-
- @Test
- public void txn_direct_03() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE) ;
- txn1.commit() ;
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_direct_04() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE) ;
- // This tests the TransactionCoordinator
- // but the TransactiolComponentLifecycle doesn't support multiple
- // transactions per thread (use of ThreadLocals).
- // To do that, the transaction object would be needed in all
- // component API calls. Doable but intrusive.
- Transaction txn2 = txnMgr.begin(ReadWrite.READ) ;
- txn1.commit() ;
- txn2.end() ;
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_direct_05() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE) ;
- txn1.prepare() ;
- txn1.commit() ;
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_direct_06() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE) ;
- // txn1.prepare() ; Optional.
- txn1.commit() ;
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_overlap_WW() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE, false) ;
- assertNotNull(txn1) ;
-
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE, false) ;
- assertNull(txn2) ; // Otherwise blocking.
-
- txn1.commit();
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_overlap_WR() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE, false) ;
- assertNotNull(txn1) ;
-
- Transaction txn2 = txnMgr.begin(ReadWrite.READ, false) ;
- assertNotNull(txn2) ;
-
- txn1.commit();
- txn1.end() ;
- txn2.end();
- checkClear() ;
- }
-
- @Test
- public void txn_overlap_RW() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ, false) ;
- assertNotNull(txn1) ;
-
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE, false) ;
- assertNotNull(txn2) ;
- txn1.commit();
- txn1.end() ;
- txn2.abort();
- txn2.end();
- checkClear() ;
- }
-
- @Test
- public void txn_overlap_RR() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ, false) ;
- assertNotNull(txn1) ;
-
- Transaction txn2 = txnMgr.begin(ReadWrite.READ, false) ;
- assertNotNull(txn2) ;
-
- txn1.commit();
- txn1.end() ;
- txn2.end();
- checkClear() ;
- }
-
- @Test
- public void txn_promote_1() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- assertNotNull(txn1) ;
- boolean b = txn1.promote() ;
- assertTrue(b) ;
- assertEquals(ReadWrite.WRITE, txn1.getMode()) ;
- txn1.commit() ;
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_promote_2() {
- Transaction txn1 = txnMgr.begin(ReadWrite.WRITE) ;
- boolean b = txn1.promote() ;
- assertTrue(b) ;
- b = txn1.promote() ;
- assertTrue(b) ;
- txn1.abort() ;
- txn1.end() ;
- checkClear() ;
- }
-
- @Test(expected=TransactionException.class)
- public void txn_promote_3() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- boolean b = txn1.promote() ;
- assertTrue(b) ;
- b = txn1.promote() ;
- assertTrue(b) ;
- // Exception - now a writer
- txn1.end() ;
- checkClear() ;
- }
-
- //Not a @Test
- public void txn_promote_deadlock() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE) ;
- // Deadlock.
- // Promotion waits for the writer to decide whether it is commiting or not.
- // This can't be done on one thread.
- boolean b = txn1.promote() ;
- assertFalse(b) ;
- txn1.end() ;
- txn2.commit();
- txn2.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_promote_thread_writer_1() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- L.syncOtherThread(()->{
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE) ;
- txn2.commit();
- txn2.end() ;
- }) ;
-
- boolean b = txn1.promote() ;
- assertFalse(b) ;
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_promote_thread_writer_2() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- L.syncOtherThread(()->{
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE) ;
- txn2.abort();
- txn2.end() ;
- }) ;
-
- boolean b = txn1.promote() ;
- assertTrue(b) ;
- // Now a writer.
- txn1.commit();
- txn1.end() ;
- checkClear() ;
- }
-
- @Test
- public void txn_promote_thread_writer_3() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- boolean b = txn1.promote() ;
- assertTrue(b) ;
- AtomicReference<Transaction> ref = new AtomicReference<>(txn1) ;
- L.syncOtherThread(()->{
- // Should fail.
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE, false) ;
- ref.set(txn2);
- }) ;
- assertNull(ref.get()) ;
- txn1.abort() ;
- txn1.end() ;
- }
-
- @Test
- public void txn_promote_thread_writer_4() {
- Transaction txn1 = txnMgr.begin(ReadWrite.READ) ;
- boolean b = txn1.promote() ;
- assertTrue(b) ;
- AtomicReference<Transaction> ref = new AtomicReference<>(txn1) ;
- L.syncOtherThread(()->{
- // Should fail.
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE, false) ;
- ref.set(txn2);
- }) ;
- assertNull(ref.get()) ;
- txn1.abort() ;
- txn1.end() ;
-
- L.syncOtherThread(()->{
- // Should suceed
- Transaction txn2 = txnMgr.begin(ReadWrite.WRITE, false) ;
- ref.set(txn2);
- txn2.abort() ;
- txn2.end() ;
- }) ;
- assertNotNull(ref.get()) ;
- checkClear() ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnId.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnId.java b/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnId.java
deleted file mode 100644
index 6c2a85f..0000000
--- a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnId.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.transaction;
-
-import static org.junit.Assert.assertEquals ;
-import static org.junit.Assert.assertNotEquals ;
-import static org.junit.Assert.assertNotNull ;
-import static org.junit.Assert.assertNotSame ;
-
-import org.junit.Test ;
-import org.seaborne.dboe.transaction.txn.TxnId ;
-import org.seaborne.dboe.transaction.txn.TxnIdFactory ;
-import org.seaborne.dboe.transaction.txn.TxnIdSimple ;
-
-public class TestTxnId {
- @Test public void txnId_1() {
- TxnId id1 = TxnIdFactory.createSimple() ;
- assertNotNull(id1) ;
- }
-
- @Test public void txnId_2() {
- TxnId id1 = TxnIdFactory.createSimple() ;
- TxnId id2 = TxnIdFactory.createSimple() ;
- assertNotSame(id1, id2) ;
- assertNotEquals(id1, id2) ;
- }
-
- @Test public void txnId_3() {
- TxnId id1 = TxnIdFactory.createSimple() ;
- TxnId id2 = TxnIdSimple.create(id1.bytes()) ;
- assertNotSame(id1, id2) ;
- assertEquals(id1, id2) ;
- assertEquals(id1.name(), id2.name()) ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib.java b/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib.java
deleted file mode 100644
index 36537fe..0000000
--- a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.transaction;
-
-import static org.junit.Assert.assertEquals ;
-import static org.junit.Assert.assertNotEquals ;
-import static org.junit.Assert.fail ;
-
-import org.apache.jena.query.ReadWrite ;
-import org.junit.Test ;
-import org.seaborne.dboe.jenax.Txn ;
-
-public class TestTxnLib extends AbstractTestTxn {
-
- @Test public void libTxn_1() {
- long v1 = counter1.value() ;
- long v2 = counter2.value() ;
- assertEquals(0, v1) ;
- assertEquals(0, v2) ;
-
- Txn.executeRead(unit, () -> {
- assertEquals(0, counter1.get()) ;
- assertEquals(0, counter2.get()) ;
- }) ;
- }
-
- @Test public void libTxn_2() {
- assertEquals(0, counter1.value()) ;
-
- Txn.executeWrite(unit, () -> {
- counter1.inc() ;
- assertEquals("In W, value()", 0, counter1.value()) ;
- assertEquals("In W, get()",1, counter1.get()) ;
- }) ;
-
- assertEquals("Direct value()", 1, counter1.value()) ;
- assertEquals("Direct get()", 1, counter1.get()) ;
-
- Txn.executeRead(unit, () -> {
- assertEquals("In R, value()", 1, counter1.get()) ;
- assertEquals("In R, get()", 1, counter1.value()) ;
- }) ;
- }
-
- @Test public void libTxn_3() {
- Txn.executeRead(unit, () -> {
- assertEquals("In R, value()", 0, counter2.get()) ;
- assertEquals("In R, get()", 0, counter2.value()) ;
- }) ;
-
- Txn.executeWrite(unit, () -> {
- counter2.inc() ;
- assertEquals("In W, value()", 0, counter2.value()) ;
- assertEquals("In W, get()",1, counter2.get()) ;
- }) ;
-
- assertEquals("Direct value()", 1, counter2.value()) ;
- assertEquals("Direct get()", 1, counter2.get()) ;
-
- Txn.executeRead(unit, () -> {
- assertEquals("In R, value()", 1, counter2.get()) ;
- assertEquals("In R, get()", 1, counter2.value()) ;
- }) ;
- }
-
- @Test public void libTxn_4() {
- long v1 = counter1.value() ;
- long v2 = counter2.value() ;
- assertEquals(0, v1) ;
- assertEquals(0, v2) ;
-
- //Txn.execWrite(unit, () -> {
-
- unit.begin(ReadWrite.WRITE);
- counter1.inc() ;
- counter2.inc() ;
- assertEquals("Counter out of step", counter1.get(), counter2.get());
- assertNotEquals("Counter 1 can see wrong state", counter1.get(), counter1.value() ) ;
- assertNotEquals("Counter 2 can see wrong state", counter2.get(), counter2.value() ) ;
- counter2.inc() ;
- assertNotEquals("Counter 1 and 2 should differ", counter1.get(), counter2.get() ) ;
- unit.commit() ;
- unit.end() ;
- //}) ;
- assertEquals("Component 1 inconsistent", 1, counter1.value()) ;
- assertEquals("Component 2 inconsistent", 2, counter2.value()) ;
-
- Txn.executeRead(unit, () -> {
- assertEquals("Component 1 inconsistent (R)", 1, counter1.get()) ;
- assertEquals("Component 2 inconsistent (R)", 2, counter2.get()) ;
- }) ;
- }
-
- @Test public void libTxn_5() {
- long x =
- Txn.calculateRead(unit, () -> {
- assertEquals("In R, value()", 0, counter2.get()) ;
- assertEquals("In R, get()", 0, counter2.value()) ;
- return counter2.get() ;
- }) ;
- assertEquals("Outside R", 0, x) ;
- }
-
- @Test public void libTxn_6() {
- long x =
- Txn.calculateWrite(unit, () -> {
- counter2.inc() ;
- assertEquals("In W, value()", 0, counter2.value()) ;
- assertEquals("In W, get()",1, counter2.get()) ;
- return counter2.get() ;
- }) ;
- assertEquals("Outside W",1, x) ;
- }
-
- @Test public void libTxn_7() {
- long x1 =
- Txn.calculateWrite(unit, () -> {
- counter2.inc() ;
- counter2.inc() ;
- return counter2.get() ;
- }) ;
- long x2 = Txn.calculateRead(unit, () -> {
- return counter2.get() ;
- }) ;
- assertEquals("After W and R",x1 , x2) ;
- }
-
- // Tests for thread transactions.
-
- @Test public void libTxnThread_1() {
- ThreadTxn t = ThreadTxn.threadTxnRead(unit, ()->{}) ;
- t.run();
- }
-
- @Test public void libTxnThread_2() {
- ThreadTxn t = ThreadTxn.threadTxnWrite(unit, ()-> fail("")) ;
- }
-
- @Test(expected=AssertionError.class)
- public void libTxnThread_3() {
- ThreadTxn t = ThreadTxn.threadTxnWrite(unit, ()-> fail("")) ;
- t.run() ;
- }
-
- @Test public void libTxnThread_10() {
- long x1 = counter1.get() ;
- ThreadTxn t = ThreadTxn.threadTxnWrite(unit, ()->{ counter1.inc() ;}) ;
- long x2 = counter1.get() ;
- assertEquals("x2", x1, x2) ;
- t.run() ;
- long x3 = counter1.get() ;
- assertEquals("x3", x1+1, x3) ;
- }
-
- @Test public void libTxnThread_11() {
- long x1 = counter1.get() ;
- Txn.executeWrite(unit, ()->{
- counter1.inc();
- // Read the "before" state
- ThreadTxn t = ThreadTxn.threadTxnRead(unit, ()->{ long z1 = counter1.get() ; assertEquals("Thread read", x1, z1) ; }) ;
- counter1.inc();
- t.run();
- }) ;
- long x2 = counter1.get() ;
- assertEquals("after", x1+2, x2) ;
- }
-
- @Test public void libTxnThread_12() {
- long x1 = counter1.get() ;
- ThreadTxn t = ThreadTxn.threadTxnRead(unit, () -> {
- long z1 = counter1.get() ;
- assertEquals("Thread", x1, z1) ;
- }) ;
- Txn.executeWrite(unit, ()->counter1.inc()) ;
- t.run() ;
- long x2 = counter1.get() ;
- assertEquals("after", x1+1, x2) ;
- }
-
-}
-
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib2.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib2.java b/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib2.java
deleted file mode 100644
index 44e76e8..0000000
--- a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnLib2.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.transaction;
-
-import org.apache.jena.atlas.lib.Pair ;
-import org.junit.After ;
-import org.junit.Assert ;
-import org.junit.Before ;
-import org.junit.Test ;
-import org.seaborne.dboe.base.file.Location ;
-import org.seaborne.dboe.jenax.Txn ;
-import org.seaborne.dboe.transaction.txn.TransactionCoordinator ;
-
-/** Unusual ways to do things.
- * Rather than a TransactionalComponent,
- * TransactionalInteger
- */
-public class TestTxnLib2 extends Assert {
- // With setup/teardown / not from AbstractTestTxn
- private final long InitValue = 7 ;
- TransactionalInteger integer ;
-
- @Before public void setup() {
- TransactionCoordinator coord = new TransactionCoordinator(Location.mem()) ;
- integer = new TransactionalInteger(coord, InitValue) ;
- coord.start() ;
- }
-
- @After public void clearup() {
- integer.shutdown();
- }
-
- @Test public void libTxn_10() {
- Txn.executeWrite(integer, integer::inc) ;
- long x = Txn.calculateRead(integer, integer::get) ;
- assertEquals(InitValue+1, x) ;
- }
-
- @Test public void libTxn_11() {
- Pair<Long, Long> p = Txn.calculateWrite(integer, () -> {
- integer.inc() ;
- return Pair.create(integer.value(), integer.get()) ;
- }) ;
- assertEquals(InitValue, p.getLeft().longValue()) ;
- assertEquals(InitValue+1, p.getRight().longValue()) ;
- assertEquals(InitValue+1, integer.get()) ;
- assertEquals(InitValue+1, integer.value()) ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnSwitching.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnSwitching.java b/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnSwitching.java
deleted file mode 100644
index 7f7b128..0000000
--- a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TestTxnSwitching.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.transaction;
-
-import static org.junit.Assert.assertEquals ;
-import static org.junit.Assert.fail ;
-
-import org.apache.jena.query.ReadWrite ;
-import org.junit.After ;
-import org.junit.Before ;
-import org.junit.Test ;
-import org.seaborne.dboe.base.file.Location ;
-import org.seaborne.dboe.jenax.Txn ;
-import org.seaborne.dboe.transaction.txn.* ;
-import org.seaborne.dboe.transaction.txn.journal.Journal ;
-
-/** Tests of changing the thread state ... carefully */
-public class TestTxnSwitching {
- TransInteger integer = new TransInteger(100) ;
- Journal jrnl = Journal.create(Location.mem()) ;
-
- //Transactional transactional = TransactionalFactory.create(jrnl, integer) ;
- TransactionalBase transactional ;
- TransactionCoordinator txnMgr = new TransactionCoordinator(jrnl) ;
- {
- txnMgr.add(integer) ;
- transactional = new TransactionalBase(txnMgr) ;
- txnMgr.start() ;
- }
-
-
- @Before public void setup() {
- }
-
- @After public void clearup() {
- }
-
- @Test public void txnSwitch_01() {
- long z = integer.value() ;
- transactional.begin(ReadWrite.WRITE);
- integer.inc();
-
- assertEquals(integer.value()+1, integer.get()) ;
- assertEquals(z+1, integer.get()) ;
-
- TransactionCoordinatorState txnState = transactional.detach() ;
-
- assertEquals(integer.value(), integer.get()) ;
- assertEquals(z, integer.get()) ;
-
- transactional.attach(txnState);
-
- assertEquals(integer.value()+1, integer.get()) ;
- assertEquals(z+1, integer.get()) ;
-
- transactional.commit() ;
- transactional.end() ;
- assertEquals(z+1, integer.get()) ;
- assertEquals(z+1, integer.value()) ;
- }
-
- @Test public void txnSwitch_02() {
- long z = integer.value() ;
- Txn.executeWrite(transactional, ()->integer.inc());
- assertEquals(z+1, integer.value()) ;
-
-
- //Transaction txn = txnMgr.begin(ReadWrite.WRITE) ;
- transactional.begin(ReadWrite.WRITE);
- integer.inc();
- assertEquals(z+2, integer.get()) ;
- TransactionCoordinatorState txnState = transactional.detach() ;
- // Can't transactional read.
- try { integer.read() ; fail() ; } catch (TransactionException ex) {}
-
- long z1 = Txn.calculateRead(transactional, ()->integer.get()) ;
- assertEquals(z+1, z1) ;
- transactional.attach(txnState) ;
- integer.inc();
- assertEquals(z+3, integer.get()) ;
-
- ThreadTxn threadTxn = ThreadTxn.threadTxnRead(transactional, ()->assertEquals(z+1, integer.get())) ;
- threadTxn.run() ;
-
- transactional.commit() ;
- transactional.end() ;
- }
-
- // As 02 but with Transaction txn = txnMgr.begin(ReadWrite.WRITE) ;
- // and txn calls and integer calls. Not transactional calls but txnMgr calls.
-
- @Test public void txnSwitch_03() {
- long z = integer.value() ;
- Txn.executeWrite(transactional, ()->integer.inc());
- assertEquals(z+1, integer.value()) ;
-
- Transaction txn = txnMgr.begin(ReadWrite.WRITE) ;
- integer.inc();
- assertEquals(z+2, integer.get()) ;
- TransactionCoordinatorState txnState = txnMgr.detach(txn) ;
-
- Transaction txnRead = txnMgr.begin(ReadWrite.READ) ;
- assertEquals(z+1, integer.get()) ;
- txnRead.end() ;
-
- try { integer.read() ; fail() ; } catch (TransactionException ex) {}
-
- txnMgr.attach(txnState);
-
- integer.inc();
- assertEquals(z+3, integer.get()) ;
-
- ThreadTxn.threadTxnRead(transactional, ()->assertEquals(z+1, integer.get())).run();
- txn.commit();
- txn.end() ;
- }
-
- // Switch between read and write all on one thread.
- @Test public void txnSwitch_04() {
- long z = integer.value() ;
-
- transactional.begin(ReadWrite.READ);
- TransactionCoordinatorState txnStateR1 = transactional.detach() ;
-
- ThreadTxn t1 = ThreadTxn.threadTxnRead(transactional, ()->assertEquals(z, integer.get() )) ;
- ThreadTxn t2 = ThreadTxn.threadTxnRead(transactional, ()->assertEquals(z, integer.get() )) ;
-
- transactional.begin(ReadWrite.WRITE);
- integer.inc();
-
- TransactionCoordinatorState txnStateW1 = transactional.detach() ;
-
- // Currently, thread has no transaction.
- long z1 = Txn.calculateRead(transactional, ()->integer.get() );
- assertEquals(z, z1) ;
-
- // Back to writer.
- transactional.attach(txnStateW1) ;
- integer.inc();
- TransactionCoordinatorState txnStateW2 = transactional.detach() ;
-
- try { integer.read() ; fail() ; } catch (TransactionException ex) {}
- // To reader.
- transactional.attach(txnStateR1) ;
- assertEquals(z1, integer.read()) ;
- t1.run() ;
-
- // And the writer again.
- TransactionCoordinatorState txnStateR2 = transactional.detach() ;
- transactional.attach(txnStateW2) ;
- integer.inc();
- transactional.commit();
- transactional.end() ;
-
- t2.run() ;
- transactional.attach(txnStateR2) ;
- assertEquals(z1, integer.read()) ;
- transactional.end() ;
- }
-
- // Some error cases.
- @Test(expected=TransactionException.class)
- public void txnSwitch_10() {
- transactional.begin(ReadWrite.READ);
- TransactionCoordinatorState txnState = transactional.detach() ;
- transactional.attach(txnState);
- transactional.attach(txnState);
- }
- @Test(expected=TransactionException.class)
- public void txnSwitch_11() {
- transactional.begin(ReadWrite.READ);
- TransactionCoordinatorState txnState1 = transactional.detach() ;
- TransactionCoordinatorState txnState2 = transactional.detach() ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TransactionalInteger.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TransactionalInteger.java b/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TransactionalInteger.java
deleted file mode 100644
index 64f521a..0000000
--- a/jena-db/jena-dboe-transaction/src/test/java/org/seaborne/dboe/transaction/TransactionalInteger.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.transaction;
-
-import org.seaborne.dboe.transaction.txn.TransactionCoordinator ;
-import org.seaborne.dboe.transaction.txn.TransactionalBase ;
-
-/**
- * A Transactional (unit of begin/commit) of a single integer component.
- * Testing support. Use {@link TransInteger} for application code.
- * @see TransInteger
- */
-public class TransactionalInteger extends TransactionalBase {
- final private TransInteger integer ;
-
- public TransactionalInteger(TransactionCoordinator coord, long v) {
- super(coord) ;
- integer = new TransInteger(v) ;
- coord.add(integer) ;
- }
-
- public void inc() {
- integer.inc() ;
- }
-
- /** Return the current value.
- * If inside a transaction, return the tarnsaction view of the value.
- * If not in a transaction return the state value (effectively
- * a fast read transaction).
- */
- public long get() {
- return integer.get() ;
- }
-
- public void set(long v) {
- integer.set(v) ;
- }
-
- /** Return the currently commited value */
- public long value() {
- return integer.value() ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-fuseki-tdb2/pom.xml
----------------------------------------------------------------------
diff --git a/jena-db/jena-fuseki-tdb2/pom.xml b/jena-db/jena-fuseki-tdb2/pom.xml
index 618d665..48cddb7 100644
--- a/jena-db/jena-fuseki-tdb2/pom.xml
+++ b/jena-db/jena-fuseki-tdb2/pom.xml
@@ -43,12 +43,13 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-fuseki-core</artifactId>
- <version>${ver.fuseki}</version>
+ <version>3.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-cmds</artifactId>
+ <version>3.5.0-SNAPSHOT</version>
</dependency>
<dependency>
@@ -71,13 +72,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
- <version>2.4.3</version>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!--<mainClass>org.apache.jena.fuseki.cmd.FusekiCmd</mainClass>-->
- <mainClass>org.seaborne.fuseki.cmd.FusekiTDB2Cmd</mainClass>
+ <mainClass>org.apache.fuseki.cmd_x.FusekiTDB2Cmd</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-fuseki-tdb2/src/main/java/org/apache/jena/cmd_x/FusekiTDB2Cmd.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-fuseki-tdb2/src/main/java/org/apache/jena/cmd_x/FusekiTDB2Cmd.java b/jena-db/jena-fuseki-tdb2/src/main/java/org/apache/jena/cmd_x/FusekiTDB2Cmd.java
new file mode 100644
index 0000000..e142186
--- /dev/null
+++ b/jena-db/jena-fuseki-tdb2/src/main/java/org/apache/jena/cmd_x/FusekiTDB2Cmd.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.cmd_x;
+
+import org.apache.jena.fuseki.Fuseki;
+import org.apache.jena.fuseki.FusekiLogging;
+import org.apache.jena.fuseki.cmd.FusekiCmd;
+
+public class FusekiTDB2Cmd {
+
+ public static void main(String... args) {
+ FusekiLogging.setLogging() ;
+ Fuseki.serverLog.info("Fuseki-TDB2 integration");
+ FusekiCmd.main(args);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-fuseki-tdb2/src/main/java/org/seaborne/fuseki/cmd/FusekiTDB2Cmd.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-fuseki-tdb2/src/main/java/org/seaborne/fuseki/cmd/FusekiTDB2Cmd.java b/jena-db/jena-fuseki-tdb2/src/main/java/org/seaborne/fuseki/cmd/FusekiTDB2Cmd.java
deleted file mode 100644
index 25e1314..0000000
--- a/jena-db/jena-fuseki-tdb2/src/main/java/org/seaborne/fuseki/cmd/FusekiTDB2Cmd.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.fuseki.cmd;
-
-import org.apache.jena.fuseki.Fuseki;
-import org.apache.jena.fuseki.FusekiLogging;
-import org.apache.jena.fuseki.cmd.FusekiCmd;
-
-public class FusekiTDB2Cmd {
-
- public static void main(String... args) {
- FusekiLogging.setLogging() ;
- Fuseki.serverLog.info("Fuseki-TDB2 integration");
- FusekiCmd.main(args);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/pom.xml
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/pom.xml b/jena-db/jena-tdb2-cmds/pom.xml
index e8d24f4..4f00d28 100644
--- a/jena-db/jena-tdb2-cmds/pom.xml
+++ b/jena-db/jena-tdb2-cmds/pom.xml
@@ -42,6 +42,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-cmds</artifactId>
+ <version>3.5.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.apache.jena</groupId>
@@ -82,7 +83,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
- <version>2.4.3</version>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDB.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDB.java
index da799fd..ed6f0f0 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDB.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDB.java
@@ -22,14 +22,14 @@ import arq.cmdline.CmdARQ ;
import org.apache.jena.Jena ;
import org.apache.jena.atlas.lib.Lib ;
import org.apache.jena.atlas.logging.LogCtl ;
+import org.apache.jena.dboe.base.file.Location;
import org.apache.jena.query.ARQ ;
import org.apache.jena.query.Dataset ;
import org.apache.jena.sparql.core.DatasetGraph ;
import org.apache.jena.system.JenaSystem ;
-import org.seaborne.dboe.base.file.Location;
-import org.seaborne.tdb2.TDB2;
-import org.seaborne.tdb2.store.DatasetGraphSwitchable ;
-import org.seaborne.tdb2.sys.TDBInternal ;
+import org.apache.jena.tdb2.TDB2;
+import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
+import org.apache.jena.tdb2.sys.TDBInternal;
public abstract class CmdTDB extends CmdARQ
{
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDBGraph.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDBGraph.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDBGraph.java
index 60b7982..ba86ec8 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDBGraph.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/CmdTDBGraph.java
@@ -25,7 +25,7 @@ import org.apache.jena.graph.Node ;
import org.apache.jena.graph.NodeFactory ;
import org.apache.jena.query.Dataset ;
import org.apache.jena.rdf.model.Model ;
-import org.seaborne.tdb2.store.GraphTDB;
+import org.apache.jena.tdb2.store.GraphTDB;
import tdb2.cmdline.CmdTDB;
public abstract class CmdTDBGraph extends CmdTDB
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModLocation.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModLocation.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModLocation.java
index 1d6b37a..5e48c16 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModLocation.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModLocation.java
@@ -22,7 +22,7 @@ import jena.cmd.ArgDecl;
import jena.cmd.CmdArgModule;
import jena.cmd.CmdGeneral;
import jena.cmd.ModBase;
-import org.seaborne.dboe.base.file.Location;
+import org.apache.jena.dboe.base.file.Location;
public class ModLocation extends ModBase
{
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBAssembler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBAssembler.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBAssembler.java
index 6fbb345..636a13f 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBAssembler.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBAssembler.java
@@ -23,7 +23,7 @@ import java.io.File;
import jena.cmd.CmdArgModule;
import jena.cmd.CmdException;
import jena.cmd.CmdGeneral;
-import org.seaborne.dboe.base.file.Location;
+import org.apache.jena.dboe.base.file.Location;
import tdb2.cmdline.ModLocation;
import arq.cmdline.ModAssembler;
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBDataset.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBDataset.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBDataset.java
index 199268a..3fd82d3 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBDataset.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/cmdline/ModTDBDataset.java
@@ -27,17 +27,17 @@ import jena.cmd.CmdArgModule;
import jena.cmd.CmdException;
import jena.cmd.CmdGeneral;
import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.dboe.base.file.Location;
import org.apache.jena.query.* ;
import org.apache.jena.rdf.model.Model ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.shared.JenaException ;
import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.tdb2.assembler.VocabTDB2;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
import org.apache.jena.util.FileManager ;
-import org.seaborne.dboe.base.file.Location;
-import org.seaborne.tdb2.TDB2Factory;
-import org.seaborne.tdb2.assembler.VocabTDB2;
-import org.seaborne.tdb2.store.DatasetGraphTDB;
public class ModTDBDataset extends ModDataset
{
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbbackup.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbbackup.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbbackup.java
index 8291514..c0046a8 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbbackup.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbbackup.java
@@ -19,8 +19,8 @@
package tdb2;
import arq.cmdline.ModLangOutput ;
-import org.seaborne.tdb2.store.DatasetGraphSwitchable ;
-import org.seaborne.tdb2.sys.DatabaseOps ;
+import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
+import org.apache.jena.tdb2.sys.DatabaseOps;
import tdb2.cmdline.CmdTDB;
public class tdbbackup extends CmdTDB
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbcompact.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbcompact.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbcompact.java
index ea2e275..59f2425 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbcompact.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbcompact.java
@@ -18,8 +18,8 @@
package tdb2;
-import org.seaborne.tdb2.store.DatasetGraphSwitchable ;
-import org.seaborne.tdb2.sys.DatabaseOps ;
+import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
+import org.apache.jena.tdb2.sys.DatabaseOps;
import tdb2.cmdline.CmdTDB;
public class tdbcompact extends CmdTDB {
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbdump.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbdump.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbdump.java
index 9c50e87..e8bd728 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbdump.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbdump.java
@@ -20,11 +20,11 @@ package tdb2;
import arq.cmdline.ModLangOutput ;
import jena.cmd.CmdException ;
+import org.apache.jena.dboe.jenax.Txn;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.riot.RDFFormat ;
import org.apache.jena.riot.RDFLanguages ;
import org.apache.jena.sparql.core.DatasetGraph ;
-import org.seaborne.dboe.jenax.Txn;
import tdb2.cmdline.CmdTDB;
public class tdbdump extends CmdTDB
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbstats.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbstats.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbstats.java
index 7f53199..19797d0 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbstats.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbstats.java
@@ -22,18 +22,18 @@ import java.util.Iterator ;
import org.apache.jena.atlas.lib.tuple.Tuple ;
import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.dboe.jenax.Txn;
import org.apache.jena.graph.Node ;
import org.apache.jena.sparql.core.Quad ;
-import org.seaborne.dboe.jenax.Txn;
-import org.seaborne.tdb2.solver.SolverLib;
-import org.seaborne.tdb2.solver.stats.Stats;
-import org.seaborne.tdb2.solver.stats.StatsCollectorNodeId;
-import org.seaborne.tdb2.solver.stats.StatsResults;
-import org.seaborne.tdb2.store.DatasetGraphTDB;
-import org.seaborne.tdb2.store.NodeId;
-import org.seaborne.tdb2.store.nodetable.NodeTable;
-import org.seaborne.tdb2.store.nodetupletable.NodeTupleTable;
-import org.seaborne.tdb2.sys.TDBInternal ;
+import org.apache.jena.tdb2.solver.SolverLib;
+import org.apache.jena.tdb2.solver.stats.Stats;
+import org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId;
+import org.apache.jena.tdb2.solver.stats.StatsResults;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+import org.apache.jena.tdb2.store.NodeId;
+import org.apache.jena.tdb2.store.nodetable.NodeTable;
+import org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable;
+import org.apache.jena.tdb2.sys.TDBInternal;
import tdb2.cmdline.CmdTDB;
import tdb2.cmdline.CmdTDBGraph;
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbupdate.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbupdate.java b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbupdate.java
index cbe0245..c40c245 100644
--- a/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbupdate.java
+++ b/jena-db/jena-tdb2-cmds/src/main/java/tdb2/tdbupdate.java
@@ -21,7 +21,7 @@ package tdb2;
import arq.cmdline.ModDataset;
import jena.cmd.CmdException;
import org.apache.jena.sparql.core.DatasetGraph;
-import org.seaborne.tdb2.TDB2;
+import org.apache.jena.tdb2.TDB2;
import tdb2.cmdline.CmdTDB;
import tdb2.cmdline.ModTDBDataset;
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2-cmds/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2-cmds/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle b/jena-db/jena-tdb2-cmds/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
index 21f02ea..2f69ca7 100644
--- a/jena-db/jena-tdb2-cmds/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
+++ b/jena-db/jena-tdb2-cmds/src/main/resources/META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
@@ -1 +1 @@
-org.seaborne.tdb2.sys.InitTDB2
+org.apache.jena.tdb2.sys.InitTDB2
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/pom.xml
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/pom.xml b/jena-db/jena-tdb2/pom.xml
index e034ca6..5c83f9c 100644
--- a/jena-db/jena-tdb2/pom.xml
+++ b/jena-db/jena-tdb2/pom.xml
@@ -42,6 +42,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
+ <version>3.5.0-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
@@ -49,6 +50,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
+ <version>3.5.0-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
@@ -56,46 +58,11 @@
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-base</artifactId>
+ <version>3.5.0-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-sources</id>
- <!-- <phase>package</phase> package is the default -->
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- </execution>
- <execution>
- <id>attach-sources-test</id>
- <goals>
- <goal>test-jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
- </build>
</project>
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java
new file mode 100644
index 0000000..e8e0091
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/DatabaseMgr.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2;
+
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+import org.apache.jena.tdb2.sys.DatabaseConnection;
+import org.apache.jena.tdb2.sys.DatabaseOps;
+import org.apache.jena.tdb2.sys.TDBInternal;
+
+/** Operations for TDBS DatasetGraph, including admin operations
+ * See {@link TDB2Factory} for creating API-level {@link Dataset Datasets}.
+ *
+ * @see TDB2Factory
+ */
+public class DatabaseMgr {
+
+ // All creation of DatasetGraph for TDB2 goes through this method.
+ private static DatasetGraph DB_ConnectCreate(Location location) {
+ return DatabaseConnection.connectCreate(location).getDatasetGraph();
+// // One level.
+// return StoreConnection.connectCreate(location).getDatasetGraph() ;
+ }
+
+ /** Create or connect to a TDB2-backed dataset */
+ public static DatasetGraph connectDatasetGraph(Location location) {
+ return DB_ConnectCreate(location);
+ }
+
+ /** Create or connect to a TDB2-backed dataset */
+ public static DatasetGraph connectDatasetGraph(String location) {
+ return connectDatasetGraph(Location.create(location)) ;
+ }
+
+ /**
+ * Compact a datasets which must be a switchable TDB database.
+ * This is the normal dataset type for on-disk TDB2 databases.
+ *
+ * @param container
+ */
+ public static void compact(DatasetGraph container) {
+ DatasetGraphSwitchable dsg = requireSwitchable(container);
+ DatabaseOps.compact(dsg);
+ }
+
+ /**
+ * Create a backup for a switchable TDB database. This is the normal dataset type for
+ * on-disk TDB2 databases.
+ * <p>
+ * The backup is created in the databases folder, under "Backups".
+ * <p>
+ * Backup creates a consistent copy og the database. It is performed as a read-transaction
+ * and does not lock out other use of the dataset.
+ *
+ * @param container
+ * @return File name of the backup.
+ */
+ public static String backup(DatasetGraph container) {
+ DatasetGraphSwitchable dsg = requireSwitchable(container);
+ return DatabaseOps.backup(dsg);
+ }
+
+
+ /** Create an in-memory TDB2-backed dataset (for testing) */
+ public static DatasetGraph createDatasetGraph() {
+ return connectDatasetGraph(Location.mem()) ;
+ }
+
+ /** Return the location of a dataset if it is backed by TDB, else null */
+ public static boolean isBackedByTDB(DatasetGraph datasetGraph) {
+ return TDBInternal.isBackedByTDB(datasetGraph);
+ }
+
+ /** Return the location of a DatasetGraph if it is backed by TDB, else null. */
+ public static Location location(DatasetGraph datasetGraph) {
+ DatasetGraphSwitchable dsg = requireSwitchable(datasetGraph);
+ if ( dsg == null )
+ return null ;
+ return dsg.getLocation();
+ }
+
+ private static DatasetGraphSwitchable requireSwitchable(DatasetGraph datasetGraph) {
+ if ( datasetGraph instanceof DatasetGraphSwitchable )
+ return (DatasetGraphSwitchable)datasetGraph;
+ throw new TDBException("Not a switchable TDB database");
+ }
+
+ static DatasetGraphTDB requireDirect(DatasetGraph datasetGraph) {
+ DatasetGraphTDB dsg = TDBInternal.getDatasetGraphTDB(datasetGraph);
+ if ( dsg == null )
+ throw new TDBException("Not a TDB database (argument is neither a switchable nor direct TDB DatasetGraph)");
+ return dsg;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2.java
new file mode 100644
index 0000000..63e4609
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2.java
@@ -0,0 +1,269 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2 ;
+
+import org.apache.jena.atlas.lib.Sync ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.ontology.OntModel ;
+import org.apache.jena.ontology.impl.OntModelImpl ;
+import org.apache.jena.query.ARQ ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.reasoner.InfGraph ;
+import org.apache.jena.riot.lang.ReaderRIOTRDFXML;
+import org.apache.jena.sparql.SystemARQ ;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
+import org.apache.jena.sparql.engine.main.StageBuilder ;
+import org.apache.jena.sparql.engine.main.StageGenerator ;
+import org.apache.jena.sparql.lib.Metadata ;
+import org.apache.jena.sparql.mgt.SystemInfo ;
+import org.apache.jena.sparql.util.Context ;
+import org.apache.jena.sparql.util.MappingRegistry ;
+import org.apache.jena.sparql.util.Symbol ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb2.assembler.VocabTDB2;
+import org.apache.jena.tdb2.modify.UpdateEngineTDB;
+import org.apache.jena.tdb2.solver.QueryEngineTDB;
+import org.apache.jena.tdb2.solver.StageGeneratorDirectTDB;
+import org.apache.jena.tdb2.sys.EnvTDB;
+import org.apache.jena.tdb2.sys.SystemTDB;
+import org.apache.jena.tdb2.sys.TDBInternal;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+public class TDB2 {
+ /** IRI for TDB */
+ public static final String tdbIRI = "http://jena.apache.org/#tdb" ;
+
+ /** Root of TDB-defined parameter names */
+ public static final String tdbParamNS = "http://jena.apache.org/TDB#" ;
+
+ /** Prefix for TDB-defined parameter names */
+ public static final String tdbSymbolPrefix = "tdb" ;
+
+ // Internal logging
+ private static final Logger log = LoggerFactory.getLogger(TDB2.class) ;
+
+ /** Logger for loading information */
+ public static final String logLoaderName = "org.apache.jena.tdb.loader" ;
+ /** Logger for loading information */
+ public static final Logger logLoader = LoggerFactory.getLogger(logLoaderName) ;
+
+ /** Logger for general information */
+ public static final String logInfoName = "org.apache.jena.info" ;
+ /** Logger for general information */
+ public static final Logger logInfo = LoggerFactory.getLogger(logInfoName) ;
+
+ // /** Logger for execution information */
+ // public static final String logExecName = "org.apache.jena.tdb.exec" ;
+ // /** Logger for execution information */
+ // public static final Logger logExec = LoggerFactory.getLogger(logExecName)
+ // ;
+
+ public final static String namespace = "http://jena.apache.org/2016/tdb#" ;
+
+ /** Symbol to use the union of named graphs as the default graph of a query */
+ public static final Symbol symUnionDefaultGraph = SystemTDB.allocSymbol("unionDefaultGraph") ;
+
+ /**
+ * A String enum Symbol that specifies the type of temporary storage for
+ * transaction journal write blocks.
+ * <p/>
+ * "mem" = Java heap memory (default) <br>
+ * "direct" = Process heap memory <br>
+ * "mapped" = Memory mapped temporary file <br>
+ */
+ public static final Symbol transactionJournalWriteBlockMode = SystemTDB.allocSymbol("transactionJournalWriteBlockMode") ;
+
+ public static Context getContext() {
+ return ARQ.getContext() ;
+ }
+
+ /**
+ * Release any and all system resources held by TDB.
+ * All release datasets or graphs held by client code are no longer valid.
+ */
+ public static void closedown() {
+ TDBInternal.reset() ;
+ }
+
+ /** Sync a TDB-backed Model. Do nothing if not TDB-backed. */
+ public static void sync(Model model) {
+ if ( model instanceof OntModelImpl ) {
+ OntModelImpl ontModel = (OntModelImpl)model ;
+ sync(ontModel.getBaseGraph()) ;
+ return ;
+ }
+ // This never happens (there is only one OntModel implementation)
+ if ( model instanceof OntModel ) {
+ OntModel ontModel = (OntModel)model ;
+ sync(ontModel.getBaseModel()) ;
+ return ;
+ }
+
+ sync(model.getGraph()) ;
+ }
+
+ /** Sync a TDB-backed Graph. Do nothing if not TDB-backed. */
+ public static void sync(Graph graph) {
+ if ( graph == null )
+ return ;
+
+ if ( graph instanceof InfGraph ) {
+ InfGraph infGraph = (InfGraph)graph ;
+ sync(infGraph.getRawGraph()) ;
+ return ;
+ }
+ syncObject(graph) ;
+ }
+
+// /** Sync a TDB-backed Dataset. Do nothing if not TDB-backed. */
+// public static void sync(Dataset dataset) {
+// if ( dataset == null )
+// return ;
+// DatasetGraph ds = dataset.asDatasetGraph() ;
+// sync(ds) ;
+// }
+//
+// /** Sync a TDB-backed DatasetGraph. Do nothing if not TDB-backed. */
+// public static void sync(DatasetGraph dataset) {
+// if ( dataset == null )
+// return ;
+//
+// // Should be: SystemARQ.sync(dataset) ;
+// if ( dataset instanceof DatasetGraphTDB ) {
+// syncObject(dataset) ;
+// return ;
+// }
+//
+// if ( dataset instanceof DatasetGraphTransaction ) {
+// DatasetGraphTransaction dsgt = (DatasetGraphTransaction)dataset ;
+// // This only sync if the dataset has not been used transactionally.
+// // Can't sync transactional datasets (it's meaningless)
+// dsgt.syncIfNotTransactional() ;
+// return ;
+// }
+//
+// // May be a general purpose dataset with TDB objects in it.
+// sync(dataset.getDefaultGraph()) ;
+// Iterator<Node> iter = dataset.listGraphNodes() ;
+// iter = Iter.toList(iter).iterator() ; // Avoid iterator concurrency.
+// for (; iter.hasNext();) {
+// Node n = iter.next() ;
+// Graph g = dataset.getGraph(n) ;
+// sync(g) ;
+// }
+// }
+
+ /**
+ * Sync a TDB synchronizable object (model, graph, dataset). If force is
+ * true, synchronize as much as possible (e.g. file metadata) else make a
+ * reasonable attenpt at synchronization but does not gauarantee disk state.
+ * Do nothing otherwise
+ */
+ private static void syncObject(Object object) {
+ if ( object == null )
+ return ;
+ if ( object instanceof Sync )
+ ((Sync)object).sync() ;
+ }
+
+ private static final Object initLock = new Object() ;
+ private static volatile boolean initialized = false ;
+ static { JenaSystem.init(); }
+
+ /**
+ * TDB System initialization - normally, this is not explicitly called
+ * because all routes to use TDB will cause initialization to occur.
+ * However, calling it repeatedly is safe and low cost.
+ */
+ public static void init() {
+ if ( initialized )
+ return ;
+ synchronized(initLock) {
+ if ( initialized ) {
+ if ( JenaSystem.DEBUG_INIT )
+ System.err.println("TDB2.init - return") ;
+ return ;
+ }
+ initialized = true ;
+ if ( JenaSystem.DEBUG_INIT )
+ System.err.println("TDB2.init - start") ;
+
+ SystemTDB.init() ;
+ ARQ.init() ;
+ ReaderRIOTRDFXML.RiotUniformCompatibility = true ;
+ EnvTDB.processGlobalSystemProperties() ;
+
+ MappingRegistry.addPrefixMapping(SystemTDB.tdbSymbolPrefix, SystemTDB.symbolNamespace) ;
+ AssemblerUtils.init() ;
+ VocabTDB2.init() ;
+ QueryEngineTDB.register() ;
+ UpdateEngineTDB.register() ;
+ MappingRegistry.addPrefixMapping(TDB2.tdbSymbolPrefix, TDB2.tdbParamNS) ;
+
+ wireIntoExecution() ;
+ if ( JenaSystem.DEBUG_INIT )
+ System.err.println("TDB.init - finish") ;
+ }
+ }
+
+ private static void wireIntoExecution() {
+ // Globally change the stage generator to intercept BGP on TDB
+ // Globally change the stage generator to intercept BGP on TDB
+ Context cxt = ARQ.getContext() ;
+ StageGenerator orig = StageBuilder.chooseStageGenerator(cxt) ;
+
+ // Wire in the TDB stage generator which will make TDB work whether
+ // or not the TDB executor is used. This means that datasets of mixed
+ // graph types inside a general purpose dataset work.
+ StageGenerator stageGenerator = new StageGeneratorDirectTDB(orig) ;
+ StageBuilder.setGenerator(ARQ.getContext(), stageGenerator) ;
+ }
+
+ // ---- Static constants read by modVersion
+ // ---- Must be after initialization.
+
+ static private String metadataLocation = "org/apache/jena/tdb/tdb-properties.xml" ;
+ static private Metadata metadata = new Metadata(metadataLocation) ;
+
+ /** The root package name for TDB */
+ public static final String PATH = "org.apache.jena.tdb" ;
+
+ // The names known to ModVersion : "NAME", "VERSION", "BUILD_DATE"
+
+ public static final String NAME = "TDB" ;
+
+ /** The full name of the current TDB version */
+ public static final String VERSION = metadata.get(PATH + ".version", "DEV") ;
+
+ /** The date and time at which this release was built */
+ public static final String BUILD_DATE = metadata.get(PATH + ".build.datetime", "unset") ;
+
+ // Final initialization (in case any statics in this file are important).
+ static {
+ initialization2() ;
+ }
+
+ private static void initialization2() {
+ // Set management information.
+ SystemInfo systemInfo = new SystemInfo(TDB2.tdbIRI, TDB2.PATH, TDB2.VERSION, TDB2.BUILD_DATE) ;
+ SystemARQ.registerSubSystem(systemInfo) ;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2Factory.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2Factory.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2Factory.java
new file mode 100644
index 0000000..078a113
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDB2Factory.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2;
+
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.DatasetFactory ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+
+/**
+ * Public factory for connecting to and creating datasets backed by TDB2 storage.
+ */
+public class TDB2Factory
+{
+ private TDB2Factory() {}
+
+ /** @deprecated Use {@link DatabaseMgr#connectDatasetGraph(Location)} */
+ @Deprecated
+ public static DatasetGraph createDatasetGraph(Location location) {
+ return DatabaseMgr.connectDatasetGraph(location);
+ }
+
+ /** @deprecated Use {@link #connectDataset(Location)} */
+ @Deprecated
+ public static Dataset createDataset(Location location) {
+ return connectDataset(location);
+ }
+
+ /** Create or connect to a TDB2-backed dataset */
+ public static Dataset connectDataset(Location location) {
+ DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(location) ;
+ return DatasetFactory.wrap(dsg) ;
+ }
+
+ /** @deprecated Use {@link DatabaseMgr#connectDatasetGraph(String)} */
+ @Deprecated
+ public static DatasetGraph createDatasetGraph(String location) {
+ return DatabaseMgr.connectDatasetGraph(location);
+ }
+
+ /** @deprecated Use {@link #connectDataset(String)} */
+ @Deprecated
+ public static Dataset createDataset(String location) {
+ return connectDataset(location);
+ }
+
+ /** Create or connect to a TDB2-backed dataset */
+ public static Dataset connectDataset(String location) {
+ return connectDataset(Location.create(location)) ; }
+
+ /**
+ * Create an in-memory TDB2-backed dataset (for testing). In-memory TDB2 datasets are use
+ * a simple simulation of disk I/O to give exact semantics, which is useful to create
+ * tests that run fast where setup and teardown of datasets can be the major cost.
+ * <p>
+ * In-memory TDB2 datasets are not designed to scale, nor provide efficient execution for
+ * applications for long-term use.
+ */
+ public static Dataset createDataset() { return connectDataset(Location.mem()) ; }
+
+// /**
+// * Read the file and assembler a dataset
+// */
+// public static Dataset assembleDataset(String assemblerFile) {
+// return (Dataset)AssemblerUtils.build(assemblerFile, VocabTDB.tDatasetTDB) ;
+// }
+//
+// /** Release from the JVM. All caching is lost. */
+// public static void release(Dataset dataset) {
+// _release(location(dataset)) ;
+// }
+//
+// /** Release from the JVM. All caching is lost. */
+// public static void release(DatasetGraph dataset) {
+// _release(location(dataset)) ;
+// }
+
+ /** Tes whether a dataset is backed by TDB or not. */
+ public static boolean isBackedByTDB(Dataset dataset) {
+ DatasetGraph dsg = dataset.asDatasetGraph() ;
+ return DatabaseMgr.isBackedByTDB(dsg) ;
+ }
+
+ /** Return the location of a dataset if it is backed by TDB, else null */
+ public static Location location(Dataset dataset) {
+ DatasetGraph dsg = dataset.asDatasetGraph() ;
+ return DatabaseMgr.location(dsg) ;
+ }
+
+// /** Set the {@link StoreParams} for specific Location.
+// * This call must only be called before a dataset from Location
+// * is created. This operation should be used with care; bad choices
+// * of {@link StoreParams} can reduce performance.
+// *
+// * <a href="http://jena.apache.org/documentation/tdb/store-paramters.html"
+// * >See documentation</a>.
+// *
+// * @param location The persistent storage location
+// * @param params StoreParams to use
+// * @throws IllegalStateException If the dataset has already been setup.
+// */
+// public static void setup(Location location, StoreParams params) {
+// StoreConnection sConn = StoreConnection.getExisting(location) ;
+// if ( sConn != null )
+// throw new IllegalStateException("Location is already active") ;
+// StoreConnection.make(location, params) ;
+// }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDBException.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDBException.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDBException.java
new file mode 100644
index 0000000..171d8eb
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/TDBException.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2;
+
+import org.apache.jena.shared.JenaException ;
+
+public class TDBException extends JenaException
+{
+ public TDBException() { super() ; }
+ public TDBException(String msg) { super(msg) ; }
+ public TDBException(Throwable th) { super(th) ; }
+ public TDBException(String msg, Throwable th) { super(msg, th) ; }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/DatasetAssemblerTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/DatasetAssemblerTDB.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/DatasetAssemblerTDB.java
new file mode 100644
index 0000000..d742538
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/DatasetAssemblerTDB.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.assembler;
+
+import static org.apache.jena.sparql.util.graph.GraphUtils.exactlyOneProperty ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.getStringValue ;
+import static org.apache.jena.tdb2.assembler.VocabTDB2.pLocation;
+import static org.apache.jena.tdb2.assembler.VocabTDB2.pUnionDefaultGraph;
+
+import org.apache.jena.assembler.Assembler ;
+import org.apache.jena.assembler.Mode ;
+import org.apache.jena.assembler.exceptions.AssemblerException ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.DatasetFactory ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
+import org.apache.jena.sparql.core.assembler.DatasetAssembler ;
+import org.apache.jena.sparql.expr.NodeValue ;
+import org.apache.jena.system.JenaSystem ;
+import org.apache.jena.tdb2.DatabaseMgr;
+import org.apache.jena.tdb2.TDB2;
+
+public class DatasetAssemblerTDB extends DatasetAssembler
+{
+ static { JenaSystem.init(); }
+
+ @Override
+ public Dataset createDataset(Assembler a, Resource root, Mode mode) {
+ TDB2.init() ;
+ return make(root) ;
+ }
+
+ static Dataset make(Resource root) {
+ if ( !exactlyOneProperty(root, pLocation) )
+ throw new AssemblerException(root, "No location given") ;
+
+ String dir = getStringValue(root, pLocation) ;
+ Location loc = Location.create(dir) ;
+ DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(loc) ;
+
+ if ( root.hasProperty(pUnionDefaultGraph) ) {
+ Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode() ;
+ NodeValue nv = NodeValue.makeNode(b) ;
+ if ( nv.isBoolean() )
+ dsg.getContext().set(TDB2.symUnionDefaultGraph, nv.getBoolean()) ;
+ else
+ Log.warn(DatasetAssemblerTDB.class, "Failed to recognize value for union graph setting (ignored): " + b) ;
+ }
+
+ /*
+ <r> rdf:type tdb:DatasetTDB2 ;
+ tdb:location "dir" ;
+ //ja:context [ ja:cxtName "arq:queryTimeout" ; ja:cxtValue "10000" ] ;
+ tdb:unionGraph true ; # or "true"
+ */
+ AssemblerUtils.setContext(root, dsg.getContext());
+ return DatasetFactory.wrap(dsg) ;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/TDBGraphAssembler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/TDBGraphAssembler.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/TDBGraphAssembler.java
new file mode 100644
index 0000000..29b72e9
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/TDBGraphAssembler.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.assembler;
+
+import static org.apache.jena.sparql.util.graph.GraphUtils.getAsStringValue ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.getResourceValue ;
+import static org.apache.jena.sparql.util.graph.GraphUtils.getStringValue ;
+import static org.apache.jena.tdb2.assembler.VocabTDB2.*;
+
+import org.apache.jena.assembler.Assembler ;
+import org.apache.jena.assembler.Mode ;
+import org.apache.jena.assembler.assemblers.AssemblerBase ;
+import org.apache.jena.assembler.exceptions.AssemblerException ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.rdf.model.* ;
+import org.apache.jena.riot.out.NodeFmtLib ;
+import org.apache.jena.tdb2.TDB2;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.tdb2.TDBException;
+
+public class TDBGraphAssembler extends AssemblerBase implements Assembler
+{
+ @Override
+ public Model open(Assembler a, Resource root, Mode mode)
+ {
+ // In case we go via explicit index construction,
+ // although given we got here, the assembler is wired in
+ // and that probably means TDB.init
+ TDB2.init() ;
+
+ // Make a model - the default model of the TDB dataset
+ // [] rdf:type tdb:GraphTDB ;
+ // tdb:location "dir" ;
+
+ // Make a named model.
+ // [] rdf:type tdb:GraphTDB ;
+ // tdb:location "dir" ;
+ // tdb:graphName <http://example/name> ;
+
+ // Location or dataset reference.
+ String locationDir = getStringValue(root, pLocation) ;
+ Resource dataset = getResourceValue(root, pDataset) ;
+
+ if ( locationDir != null && dataset != null )
+ throw new AssemblerException(root, "Both location and dataset given: exactly one required") ;
+
+ if ( locationDir == null && dataset == null )
+ throw new AssemblerException(root, "Must give location or refer to a dataset description") ;
+
+ String graphName = null ;
+ if ( root.hasProperty(pGraphName1) )
+ graphName = getAsStringValue(root, pGraphName1) ;
+ if ( root.hasProperty(pGraphName2) )
+ graphName = getAsStringValue(root, pGraphName2) ;
+
+ if ( root.hasProperty(pIndex) )
+ Log.warn(this, "Custom indexes not implemented yet - ignored") ;
+
+ final Dataset ds ;
+
+ if ( locationDir != null )
+ {
+ Location location = Location.create(locationDir) ;
+ ds = TDB2Factory.connectDataset(location) ;
+ }
+ else
+ ds = DatasetAssemblerTDB.make(dataset) ;
+
+ try {
+ if ( graphName != null )
+ return ds.getNamedModel(graphName) ;
+ else
+ return ds.getDefaultModel() ;
+ } catch (RuntimeException ex)
+ {
+ ex.printStackTrace(System.err) ;
+ throw ex ;
+ }
+ }
+
+ //@Unused
+ private void indexes(Resource root)
+ {
+ // ---- API ways
+
+ StmtIterator sIter = root.listProperties(pIndex) ;
+ while(sIter.hasNext())
+ {
+ RDFNode obj = sIter.nextStatement().getObject() ;
+ if ( obj.isLiteral() )
+ {
+ String desc = ((Literal)obj).getString() ;
+ System.out.printf("Index: %s\n", desc) ; System.out.flush();
+ continue ;
+ }
+ throw new TDBException("Wrong format for tdb:index: should be a string: found: "+NodeFmtLib.displayStr(obj)) ;
+ // Resource x = (Resource)obj ;
+ // String desc = x.getProperty(pDescription).getString() ;
+ // String file = x.getProperty(pFile).getString() ;
+ // System.out.printf("Index: %s in file %s\n", desc, file) ; System.out.flush();
+ }
+
+ System.out.flush();
+ throw new TDBException("Custom indexes turned off") ;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/Vocab.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/Vocab.java b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/Vocab.java
new file mode 100644
index 0000000..557bbd6
--- /dev/null
+++ b/jena-db/jena-tdb2/src/main/java/org/apache/jena/tdb2/assembler/Vocab.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.assembler ;
+
+import org.apache.jena.rdf.model.Property ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+
+public class Vocab {
+ public static Resource type(String namespace, String localName) {
+ return ResourceFactory.createResource(namespace + localName) ;
+ }
+
+ public static Resource resource(String namespace, String localName) {
+ return ResourceFactory.createResource(namespace + localName) ;
+ }
+
+ public static Property property(String namespace, String localName) {
+ return ResourceFactory.createProperty(namespace + localName) ;
+ }
+}