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 [2] 3
Print
Author Topic: AIR - Sqlite Proxy object  (Read 67720 times)
Rhysyngsun
Courseware Beta
Sr. Member
***
Posts: 51

Nathan Levesque

 - rhysyngsun@gmail.com  - rhysyngsun
View Profile WWW Email
« Reply #15 on: April 19, 2008, 03:10:15 »

Jiri, another recommendation I'd make with you SQL code is to code any table or row names as constants and simply concatenate them into your query strings. That'll avoid any typos that could potentially cause issues. This would also allow you to refactor your tables quickly although you'd still have to delete your local data store.
Logged

Jiri
Jr. Member
**
Posts: 13


View Profile Email
« Reply #16 on: April 21, 2008, 01:30:53 »

Would it be considered good practice if I would create custom made notifiers that extends the Notification class and have them add to a proxy as responders. Like so
:
ISQLiteErrorResponder extends Notification
ISQLiteResultResponder extends Notification

function doQuery(queryString , ISQLiteErrorResponder , ISQLiteResultResponder):void
{
//do stuff and listen to the sql callback using flash eventlisteners to fire the responders
//only how to remove listeners, without having both responder know about each other
}
Jiri
Logged
Jiri
Jr. Member
**
Posts: 13


View Profile Email
« Reply #17 on: April 21, 2008, 01:33:43 »

Rhysyngsun, does one put constants in a UML scheme? I am new to UML, but want to learn. Allready in this thread it has proven me that it is a nice way to communicate code concepts :)

Jiri
Logged
Rhysyngsun
Courseware Beta
Sr. Member
***
Posts: 51

Nathan Levesque

 - rhysyngsun@gmail.com  - rhysyngsun
View Profile WWW Email
« Reply #18 on: April 21, 2008, 05:45:07 »

Rhysyngsun, does one put constants in a UML scheme? I am new to UML, but want to learn. Allready in this thread it has proven me that it is a nice way to communicate code concepts :)

Jiri

I'm not sure as I don't use UML myself (I typically diagram on paper). I believe Cliff is more familiar with it than I.

I forgot to mention, those constants should be protected as well since only the Proxy would know about the structure of the database, so no need to expose them publicly.
Logged

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



View Profile WWW Email
« Reply #19 on: April 21, 2008, 05:53:43 »

The custom notification as responder idea doesn't really sound right.

Typically the Proxy is long lived and having it be a responder doesn't lead to any GC issues.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #20 on: April 21, 2008, 05:55:07 »

Sure you can put your constants in the UML class diagrams.

-=Cliff>
Logged
skipintro
Courseware Beta
Newbie
***
Posts: 6


View Profile Email
« Reply #21 on: April 29, 2008, 05:02:40 »

Hi,

I tried a different approach to access the local sqlLite DB from flex. Rather using proxies to handle my database logic, I let the the proxy only know little about the "service" and wrote the logic to a delegate. This way its easier to reuse the proxy and its logic if you want to exchange the "database service" to a "remoting service" for instance.

The implementation inside the proxy class then looks like this:
:

public class PageDataProxy extends Proxy implements IProxy, IDelegateResponder
{

.....

// service IDs
private static const _LOAD_PAGE:String = "loadPage";

.....

public function loadPage( id:int ):void
{
     // accessing a remote service
     new RemoteDelegate( "GetPageDocument", [id, ""], this, _LOAD_PAGE ).execute();
  
     // or optional

     // accessing a local database
     // new LocalDBDelegate( "SELECT * FROM....",  LocalDBDelegate.MODE_SYNC, this, _LOAD_PAGE ).execute();

}

public function onDelegateResult( serviceid:String, data:Object ):void
{
switch( serviceid )
{
case _LOAD_PAGE:

// parse xml page data to PageVO
parsePageData( data as XML );

// send notification
sendNotification( ApplicationFacade.PROXY_PAGE_LOADED );
break;
}
}

public function onDelegateFault( serviceid:String, data:Object ):void
{
     sendNotification( ApplicationFacade.PROXY_ERROR, serviceid );
}

.....


Please note, that the static LocalDBDelegate.init() method must be called before any DB operations. You can do this within the ModelPrepCommand or at any other point. See attachment for details.

Thomas

Logged
neil
Jr. Member
**
Posts: 16


View Profile Email
« Reply #22 on: July 31, 2008, 06:14:40 »

Has anybody had any sucess with any of these suggestions for integrating SQLite?

I'm very new to all this... only started looking at Flex last month and came onto PureMVC 2 days ago.

I've read the Best Practices doc three times so that it is starting to sink in, but there's still a lot of terminology etc. that I still don't understand.

I'm hacking away at the EmployeeAdmin example and would love to know if anyone has got SQLite to populate the data.

I've downloaded the delegates zip from the above post, but really don't know where to start.

Any help would be really appreciated as I'm fumbling around in the dark at the moment!

Many thanks,

Neil
Logged
skipintro
Courseware Beta
Newbie
***
Posts: 6


View Profile Email
« Reply #23 on: July 31, 2008, 07:06:52 »

Hi Neil,

the LocalDBDelegate class (or any other delegate) can be used by any class that implements the IDelegateResponder interface.
In PureMVC AIR Projects I usually use them with Proxies in order to write in or retrieve data from the local SQLite DB.

If you dig into the framework at the moment, you might already know that Proxy Classes are generally used to manipulate and read from data entities (VOs). In case you want to retrieve or write from any other location than your programms memory, Delegates can come into play in order to handle more complex data oprations such as remote or local db calls. The key benefit of these "helper classes" is reusability, as you dont have to write db or remote code inside your proxy again and again.

I hope I could help...

Thomas



Logged
neil
Jr. Member
**
Posts: 16


View Profile Email
« Reply #24 on: July 31, 2008, 08:29:35 »

Hi Thomas.

Thanks for your reply. Forgive my me sounding stupid, but...
Where do the files in your zip file go in relation to the proxy?
I'm using the EmployeeAdmin demo and I want to be able to pull in the user data from SQLite.

I've put them in the model directory (I don't know if this is right) and I've tried adding:

