Package com.jengine.orm.db

Examples of com.jengine.orm.db.DBConnection


        for (int i=0; i < 10; i++) {
            threads.add(new Thread() {
                public void run() {
                    try {
                        DBConnection connection = DBFactory.get().getConnection();
                        try {
                            check(Book.cls.get(1).getLibrary().equals(Library.cls.get(1)));
                            Library globe = Library.cls.filter("name = ?", "Globe").one();
                            check( globe.getMemberList().size() == 4 );
                            check( globe.getMembers().list().size() == 4 );
View Full Code Here


     * Transaction testing
     */
    public static void test9() throws Exception {
        System.out.println("** Test 9: Transaction testing");

        DBConnection connection = DBFactory.get().getConnection();
        clearData();
        try {
            connection.startTransaction();
            loadData();
            throw new Exception("test!!!");
        } catch (Exception e) {
            connection.rollback();
            // checking
            check( Author.cls.count() == 0 );
            check( Library.cls.count() == 0 );
            check( Book.cls.count() == 0 );
            check( Member.cls.count() == 0 );
            check( Transaction.cls.count() == 0 );
        } finally {
            connection.finishTransaction();
        }

        clearData();
        connection.startTransaction();
        loadData();
        connection.commit();
        check( Author.cls.count() > 0 );
        check( Library.cls.count() > 0 );
        check( Book.cls.count() > 0 );
        check( Member.cls.count() > 0 );
        check( Transaction.cls.count() > 0 );
        connection.finishTransaction();


        clearData();
        connection.startTransaction();
        loadData();
            // save point
            DBSavePoint point = connection.savePoint();
            Author.cls.get(1).setLastName("test1");
            connection.rollback(point);
            connection.releasePoint(point);
        connection.commit();
        check( Author.cls.count() > 0 );
        check( Library.cls.count() > 0 );
        check( Book.cls.count() > 0 );
        check( Member.cls.count() > 0 );
        check( Transaction.cls.count() > 0 );
        connection.finishTransaction();
    }
View Full Code Here

    public void remove() throws DBException {
        getMiddleClass().remove();
    }

    public void update(Model obj) throws ValidateException, DBException {
        DBConnection connection = manager.getModelClass().getProvider().getConnection();

        if (!connection.isTransactionActive()) {
            try {
                connection.startTransaction();
                remove(obj);
                insert(obj);
                connection.commit();
            } catch (Exception e) {
                connection.rollback();
                throw new DBException(e);
            } finally {
                connection.finishTransaction();
            }
        } else {
            DBSavePoint point = connection.savePoint();
            try{
                remove(obj);
                insert(obj);
            } catch (Exception e) {
                connection.rollback(point);
                throw new DBException(e);
            } finally {
                connection.releasePoint(point);
            }
        }
    }
View Full Code Here

        sql.append("INSERT INTO ")
                .append(table)
                .append(" (").append(concat(columns, ", ")).append(") ")
                .append(" VALUES ").append(" (").append(concat(valuesMarks, ", ")).append(") ");

        DBConnection connection = this.adapter.getConnection();
        this.adapter.executeUpdate(connection, sql.toString(), values, map("return_generated_keys", autoIncrement));
        return connection.getGeneratedKeys().size() == 1 ? connection.getGeneratedKeys().remove(0) : null;
    }
View Full Code Here

        }
        params.add(id);
        sql.append("UPDATE ").append(table).append(" SET ").append(concat(pairs, ", "))
                .append(" WHERE ").append(keyName).append("=").append("?");

        DBConnection connection = this.adapter.getConnection();
        this.adapter.executeUpdate(connection, sql.toString(), params);
    }
View Full Code Here

        StringBuffer sql = new StringBuffer();
        List params = list(id);

        sql.append("DELETE FROM ").append(table).append(" WHERE ").append(key).append("=").append("?");

        DBConnection connection = this.adapter.getConnection();
        this.adapter.executeUpdate(connection, sql.toString(), params);
    }
View Full Code Here

        this.adapter.executeUpdate(connection, sql.toString(), params);
    }

    public Object insert(SQLQuery query) throws DBException {
        String sql = buildInsertSQL(query);
        DBConnection connection = this.adapter.getConnection();
        this.adapter.executeUpdate(connection, sql, query.getParams());
        return connection.getGeneratedKeys();
    }
View Full Code Here

        return connection.getGeneratedKeys();
    }

    public void remove(SQLQuery query) throws DBException {
        String sql = buildRemoveSQL(query);
        DBConnection connection = this.adapter.getConnection();
        this.adapter.executeUpdate(connection, sql, query.getParams());
    }
View Full Code Here

        this.adapter.executeUpdate(connection, sql, query.getParams());
    }

    public void update(SQLQuery query) throws DBException{
        String sql = buildUpdateSQL(query);
        DBConnection connection = this.adapter.getConnection();
        this.adapter.executeUpdate(connection, sql, query.getParams());
    }
View Full Code Here

        this.adapter.executeUpdate(connection, sql, query.getParams());
    }

    public List select(SQLQuery sqlQuery) throws DBException {
        String sql = buildSelectSQL(sqlQuery);
        DBConnection connection = this.adapter.getConnection();
        return this.adapter.executeQuery(connection, sql, sqlQuery.getParams(), sqlQuery.getTargetTypes());
    }
View Full Code Here

TOP

Related Classes of com.jengine.orm.db.DBConnection

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.