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

< Previous PageNext Page > Hide TOC

Connection Dictionary

Enterprise Objects uses an EOAdaptor object to connect and log in to a database. WebObjects 5.2 provide two adaptors: one for JDBC data sources and one for JNDI data sources. An adaptor uses a connection dictionary to identify the address of the database and to provide login credentials.

When you’re developing an Enterprise Objects application, you usually supply the connection dictionary information in the EOModel files the application uses. While this is convenient during development, it may not be adequate for deployed applications. Instead, you may need to provide the connection dictionary programmatically. The following sections describe the two ways to provide connection dictionary information to an application.

In this section:

Storing in a Model File
Storing in Code


Storing in a Model File

When you create a new EOModel file, you are prompted to provide login information for the data source to which that model connects. The window that asks for this information is shown in “Figure 10-3.”


Figure 9-3  Connection dictionary window in EOModeler

Connection dictionary window in EOModeler

The information you provide in this window becomes the model file’s connection dictionary. The connection dictionary is stored in the model file and doesn’t require you to write any code to use it. This approach is useful when all users of the application log in to the database with the same connection information and when the login information is not regarded as sensitive.

However, if you need to provide users with different database connection information or if you still want to allow all users to share the same credentials but you want to secure those credentials, you need to provide some of the connection dictionary information programmatically. You can still provide nonsensitive connection information in the model, such as the database URL, driver, and plug-in, and just provide login credentials programmatically.

Providing the connection dictionary programmatically (or even just part of the connection dictionary) requires more code on your part, so you should do it only if you really need to. “Storing in Code” tells you how to provide the connection dictionary programmatically.

All EOAdaptor objects that Enterprise Objects creates automatically use the connection dictionary information specified in the model. If you instantiate an adaptor programmatically, however, it doesn’t automatically use the model’s connection dictionary information, so you have to provide it programmatically.

Storing in Code

For any number of reasons, you may need to provide all or part of an EOAdaptor’s connection dictionary programmatically. To do this, you first need to identify the dictionary’s keys so you can set their values.

The following code prints the connection dictionary keys of the Real Estate model:

EOModel model = EOModelGroup.defaultGroup().modelNamed("RealEstate");
NSLog.out.appendln("connection dictionary keys: " +     model.connectionDictionary().allKeys());

The output of this code is:

connection dictionary keys: ("plugin", "jdbc2Info", "username", "driver", "password", "URL")

Now that you know the names of the connection dictionary’s keys, you need to set the values for some of them. You don’t need to set the values for all of the keys, only for the keys you care about. When you force a model to use a new connection dictionary with the method discussed below, only the keys for which you explicitly set values are overridden. So if, for example, the original connection dictionary in the model specifies the database URL and you don’t provide a value for that key in the dictionary of overrides, the value in the model’s dictionary is still used even after you’ve provided an updated connection dictionary.

Where in an application’s execution should you set the values? It depends on your application’s requirements. If you provide each user with an independent connection to the database by giving each user a separate stack as described in “Providing Separate Stacks,” you should first get a user’s database username and password and then set the values of the connection dictionary before instantiating the stack. After you set the values in the connection dictionary but before you instantiate a stack for each user, you need to invoke the method EODatabaseContext.forceConnectionWithModel. You pass to this method as arguments an EOModel object, a connection dictionary of keys to override with the values you supply programmatically, and an editing context.

The code in “Providing a Connection Dictionary in Code” shows all these steps.



< 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