Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Providing Multiple Database Channels

To create and register a new database channel with a particular database context, you can use the code in “Listing 10-2.” It’s probably most appropriate to put this code in your Session class, as this listing does. The code listing also shows how to register for the notification that EODatabaseContext posts when it needs another database channel.

Listing 9-2  Creating and registering a new database channel

import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
 
public class Session extends WOSession {
 
    private final int DatabaseChannelCountMax = 3;
 
    public Session() {
        super();
        NSNotificationCenter.defaultCenter().addObserver(this, new
            NSSelector("registerNewDatabaseChannel",
            new Class[] { NSNotification.class } ),
            EODatabaseContext.DatabaseChannelNeededNotification, null);
    }
 
    public void registerNewDatabaseChannel(NSNotification notification) {
        EODatabaseContext databaseContext = (EODatabaseContext)notification.object();
        if (databaseContext.registeredChannels().count() < DatabaseChannelCountMax){
            EODatabaseChannel channel = new EODatabaseChannel(databaseContext);
            databaseContext.registerChannel(channel);
        }
    }
 
}

If you create database channels programmatically on a per-session basis, you may end up with a large number of database channels per application instance. “When Database Connections Are Closed” describes how to check for and close extraneous database connections.



< Previous PageNext Page > Hide TOC


Last updated: 2007-07-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice