Permalink
Browse files

Updates API slightly and adds JSON stuff for the REST-API

  • Loading branch information...
JohannesLichtenberger committed Feb 9, 2019
1 parent df1e3c4 commit 93223d20c0a6c3730ec5b8a5aa19e8428bac675d
Showing with 879 additions and 141 deletions.
  1. +2 −2 bundles/sirix-core/src/main/java/org/sirix/access/LocalJsonDatabase.java
  2. +2 −2 bundles/sirix-core/src/main/java/org/sirix/access/LocalXdmDatabase.java
  3. +1 −1 bundles/sirix-core/src/main/java/org/sirix/api/Database.java
  4. +3 −3 bundles/sirix-core/src/main/java/org/sirix/diff/service/FMSEImport.java
  5. +1 −1 bundles/sirix-core/src/main/java/org/sirix/service/json/serialize/JsonSerializer.java
  6. +3 −3 bundles/sirix-core/src/main/java/org/sirix/service/json/shredder/JsonShredder.java
  7. +1 −1 bundles/sirix-core/src/main/java/org/sirix/service/xml/serialize/SAXSerializer.java
  8. +1 −1 bundles/sirix-core/src/main/java/org/sirix/service/xml/serialize/XmlSerializer.java
  9. +2 −2 bundles/sirix-core/src/main/java/org/sirix/service/xml/shredder/WikipediaImport.java
  10. +1 −1 bundles/sirix-core/src/main/java/org/sirix/service/xml/shredder/XMLUpdateShredder.java
  11. +4 −5 bundles/sirix-core/src/main/java/org/sirix/service/xml/shredder/XmlShredder.java
  12. +3 −3 bundles/sirix-core/src/test/java/org/sirix/Holder.java
  13. +1 −1 bundles/sirix-core/src/test/java/org/sirix/JsonTestHelper.java
  14. +2 −2 bundles/sirix-core/src/test/java/org/sirix/XdmTestHelper.java
  15. +1 −1 bundles/sirix-core/src/test/java/org/sirix/access/HashTest.java
  16. +1 −1 bundles/sirix-core/src/test/java/org/sirix/access/NodeReadTrxImplTest.java
  17. +5 −5 bundles/sirix-core/src/test/java/org/sirix/access/XdmResourceManagerTest.java
  18. +2 −2 bundles/sirix-core/src/test/java/org/sirix/diff/algorithm/FMSETest.java
  19. +2 −2 bundles/sirix-core/src/test/java/org/sirix/service/json/serializer/JsonSerializerTest.java
  20. +3 −3 bundles/sirix-core/src/test/java/org/sirix/service/json/shredder/JsonShredderTest.java
  21. +6 −6 bundles/sirix-core/src/test/java/org/sirix/service/xml/serialize/XmlSerializerTest.java
  22. +1 −1 bundles/sirix-core/src/test/java/org/sirix/service/xml/shredder/XMLUpdateShredderTest.java
  23. +4 −4 bundles/sirix-core/src/test/java/org/sirix/service/xml/shredder/XmlShredderTest.java
  24. +1 −1 bundles/sirix-core/src/test/java/org/sirix/service/xml/xpath/XPathWriteTransactionTest.java
  25. +3 −3 bundles/sirix-core/src/test/java/org/sirix/settings/VersioningTest.java
  26. +1 −1 bundles/sirix-core/src/test/java/org/sirix/utils/XdmDocumentCreator.java
  27. +1 −1 bundles/sirix-examples/src/main/java/org/sirix/examples/ResourceTransactionUsage.java
  28. +1 −1 bundles/sirix-fs/src/main/java/org/sirix/fs/FileHierarchyWalker.java
  29. +1 −1 bundles/sirix-fs/src/main/java/org/sirix/fs/FileSystemWatcher.java
  30. +18 −0 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/JsonSerializeHelper.kt
  31. +118 −31 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/SirixVerticle.kt
  32. +1 −1 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/{Serialize.kt → XdmSerializeHelper.kt}
  33. +165 −0 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/JsonCreate.kt
  34. +110 −0 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/JsonDelete.kt
  35. +262 −0 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/JsonGet.kt
  36. +97 −0 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/JsonUpdate.kt
  37. +5 −5 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/{Create.kt → XdmCreate.kt}
  38. +2 −2 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/{Delete.kt → XdmDelete.kt}
  39. +4 −4 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/{Get.kt → XdmGet.kt}
  40. +6 −6 bundles/sirix-rest-api/src/main/kotlin/org/sirix/rest/crud/{Update.kt → XdmUpdate.kt}
  41. +20 −20 bundles/sirix-rest-api/src/test/kotlin/org/sirix/rest/SirixVerticleTest.kt
  42. +1 −1 bundles/sirix-xquery/src/main/java/org/sirix/xquery/function/sdb/io/Import.java
  43. +2 −2 bundles/sirix-xquery/src/main/java/org/sirix/xquery/node/BasicDBStore.java
  44. +7 −7 bundles/sirix-xquery/src/main/java/org/sirix/xquery/node/DBCollection.java
  45. +1 −1 bundles/sirix-xquery/src/test/java/org/sirix/xquery/function/sdb/diff/DiffTest.java
