Skip to content
Permalink
Browse files
-Delay exit until DB closed
git-svn-id: https://svn.apache.org/repos/asf/flex/whiteboard@1448561 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
doublefx committed Feb 21, 2013
1 parent 67c173e commit da7ae8f8a5a0ec719a47d90818708862b1d6b968
Showing 3 changed files with 23 additions and 13 deletions.
@@ -1,6 +1,7 @@
package org.apache.flex.utilities.developerToolSuite.infrastructure.command {
import flash.data.SQLResult;
import flash.errors.SQLError;
import flash.events.SQLEvent;

import mx.utils.ObjectUtil;

@@ -13,6 +14,7 @@ package org.apache.flex.utilities.developerToolSuite.infrastructure.command {
public class ExitUICommand extends AbstractDBCommand {

private var _msg:RequestExitApplicationMessage;
private var _terminateCommand:Function;

public function execute(msg:RequestExitApplicationMessage):void {
log.debug("Executing Command with message: " + ObjectUtil.toString(msg));
@@ -32,10 +34,12 @@ package org.apache.flex.utilities.developerToolSuite.infrastructure.command {
override protected function result(result:SQLResult, terminateCommand:Boolean = true):void {
super.result(result, false);

dispatch(new ApplicationExitReadyMessage());
db.addEventListener(SQLEvent.CLOSE, onDBClosed);

if (terminateCommand) {
callback(new CommandCallBackResult(result));
_terminateCommand = function ():void {
callback(new CommandCallBackResult(result));
}
}
}

@@ -48,5 +52,13 @@ package org.apache.flex.utilities.developerToolSuite.infrastructure.command {
callback(new CommandCallBackError(error.message, error.detailID));
}
}

private function onDBClosed(event:SQLEvent):void {
dispatch(new ApplicationExitReadyMessage());

if (_terminateCommand) {
_terminateCommand();
}
}
}
}
@@ -19,6 +19,7 @@ package org.apache.flex.utilities.developerToolSuite.executor.application.databa
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.errors.SQLError;
import flash.events.EventDispatcher;
import flash.events.SQLErrorEvent;
import flash.events.SQLEvent;
import flash.filesystem.File;
@@ -29,7 +30,7 @@ package org.apache.flex.utilities.developerToolSuite.executor.application.databa

import org.apache.flex.utilities.developerToolSuite.executor.application.util.LogUtil;

public class ApplicationDB {
public class ApplicationDB extends EventDispatcher{

public static const DB_VERSION:uint = 1;

@@ -82,6 +83,7 @@ package org.apache.flex.utilities.developerToolSuite.executor.application.databa

protected function closedHandler(event:SQLEvent):void {
LOG.debug("the database was closed successfully");
dispatchEvent(event);
}

protected function errorHandler(event:SQLErrorEvent):void {
@@ -100,7 +102,7 @@ package org.apache.flex.utilities.developerToolSuite.executor.application.databa
}

private function result(result:SQLResult):void {
_isBusy = false
_isBusy = false;
if (_resultCallback) {
_resultCallback(result);
_resultCallback = null;
@@ -127,13 +129,5 @@ package org.apache.flex.utilities.developerToolSuite.executor.application.databa
}
}
}

public function get isReady():Boolean {
return _isReady;
}

public function get isBusy():Boolean {
return _isBusy;
}
}
}
@@ -27,7 +27,7 @@ package org.apache.flex.utilities.developerToolSuite.executor.infrastructure.com

public class AbstractDBCommand {

protected var log:ILogger = LogUtil.getLogger(this);
protected var log:ILogger;

[MessageDispatcher]
public var dispatch:Function;
@@ -40,6 +40,10 @@ package org.apache.flex.utilities.developerToolSuite.executor.infrastructure.com
protected var sql:String;
protected var stmt:SQLStatement = new SQLStatement();

function AbstractDBCommand():void {
log = LogUtil.getLogger(this);
}

protected function executeAsync():void {
db.connect(prepareSql);
}

0 comments on commit da7ae8f

Please sign in to comment.