Package org.tmatesoft.sqljet.core.table

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


                {
                    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);
View Full Code Here


    private boolean isAnswered(int number) throws SqlJetException {
        db.beginTransaction(SqlJetTransactionMode.READ_ONLY);
        try {
            ISqlJetTable table = db.getTable("answers");
            ISqlJetCursor cursor = table.lookup("login_question", login.getLogin(), number);
            return !cursor.eof();
        } finally {
            db.commit();
        }
    }
View Full Code Here

    }

    private String printShortSummary() throws SqlJetException {
        db.beginTransaction(SqlJetTransactionMode.WRITE);
        ISqlJetTable table = db.getTable("answers");
        final ISqlJetCursor cursor = table.lookup("login", login.getLogin());
        int answered = (int) cursor.getRowCount();
        int right = 0;
        if (!cursor.eof()) {
            do {
                if (Integer.parseInt(cursor.getString("answer")) == 1) ++right;
            } while (cursor.next());
        }
        cursor.close();
        db.commit();
        StringBuilder result = new StringBuilder();
        result.append("Results of " + login.getLogin() + "\n");
        result.append("Number of questions: " + javaPuzzlersGame.maxQuestion + "\n");
        result.append("Number of answers: " + answered + "\n");
View Full Code Here

    private boolean tryLogin(String login, String password) throws SqlJetException {
        db.beginTransaction(SqlJetTransactionMode.WRITE);
        try {
            ISqlJetTable table = db.getTable("users");
            ISqlJetCursor cursor = table.lookup("login_password", login, password);
            return !cursor.eof();
        } finally {
            db.commit();
        }
    }
View Full Code Here

    private void printResults() throws SqlJetException {
        db.beginTransaction(SqlJetTransactionMode.WRITE);
        try {
            ISqlJetTable table = db.getTable("answers");
            final ISqlJetCursor cursor = table.lookup("login", login.getLogin());
            TableModel dataModel = new AbstractTableModel() {
                String[][] mas = new String[(int) cursor.getRowCount()][2];

                {
                    makeMas();
                }

                public int getRowCount() {
                    try {
                        return (int) cursor.getRowCount();
                    } catch (SqlJetException e) {
                        e.printStackTrace();
                    }
                    return 0;
                }

                public int getColumnCount() {
                    return 2;
                }

                public String getColumnName(int i) {
                    return i == 0 ? "Number of question" : "Result";
                }

                public void makeMas() throws SqlJetException {
                    int i = 0;
                    if (!cursor.eof()) {
                        do {
                            mas[i][0] = cursor.getString("question");
                            mas[i][1] = cursor.getString("answer").equals("1") ? "Correct" : "Incorrect";
                            i++;
                        } while (cursor.next());
                    }

                }

                public Object getValueAt(int row, int col) {
                    return mas[row][col];
                }
            };
            results.getResultTable().setModel(dataModel);
            results.getResultsHeader().getColumnModel().addColumn(new TableColumn());
            results.getResultsHeader().getColumnModel().addColumn(new TableColumn());
            results.getResultsHeader().getColumnModel().getColumn(0).setHeaderValue("Number of question");
            results.getResultsHeader().getColumnModel().getColumn(1).setHeaderValue("Your answer is");
            results.getResultsHeader().getColumnModel().getColumn(0).setWidth(300);
            results.getResultsHeader().getColumnModel().getColumn(1).setWidth(300);
            cursor.close();
        } finally {
            db.commit();
        }
    }
View Full Code Here

TOP

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

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.