Package org.tmatesoft.sqljet.core.table

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


        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("HtmlReader");
                    ISqlJetCursor cursor = table.open();
                    try
                    {
                        do
                        {
                            final String siteLanguage = cursor.getString("language");
                            final String siteTitle = cursor.getString("title");
                            final String siteUrl = cursor.getString("url");
                            final String xpathToFrontPageTitle = cursor.getString("xp_fp_title");
                            final String xpathToArticleNodes = cursor.getString("xp_a_nodes");
                            final String xpathToArticleTitle = cursor.getString("xp_a_title");
                            final String xpathToArticleContent = cursor.getString("xp_a_content");
                            final String xpathToArticleUrl = cursor.getString("xp_a_url");
                            final String xpathToArticleGuid = cursor.getString("xp_a_guid");
                            final String xpathToArticleImageUrl = cursor.getString("xp_a_img");
                            final String xpathToArticlePubDate = cursor.getString("xp_a_date");
                           
                            JMenu parent = FindMenu(websitesMenu, siteLanguage);
                            JMenuItem item = new JMenuItem(siteTitle);
                           
                            item.addActionListener( new ActionListener()
                            {
                                @Override
                                public void actionPerformed(ActionEvent ae)
                                {
                                    addHtmlReader(siteTitle, siteUrl,
                                            xpathToFrontPageTitle,
                                            xpathToArticleNodes,
                                            xpathToArticleTitle,
                                            xpathToArticleContent,
                                            xpathToArticleUrl,
                                            xpathToArticleGuid,
                                            xpathToArticleImageUrl,
                                            xpathToArticlePubDate);
                                }                           
                            });
                           
                            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


            try
            {
                // open the user's storage area
                File dbFile = getNewsSafePath();          

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

                try
                {
                    CreateDatabaseIfNotExists(db);
                    CreateOrUpdateFrontPage(db, fp);
                    for(int i=0; i<fp.getArticlesCount(); i++)
                    {
                        if( CreateOrUpdateArticle(db, fp, fp.getArticle(i), true) == false )
                        {
                            CreateOrUpdateArticle(db, fp, fp.getArticle(i), false);
                        }
                    }
                }
                finally
                {
                    db.close();
                }
            }
            catch (SqlJetException ex)
            {
                Logger.getLogger(NewsSafe.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

            try
            {
                // open the user's storage area
                File dbFile = getNewsSafePath();          

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

                try
                {
                    db.beginTransaction(SqlJetTransactionMode.READ_ONLY);
                    try
                    {
                        ISqlJetTable table = db.getTable("articles");
                        ISqlJetCursor cursor = table.order("published_article_index"/*table.getPrimaryKeyIndexName()*/);
                        long rowCount = cursor.getRowCount();
                        try
                        {
                            if( cursor.goToRow(index) == false )
                            {
                                return null;
                            }

                            // the front page name of this first article
                            // will be memorized, because all the following
                            // articles will have to match the same.
                            String frontPageName = cursor.getString("front_page");

                            // build the front page from database:
                            BasicFrontPage fp = getFrontPage(db, frontPageName);

                            do
                            {
                                if( frontPageName.compareTo( cursor.getString("front_page"))!=0)
                                {
                                    break;
                                }

                                // build article from the cursor's current
                                // position:

                                try
                                {
                                    Article a = getArticle(cursor);
                                    fp.articles.add(a);
                                }
                                catch (IOException ex)
                                {
                                    Logger.getLogger(NewsSafe.class.getName()).log(Level.SEVERE, null, ex);
                                    break;
                                }


                                if( cursor.next() == false )
                                {
                                    break;
                                }

                            }while( fp.articles.size()<count);

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

            File dbFile = getNewsSafePath();          

            try
            {

                SqlJetDb db = SqlJetDb.open(dbFile, true);
                try
                {
                    db.beginTransaction(SqlJetTransactionMode.WRITE);
                    try
                    {
                        ISqlJetTable table = db.getTable("articles");
                        ISqlJetCursor cursor = table.open();
                        try
                        {
                            //- - - - - - - - - - - - - - -
                            // For each entry in the
                            // "articles" table...
                            //- - - - - - - - - - - - - - -
                           
                            do
                            {
                               
                                // Remove the article if it has not
                                // been refreshed for too long
                                long refreshDateInMillis = cursor.getInteger("refreshed");
                                long diffTime = Math.abs(currentDateTimeInMillis - refreshDateInMillis);
                                if( diffTime > (1000*60*60) ) // not refreshed during the last 60 minutes
                                {
                                    String entry = String.format("\tDelete old article \"%s (%s)\" \r\n",
                                            cursor.getString("title"),
                                            cursor.getString("front_page"));
                                    System.out.println(entry);
                                    cursor.delete();
                                }
                                else
                                {
                                    // Remove registered image from the list
                                    // of ".dat" files to erase from disk

                                    String imageFileName = cursor.getString("image");
                                    filesList.remove(imageFileName);                           
                                }
                               
                            }while( cursor.next() == true);

                            db.commit();
                        }
                        finally
                        {
                            cursor.close();
                        }

                        for(String imageFileName : filesList )
                        {
                            System.out.format("\tDelete unused file %s\r\n", imageFileName);
                            File imageFile = new File(gfPath, imageFileName);
                            imageFile.delete();
                        }
                    }
                    catch(Exception ex)
                    {
                        db.rollback();
                    }
                }
                finally
                {
                    db.close();
                }
            }
            catch (Exception ex)
            {
                Logger.getLogger(NewsSafe.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.