Package org.odmg

Examples of org.odmg.Database


        // get facade instance
        // use one Implementation instance per database
        // it's recommended to share the Implementation and Database instances
        // in the application, instead of always instantiate and open it.
        Implementation odmg = OJB.getInstance();
        Database       db   = odmg.newDatabase();

        // open database
        try
        {
            db.open(DATABASE_NAME, Database.OPEN_READ_WRITE);
        }
        catch (ODMGException ex)
        {
            ex.printStackTrace();
        }
View Full Code Here


        super.dispose();
        synchronized(this.databases) {
            final Set keys = this.databases.keySet();
            for( Iterator i = keys.iterator(); i.hasNext(); )
            {
                final Database db = (Database)i.next();
                try
                {
                    db.close();
                }
                catch( final ODMGException e) {
                    getLogger().error( "OJB-ODMG: Cannot close Database", e);
                }
                i.remove();
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.cocoon.ojb.odmg.components.Odmg#getInstance()
     */
    public Implementation getInstance() throws ODMGException {
        Database db = (Database)this.databases.get( DEFAULT_CONNECTION );
        if(null == db ) {
            db = this.odmg.newDatabase();
            db.open(DEFAULT_CONNECTION, DEFAULT_MODE);
            synchronized (this.databases) {
                this.databases.put( DEFAULT_CONNECTION + DEFAULT_MODE, db );
            }
        }
        return this.odmg;
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.cocoon.ojb.odmg.components.Odmg#getInstance(java.lang.String, int)
     */
    public Implementation getInstance(String connection, int mode) throws ODMGException {
        Database db = (Database)this.databases.get( connection + mode);
        if(null == db ) {
            db = this.odmg.newDatabase();
            db.open(connection, mode);
            synchronized (this.databases) {
                this.databases.put( connection + mode, db );
            }
        }
        return this.odmg;
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.cocoon.ojb.odmg.components.Odmg#getInstance(java.lang.String)
     */
    public Implementation getInstance(String connection) throws ODMGException {
        Database db = (Database)this.databases.get( connection + DEFAULT_MODE);
        if(null == db ) {
            db = this.odmg.newDatabase();
            db.open(connection, DEFAULT_MODE);
            synchronized (this.databases) {
                this.databases.put( connection + DEFAULT_MODE, db );
            }
        }
        return this.odmg;
View Full Code Here

    }
    /* (non-Javadoc)
     * @see org.apache.cocoon.ojb.odmg.components.OdmgImplementation#getInstance(int)
     */
    public Implementation getInstance( int mode ) throws ODMGException  {
        Database db = (Database)this.databases.get( DEFAULT_CONNECTION+ mode);
        if(null == db ) {
            db = this.odmg.newDatabase();
            db.open(DEFAULT_CONNECTION, mode);
            synchronized (this.databases) {
                this.databases.put( DEFAULT_CONNECTION+ mode, db );
            }
        }
        return this.odmg;
View Full Code Here

     * @see org.apache.avalon.framework.activity.Disposable#dispose()
     */
    public void dispose() {
        final Set keys = this.databases.keySet();
        for (Iterator i = keys.iterator(); i.hasNext();) {
            final Database db = (Database) i.next();
            try {
                db.close();
            } catch (ODMGException e) {
                getLogger().error("OJB-ODMG: Cannot close Database", e);
            }
            i.remove();
        }
View Full Code Here

    /* (non-Javadoc)
     * @see org.apache.cocoon.ojb.odmg.components.ODMG#getInstance(java.lang.String, int)
     */
    public Implementation getInstance(String connection, int mode) throws ODMGException {
        synchronized (this.databases) {
            Database db = (Database) this.databases.get(connection + ":" + mode);
            if (null == db) {
                db = this.odmg.newDatabase();
                db.open(connection, mode);
                this.databases.put(connection + ":" + mode, db);
            }
        }
        return this.odmg;
    }
View Full Code Here

     * unique in the DB.
     */
    public void testDuplicateInsertion() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        String name = "testDuplicateInsertion_" + System.currentTimeMillis();
        String nameNew = "testDuplicateInsertion_New_" + System.currentTimeMillis();

        db.open(databaseName, Database.OPEN_READ_WRITE);
        //System.out.println("TEST: Database open");

        // insert an object with UNIQUE field NAME="A site"
        //System.out.println("TEST: Insert first object");
        newSite(odmg, name, 2, 1);

        // insert another object with UNIQUE field NAME="A site"
        // This should not create a new object (UNIQUE fields conflict) but
        // should resume gracefuly
        //System.out.println("TEST: Insert second object, should fail");
        try
        {
            newSite(odmg, name, 3, 2);
            assertTrue("We should get a SqlException 'Violation of unique index'", false);
        }
        catch (Exception e)
        {
            // we wait for this exception
            assertTrue(true);
        }

        // insert an object with new UNIQUE field NAME
        // should always work
        //System.out.println("TEST: Insert third object");
        try
        {
            newSite(odmg, nameNew, 1, 2);
            assertTrue(true);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            assertTrue("This exception should not happend: " + e.getMessage(), false);
            throw e;
        }

        db.close();
        //System.out.println("TEST: Database closed");
    }
View Full Code Here

    }

    public void testSimpleQueryDelete() throws Exception
    {
        Implementation odmg = OJB.getInstance();
        Database db = odmg.newDatabase();
        String name = "testSimpleQueryDelete - " + System.currentTimeMillis();

        db.open(databaseName, Database.OPEN_READ_WRITE);
        Site site = new Site();
        site.setName(name);
        Transaction tx = odmg.newTransaction();
        tx.begin();
        tx.lock(site, Transaction.WRITE);
        tx.commit();

        OQLQuery query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
        tx.begin();
        List result = (List) query.execute();
        if (result.size() == 0)
        {
            fail("Stored object not found");
        }
        tx.commit();

        tx.begin();
        db.deletePersistent(site);
        tx.commit();

        query = odmg.newOQLQuery();
        query.create("select sites from " + Site.class.getName() + " where name=$1");
        query.bind(name);
View Full Code Here

TOP

Related Classes of org.odmg.Database

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.