Skip to content

Commit

Permalink
Revert last commit because SqlJet doesn't support parallel read.
Browse files Browse the repository at this point in the history
This reverts commit 1e69e23.
  • Loading branch information
Sheep-y committed Aug 4, 2016
1 parent 1e69e23 commit faebd4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
7 changes: 0 additions & 7 deletions java/db4e/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import netscape.javascript.JSException;
import org.tmatesoft.sqljet.core.SqlJetException;
import org.tmatesoft.sqljet.core.table.SqlJetDb;
import org.w3c.dom.Document;
import sheepy.util.Utils;
Expand Down Expand Up @@ -260,7 +259,6 @@ private void openOrCreateTable () {
synchronized ( categories ) {
dal.setDb( db, categories, state );
}
loadIndex();

} catch ( Exception e1 ) {

Expand All @@ -270,7 +268,6 @@ private void openOrCreateTable () {
synchronized ( categories ) {
dal.setDb( db, categories, state );
}
loadIndex();

} catch ( Exception e2 ) {
log.log( Level.SEVERE, "Cannot create tables: {0}", Utils.stacktrace( e2 ) );
Expand All @@ -292,10 +289,6 @@ private void openOrCreateTable () {
state.update();
}

private void loadIndex() throws SqlJetException {
dal.loadEntryIndex( categories, state );
}

/**
* If current database is bigger than last backup, update the backup.
*/
Expand Down
13 changes: 9 additions & 4 deletions java/db4e/controller/DbAbstraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.tmatesoft.sqljet.core.table.SqlJetDb;
import sheepy.util.JavaFX;

/**
* Database abstraction.
* Note that SqlJet does not support multi-thread.
*/
class DbAbstraction {

private static final Logger log = Main.log;
Expand Down Expand Up @@ -46,6 +50,7 @@ void setDb ( SqlJetDb db, ObservableList<Category> categories, ProgressState sta
log.log( Level.CONFIG, "Database version {0,number,#}, opened.", version );

loadCategory( categories );
loadEntryIndex( categories, state );
}

void createTables () throws SqlJetException {
Expand Down Expand Up @@ -137,7 +142,7 @@ private void loadCategory ( ObservableList<Category> categories ) throws SqlJetE
// TODO: Backup good db.
}

void loadEntryIndex ( List<Category> categories, ProgressState state ) throws SqlJetException {
private void loadEntryIndex ( List<Category> categories, ProgressState state ) throws SqlJetException {
int downCount = 0;
state.reset();

Expand All @@ -149,7 +154,7 @@ void loadEntryIndex ( List<Category> categories, ProgressState state ) throws Sq
state.total = total;
cursor.close();

for ( Category category : categories ) {
for ( Category category : categories ) synchronized( category ) {
int countWithData = 0, size = category.total_entry.get();
List<Entry> list = category.entries;
list.clear();
Expand Down Expand Up @@ -184,7 +189,7 @@ void loadEntityContent ( List<Category> categories, ProgressState state ) throws
db.beginTransaction( SqlJetTransactionMode.READ_ONLY );
try {
ISqlJetTable tblEntry = db.getTable( "entry" );
for ( Category category : categories ) {
for ( Category category : categories ) synchronized( category ) {
log.log( Level.FINE, "Loading {0} content", category.id );
for ( Entry entry : category.entries ) {
if ( entry.fields == null || entry.content == null ) {
Expand Down Expand Up @@ -265,7 +270,7 @@ void saveEntry ( Entry entry ) throws SqlJetException {
// Utils
/////////////////////////////////////////////////////////////////////////////

private static final String csvTokenPattern = "(?<=^|,)([^\"\\r\\n,]*|\"(?:\"\"|[^\"])*\")(?:,|$)";
private final String csvTokenPattern = "(?<=^|,)([^\"\\r\\n,]*|\"(?:\"\"|[^\"])*\")(?:,|$)";
private final Matcher csvToken = Pattern.compile( csvTokenPattern ).matcher( "" );
private final List<String> csvBuffer = new ArrayList<>();

Expand Down

0 comments on commit faebd4f

Please sign in to comment.