Created
August 16, 2011 21:31
-
-
Save destroytoday/1150226 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.destroytoday.twitterdiff.command.snapshot.follower | |
{ | |
import com.destroytoday.twitterdiff.core.IDatabaseService; | |
import com.destroytoday.twitterdiff.model.FollowerSnapshotModel; | |
import com.destroytoday.twitterdiff.model.vo.User; | |
import com.destroytoday.util.VectorUtil; | |
import com.destroytoday.vo.Timespan; | |
import flash.data.SQLResult; | |
import flash.errors.SQLError; | |
import org.robotlegs.mvcs.AsyncSignalCommand; | |
public class GetNewFollowerListCommand extends AsyncSignalCommand | |
{ | |
//-------------------------------------------------------------------------- | |
// | |
// Injections | |
// | |
//-------------------------------------------------------------------------- | |
[Inject] | |
public var databaseService:IDatabaseService; | |
[Inject] | |
public var model:FollowerSnapshotModel; | |
[Inject] | |
public var timespan:Timespan; | |
//-------------------------------------------------------------------------- | |
// | |
// Constructor | |
// | |
//-------------------------------------------------------------------------- | |
public function GetNewFollowerListCommand() | |
{ | |
} | |
//-------------------------------------------------------------------------- | |
// | |
// Methods | |
// | |
//-------------------------------------------------------------------------- | |
override public function execute():void | |
{ | |
const selectNewFollowerListQuery:String = | |
"SELECT u.* FROM followerSnapshots fs LEFT JOIN users u ON fs.id=u.id " + | |
"WHERE fs.createdTimestamp >= :timespanStartDate AND fs.createdTimestamp <= :timestampEndDate " + | |
"AND fs.createdTimestamp > (SELECT createdTimestamp FROM followerSnapshots ORDER BY createdTimestamp ASC LIMIT 1)"; | |
databaseService.execute(selectNewFollowerListQuery, | |
{timespanStartDate: timespan.startDate.time, timestampEndDate: timespan.endDate.time}, | |
resultHandler, User, errorHandler); | |
} | |
//-------------------------------------------------------------------------- | |
// | |
// Handlers | |
// | |
//-------------------------------------------------------------------------- | |
protected function resultHandler(result:SQLResult):void | |
{ | |
var newFollowerList:Vector.<User> = new Vector.<User>(); | |
VectorUtil.pushArray(newFollowerList, result.data); | |
model.newFollowerList = newFollowerList; | |
completed.dispatch(); | |
} | |
protected function errorHandler(error:SQLError):void | |
{ | |
failed.dispatch(error.message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment