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);
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations