Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Air sqlite Proxy question  (Read 16189 times)
shizny
Full Member
***
Posts: 31


View Profile Email
« on: March 05, 2008, 01:35:41 »

Hello.  I am building an air application with puremvc.  I am trying to use the sqlite database on the project as well. I've got a login box that is tied to a userproxy.  In the userproxy I've put the database connection/creation code, in the constructor.  Putting the code in the user proxy seems like a bad place to me because I have other proxies that need to get information from the same database.  What should I do here?  Is there a recommended central place that I  create the database connection and have it available to all proxies for sql inserts, selects etc.  ?  Should I use a bunch of different databases?  Here is a portion of my code in the userproxy.  Is it bad form?

:
public class UserProxy extends Proxy implements IProxy
    {
public static const NAME:String = "UserProxy";
private var _sqlConnection:SQLConnection;
private var _dbFile:File;

public function UserProxy ( data:Object = null )
        {
            super ( NAME, data );
        _sqlConnection = new SQLConnection();
_sqlConnection.addEventListener(SQLEvent.OPEN, openHandler);
_sqlConnection.addEventListener(SQLErrorEvent.ERROR, errorHandler);

_dbFile = File.applicationStorageDirectory.resolvePath("gTT.db");
_sqlConnection.openAsync(_dbFile);

        }

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 05, 2008, 08:55:10 »

A DAO would be a good place to put this. For full details refer to the Data Access Object pattern at Sun's site http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html

Essentially the DAO is in charge of creating the connection and accessing the database, returning an object to the caller. In the attached Sequence diagram, the "Business Object" actor is any given Proxy.

You put all your SQL-slinging CRUD in the DAO, and have it accept or return a Transfer Object (aka Value Object); a plain old object with nothing but properties that correspond to the fields of your DB. That way nothing else in the app has to deal with SQL, it's all object manipulation from the Proxy on.

-=Cliff>
« Last Edit: March 05, 2008, 08:58:33 by puremvc » Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #2 on: March 05, 2008, 10:21:39 »

Thanks, I'm sure I'll have that figured out lickidy split  ???
Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #3 on: March 05, 2008, 11:05:44 »

Outside of the DAO pattern, would it be a good idea to create a Database proxy that populated a value object that was accessible from a variety of mediators or commands. 
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: March 06, 2008, 07:04:27 »

Really what you want is to put all you db stuff in one or more DAOs and then have your Proxies be named like UserProxy or OrderProxy. The idea is that the Proxy hides the location of the data from the rest of the app which should not care that there is a database involved.

So for instance, to do an update of a UserVO that has been mudified at the view in a component called UserPanel, the UserPanelMediator might retrieve the UserProxy and call userProxy.updateUser(userPanel.userVO).

Then the UserProxy instantiates the DAO (or has one as a private property already) and calls its updateUser method, passing the VO.

This keeps the boundary code in a boundary object that the Proxy knows rather than in the Proxy itself.

The DAO takes care of turnin objects into rows and vise versa.

-=Cliff>
Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #5 on: March 06, 2008, 03:48:02 »

Thanks again.
Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #6 on: March 07, 2008, 04:43:54 »

ok, so what about this line of thought.  I have one database, three proxies.  The proxies are databaseProxy, userProxy, and playProxy.

I'm basically creating the databaseProxy in order to create one point of access to database creation and access (I'm going to try and use the DAO pattern for the creation and access).

So in my modelPrepCommand I have

facade.registerProxy(new databaseProxy());
var dbProxy = facade.retrieveProxy( databaseProxy.NAME ) as databaseProxy;
facade.registerProxy(new userProxy(dbProxy));
facade.registerProxy(new playProxy(dbProxy));

Then I can access that databaseProxy from my user and play Proxies using the getData method they inherit from Proxy.  Is this a good way to structure this 2 proxies wanting different portions of the same dataobject? 


Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #7 on: March 07, 2008, 04:59:39 »

Just checked out code peek, with the AbstractProxy, seems like that may be the better way to have one database provide data to multiple proxies.  Is this correct?
Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #8 on: March 07, 2008, 05:12:03 »

In anybody's opinion, should I even be using the sqlite database, or is Flex/AIR better with xml as a datasource?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: March 07, 2008, 09:47:15 »

Reeeeeaaalllly soon now, you're going to see a nice AIR utility for managing XML Databases. It was extracted from the CodePeek demo and turned into a Utility, which CodePeek now uses to store your code search terms by language. And another Utility, DesktopCitizen uses it to store window metrics so your PureMVC-based AIR apps can automagically remember their desktop position, size and maximized state.

Stay Tuned for 2.0

-=Cliff>
Logged
shizny
Full Member
***
Posts: 31


View Profile Email
« Reply #10 on: March 08, 2008, 08:33:56 »

So, sounds like you're feeling xml as opposed to sqlite for a datasource.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #11 on: March 08, 2008, 08:42:43 »

SQL, is, well, SQL. You sling it when you have to. But on a client where the data isn't having to go over the line, XML is so easy and you don't really care how fat it is. And all the Flex controls play so nicely with XMLListCollections as dataProviders.

-=Cliff>
Logged
Pages: [1]
Print