@@ -80,7 +80,7 @@ public synchronized void close() throws SirixException {
}

@Override
public synchronized JsonResourceManager getResourceManager(final String resource) {
public synchronized JsonResourceManager openResourceManager(final String resource) {
assertNotClosed();

final Path resourceFile =
@@ -122,7 +122,7 @@ protected boolean bootstrapResource(ResourceConfiguration resConfig) {

try (
final JsonResourceManager resourceTrxManager =
getResourceManager(resConfig.getResource().getFileName().toString());
openResourceManager(resConfig.getResource().getFileName().toString());
final JsonNodeTrx wtx = resourceTrxManager.beginNodeTrx()) {
wtx.commit();
} catch (final SirixException e) {
@@ -80,7 +80,7 @@ public synchronized void close() throws SirixException {
}

@Override
public synchronized XdmResourceManager getResourceManager(final String resource) {
public synchronized XdmResourceManager openResourceManager(final String resource) {
assertNotClosed();

final Path resourceFile =
@@ -122,7 +122,7 @@ protected boolean bootstrapResource(ResourceConfiguration resConfig) {

try (
final XdmResourceManager resourceTrxManager =
getResourceManager(resConfig.getResource().getFileName().toString());
openResourceManager(resConfig.getResource().getFileName().toString());
final XdmNodeTrx wtx = resourceTrxManager.beginNodeTrx()) {
wtx.commit();
} catch (final SirixException e) {
@@ -80,7 +80,7 @@
* @return the session
* @throws SirixException if can't get session
*/
T getResourceManager(String resourceName) throws SirixException;
T openResourceManager(String resourceName) throws SirixException;

/**
* Truncating a resource. This includes the removal of all data stored within this resource.
@@ -72,7 +72,7 @@ public static void shredder(final Path resNewRev, @Nonnull final Path newRev)

try (final var db = Databases.openXdmDatabase(newRev)) {
db.createResource(new ResourceConfiguration.Builder("shredded").build());
try (final var resMgr = db.getResourceManager("shredded");
try (final var resMgr = db.openResourceManager("shredded");
final var wtx = resMgr.beginNodeTrx();
final var fis = new FileInputStream(resNewRev.toFile())) {
final var fileReader = XmlShredder.createFileReader(fis);
@@ -98,10 +98,10 @@ private static void xmlDataImport(final Path resOldRev, @Nonnull final Path resN
shredder(checkNotNull(resNewRev), newRevTarget);

try (final var databaseOld = Databases.openXdmDatabase(resOldRev);
final var resMgrOld = databaseOld.getResourceManager("shredded");
final var resMgrOld = databaseOld.openResourceManager("shredded");
final var wtx = resMgrOld.beginNodeTrx();
final var databaseNew = Databases.openXdmDatabase(newRevTarget);
final var resourceNew = databaseNew.getResourceManager("shredded");
final var resourceNew = databaseNew.openResourceManager("shredded");
final var rtx = resourceNew.beginNodeReadOnlyTrx();
final var fmes = new FMSE()) {
fmes.diff(wtx, rtx);
@@ -350,7 +350,7 @@ public static void main(final String... args) throws Exception {
try (final var db = Databases.openJsonDatabase(databaseFile)) {
db.createResource(new ResourceConfiguration.Builder("shredded").build());

try (final JsonResourceManager resMgr = db.getResourceManager("shredded");
try (final JsonResourceManager resMgr = db.openResourceManager("shredded");
final FileWriter outputStream = new FileWriter(target.toFile())) {
final JsonSerializer serializer = JsonSerializer.newBuilder(resMgr, outputStream).build();
serializer.call();
@@ -473,7 +473,7 @@ public static void main(final String... args) throws SirixException, IOException

try (final var db = Databases.openJsonDatabase(targetDatabasePath)) {
db.createResource(new ResourceConfiguration.Builder("shredded").build());
try (final var resMgr = db.getResourceManager("shredded"); final var wtx = resMgr.beginNodeTrx()) {
try (final var resMgr = db.openResourceManager("shredded"); final var wtx = resMgr.beginNodeTrx()) {
final var path = Paths.get(args[0]);
final var jsonReader = createFileReader(path);
final var shredder =
@@ -491,7 +491,7 @@ public static void main(final String... args) throws SirixException, IOException
* @param path the path to the file
* @return an {@link JsonReader} instance
*/
public static synchronized JsonReader createFileReader(final Path path) {
public static JsonReader createFileReader(final Path path) {
checkNotNull(path);

try {
@@ -508,7 +508,7 @@ public static synchronized JsonReader createFileReader(final Path path) {
* @param json the JSON as a string
* @return an {@link JsonReader} instance
*/
public static synchronized JsonReader createStringReader(final String json) {
public static JsonReader createStringReader(final String json) {
checkNotNull(json);

final var stringReader = new StringReader(json);
@@ -250,7 +250,7 @@ public static void main(final String... args) {
Databases.createXdmDatabase(config);
final var database = Databases.openXdmDatabase(path);
database.createResource(new ResourceConfiguration.Builder("shredded").build());
try (final XdmResourceManager resource = database.getResourceManager("shredded")) {
try (final XdmResourceManager resource = database.openResourceManager("shredded")) {
final DefaultHandler defHandler = new DefaultHandler();
final SAXSerializer serializer = new SAXSerializer(resource, defHandler, resource.getMostRecentRevisionNumber());
serializer.call();
@@ -468,7 +468,7 @@ public static void main(final String... args) throws Exception {
try (final var db = Databases.openXdmDatabase(databaseFile)) {
db.createResource(new ResourceConfiguration.Builder("shredded").build());

try (final XdmResourceManager resMgr = db.getResourceManager("shredded");
try (final XdmResourceManager resMgr = db.openResourceManager("shredded");
final FileOutputStream outputStream = new FileOutputStream(target.toFile())) {
final XmlSerializer serializer = XmlSerializer.newBuilder(resMgr, outputStream).emitXMLDeclaration().build();
serializer.call();
@@ -141,7 +141,7 @@ public WikipediaImport(final Path xmlFile, final Path sirixDatabase) throws Siri
Databases.createXdmDatabase(config);
mDatabase = Databases.openXdmDatabase(sirixDatabase);
mDatabase.createResource(new ResourceConfiguration.Builder("shredded").build());
mResourceManager = mDatabase.getResourceManager("shredded");
mResourceManager = mDatabase.openResourceManager("shredded");
mWtx = mResourceManager.beginNodeTrx();
}

@@ -278,7 +278,7 @@ private void updateShredder() throws SirixException, IOException, XMLStreamExcep
Databases.createXdmDatabase(dbConf);
final var db = Databases.openXdmDatabase(path);
db.createResource(new ResourceConfiguration.Builder("wiki").build());
final XdmResourceManager resourceManager = db.getResourceManager("wiki");
final XdmResourceManager resourceManager = db.openResourceManager("wiki");
if (mPageEvents.peek().isStartElement()
&& !mPageEvents.peek().asStartElement().getName().getLocalPart().equals("root")) {
mPageEvents.addFirst(XMLEventFactory.newInstance().createStartElement(new QName("root"), null, null));
@@ -1154,7 +1154,7 @@ public static void main(final String[] args) {
Databases.createXdmDatabase(config);
final var db = Databases.openXdmDatabase(target);
db.createResource(new ResourceConfiguration.Builder("shredded").build());
try (final XdmResourceManager resMgr = db.getResourceManager("shredded");
try (final XdmResourceManager resMgr = db.openResourceManager("shredded");
final XdmNodeTrx wtx = resMgr.beginNodeTrx();
final FileInputStream fis = new FileInputStream(Paths.get(args[0]).toFile())) {
final XMLEventReader reader = XmlShredder.createFileReader(fis);
@@ -319,7 +319,7 @@ public static void main(final String... args) throws SirixException, IOException

try (final var db = Databases.openXdmDatabase(target)) {
db.createResource(new ResourceConfiguration.Builder("shredded").build());
try (final XdmResourceManager resMgr = db.getResourceManager("shredded");
try (final XdmResourceManager resMgr = db.openResourceManager("shredded");
final XdmNodeTrx wtx = resMgr.beginNodeTrx();
final FileInputStream fis = new FileInputStream(Paths.get(args[0]).toFile())) {
final XMLEventReader reader = createFileReader(fis);
@@ -345,7 +345,7 @@ public static void main(final String... args) throws SirixException, IOException
* @return an {@link XMLEventReader}
* @throws SirixException if creating the xml event reader fails.
*/
public static synchronized XMLEventReader createFileReader(final FileInputStream fis) {
public static XMLEventReader createFileReader(final FileInputStream fis) {
checkNotNull(fis);
final XMLInputFactory factory = XMLInputFactory.newInstance();
setProperties(factory);
@@ -369,7 +369,7 @@ private static void setProperties(final XMLInputFactory factory) {
* @return an {@link XMLEventReader}
* @throws SirixException if creating the xml event reader fails.
*/
public static synchronized XMLEventReader createStringReader(final String xmlString) {
public static XMLEventReader createStringReader(final String xmlString) {
checkNotNull(xmlString);
final XMLInputFactory factory = XMLInputFactory.newInstance();
setProperties(factory);
@@ -389,8 +389,7 @@ public static synchronized XMLEventReader createStringReader(final String xmlStr
* @throws IOException if I/O operation fails
* @throws XMLStreamException if any parsing error occurs
*/
public static synchronized XMLEventReader createQueueReader(final Queue<XMLEvent> events)
throws IOException, XMLStreamException {
public static XMLEventReader createQueueReader(final Queue<XMLEvent> events) throws IOException, XMLStreamException {
return new QueueEventReader(checkNotNull(events));
}
}
@@ -72,7 +72,7 @@ public static Holder generateDeweyIDResourceMgr() throws SirixException {
}
final var database = Databases.openXdmDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(XdmTestHelper.RESOURCE).useDeweyIDs(true).build());
final XdmResourceManager resourceManager = database.getResourceManager(XdmTestHelper.RESOURCE);
final XdmResourceManager resourceManager = database.openResourceManager(XdmTestHelper.RESOURCE);
final Holder holder = new Holder();
holder.setDatabase(database);
holder.setResourceManager(resourceManager);
@@ -93,7 +93,7 @@ public static Holder generatePathSummary() throws SirixException {
}
final var database = Databases.openXdmDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(XdmTestHelper.RESOURCE).buildPathSummary(true).build());
final XdmResourceManager resourceManager = database.getResourceManager(XdmTestHelper.RESOURCE);
final XdmResourceManager resourceManager = database.openResourceManager(XdmTestHelper.RESOURCE);
final Holder holder = new Holder();
holder.setDatabase(database);
holder.setResourceManager(resourceManager);
@@ -108,7 +108,7 @@ public static Holder generatePathSummary() throws SirixException {
*/
public static Holder openResourceManager() throws SirixException {
final var database = XdmTestHelper.getDatabase(PATHS.PATH1.getFile());
final XdmResourceManager resMgr = database.getResourceManager(XdmTestHelper.RESOURCE);
final XdmResourceManager resMgr = database.openResourceManager(XdmTestHelper.RESOURCE);
final Holder holder = new Holder();
holder.setDatabase(database);
holder.setResourceManager(resMgr);
@@ -164,7 +164,7 @@ public static final void closeEverything() {
public static void createTestDocument() {
final var database = JsonTestHelper.getDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(RESOURCE).build());
try (final JsonResourceManager manager = database.getResourceManager(RESOURCE);
try (final JsonResourceManager manager = database.openResourceManager(RESOURCE);
final JsonNodeTrx wtx = manager.beginNodeTrx()) {
JsonDocumentCreator.create(wtx);
wtx.commit();
@@ -201,7 +201,7 @@ public static StringBuilder readFile(final Path file, final boolean whitespaces)
public static void createTestDocument() {
final var database = XdmTestHelper.getDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(RESOURCE).build());
try (final XdmResourceManager manager = database.getResourceManager(RESOURCE);
try (final XdmResourceManager manager = database.openResourceManager(RESOURCE);
final XdmNodeTrx wtx = manager.beginNodeTrx()) {
XdmDocumentCreator.create(wtx);
wtx.commit();
@@ -216,7 +216,7 @@ public static void createTestDocument() {
public static void createPICommentTestDocument() {
final var database = XdmTestHelper.getDatabase(PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(RESOURCE).build());
try (final XdmResourceManager manager = database.getResourceManager(RESOURCE);
try (final XdmResourceManager manager = database.openResourceManager(RESOURCE);
final XdmNodeTrx wtx = manager.beginNodeTrx()) {
XdmDocumentCreator.createCommentPI(wtx);
wtx.commit();
@@ -218,7 +218,7 @@ private void testSetter(final XdmNodeTrx wtx) throws SirixException {
private XdmNodeTrx createWtx(final HashType kind) throws SirixException {
final var database = XdmTestHelper.getDatabase(XdmTestHelper.PATHS.PATH1.getFile());
database.createResource(new ResourceConfiguration.Builder(XdmTestHelper.RESOURCE).build());
final XdmResourceManager manager = database.getResourceManager(XdmTestHelper.RESOURCE);
final XdmResourceManager manager = database.openResourceManager(XdmTestHelper.RESOURCE);
final XdmNodeTrx wTrx = manager.beginNodeTrx();
return wTrx;
}
@@ -58,7 +58,7 @@ public void testEmptyRtx() {

try (final var db = Databases.openXdmDatabase(PATHS.PATH2.getFile())) {
db.createResource(new ResourceConfiguration.Builder(XdmTestHelper.RESOURCE).build());
try (final XdmResourceManager resMgr = db.getResourceManager(XdmTestHelper.RESOURCE);
try (final XdmResourceManager resMgr = db.openResourceManager(XdmTestHelper.RESOURCE);
final XdmNodeReadOnlyTrx rtx = resMgr.beginNodeReadOnlyTrx()) {
assertEquals(0, rtx.getRevisionNumber());
}
@@ -64,11 +64,11 @@ public void testSingleton() {
try (final var database = Holder.openResourceManager().getDatabase()) {
assertEquals(database, holder.getDatabase());

try (final XdmResourceManager manager = database.getResourceManager(XdmTestHelper.RESOURCE)) {
try (final XdmResourceManager manager = database.openResourceManager(XdmTestHelper.RESOURCE)) {
assertEquals(manager, holder.getResourceManager());
}

try (final XdmResourceManager manager2 = database.getResourceManager(XdmTestHelper.RESOURCE)) {
try (final XdmResourceManager manager2 = database.openResourceManager(XdmTestHelper.RESOURCE)) {
assertNotSame(manager2, holder.getResourceManager());
}
}
@@ -171,7 +171,7 @@ public void testShreddedRevision() {
@Test
public void testExisting() {
final var database = XdmTestHelper.getDatabase(PATHS.PATH1.getFile());
final XdmResourceManager resource = database.getResourceManager(XdmTestHelper.RESOURCE);
final XdmResourceManager resource = database.openResourceManager(XdmTestHelper.RESOURCE);

final XdmNodeTrx wtx1 = resource.beginNodeTrx();
XdmDocumentCreator.create(wtx1);
@@ -180,7 +180,7 @@ public void testExisting() {
wtx1.close();
resource.close();

final XdmResourceManager resource2 = database.getResourceManager(XdmTestHelper.RESOURCE);
final XdmResourceManager resource2 = database.openResourceManager(XdmTestHelper.RESOURCE);
final XdmNodeReadOnlyTrx rtx1 = resource2.beginNodeReadOnlyTrx();
assertEquals(1L, rtx1.getRevisionNumber());
rtx1.moveTo(12L);
@@ -199,7 +199,7 @@ public void testExisting() {
wtx2.close();

final var database2 = XdmTestHelper.getDatabase(PATHS.PATH1.getFile());
final XdmResourceManager resource3 = database2.getResourceManager(XdmTestHelper.RESOURCE);
final XdmResourceManager resource3 = database2.openResourceManager(XdmTestHelper.RESOURCE);
final XdmNodeReadOnlyTrx rtx2 = resource3.beginNodeReadOnlyTrx();
assertEquals(2L, rtx2.getRevisionNumber());
rtx2.moveTo(12L);
@@ -209,7 +209,7 @@ public void testLinguistics() throws Exception {
*/
private void test(final Path folder) throws Exception {
try (var database = XdmTestHelper.getDatabase(PATHS.PATH1.getFile())) {
XdmResourceManager resource = database.getResourceManager(XdmTestHelper.RESOURCE);
XdmResourceManager resource = database.openResourceManager(XdmTestHelper.RESOURCE);
Predicate<Path> fileNameFilter = path -> path.getFileName().toString().endsWith(".xml");
final List<Path> list = Files.list(folder).filter(fileNameFilter).collect(toList());

@@ -248,7 +248,7 @@ private void test(final Path folder) throws Exception {
}

resource.close();
resource = database.getResourceManager(XdmTestHelper.RESOURCE);
resource = database.openResourceManager(XdmTestHelper.RESOURCE);

final OutputStream out = new ByteArrayOutputStream();
final XmlSerializer serializer = new XmlSerializerBuilder(resource, out).build();
@@ -32,7 +32,7 @@ public void testJsonDocument() throws IOException {
JsonTestHelper.createTestDocument();

final var database = JsonTestHelper.getDatabase(PATHS.PATH1.getFile());
try (final var manager = database.getResourceManager(JsonTestHelper.RESOURCE);
try (final var manager = database.openResourceManager(JsonTestHelper.RESOURCE);
final Writer writer = new StringWriter()) {
final var serializer = new JsonSerializer.Builder(manager, writer).build();
serializer.call();
@@ -46,7 +46,7 @@ public void testMultipleRevisionsJsonDocument() throws IOException {
JsonTestHelper.createTestDocument();

final var database = JsonTestHelper.getDatabase(PATHS.PATH1.getFile());
try (final var manager = database.getResourceManager(JsonTestHelper.RESOURCE);
try (final var manager = database.openResourceManager(JsonTestHelper.RESOURCE);
final var writer = new StringWriter();
final var wtx = manager.beginNodeTrx()) {
wtx.moveToDocumentRoot().getCursor().moveToFirstChild();
Oops, something went wrong.

0 comments on commit 93223d2

Please sign in to comment.