Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6063f45
commit e3432d2
Showing
4 changed files
with
242 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package mesh.model.query | ||
{ | ||
import collections.HashMap; | ||
|
||
import mesh.model.Store; | ||
|
||
/** | ||
* A class that caches the results of each query in the store. | ||
* | ||
* @author Dan Schultz | ||
*/ | ||
public class Queries | ||
{ | ||
private var _store:Store; | ||
private var _cache:HashMap = new HashMap(); | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param store The store that owns these queries. | ||
*/ | ||
public function Queries(store:Store) | ||
{ | ||
_store = store; | ||
} | ||
|
||
/** | ||
* Returns the cached result for the given query. If the result hasn't been | ||
* cached, then a new result is created. | ||
* | ||
* @param query The query to get the results for. | ||
* @return The query's result. | ||
*/ | ||
public function result(query:Query):ResultList | ||
{ | ||
if (!isCached(query)) { | ||
_cache.put(query, new ResultList(query, _store).refresh()); | ||
} | ||
return _cache.grab(query); | ||
} | ||
|
||
private function isCached(query:Query):Boolean | ||
{ | ||
return _cache.containsKey(query); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package mesh.model.query | ||
{ | ||
import mesh.core.List; | ||
import mesh.model.Store; | ||
|
||
/** | ||
* The <code>ResultList</code> is a list of entities after an execution of a | ||
* query. | ||
* | ||
* @author Dan Schultz | ||
*/ | ||
public class ResultList extends List | ||
{ | ||
private var _query:Query; | ||
private var _store:Store; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param query The query bound to this result. | ||
* @param store The store that the query is executing against. | ||
*/ | ||
public function ResultList(query:Query, store:Store) | ||
{ | ||
super(); | ||
_query = query; | ||
_store = store; | ||
} | ||
|
||
/** | ||
* Refreshes the results of this list based on the list's query. | ||
* | ||
* @return This list. | ||
*/ | ||
public function refresh():ResultList | ||
{ | ||
return this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
override public function get source():Array | ||
{ | ||
return super.source.concat(); | ||
} | ||
override public function set source(value:Array):void | ||
{ | ||
// Don't allow clients to set the source. | ||
} | ||
} | ||
} |