Package org.tmatesoft.sqljet.core.table

Examples of org.tmatesoft.sqljet.core.table.SqlJetDb


        final File createFile = File.createTempFile(SCHEMA_TEST, null);
        if (DELETE_COPY)
            createFile.deleteOnExit();

        final SqlJetDb createDb = SqlJetDb.open(createFile, true);
        createDb.getOptions().setFileFormat(ISqlJetLimits.SQLJET_MAX_FILE_FORMAT);
        createDb.close();

        final SqlJetDb openDb = SqlJetDb.open(createFile, true);
        final int fileFormat = openDb.getOptions().getFileFormat();
        Assert.assertEquals(ISqlJetLimits.SQLJET_MAX_FILE_FORMAT, fileFormat);

    }
View Full Code Here


            final Thread currentThread = Thread.currentThread();
            final String threadName = currentThread.getName();
            try {
                currentThread.setName(taskName);
                while (run) {
                    SqlJetDb db = null;
                    try {
                        final int n = i++;
                        db = SqlJetDb.open(file, true);
                        synchronized (TransactionTask.class) {
                            db.runWriteTransaction(new ISqlJetTransaction() {
                                public Object run(SqlJetDb db) throws SqlJetException {
                                    return workInTransaction(db, n);
                                }
                            });
                        }
                    } finally {
                        if (db != null) {
                            db.close();
                        }
                    }
                }
            } finally {
                currentThread.setName(threadName);
View Full Code Here

  private void execute(Transaction transaction, DB db) throws SqlJetException
  {
    Pool<SqlJetDb, SqlJetException> pool = this.pools.get(db);
    Lock lock = this.locks.get(db).writeLock();
   
    SqlJetDb database = pool.take();
   
    lock.lock();
   
    try
    {
      database.beginTransaction(SqlJetTransactionMode.WRITE);
     
      try
      {
        transaction.execute(database);
       
        database.commit();
      }
      catch (SqlJetException e)
      {
        try
        {
          database.rollback();
        }
        catch (SqlJetException ex)
        {
          logger.log(Level.WARN, ex);
        }
View Full Code Here

  private <T> T execute(Query<T> query, DB db) throws SqlJetException
  {
    Pool<SqlJetDb, SqlJetException> pool = this.pools.get(db);
    Lock lock = this.locks.get(db).readLock();
   
    SqlJetDb database = pool.take();
   
    lock.lock();
   
    try
    {
      database.beginTransaction(SqlJetTransactionMode.READ_ONLY);
     
      try
      {
        return query.execute(database);
      }
      finally
      {
        database.commit();
      }
    }
    finally
    {
      lock.unlock();
View Full Code Here

   */
  @Override
  public synchronized SqlJetDb create() throws SqlJetException
  {
    boolean exists = this.file.exists();
    SqlJetDb db = SqlJetDb.open(this.file, true);
    if (!exists)
    {
      db.getOptions().setAutovacuum(true);
      db.getOptions().setIncrementalVacuum(true);
    }
    return db;
  }
View Full Code Here

     * The name of the table this is related to.
     */
  private String name;
 
  public TableView(File databaseFile){
    db = new SqlJetDb(databaseFile,true);
    columnList = new HashMap<Integer,TableColumn>();
  }
View Full Code Here

  public synchronized SqlJetDb create() throws SqlJetException
  {
    try
    {
      boolean exists = this.file.exists();
      SqlJetDb db = SqlJetDb.open(this.file, true);
      if (!exists)
      {
        db.getOptions().setAutovacuum(true);
        db.getOptions().setIncrementalVacuum(true);
      }
      return db;
    }
    catch (SqlJetException e)
    {
View Full Code Here

    boolean firstRun = true;
    ISqlJetTable table = null;
   
    File podsalinanDBFile = new File(settingsDir.concat("/podsalinan.db"));
    if (podsalinanDBFile.exists()){
      SqlJetDb podsalinanDB = new SqlJetDb(podsalinanDBFile,true);
     
      addColumnToTable(podsalinanDB,"podcasts","auto_queue","INTEGER");
     
      try {
        table = podsalinanDB.getTable("downloads");
        podsalinanDB.beginTransaction(SqlJetTransactionMode.READ_ONLY);
        if (table!=null){
          ISqlJetCursor currentDBLine = table.order(table.getPrimaryKeyIndexName());
          if (!currentDBLine.eof()){
            do {
              URLDownload newDownload = new URLDownload(currentDBLine.getString("url"),
                                    currentDBLine.getString("size"),
                                      currentDBLine.getString("destination"),
                                      currentDBLine.getString("podcastSource"),
                                      (int)currentDBLine.getInteger("status"));
                newDownload.setAdded(true);
                downloads.addDownload(newDownload, (int)currentDBLine.getInteger("priority"));
            } while (currentDBLine.next());
          }
        }
      } catch (SqlJetException e){
        debugOutput.printStackTrace(e.getStackTrace());
        return -1;
      } finally {
        try {
          podsalinanDB.commit();
        } catch (SqlJetException e) {
          debugOutput.printStackTrace(e.getStackTrace());
          return -1;
        }
      }
       
      try {
        table = podsalinanDB.getTable("settings");
        podsalinanDB.beginTransaction(SqlJetTransactionMode.READ_ONLY);
       
        if (table!=null){
          ISqlJetCursor currentDBLine = table.order(table.getPrimaryKeyIndexName());
          if (!currentDBLine.eof()){
            do {
              settings.addSetting(currentDBLine.getString("name"), currentDBLine.getString("value"));
            } while (currentDBLine.next());
          }
        }
      } catch (SqlJetException e) {
        debugOutput.printStackTrace(e.getStackTrace());
        return -1;
      } finally {
        try {
          podsalinanDB.commit();
        } catch (SqlJetException e) {
          debugOutput.printStackTrace(e.getStackTrace());
          return -1;
        }
      }

      try {
        table = podsalinanDB.getTable("podcasts");
        podsalinanDB.beginTransaction(SqlJetTransactionMode.READ_ONLY);
        if (table!=null){
          ISqlJetCursor currentDBLine = table.order(table.getPrimaryKeyIndexName());
          if (!currentDBLine.eof()){
            do {
              Podcast newPodcast = new Podcast(currentDBLine.getString("name"),
                               currentDBLine.getString("url"),
                               currentDBLine.getString("directory"),
                               currentDBLine.getString("localFile").replaceAll("&apos;", "\'"),
                               currentDBLine.getInteger("auto_queue")==1);
              newPodcast.setAdded(true);
              podcasts.add(newPodcast);
            } while (currentDBLine.next());
          }
        }
       
      } catch (SqlJetException e) {
        debugOutput.printStackTrace(e.getStackTrace());
        return -1;
      } finally {
        try {
          podsalinanDB.commit();
        } catch (SqlJetException e) {
          debugOutput.printStackTrace(e.getStackTrace());
          return -1;
        }
      }
      try {
        podsalinanDB.close();
      } catch (SqlJetException e) {
        debugOutput.printStackTrace(e.getStackTrace());
        return -1;
      }
    }
View Full Code Here

               URLDownloadList downloads,
               ProgSettings settings) {
   
    File podsalinanDBFile = new File(settingsDir.concat("/podsalinan.db"));
    boolean dataFileExists = podsalinanDBFile.exists();
    SqlJetDb db = new SqlJetDb(podsalinanDBFile,true);
    db.beginTransaction(SqlJetTransactionMode.WRITE);
    if (!dataFileExists){
      try {
        db.createTable(CREATE_DOWNLOADS);
      } catch (SqlJetException e) {
        debugOutput.printStackTrace(e.getStackTrace());
      } finally {
        db.commit();
      }
      try {
        db.createTable(CREATE_PODCAST);
      } catch (SqlJetException e) {
        debugOutput.printStackTrace(e.getStackTrace());
      } finally {
        db.commit();
      }
      try {
        db.createTable(CREATE_SETTINGS);
      } catch (SqlJetException e) {
        debugOutput.printStackTrace(e.getStackTrace());
      } finally {
        db.commit();
      }
    }
    int downloadCount=0;
    for (URLDownload download : downloads.getDownloads()){
      //System.out.println("download: "+download.getURL());
      try {
        int sqlType=0;
        if (!download.isAdded()){
          //System.out.println("Adding Download");
          //System.out.println("URL= "+download.getURL().toString());
          //System.out.println("Destination= "+download.getDestination());
          ISqlJetTable table = db.getTable("downloads");
          table.insert(null,download.getURL().toString(),
                        Long.parseLong(download.getSize()),
                        download.getDestination(),
                        downloadCount,download.getPodcastId(),
                        download.getStatus());
          sqlType=1;
        } else if (download.isRemoved()){
          //System.out.println("Deleting Download");
          //System.out.println("URL= "+download.getURL().toString());
         
          sql = podsalinanDB.prepare("DELETE FROM downloads " +
                         "WHERE url='"+download.getURL().toString()+"';");
          //System.out.println("download being removed to database");
        } else if (download.isUpdated()){
          sql = podsalinanDB.prepare("UPDATE downloads " +
                         "SET destination='"+download.getDestination()+"',"+
                              "size='"+download.getSize()+"',"+
                             "priority='"+downloadCount+"',"+
                             "podcastSource='"+download.getPodcastId()+"',"+
                             "status='"+download.getStatus()+"'"+
                         "WHERE url='"+download.getURL()+"';");
          sqlType=3;
          //System.out.println("download being updated to database");
        }
        switch (sqlType){
            case 1:
              download.setAdded(true);
              break;
            case 3:
              download.setUpdated(false);
              break;
          }
        db.commit();
       
        cleanDownloadsinDB(db,download.getURL(),"downloads");
       
      } catch (SqlJetException e) {
        debugOutput.printStackTrace(e.getStackTrace());
View Full Code Here

        try
        {
            // open the storage area
            File dbFile = getTemplatesDbFile();          

            SqlJetDb db = SqlJetDb.open(dbFile, false);

            try
            {
                db.beginTransaction(SqlJetTransactionMode.READ_ONLY);
                try
                {
                    ISqlJetTable table = db.getTable("RssReader");
                    ISqlJetCursor cursor = table.open();
                    try
                    {
                        do
                        {
                            final String feedLanguage = cursor.getString("language");
                            final String feedTitle = cursor.getString("title");
                            final String feedUrl = cursor.getString("url");
                           
                            JMenu parent = FindMenu(rssFeedsMenu, feedLanguage);
                            JMenuItem item = new JMenuItem(feedTitle);
                           
                            item.addActionListener( new ActionListener()
                            {
                                @Override
                                public void actionPerformed(ActionEvent ae)
                                {
                                    addRssReader(feedTitle, feedUrl);
                                }
                            });
                           
                            parent.add(item);

                        }while( cursor.next() );
                    }
                    finally
                    {
                        cursor.close();
                    }
                }
                finally
                {
                    db.rollback();
                }
            }
            finally
            {
                db.close();
            }
        }
        catch (SqlJetException ex)
        {
            Logger.getLogger(ConfigurationFrame.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.table.SqlJetDb

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.