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.
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.