public class UserProxy extends Proxy implements IProxy, IDelegateResponder

to my proxy as per your example, but I get error:
1044: Interface method onDelegateFault in namespace org.puremvc.as3.demos.flex.employeeadmin.model:IDelegateResponder not implemented by class org.puremvc.as3.demos.flex.employeeadmin.model:UserProxy

I've not come accross delegates before so don't know how they work.

Any nudges in the right direction you could give wuold be appreciated!

Cheers,

Neil


Logged
skipintro
Courseware Beta
Newbie
***
Posts: 6


View Profile Email
« Reply #25 on: July 31, 2008, 09:07:05 »

Hi Neil,

I usually put the Delegate Classes inside a "utility" package and import them to my project. Optionally, you can  leave them inside your applications model package for testing purposes. As long as your imports work, thats fine...

in order to make use of the LocalDBDelegate you need to:

1. implement the IDelegateResponder interface ( as you already did )
2. implement the 3 methods, the last 2 defined by the IDelegateResonder interface, similar to this

:
public function loadPage( id:int ):void
{
       new LocalDBDelegate( "CREATE TABLE 'users' .... ",  LocalDBDelegate.MODE_SYNC, this, null ).execute();
}

public function onDelegateResult( serviceid:String, data:Object ):void
{
    // this method is called by the Delegate after the query has been sucessfully executed
}

public function onDelegateFault( serviceid:String, data:Object ):void
{
   // this method is called by the Delegate, if the query has caused an error
}


Your code is probably only missing the "onDelegateFault" method as stated in the error message you received.
Do not forget to call the static "init()" method of the LocalDBDelegate class prior to any db operations.

Good luck ;)
Thomas
Logged
neil
Jr. Member
**
Posts: 16


View Profile Email
« Reply #26 on: July 31, 2008, 09:41:35 »

Hi Thomas.

Okay, the errors have gone, but how do I call 'the static "init()" method of the LocalDBDelegate class prior to any db operations'.

This is all very new to me so as simply as possible, please!!

Cheers,

Neil

Logged
skipintro
Courseware Beta
Newbie
***
Posts: 6


View Profile Email
« Reply #27 on: August 01, 2008, 12:25:36 »

Hi Neil,

call the static init() Method of the LocalDBDelegate class within the execute method your ModelPrepCommand or any other location prior to any db operationslike this:

:
var file:File = File.applicationStorageDirectory;
LocalDBDelegate.init( file );

greets
thomas
Logged
neil
Jr. Member
**
Posts: 16


View Profile Email
« Reply #28 on: August 01, 2008, 02:08:41 »

Hi Thomas.

Okay, I'm getting somewhere. The query is executing, but how do I set the responder?

I can see that LocalDBDelegate gets passed by responder:IDelegateResponder = null

:
public function LocalDBDelegate( query:String, mode:String = MODE_SYNC, responder:IDelegateResponder = null, serviceid:String = "" )
{
super( serviceid, responder );

m_query = query;
m_mode = mode;
}

and that in IDelegateResponder.as we have:

:
public interface IDelegateResponder
{
function onDelegateResult( serviceid:String, data:Object ):void;
function onDelegateFault( serviceid:String, data:Object ):void;
}


but it's not getting to IDelegateResponder.as

I really appreciate your help!

Cheers,

Neil
Logged
skipintro
Courseware Beta
Newbie
***
Posts: 6


View Profile Email
« Reply #29 on: August 01, 2008, 02:22:53 »

hi neil,

if you take a look at my previous post ( the one with the loadPage example ) you can see, that "this" is passed to the constructor of the LocalDBDelegate as the "responder". As this class is probably a proxy that implements the interface, this is also the place ( with the onDelegateResult method), where the response is called by the Delegate.

Greets Thomas

Logged
Pages: 1 [2] 3
Print