Exemple #1
0
 private void createTableNIndex(SqlJetDb sqlJetDb, String table) throws Exception {
   System.out.println("Create Table... " + table);
   sqlJetDb.createTable(this.tableSchemaMap.get(table));
   for (int j = 0; j < this.tableIndexMap.get(table).size(); j++) {
     System.out.println("Create Index... " + table);
     sqlJetDb.createIndex(this.tableIndexMap.get(table).get(j));
   }
   for (int j = 0; j < this.tableDataMap.get(table).size(); j++) {
     System.out.println("Insert data... " + table);
     sqlJetDb.createTrigger(this.tableDataMap.get(table).get(j));
   }
 }
  private void loadTableData(
      final File dbFile, final TableViewer guiTableViewer, final String dbTableName) {
    SqlJetDb db = null;
    try {
      db = SqlJetDb.open(dbFile, true);
      final ISqlJetTable dbTable = db.getTable(dbTableName);
      final ArrayList<DataRow> data = new ArrayList<DataRow>();
      final ISqlJetTableDef tableDef = dbTable.getDefinition();
      final List<String> names = new ArrayList<String>();
      for (final ISqlJetColumnDef column : tableDef.getColumns()) {
        names.add(column.getName());
      }
      final String[] namesArray = names.toArray(new String[names.size()]);

      final Table guiTable = guiTableViewer.getTable();
      createGuiTableColumns(guiTable, namesArray);

      dbTable
          .getDataBase()
          .runReadTransaction(
              new ISqlJetTransaction() {
                @Override
                public Object run(final SqlJetDb db) throws SqlJetException {
                  final ISqlJetCursor cursor = dbTable.open();
                  try {
                    int count = 0;
                    while (!cursor.eof()) {
                      data.add(DataRow.read(cursor, count, namesArray));
                      cursor.next();
                      count++;
                    }
                  } finally {
                    cursor.close();
                  }
                  return null;
                }
              });
      // Populate data and refresh table viewer
      guiTableViewer.setInput(data);
      guiTableViewer.refresh();
    } catch (final Exception e) {
      e.printStackTrace();
    } finally {
      if (db != null) {
        try {
          db.close();
        } catch (final SqlJetException e) {
          e.printStackTrace();
        }
      }
    }
  }
Exemple #3
0
  private void insertDb(SqlJetDb sqlJetDb, List<?> list, String table) throws Exception {
    try {
      sqlJetDb.beginTransaction(SqlJetTransactionMode.WRITE);
      ISqlJetTable iSqlJetTable = sqlJetDb.getTable(table);
      for (int i = 0; i < list.size(); i++)
        iSqlJetTable.insertByFieldNames(this.retrieveObjectMap(list.get(i)));

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      sqlJetDb.commit();
    }
  }
 private ISqlJetSchema getSqlJetSchema(final File dbFile) {
   SqlJetDb db = null;
   try {
     db = SqlJetDb.open(dbFile, true);
     return db.getSchema();
   } catch (final SqlJetException e) {
     e.printStackTrace();
   } finally {
     if (db != null) {
       try {
         db.close();
       } catch (final SqlJetException e) {
         e.printStackTrace();
       }
     }
   }
   return null;
 }
Exemple #5
0
  private File createNewRawDbFile(List<String> tableList) throws Exception {
    File tempDbFile = File.createTempFile("temp", System.currentTimeMillis() + ".sql");

    SqlJetDb sqlJetDb = SqlJetDb.open(tempDbFile, true);
    sqlJetDb.getOptions().setAutovacuum(true);
    sqlJetDb.beginTransaction(SqlJetTransactionMode.WRITE);
    try {
      sqlJetDb.getOptions().setUserVersion(1);
      for (int i = 0; i < tableList.size(); i++) this.createTableNIndex(sqlJetDb, tableList.get(i));
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      sqlJetDb.commit();
    }

    return tempDbFile;
  }