 |
 |
Cocoa-Java data storage question
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2001
Location: Australia
Status:
Offline
|
|
Hello all.
I'd like to re-write a Visual Basic application to cocoa. I've decided to use cocoa-java since I know Java, and the point of the exercise is to learn cocoa. Objective-c will come later.
The Visual Basic app allowed the storage and retrieval of sports injury data for a group of people. To do this, the data was stored in a MS Access database that was easily manipulated directly with Visual Basic.
My question is what would be the best bet for data storage and retrieval using cocoa-java for this scenario? I need a way to read sets of data from disk, change it and write it back. Also, I was thinking of creating an object for each person, and using instance variables to store the data. Is there a better way? Perhaps using NSDictionary? Which way translates to disk storage easier?
Any feedback much appreciated 
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Location: brooklyn, ny
Status:
Offline
|
|
If you want to keep the same model of an application talking to a separate database you could use MySql. I've been working with it through Java on OS X for months. Although I've only done it with jsp/servlets through Tomcat. I haven't used stanf alone applications so I don't know if there are any "gotchas" or other hurdles.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2001
Location: Boston, MA
Status:
Offline
|
|
You could definitely run MySQL locally and use JDBC to get into it and retrieve the data. If the data structures are complex, you'd be better off than using an NSDictionary (which really isn't designed for this type of thing). There may be some other low-footprint databases you could install on OS X to do the same thing (PointBase maybe?).
Microsoft's recent release of VisualStudio.NET includes a low-footprint database which applications can use for storage like this. The implementation not withstanding, it's a great way for applications to have a powerful system-provided datastore rather than force application developers to roll their own or have to use a heavy-weight backend. Apple needs to include a similar piece of functionality. It doesn't have to be a full-blown SQL database, but some small and lightweight, built into the OS with nice Cocoa and Carbon APIs would be a huge boon for Mac software developers. Through in some SOAP wrappers and you have a powerful platform for application development.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status:
Offline
|
|
The first question you have to decide is whether to go with a Database (such as MySQL) or not. Here are the issues: - DataBases allow you to have multiple clients all accessing the same data without having file locking/concurrency issues. This is assuming you are not embedding the database.
- DataBases are accessible over a network with the same amount of programming.
- DataBases give you all your
- Simple serialization means that you don't have to make sure that the database is present and setup on the system, or available over a network. You also don't have to worry about different people stomping on each-others settings. This is better if you are just looking at a simple application.
If you decide to go with the database route, then Java makes it relatively easy through JDBC. You can pick and choose your database, and even have it access a common database over the network with no extra programming. Switching DataBase Vendors is a snap. There is a little bit of a learning curve oon JDBC if you have never written SQL before.
If you go the serialization route, then Apple has done most of the work for you. All of the basic data classes (NSArray, NSDictionary, etc) have serialization built in. Here is a link to the documentation. It is very simple and very quick if you build off of the NS data types. Or you can use Java's native serializers, but you will have to get your own documentation for that...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Database connectivity may be nice, but it's a little complex for a first project.  I'd suggest using your own custom objects to model the data and using NSDictionary for storage. A primitive database can be implemented as an array of dictionaries, and each model object can be designed to initialize its instance variables based on the keys in a dictionary (and write them back out that way too).
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2001
Location: Australia
Status:
Offline
|
|
Thanks for the info!
Just to clear things up: I'll make custom Java objects to model my data, NSDictionary to store the objects in a pseudo database, then actually write it to disk using NSPropertyListSerialization?
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2001
Location: Australia
Status:
Offline
|
|
This is what I've done, for those who may be interested:
I'm using custom Java objects to model the data, and storing each object in a NSDictionary with unique keys for easy access. This is just for internal storage and retrieval of the data. To write the data to disk, I retrieve each piece of data from the custom object's instance variables and store them in a NSDictionary (one for each object). I then store the NSDictionary's in one NSMutableArray, and write the array to disk using NSArchiver.
Currently, the NSDictionary (used for internal purposes) and the NSMutableArray (used to write data to disk) run sort-of in parallel to each other. When a new object is added to the NSDictionary, it is also converted to a NSDictionary itself and stored in the array, as described above. I could change the code so that the array is only used in the saving (and loading) methods, then discarded. Does it really matter?
Loading data from disk is basically the reverse of writing to disk. If anyone wants me to detail how it's done, just say so.
Otherwise, anyone agree/disagree with what I've done?
Thanks.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|