Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queryToken and PgUrl parse changes #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions driver/src/org/postgresql/PgURL.as
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ package org.postgresql {
var urlParts:Array = url.split('?');
var root:String = urlParts[0];
var args:String = urlParts.length > 1 ? urlParts[1] : null;
var rootElems:Array = new RegExp("asdbc:postgresql://([\\w\\.]+)(?::(\\d+))?/(\\w+)").exec(root);
var rootElems:Array = new RegExp("asdbc:postgresql://([\\w\\.]+)(?::(\\d+))?/([\\w\\-]+)").exec(root);
var argElems:Array = args ? args.split("&") : [];
if (!rootElems) {
throw new ArgumentError("Invalid url: " + url);
Expand Down Expand Up @@ -91,4 +91,4 @@ package org.postgresql {
}

}
}
}
142 changes: 71 additions & 71 deletions driver/src/org/postgresql/db/CallbackResultHandler.as
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
package org.postgresql.db {

/**
* An <code>IResultHandler</code> which invokes user-supplied callbacks when
* query results are returned and on query completion.
*/
public class CallbackResultHandler extends ResultHandlerBase {
/**
* An <code>IResultHandler</code> which invokes user-supplied callbacks when
* query results are returned and on query completion.
*/
public class CallbackResultHandler extends ResultHandlerBase {

private var _onCompletion:Function;
private var _onQueryResult:Function;
private var _onCompletion:Function;
private var _onQueryResult:Function;

/**
* Create a new <code>CallbackResultHandler</code> with specified callbacks.
* The <code>onQueryCompletion</code> callback is required and should have the
* following signature:
* <pre>
* function(command:String, affectedRows:int):void
* </pre>
* where <code>command</code> is the PotsgreSQL command tag for the given query
* (e.g., <code>SELECT</code> or <code>INSERT</code>) and <code>affectedRows</code>
* is the number of rows affected if an update was performed (note that this is
* <em>not</em> the number of rows returned).
* <br/>
* The <code>onQueryResult</code> callback is optional and should have the
* following signature:
* <pre>
* function(columns:Array, data:Array):void
* </pre>
* where <code>columns</code> is an array of <code>IColumn</code> objects defining the
* fields returned and <code>data</code> is an array of <code>Object</code>s, each
* representing a row with keys (property names) defined by the <code>IColumn</code>
* objects and values corresponding to row values.
* <br/>
* If specified, the query result handler is invoked before the query completion
* handler. Note that for a query with multiple statements, these may be invoked
* multiple times.
*
* @param onCompletion query completion callback
* @param onQueryResult query result callback
* @see org.postgresql.db.IColumn
*/
public function CallbackResultHandler(onCompletion:Function, onQueryResult:Function=null) {
if (onCompletion == null) {
throw new ArgumentError("Completion handler cannot be null");
}
_onQueryResult = onQueryResult;
_onCompletion = onCompletion;
}
/**
* Create a new <code>CallbackResultHandler</code> with specified callbacks.
* The <code>onQueryCompletion</code> callback is required and should have the
* following signature:
* <pre>
* function(command:String, affectedRows:int):void
* </pre>
* where <code>command</code> is the PotsgreSQL command tag for the given query
* (e.g., <code>SELECT</code> or <code>INSERT</code>) and <code>affectedRows</code>
* is the number of rows affected if an update was performed (note that this is
* <em>not</em> the number of rows returned).
* <br/>
* The <code>onQueryResult</code> callback is optional and should have the
* following signature:
* <pre>
* function(columns:Array, data:Array):void
* </pre>
* where <code>columns</code> is an array of <code>IColumn</code> objects defining the
* fields returned and <code>data</code> is an array of <code>Object</code>s, each
* representing a row with keys (property names) defined by the <code>IColumn</code>
* objects and values corresponding to row values.
* <br/>
* If specified, the query result handler is invoked before the query completion
* handler. Note that for a query with multiple statements, these may be invoked
* multiple times.
*
* @param onCompletion query completion callback
* @param onQueryResult query result callback
* @see org.postgresql.db.IColumn
*/
public function CallbackResultHandler(onCompletion:Function, onQueryResult:Function=null) {
if (onCompletion == null) {
throw new ArgumentError("Completion handler cannot be null");
}
_onQueryResult = onQueryResult;
_onCompletion = onCompletion;
}

/**
* @private
*/
public override function doHandleCompletion(command:String, rows:int, oid:int):void {
if (columns) {
onQueryResult(columns, data);
}
onCompletion(command, rows);
}
/**
* @private
*/
public override function doHandleCompletion(command:String, rows:int, oid:int, token:QueryToken):void {
if (columns) {
onQueryResult(columns, data);
}
onCompletion(command, rows);
}

/**
* @private
* Invokes the <code>onQueryResult</code> callback.
*/
protected function onQueryResult(columns:Array, data:Array):void {
if (_onQueryResult != null) {
_onQueryResult(columns, data);
}
}
/**
* @private
* Invokes the <code>onQueryResult</code> callback.
*/
protected function onQueryResult(columns:Array, data:Array):void {
if (_onQueryResult != null) {
_onQueryResult(columns, data);
}
}

/**
* @private
* Invokes the <code>onCompletion</code> callback.
*/
protected function onCompletion(command:String, rows:int):void {
_onCompletion(command, rows);
}
/**
* @private
* Invokes the <code>onCompletion</code> callback.
*/
protected function onCompletion(command:String, rows:int):void {
_onCompletion(command, rows);
}

}
}
}
}
136 changes: 68 additions & 68 deletions driver/src/org/postgresql/db/EventResultHandler.as
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
package org.postgresql.db {

import org.postgresql.db.event.QueryResultEvent;
import org.postgresql.db.event.QueryCompletionEvent;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.EventDispatcher;
import org.postgresql.db.event.QueryResultEvent;
import org.postgresql.db.event.QueryCompletionEvent;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.EventDispatcher;


/**
* Dispatched when a query completes.
*
* @eventType org.postgresql.db.event.QueryCompletionEvent
*/
[Event(name="queryCompletion", type="org.postgresql.db.event.QueryCompletionEvent")]
/**
* Dispatched when a query completes.
*
* @eventType org.postgresql.db.event.QueryCompletionEvent
*/
[Event(name="queryCompletion", type="org.postgresql.db.event.QueryCompletionEvent")]

/**
* Dispatched when a query result set is available.
*
* @eventType org.postgresql.db.event.QueryResultEvent.RESULT
*/
[Event(name="queryResult", type="org.postgresql.db.event.QueryResultEvent")]
/**
* Dispatched when a query result set is available.
*
* @eventType org.postgresql.db.event.QueryResultEvent.RESULT
*/
[Event(name="queryResult", type="org.postgresql.db.event.QueryResultEvent")]

/**
* An <code>IResultHandler</code> which dispatches events when queries complete.
*/
public class EventResultHandler extends ResultHandlerBase implements IEventDispatcher {
/**
* An <code>IResultHandler</code> which dispatches events when queries complete.
*/
public class EventResultHandler extends ResultHandlerBase implements IEventDispatcher {

private var _dispatcher:IEventDispatcher;
private var _dispatcher:IEventDispatcher;

/**
* @private
*/
public function EventResultHandler() {
_dispatcher = new EventDispatcher();
}
/**
* @private
*/
public function EventResultHandler() {
_dispatcher = new EventDispatcher();
}

/**
* @private
*/
public override function handleCompletion(command:String, rows:int, oid:int):void {
if (columns) {
_dispatcher.dispatchEvent(new QueryResultEvent(QueryResultEvent.RESULT, columns, data));
}
_dispatcher.dispatchEvent(new QueryCompletionEvent(QueryCompletionEvent.COMPLETE, command, rows, oid));
}
/**
* @private
*/
public override function handleCompletion(command:String, rows:int, oid:int, token:QueryToken):void {
if (columns) {
_dispatcher.dispatchEvent(new QueryResultEvent(QueryResultEvent.RESULT, columns, data, token));
}
_dispatcher.dispatchEvent(new QueryCompletionEvent(QueryCompletionEvent.COMPLETE, command, rows, oid, token));
}

/**
* @private
*/
public function dispatchEvent(event:Event):Boolean {
return _dispatcher.dispatchEvent(event);
}
/**
* @private
*/
public function dispatchEvent(event:Event):Boolean {
return _dispatcher.dispatchEvent(event);
}

/**
* @inheritDoc
*/
public function hasEventListener(type:String):Boolean {
return _dispatcher.hasEventListener(type);
}
/**
* @inheritDoc
*/
public function hasEventListener(type:String):Boolean {
return _dispatcher.hasEventListener(type);
}

/**
* @inheritDoc
*/
public function willTrigger(type:String):Boolean {
return _dispatcher.willTrigger(type);
}
/**
* @inheritDoc
*/
public function willTrigger(type:String):Boolean {
return _dispatcher.willTrigger(type);
}

/**
* @inheritDoc
*/
public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void {
_dispatcher.removeEventListener(type, listener, useCapture);
}
/**
* @inheritDoc
*/
public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void {
_dispatcher.removeEventListener(type, listener, useCapture);
}

/**
* @inheritDoc
*/
public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void {
_dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
}
/**
* @inheritDoc
*/
public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void {
_dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
}
}
Loading