PDA

View Full Version : ActionScript plugin access to DatabasePlugin



tcarr
03-23-2008, 11:32 PM
I figured this was worth posting separately. I figured out how to make an ActionScript plugin that can access the DatabasePlugin! Eventually this will be a tutorial on the wiki, but in the meantime:

1. Start with the DatabaseExample (http://www.es-wiki.com/zips/DatabaseExample.zip)

2. You don't need the TestDatabasePlugin.class but it doesn't hurt to leave it in.

3. Make a scripts folder in the extension, and add an AS file to it. I named mine TestDatabasePlugin.as:

var databasePlugin;

function init(parameters)
{
databasePlugin = getApi().getServerPlugin("DatabasePlugin");
test();
}

function request(userName, esob)
{
var query = requestParameters.getString("query");
if (query != null && query.length() > 0) {
var msg = databasePlugin.doQuery(query);
getApi().sendPluginMessageToUser(username, msg);
}
}

function trace(str)
{
java.lang.System.out.println(str);
}

function test()
{
var query = "SELECT username, password FROM ADMINISTRATOR.USERPASSWORDS";
var msg = databasePlugin.doQuery(query);
var output = msg.toString();
trace(output);
}

4. Edit the Extension.xml file to remove the reference to the Java TestDatabasePlugin class, and replace it with

ActionScript
TestDatabasePlugin.as</Path>


5. Reboot ES4. In the web admin, make DatabasePlugin a server level component. Then make TestDatabasePlugin a server level component.

6. Make sure that your database is running.

7. Reboot ES4 again. You should now see the results of the query on the server console. Note: if you don't have access to the server console, you can make a plugin request from a client instead. TestDatabasePlugin only has to be a server level component if you want to test without making a client.

8. Remove the test() line from the init() method after you don't need it any more. Just use plugin requests from a client to access your database. You can invoke other methods in DatabasePlugin in similar fashion to the query one.

borisd
08-29-2008, 07:44 AM
Hi Teresa,

Any progress on that wiki tutorial? I would love to see a more detailed article on database access from ActionScript plugins...

Anyway, I'm not able to find a TestDatabasePlugin.class file in the DatabaseExample.zip I downloaded from the wiki. Has this been updated?

tcarr
08-29-2008, 08:01 AM
No I never got the tutorial written, sorry, and I'm no good at writing ActionScript plugins. I was placed on a high priority project and it's taken over my life. Some weeks it's been 80 hours; I think I've got it down to where it doesn't need more than 50 hours a week of my time, but still... no time for wiki articles until we finally get this project under control.

orthiac
08-30-2008, 07:26 AM
Although this is not been reviewed yet to be added to the wiki, I had created a page in the hopes of helping someone AVOID going through the same issues I went through.
This is adapted from the original Database Example and has the information for the client side calls.
You are welcome to review it and I hope it helps to make your understanding a little clearer.

DatabasePlugin-Multipart Example (http://www.es-wiki.com/index.php?title=DatabasePlugin-Multipart_Example)

- Mike