Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions src/as3/mongo/db/DB.as
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package as3.mongo.db
{
protected var _authenticated:Signal = new Signal(DB);
protected var _authenticationProblem:Signal = new Signal(DB);
protected var _connected:Signal = new Signal(DB);
// protected var _connected:Signal = new Signal(DB);
protected var _connectionFailed:Signal = new Signal(DB);
protected var _socketPolicyFileError:Signal = new Signal(DB);

Expand All @@ -41,12 +41,12 @@ package as3.mongo.db
{
return _connectionFailed;
}

/*
public function get connected():Signal
{
return _connected;
}

*/
public function get authenticationProblem():Signal
{
return _authenticationProblem;
Expand Down Expand Up @@ -76,12 +76,12 @@ package as3.mongo.db
{
return (_credentials is Credentials);
}

/*
public function get isConnected():Boolean
{
return _isConnected;
}

*/
public function get port():uint
{
return _port;
Expand Down Expand Up @@ -114,14 +114,14 @@ package as3.mongo.db

private function _initialize(databaseName:String, databaseHost:String, databasePort:uint):void
{
_wire = new Wire(this);

_collections = new Dictionary();
_authenticationFactory = new AuthenticationFactory();

_name = databaseName;
_host = databaseHost;
_port = databasePort;

_wire = new Wire(this);
}

public function setCredentials(dbCredentials:Credentials):void
Expand Down Expand Up @@ -165,12 +165,12 @@ package as3.mongo.db
{
return wire.runCommand(command);
}

/*
public function connect():void
{
wire.connect();
}

*/
public function insert(collectionName:String, document:Document):void
{
wire.insert(name, collectionName, document);
Expand Down
11 changes: 11 additions & 0 deletions src/as3/mongo/db/document/Document.as
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ package as3.mongo.db.document
{
return _values[index];
}

/**
* ERICSOCO ADDED
* I hate this fucking Document class....so bloated.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I had to add this Document class is because the authentication command sent to MongoDB has to have the keys encoded in the correct order. Ideally I wanted to use plain Object type to create command structures to send to MongoDB, but because Object is a dynamic class the properties can not be iterated in a predictable order, so I made this Document object w/ the put() method.

Do you have any suggestions for an alternate solution that would let the driver enumerate over keys in an ordinal manner?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes! sorry. didn't mean to leave that comment in, it was in a moment of frustration...i apologize.

i'm not working with authentication, so hadn't run across that issue. in the meantime, please let me remove that comment.

so sorry about that. really appreciate the work you did on this project, it's a huge leap forward from ActionMongo.

-eric

On Apr 5, 2012, at 2:49 PM, Omar Gonzalez wrote:

@@ -71,6 +71,17 @@ package as3.mongo.db.document
{
return _values[index];
}

  •    /**
    
  •     \* ERICSOCO ADDED
    
  •     \* I hate this fucking Document class....so bloated.
    

The reason I had to add this Document class is because the authentication command sent to MongoDB has to have the keys encoded in the correct order. Ideally I wanted to use plain Object type to create command structures to send to MongoDB, but because Object is a dynamic class the properties can not be iterated in a predictable order, so I made this Document object w/ the put() method.

Do you have any suggestions for an alternate solution that would let the driver enumerate over keys in an ordinal manner?


Reply to this email directly or view it on GitHub:
https://github.com/s9tpepper/MongoAS3/pull/12/files#r652925

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, I share a bit of the frustration with creating command structures with this Document object. I have some ideas for alleviating some of that, I think I will add those when I merge your pull request. Its a good discussion to have though, if we can find a different solution around this Document object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll try to give this some more thorough thought soon, probably tomorrow.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, i'm pretty new to github (this is my first pull request) -- it looks like the commit that removed that comment is automatically added to the pull request. can you confirm?

and, not sure if you want the method i added or not, up to you. i think you understand where my frustration came from tho -- if Document were just an Object getValueByKey would just be doc[key].

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more thing -- after a quick look at the authentication concern you wrote above, i wonder: can't you just manually pull out the specific keys needed for authentication and push those into the ByteArray first? then, remove them from the object you're parsing into the ByteArray, and serialize the remainder of the document object in a non-determinate way (e.g. for-in).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather find a solution that worked across the board. I only found out about the ordinal expectation from MongoDB because the authentication commands were failing. I would assume there are other commands that require to be serialized in the correct key order.

*/
public function getValueByKey(key:String):*
{
var index:uint = _keys.indexOf(key);
if (index == -1) { return null; }
else { return _values[index]; }
}

public function put(key:String, value:*):void
{
Expand Down
105 changes: 105 additions & 0 deletions src/as3/mongo/wire/RequestSequence.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package as3.mongo.wire {
import as3.mongo.wire.cursor.Cursor;
import as3.mongo.wire.messages.IMessage;
import as3.mongo.wire.messages.database.OpReply;
import as3.mongo.wire.messages.database.OpReplyLoader;

import com.transmote.utils.time.Timeout;

import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.net.Socket;

public class RequestSequence extends EventDispatcher {
private var query:IMessage;
private var replyLoader:OpReplyLoader;
private var socket:Socket;
private var cursor:Cursor;

public function RequestSequence (query:IMessage, replyLoader:OpReplyLoader, cursor:Cursor=null) {
this.query = query;
this.replyLoader = replyLoader;
this.cursor = cursor;

init();
}

public function begin (host:String, port:int) :void {
if (!socket.connected) {
socket.connect(host, port);
} else {
// force asynchronicity
var beginTimeout:Timeout = new Timeout(beginSequence, 1);
}
}

private function init () :void {
initSocket();
}



//-----<REQUEST SEQUENCE>------------------------------------//
private function beginSequence () :void {
initReplyLoader();
doQuery();
}

private function initReplyLoader () :void {
replyLoader.initializeOpReplyLoader(socket);
replyLoader.LOADED.addOnce(onReplyLoaded);
}

private function doQuery () :void {
socket.writeBytes(query.toByteArray());
socket.flush();
}

private function onReplyLoaded (reply:OpReply) :void {
if (cursor) {
cursor.onReplyLoaded(reply);
}

closeSocket();
dispatchEvent(new Event(Event.COMPLETE));
}
//-----</REQUEST SEQUENCE>-----------------------------------//



//-----<SOCKET MANAGEMENT>-----------------------------------//
private function initSocket () :void {
socket = new Socket();
socket.addEventListener(IOErrorEvent.IO_ERROR, onSocketReady);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSocketReady);
socket.addEventListener(Event.CONNECT, onSocketReady);
}

private function onSocketReady (evt:Event) :void {
var socket:Socket = evt.target as Socket;
if (!socket) { return; }
socket.removeEventListener(IOErrorEvent.IO_ERROR, onSocketReady);
socket.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, onSocketReady);
socket.removeEventListener(Event.CONNECT, onSocketReady);

if (evt is ErrorEvent) {
dispatchEvent(evt);
return;
}

beginSequence();
}

private function closeSocket () :void {
try {
socket.close();
} catch (e:Error) {}

socket = null;
}
//-----</SOCKET MANAGEMENT>----------------------------------//
}
}
Loading