Added LevelDB transaction db reader
This commit is contained in:
parent
97a806f9d9
commit
8d7acdb9cb
9
com.minres.scviewer.database.leveldb/.classpath
Normal file
9
com.minres.scviewer.database.leveldb/.classpath
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry exported="true" kind="lib" path="json-20180813.jar" sourcepath="json-20180813-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="leveldb-0.11-SNAPSHOT-uber.jar" sourcepath="leveldb-0.11-SNAPSHOT-sources.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
4
com.minres.scviewer.database.leveldb/.gitignore
vendored
Normal file
4
com.minres.scviewer.database.leveldb/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/json-20180813-sources.jar
|
||||
/leveldb-0.11-SNAPSHOT-sources.jar
|
||||
/bin/
|
||||
/target/
|
33
com.minres.scviewer.database.leveldb/.project
Normal file
33
com.minres.scviewer.database.leveldb/.project
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.minres.scviewer.database.leveldb</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ds.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
pluginProject.equinox=false
|
||||
pluginProject.extensions=false
|
||||
resolve.requirebundle=false
|
@ -0,0 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
enabled=true
|
||||
path=OSGI-INF
|
||||
validationErrorLevel=error
|
||||
validationErrorLevel.missingImplicitUnbindMethod=error
|
18
com.minres.scviewer.database.leveldb/META-INF/MANIFEST.MF
Normal file
18
com.minres.scviewer.database.leveldb/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,18 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Leveldb
|
||||
Bundle-SymbolicName: com.minres.scviewer.database.leveldb
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Import-Package: org.osgi.framework;version="1.3.0"
|
||||
Automatic-Module-Name: com.minres.scviewer.database.leveldb
|
||||
Service-Component: OSGI-INF/*.xml
|
||||
Require-Bundle: com.minres.scviewer.database;bundle-version="1.0.0",
|
||||
org.eclipse.equinox.util;bundle-version="1.0.500",
|
||||
org.eclipse.equinox.ds;bundle-version="1.4.200",
|
||||
org.eclipse.osgi.services;bundle-version="3.4.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-ClassPath: leveldb-0.11-SNAPSHOT-uber.jar,
|
||||
.,
|
||||
json-20180813.jar
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="LevelDbLoader">
|
||||
<implementation class="com.minres.scviewer.database.leveldb.LevelDBLoader"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoader"/>
|
||||
</service>
|
||||
</scr:component>
|
7
com.minres.scviewer.database.leveldb/build.properties
Normal file
7
com.minres.scviewer.database.leveldb/build.properties
Normal file
@ -0,0 +1,7 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
OSGI-INF/,\
|
||||
leveldb-0.11-SNAPSHOT-uber.jar,\
|
||||
json-20180813.jar
|
BIN
com.minres.scviewer.database.leveldb/json-20180813-sources.jar
Normal file
BIN
com.minres.scviewer.database.leveldb/json-20180813-sources.jar
Normal file
Binary file not shown.
BIN
com.minres.scviewer.database.leveldb/json-20180813.jar
Normal file
BIN
com.minres.scviewer.database.leveldb/json-20180813.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
43
com.minres.scviewer.database.leveldb/pom.xml
Normal file
43
com.minres.scviewer.database.leveldb/pom.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>com.minres.scviewer.database.leveldb</artifactId>
|
||||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../com.minres.scviewer.parent</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-compiler-plugin</artifactId>
|
||||
<version>0.23.1</version>
|
||||
<configuration>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
<!-- set verbose to be true if you want lots of uninteresting messages -->
|
||||
<!-- <verbose>true</verbose> -->
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>${groovy-eclipse-compiler-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-batch</artifactId>
|
||||
<version>${groovy-eclipse-batch-version}</version>
|
||||
<!-- or choose a different compiler version -->
|
||||
<!-- <version>2.1.8-01</version> -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</project>
|
@ -0,0 +1,85 @@
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.iq80.leveldb.Options;
|
||||
import org.iq80.leveldb.impl.SeekingIterator;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
public class LevelDBLoader implements IWaveformDbLoader {
|
||||
|
||||
static byte[] toByteArray(String value) {
|
||||
return value.getBytes(UTF_8);
|
||||
}
|
||||
|
||||
private StringDBWrapper levelDb;
|
||||
private IWaveformDb db;
|
||||
private Long maxTime=null;
|
||||
private List<RelationType> usedRelationsList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean load(IWaveformDb db, File inp) throws Exception {
|
||||
try {
|
||||
this.db=db;
|
||||
levelDb = new StringDBWrapper(new Options(), inp);
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getMaxTime() {
|
||||
if(maxTime==null) {
|
||||
SeekingIterator<String, String> it = levelDb.iterator();
|
||||
it.seek("st~");
|
||||
Entry<String, String> val = null;
|
||||
while(it.hasNext()) {
|
||||
Entry<String, String> v = it.next();
|
||||
if(!v.getKey().startsWith("st~")) continue;
|
||||
val=v;
|
||||
}
|
||||
if(val==null)
|
||||
maxTime = 0L;
|
||||
else {
|
||||
String[] token = val.getKey().split("~");
|
||||
maxTime = Long.parseLong(token[2], 16);
|
||||
}
|
||||
}
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IWaveform<? extends IWaveformEvent>> getAllWaves() {
|
||||
List<IWaveform<? extends IWaveformEvent>> streams=new ArrayList<IWaveform<? extends IWaveformEvent>>();
|
||||
SeekingIterator<String, String> it = levelDb.iterator();
|
||||
it.seek("s~");
|
||||
while(it.hasNext()) {
|
||||
Entry<String, String> val = it.next();
|
||||
if(!val.getKey().startsWith("s~")) break;
|
||||
TxStream stream = new TxStream(levelDb, db, new JSONObject(val.getValue()));
|
||||
stream.setRelationTypeList(usedRelationsList);
|
||||
streams.add(stream);
|
||||
}
|
||||
return streams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RelationType> getAllRelationTypes() {
|
||||
// return Collections.emptyList();
|
||||
return usedRelationsList;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.iq80.leveldb.Options;
|
||||
import org.iq80.leveldb.Range;
|
||||
import org.iq80.leveldb.ReadOptions;
|
||||
import org.iq80.leveldb.Snapshot;
|
||||
import org.iq80.leveldb.impl.DbImpl;
|
||||
import org.iq80.leveldb.impl.SeekingIterator;
|
||||
import org.json.*;
|
||||
|
||||
class StringDBWrapper {
|
||||
private final Options options;
|
||||
private final File databaseDir;
|
||||
private DbImpl db;
|
||||
|
||||
StringDBWrapper(Options options, File databaseDir) throws IOException {
|
||||
this.options = options.verifyChecksums(true).createIfMissing(false).errorIfExists(false);
|
||||
this.databaseDir = databaseDir;
|
||||
this.db = new DbImpl(options, databaseDir);
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
byte[] slice = db.get(LevelDBLoader.toByteArray(key));
|
||||
if (slice == null) {
|
||||
return null;
|
||||
}
|
||||
return new String(slice, UTF_8);
|
||||
}
|
||||
|
||||
public String get(String key, Snapshot snapshot) {
|
||||
byte[] slice = db.get(LevelDBLoader.toByteArray(key), new ReadOptions().snapshot(snapshot));
|
||||
if (slice == null) {
|
||||
return null;
|
||||
}
|
||||
return new String(slice, UTF_8);
|
||||
}
|
||||
|
||||
public void put(String key, String value) {
|
||||
db.put(LevelDBLoader.toByteArray(key), LevelDBLoader.toByteArray(value));
|
||||
}
|
||||
|
||||
public void delete(String key) {
|
||||
db.delete(LevelDBLoader.toByteArray(key));
|
||||
}
|
||||
|
||||
public SeekingIterator<String, String> iterator() {
|
||||
return new StringDbIterator(db.iterator());
|
||||
}
|
||||
|
||||
public Snapshot getSnapshot() {
|
||||
return db.getSnapshot();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
db.close();
|
||||
}
|
||||
|
||||
public long size(String start, String limit) {
|
||||
return db.getApproximateSizes(new Range(LevelDBLoader.toByteArray(start), LevelDBLoader.toByteArray(limit)));
|
||||
}
|
||||
|
||||
public long getMaxNextLevelOverlappingBytes() {
|
||||
return db.getMaxNextLevelOverlappingBytes();
|
||||
}
|
||||
|
||||
public void reopen() throws IOException {
|
||||
reopen(options);
|
||||
}
|
||||
|
||||
public void reopen(Options options) throws IOException {
|
||||
db.close();
|
||||
db = new DbImpl(options.verifyChecksums(true).createIfMissing(false).errorIfExists(false), databaseDir);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.iq80.leveldb.shaded.guava.collect.Maps.immutableEntry;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.iq80.leveldb.DBIterator;
|
||||
import org.iq80.leveldb.impl.SeekingIterator;
|
||||
|
||||
class StringDbIterator implements SeekingIterator<String, String> {
|
||||
private final DBIterator iterator;
|
||||
|
||||
StringDbIterator(DBIterator iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekToFirst() {
|
||||
iterator.seekToFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seek(String targetKey) {
|
||||
iterator.seek(targetKey.getBytes(UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<String, String> peek() {
|
||||
return adapt(iterator.peekNext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<String, String> next() {
|
||||
return adapt(iterator.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private Entry<String, String> adapt(Entry<byte[], byte[]> next) {
|
||||
return immutableEntry(new String(next.getKey(), UTF_8), new String(next.getValue(), UTF_8));
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
|
||||
public class Tx implements ITx {
|
||||
|
||||
private StringDBWrapper levelDb;
|
||||
private TxStream trStream;
|
||||
private TxGenerator trGenerator;
|
||||
private long id;
|
||||
private JSONObject dbVal;
|
||||
private List<ITxAttribute> attributes;
|
||||
private List<ITxRelation> incoming, outgoing;
|
||||
|
||||
public Tx(StringDBWrapper levelDb, TxStream trStream, TxGenerator trGenerator, long id) {
|
||||
this.levelDb=levelDb;
|
||||
this.trStream=trStream;
|
||||
this.trGenerator=trGenerator;
|
||||
this.id=id;
|
||||
this.dbVal=null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITxStream<ITxEvent> getStream() {
|
||||
return trStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITxGenerator getGenerator() {
|
||||
return trGenerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConcurrencyIndex() {
|
||||
checkDb();
|
||||
return dbVal.getInt("conc");
|
||||
}
|
||||
|
||||
private void checkDb() throws JSONException {
|
||||
if(dbVal==null) {
|
||||
dbVal = new JSONObject(levelDb.get("x~"+ String.format("%016x", id)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getBeginTime() {
|
||||
checkDb();
|
||||
return dbVal.getLong("START_TIME");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getEndTime() {
|
||||
checkDb();
|
||||
return dbVal.getLong("END_TIME");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
if(attributes==null) {
|
||||
checkDb();
|
||||
attributes=new ArrayList<>();
|
||||
JSONArray arr = dbVal.getJSONArray("attr");
|
||||
arr.forEach(entry -> {
|
||||
TxAttribute attr = new TxAttribute(this, (JSONObject) entry);
|
||||
attributes.add(attr);
|
||||
});
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
return incoming;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ITx o) {
|
||||
int res = this.getBeginTime().compareTo(o.getBeginTime());
|
||||
if(res!=0)
|
||||
return res;
|
||||
else
|
||||
return this.getId().compareTo(o.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]";
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
|
||||
public class TxAttribute implements ITxAttribute{
|
||||
|
||||
private Tx trTransaction;
|
||||
|
||||
private String name;
|
||||
|
||||
private DataType dataType;
|
||||
|
||||
private AssociationType associationType;
|
||||
|
||||
private Object value;
|
||||
|
||||
public TxAttribute(Tx trTransaction, JSONObject attribute) {
|
||||
this.trTransaction=trTransaction;
|
||||
this.name=attribute.getString("name");
|
||||
this.dataType=DataType.values()[attribute.getInt("type")];
|
||||
this.associationType=AssociationType.values()[attribute.getInt("assoc")];
|
||||
this.value=attribute.get("value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
return associationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
|
||||
public class TxEvent implements ITxEvent {
|
||||
|
||||
private final Type type;
|
||||
private ITx tx;
|
||||
|
||||
public TxEvent(Type type, ITx tx) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.tx = tx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTime() {
|
||||
return type==Type.BEGIN?tx.getBeginTime():tx.getEndTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformEvent duplicate() throws CloneNotSupportedException {
|
||||
return new TxEvent(type, tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IWaveformEvent o) {
|
||||
return getTime().compareTo(o.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITx getTransaction() {
|
||||
return tx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type.toString()+"@"+getTime()+" of tx #"+tx.getId();
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
|
||||
public class TxGenerator implements ITxGenerator {
|
||||
|
||||
private ITxStream<ITxEvent> stream;
|
||||
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public TxGenerator(ITxStream<ITxEvent> stream, JSONObject object) {
|
||||
this.stream=stream;
|
||||
this.id=object.getLong("id");
|
||||
this.name=object.getString("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITxStream<ITxEvent> getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITx> getTransactions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
public class TxRelation implements ITxRelation {
|
||||
|
||||
RelationType relationType;
|
||||
Tx source, target;
|
||||
|
||||
public TxRelation(RelationType relationType, Tx source, Tx target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.relationType = relationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RelationType getRelationType() {
|
||||
return relationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITx getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITx getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.leveldb;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.iq80.leveldb.impl.SeekingIterator;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.NavigableMap;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
public class TxStream extends HierNode implements ITxStream<ITxEvent> {
|
||||
|
||||
private StringDBWrapper levelDb;
|
||||
|
||||
private String fullName;
|
||||
|
||||
private String kind;
|
||||
|
||||
private IWaveformDb db;
|
||||
|
||||
private long id;
|
||||
|
||||
private TreeMap<Long, TxGenerator> generators;
|
||||
|
||||
private TreeMap<Long, ITx> transactions;
|
||||
|
||||
private Integer maxConcurrency;
|
||||
|
||||
private TreeMap<Long, List<ITxEvent>> events;
|
||||
|
||||
private List<RelationType> usedRelationsList;
|
||||
|
||||
public TxStream(StringDBWrapper database, IWaveformDb waveformDb, JSONObject object) {
|
||||
super(object.get("name").toString());
|
||||
this.levelDb=database;
|
||||
this.db=waveformDb;
|
||||
this.fullName=object.getString("name");
|
||||
this.kind=object.getString("kind");
|
||||
this.id = object.getLong("id");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITxGenerator> getGenerators() {
|
||||
if(generators==null){
|
||||
generators=new TreeMap<Long, TxGenerator>();
|
||||
SeekingIterator<String, String> it = levelDb.iterator();
|
||||
it.seek("sg~"+String.format("%016x", id));
|
||||
while(it.hasNext()) {
|
||||
Entry<String, String> val = it.next();
|
||||
if(!val.getKey().startsWith("sg~")) break;
|
||||
JSONObject jVal = new JSONObject(val.getValue());
|
||||
generators.put(jVal.getLong("id"), new TxGenerator(this, jVal));
|
||||
}
|
||||
}
|
||||
return new ArrayList<ITxGenerator>(generators.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxConcurrency() {
|
||||
if(maxConcurrency==null){
|
||||
maxConcurrency=1;
|
||||
}
|
||||
return maxConcurrency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableMap<Long, List<ITxEvent>> getEvents(){
|
||||
if(events==null){
|
||||
events=new TreeMap<Long, List<ITxEvent>>();
|
||||
for(Entry<Long, ITx> entry:getTransactions().entrySet()){
|
||||
putEvent(new TxEvent(TxEvent.Type.BEGIN, entry.getValue()));
|
||||
putEvent(new TxEvent(TxEvent.Type.END, entry.getValue()));
|
||||
}
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
private void putEvent(TxEvent ev){
|
||||
Long time = ev.getTime();
|
||||
if(!events.containsKey(time)){
|
||||
Vector<ITxEvent> vector=new Vector<ITxEvent>();
|
||||
vector.add(ev);
|
||||
events.put(time, vector);
|
||||
} else {
|
||||
events.get(time).add(ev);
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<Long, ITx> getTransactions() {
|
||||
if(transactions==null){
|
||||
if(generators==null) getGenerators();
|
||||
transactions = new TreeMap<Long, ITx>();
|
||||
SeekingIterator<String, String> it = levelDb.iterator();
|
||||
it.seek("sgx~"+String.format("%016x", id));
|
||||
while(it.hasNext()) {
|
||||
Entry<String, String> val = it.next();
|
||||
if(!val.getKey().startsWith("sgx~")) break;
|
||||
String[] token = val.getKey().split("~");
|
||||
long gid = Long.parseLong(token[2], 16); // gen id
|
||||
long id = Long.parseLong(token[3], 16); // tx id
|
||||
transactions.put(id, new Tx(levelDb, this, generators.get(gid), id));
|
||||
}
|
||||
}
|
||||
return transactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxEvent> getWaveformEventsAtTime(Long time) {
|
||||
return getEvents().get(time);
|
||||
}
|
||||
|
||||
public void setRelationTypeList(List<RelationType> usedRelationsList){
|
||||
this.usedRelationsList=usedRelationsList;
|
||||
}
|
||||
|
||||
public RelationType getRelationType(String name) {
|
||||
RelationType relType=RelationType.create(name);
|
||||
if(!usedRelationsList.contains(relType)) usedRelationsList.add(relType);
|
||||
return relType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean equals(IWaveform<? extends IWaveformEvent> other) {
|
||||
return(other instanceof TxStream && this.getId()==other.getId());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>com.minres.scviewer.database.text</artifactId>
|
||||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../com.minres.scviewer.parent</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-compiler-plugin</artifactId>
|
||||
<version>0.23.1</version>
|
||||
<configuration>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
<!-- set verbose to be true if you want lots of uninteresting messages -->
|
||||
<!-- <verbose>true</verbose> -->
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>${groovy-eclipse-compiler-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-batch</artifactId>
|
||||
<version>${groovy-eclipse-batch-version}</version>
|
||||
<!-- or choose a different compiler version -->
|
||||
<!-- <version>2.1.8-01</version> -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</project>
|
Loading…
Reference in New Issue
Block a user