Search in sources :

Example 21 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class DatabaseConfiguration method serialize.

/**
 * Serializing a {@link DatabaseConfiguration} to a json file.
 *
 * @param config to be serialized
 * @throws SirixIOException if an I/O error occurs
 */
public static void serialize(final DatabaseConfiguration config) throws SirixIOException {
    try (final FileWriter fileWriter = new FileWriter(config.getConfigFile().toFile());
        final JsonWriter jsonWriter = new JsonWriter(fileWriter)) {
        jsonWriter.beginObject();
        final String filePath = config.mFile.toAbsolutePath().toString();
        jsonWriter.name("file").value(filePath);
        jsonWriter.name("ID").value(config.mMaxResourceID);
        jsonWriter.name("max-resource-read-trx").value(config.mMaxResourceReadTrx);
        jsonWriter.endObject();
    } catch (final IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException) JsonWriter(com.google.gson.stream.JsonWriter) SirixIOException(org.sirix.exception.SirixIOException)

Example 22 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class DatabaseConfiguration method deserialize.

/**
 * Generate a DatabaseConfiguration out of a file.
 *
 * @param file where the DatabaseConfiguration lies in as json
 * @return a new {@link DatabaseConfiguration} class
 * @throws SirixIOException if an I/O error occurs
 */
public static DatabaseConfiguration deserialize(final Path file) throws SirixIOException {
    try (final FileReader fileReader = new FileReader(file.resolve(DatabasePaths.CONFIGBINARY.getFile()).toFile());
        final JsonReader jsonReader = new JsonReader(fileReader)) {
        jsonReader.beginObject();
        final String fileName = jsonReader.nextName();
        assert fileName.equals("file");
        final Path dbFile = Paths.get(jsonReader.nextString());
        final String IDName = jsonReader.nextName();
        assert IDName.equals("ID");
        final int ID = jsonReader.nextInt();
        final String maxResourceRtxName = jsonReader.nextName();
        assert maxResourceRtxName.equals("max-resource-read-trx");
        final int maxResourceRtx = jsonReader.nextInt();
        jsonReader.endObject();
        return new DatabaseConfiguration(dbFile).setMaximumResourceID(ID).setMaxResourceReadTrx(maxResourceRtx);
    } catch (final IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : Path(java.nio.file.Path) JsonReader(com.google.gson.stream.JsonReader) FileReader(java.io.FileReader) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException)

Example 23 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class XMarkBenchQueries method getQuery.

/**
 * Return the query by query number and factor
 *
 * @param queryNr XMark query number.
 * @param factor Factor of XML size.
 * @return query Query by number and factor.
 */
public String getQuery(final int queryNr, final String factor) {
    final StringBuilder sb = new StringBuilder();
    sb.append("Q");
    sb.append(Integer.toString(queryNr));
    sb.append("_Fac");
    String fac = null;
    if (factor.equals("0.01")) {
        fac = "001";
    } else if (factor.equals("0.1")) {
        fac = "01";
    } else if (factor.equals("1.0")) {
        fac = "1";
    } else if (factor.equals("10.0")) {
        fac = "10";
    } else {
        try {
            throw new SirixIOException("XMark Benchmarking query factor does not exist!");
        } catch (final SirixIOException mExp) {
            mExp.printStackTrace();
        }
    }
    sb.append(fac);
    String queryValue = null;
    try {
        final Field privateStringField = XMarkBenchQueries.class.getDeclaredField(sb.toString());
        privateStringField.setAccessible(true);
        queryValue = (String) privateStringField.get(this);
    } catch (final Exception mExp) {
        mExp.printStackTrace();
    }
    return queryValue;
}
Also used : Field(java.lang.reflect.Field) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException)

Example 24 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class XMLShredder method insertNewContent.

/**
 * Insert new content based on a StAX parser {@link XMLStreamReader}.
 *
 * @throws SirixException if something went wrong while inserting
 */
protected final void insertNewContent() throws SirixException {
    try {
        boolean firstElement = true;
        int level = 0;
        QName rootElement = null;
        boolean endElemReached = false;
        final StringBuilder sBuilder = new StringBuilder();
        long insertedRootNodeKey = -1;
        // Iterate over all nodes.
        while (mReader.hasNext() && !endElemReached) {
            final XMLEvent event = mReader.nextEvent();
            switch(event.getEventType()) {
                case XMLStreamConstants.START_ELEMENT:
                    level++;
                    addNewElement(event.asStartElement());
                    if (firstElement) {
                        firstElement = false;
                        insertedRootNodeKey = mWtx.getNodeKey();
                        rootElement = event.asStartElement().getName();
                    }
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    level--;
                    if (level == 0 && rootElement != null && rootElement.equals(event.asEndElement().getName())) {
                        endElemReached = true;
                    }
                    final QName name = event.asEndElement().getName();
                    processEndTag(new QNm(name.getNamespaceURI(), name.getPrefix(), name.getLocalPart()));
                    break;
                case XMLStreamConstants.CHARACTERS:
                    if (mReader.peek().getEventType() == XMLStreamConstants.CHARACTERS) {
                        sBuilder.append(event.asCharacters().getData().trim());
                    } else {
                        sBuilder.append(event.asCharacters().getData().trim());
                        processText(sBuilder.toString());
                        sBuilder.setLength(0);
                    }
                    break;
                case XMLStreamConstants.COMMENT:
                    if (mIncludeComments) {
                        processComment(((Comment) event).getText());
                    }
                    break;
                case XMLStreamConstants.PROCESSING_INSTRUCTION:
                    if (mIncludePIs) {
                        final ProcessingInstruction pi = (ProcessingInstruction) event;
                        processPI(pi.getData(), pi.getTarget());
                    }
                    break;
                default:
            }
        }
        mWtx.moveTo(insertedRootNodeKey);
    } catch (final XMLStreamException e) {
        throw new SirixIOException(e);
    }
}
Also used : QNm(org.brackit.xquery.atomic.QNm) XMLStreamException(javax.xml.stream.XMLStreamException) QName(javax.xml.namespace.QName) XMLEvent(javax.xml.stream.events.XMLEvent) SirixIOException(org.sirix.exception.SirixIOException) ProcessingInstruction(javax.xml.stream.events.ProcessingInstruction)

Example 25 with SirixIOException

use of org.sirix.exception.SirixIOException in project sirix by sirixdb.

the class UnorderedKeyValuePage method getValue.

@Override
public Record getValue(final Long key) {
    assert key != null : "key must not be null!";
    Record record = mRecords.get(key);
    if (record == null) {
        byte[] data = null;
        try {
            final PageReference reference = mReferences.get(key);
            if (reference != null && reference.getKey() != Constants.NULL_ID_LONG) {
                data = ((OverflowPage) mPageReadTrx.getReader().read(reference, mPageReadTrx)).getData();
            } else {
                return null;
            }
        } catch (final SirixIOException e) {
            return null;
        }
        final InputStream in = new ByteArrayInputStream(data);
        try {
            record = mPersistenter.deserialize(new DataInputStream(in), key, Optional.empty(), null);
        } catch (final IOException e) {
            return null;
        }
        mRecords.put(key, record);
    }
    return record;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Record(org.sirix.node.interfaces.Record) SirixIOException(org.sirix.exception.SirixIOException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) SirixIOException(org.sirix.exception.SirixIOException)

Aggregations

SirixIOException (org.sirix.exception.SirixIOException)42 IOException (java.io.IOException)14 DatabaseException (com.sleepycat.je.DatabaseException)9 DatabaseEntry (com.sleepycat.je.DatabaseEntry)7 UberPage (org.sirix.page.UberPage)6 OperationStatus (com.sleepycat.je.OperationStatus)5 Path (java.nio.file.Path)5 QNm (org.brackit.xquery.atomic.QNm)5 PageReference (org.sirix.page.PageReference)5 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)5 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Str (org.brackit.xquery.atomic.Str)4 Page (org.sirix.page.interfaces.Page)4 UncheckedIOException (java.io.UncheckedIOException)3 HashSet (java.util.HashSet)3 QueryException (org.brackit.xquery.QueryException)3 Item (org.brackit.xquery.xdm.Item)3 Iter (org.brackit.xquery.xdm.Iter)3 IndexController (org.sirix.access.IndexController)3