2015-01-21 21:58:35 +01:00
|
|
|
/*******************************************************************************
|
2021-01-09 14:26:49 +01:00
|
|
|
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
|
2015-01-21 21:58:35 +01:00
|
|
|
* 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
|
|
|
|
*******************************************************************************/
|
2015-01-03 16:34:32 +01:00
|
|
|
package com.minres.scviewer.database.sqlite;
|
|
|
|
|
|
|
|
import java.beans.IntrospectionException;
|
2021-01-09 20:10:58 +01:00
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
import java.beans.PropertyChangeSupport;
|
2015-01-03 16:34:32 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
2015-11-15 22:15:37 +01:00
|
|
|
import java.util.Collection;
|
2015-01-03 16:34:32 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-01-06 17:14:16 +01:00
|
|
|
import com.minres.scviewer.database.IWaveform;
|
2015-01-10 00:23:46 +01:00
|
|
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
2020-11-29 10:25:48 +01:00
|
|
|
import com.minres.scviewer.database.InputFormatException;
|
2015-11-15 22:15:37 +01:00
|
|
|
import com.minres.scviewer.database.RelationType;
|
2015-01-03 16:34:32 +01:00
|
|
|
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
2015-01-06 17:14:16 +01:00
|
|
|
import com.minres.scviewer.database.sqlite.db.SQLiteDatabase;
|
2015-01-03 16:34:32 +01:00
|
|
|
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
|
|
|
|
import com.minres.scviewer.database.sqlite.tables.ScvSimProps;
|
|
|
|
import com.minres.scviewer.database.sqlite.tables.ScvStream;
|
|
|
|
import com.minres.scviewer.database.sqlite.tables.ScvTxEvent;
|
|
|
|
|
2015-01-10 00:23:46 +01:00
|
|
|
public class SQLiteDbLoader implements IWaveformDbLoader {
|
2015-01-03 16:34:32 +01:00
|
|
|
|
|
|
|
protected IDatabase database;
|
|
|
|
|
2015-11-15 22:15:37 +01:00
|
|
|
private List<RelationType> usedRelationsList = new ArrayList<>();
|
2015-01-03 16:34:32 +01:00
|
|
|
|
2015-01-21 21:58:35 +01:00
|
|
|
private ScvSimProps scvSimProps;
|
|
|
|
|
2021-01-09 20:10:58 +01:00
|
|
|
/** The pcs. */
|
|
|
|
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
|
|
|
|
2015-01-03 16:34:32 +01:00
|
|
|
@Override
|
2021-02-27 14:59:00 +01:00
|
|
|
public long getMaxTime() {
|
2020-11-29 10:25:48 +01:00
|
|
|
SQLiteDatabaseSelectHandler<ScvTxEvent> handler = new SQLiteDatabaseSelectHandler<>(ScvTxEvent.class,
|
2015-01-20 18:50:15 +01:00
|
|
|
database, "time = (SELECT MAX(time) FROM ScvTxEvent)");
|
2015-01-03 16:34:32 +01:00
|
|
|
try {
|
|
|
|
List<ScvTxEvent> event = handler.selectObjects();
|
2020-11-29 10:25:48 +01:00
|
|
|
if(!event.isEmpty())
|
2015-01-21 21:58:35 +01:00
|
|
|
return event.get(0).getTime()*scvSimProps.getTime_resolution();
|
2015-01-03 16:34:32 +01:00
|
|
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
2021-02-18 07:32:14 +01:00
|
|
|
| InvocationTargetException | SQLException | IntrospectionException | NoSuchMethodException e) {
|
2015-01-03 16:34:32 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2015-01-20 18:50:15 +01:00
|
|
|
return 0L;
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-02 14:13:39 +02:00
|
|
|
public Collection<IWaveform> getAllWaves() {
|
2020-11-29 10:25:48 +01:00
|
|
|
SQLiteDatabaseSelectHandler<ScvStream> handler = new SQLiteDatabaseSelectHandler<>(ScvStream.class, database);
|
|
|
|
List<IWaveform> streams=new ArrayList<>();
|
2015-10-22 00:02:58 +02:00
|
|
|
try {
|
|
|
|
for(ScvStream scvStream:handler.selectObjects()){
|
2021-01-02 17:02:05 +01:00
|
|
|
TxStream stream = new TxStream(database, scvStream);
|
2015-11-15 22:15:37 +01:00
|
|
|
stream.setRelationTypeList(usedRelationsList);
|
2015-10-22 00:02:58 +02:00
|
|
|
streams.add(stream);
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
2015-10-22 00:02:58 +02:00
|
|
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
2021-02-18 07:32:14 +01:00
|
|
|
| InvocationTargetException | SQLException | IntrospectionException | NoSuchMethodException e) {
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
return streams;
|
|
|
|
}
|
|
|
|
|
2022-05-17 16:40:56 +02:00
|
|
|
// @Override
|
|
|
|
// public boolean canLoad(File inputFile) {
|
|
|
|
// if (!inputFile.isDirectory() && inputFile.exists()) {
|
|
|
|
// try(InputStream stream = new FileInputStream(inputFile)){
|
|
|
|
// byte[] buffer = new byte[x.length];
|
|
|
|
// int readCnt = stream.read(buffer, 0, x.length);
|
|
|
|
// if (readCnt == x.length) {
|
|
|
|
// for (int i = 0; i < x.length; i++)
|
|
|
|
// if (buffer[i] != x[i])
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
// }
|
2015-01-10 00:23:46 +01:00
|
|
|
|
2015-01-03 16:34:32 +01:00
|
|
|
@Override
|
2023-02-27 13:07:10 +01:00
|
|
|
public void load(File file) throws InputFormatException {
|
|
|
|
database=new SQLiteDatabase(file.getAbsolutePath());
|
2015-01-10 00:23:46 +01:00
|
|
|
database.setData("TIMERESOLUTION", 1L);
|
2020-11-29 10:25:48 +01:00
|
|
|
SQLiteDatabaseSelectHandler<ScvSimProps> handler = new SQLiteDatabaseSelectHandler<>(ScvSimProps.class, database);
|
2015-01-03 16:34:32 +01:00
|
|
|
try {
|
2015-01-21 21:58:35 +01:00
|
|
|
for(ScvSimProps simProps:handler.selectObjects()){
|
|
|
|
scvSimProps=simProps;
|
2015-01-10 00:23:46 +01:00
|
|
|
database.setData("TIMERESOLUTION", scvSimProps.getTime_resolution());
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
2021-01-09 20:10:58 +01:00
|
|
|
pcs.firePropertyChange(IWaveformDbLoader.LOADING_FINISHED, null, null);
|
2015-01-03 16:34:32 +01:00
|
|
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
2021-02-18 07:32:14 +01:00
|
|
|
| InvocationTargetException | SQLException | IntrospectionException | NoSuchMethodException e) {
|
2021-01-09 23:24:00 +01:00
|
|
|
throw new InputFormatException(e.toString());
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-08 15:04:30 +01:00
|
|
|
|
|
|
|
public void dispose() {
|
|
|
|
database=null;
|
|
|
|
usedRelationsList=null;
|
|
|
|
}
|
|
|
|
|
2015-11-15 22:15:37 +01:00
|
|
|
@Override
|
|
|
|
public Collection<RelationType> getAllRelationTypes(){
|
|
|
|
return usedRelationsList;
|
|
|
|
}
|
|
|
|
|
2021-01-09 20:10:58 +01:00
|
|
|
/**
|
|
|
|
* Adds the property change listener.
|
|
|
|
*
|
|
|
|
* @param l the l
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void addPropertyChangeListener(PropertyChangeListener l) {
|
|
|
|
pcs.addPropertyChangeListener(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the property change listener.
|
|
|
|
*
|
|
|
|
* @param l the l
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void removePropertyChangeListener(PropertyChangeListener l) {
|
|
|
|
pcs.removePropertyChangeListener(l);
|
|
|
|
}
|
|
|
|
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|