Permalink
Browse files

merged w/remote branch

  • Loading branch information...
unknown unknown
unknown authored and unknown committed Dec 28, 2009
2 parents c6314a0 + 18ae296 commit ecf4451e3aef9bf043b999b56bd535a839e371c1
Showing with 19,706 additions and 0 deletions.
  1. +11 −0 .project
  2. +11 −0 Mongo.cfc
  3. +8 −0 components/Collection.cfc
  4. +56 −0 components/Database.cfc
  5. +67 −0 components/Document.cfc
  6. +191 −0 components/ExpressionBuilder.cfc
  7. +27 −0 components/IDocument.cfc
  8. +13 −0 components/MongoConfig.cfc
  9. +296 −0 components/MongoDB.cfc
  10. +67 −0 components/MongoDocument.cfc
  11. +9 −0 doc/ build_doc.cfm
  12. +436 −0 doc/ColdDoc.cfc
  13. +20 −0 doc/ColdDoc.cfc.diff
  14. +84 −0 doc/UseCase.cfc
  15. BIN doc/api-uml.zargo
  16. BIN doc/api-uml.zargo~
  17. +82 −0 doc/api/allclasses-frame.html
  18. +289 −0 doc/api/cfmongodb/Mongo.html
  19. +477 −0 doc/api/cfmongodb/components/-.html
  20. +293 −0 doc/api/cfmongodb/components/Collection.html
  21. +303 −0 doc/api/cfmongodb/components/Database.html
  22. +594 −0 doc/api/cfmongodb/components/Document.html
  23. +1,088 −0 doc/api/cfmongodb/components/ExpressionBuilder.html
  24. +1,535 −0 doc/api/cfmongodb/components/MongoDB.html
  25. +54 −0 doc/api/cfmongodb/components/package-frame.html
  26. +225 −0 doc/api/cfmongodb/components/package-summary.html
  27. +1,021 −0 doc/api/cfmongodb/doc/ColdDoc.html
  28. +39 −0 doc/api/cfmongodb/doc/package-frame.html
  29. +169 −0 doc/api/cfmongodb/doc/package-summary.html
  30. +777 −0 doc/api/cfmongodb/javaloader/JavaLoader.html
  31. +1,167 −0 doc/api/cfmongodb/javaloader/JavaProxy.html
  32. +42 −0 doc/api/cfmongodb/javaloader/package-frame.html
  33. +179 −0 doc/api/cfmongodb/javaloader/package-summary.html
  34. +39 −0 doc/api/cfmongodb/package-frame.html
  35. +169 −0 doc/api/cfmongodb/package-summary.html
  36. +752 −0 doc/api/cfmongodb/test/BaseTest.html
  37. +793 −0 doc/api/cfmongodb/test/DatabaseTest.html
  38. +1,110 −0 doc/api/cfmongodb/test/DocumentTest.html
  39. +1,052 −0 doc/api/cfmongodb/test/MongoDBTest.html
  40. +823 −0 doc/api/cfmongodb/test/MongoSmokeTest.html
  41. +1,269 −0 doc/api/cfmongodb/test/SearchMongoTest.html
  42. +367 −0 doc/api/cfmongodb/test/SomeDoc.html
  43. +54 −0 doc/api/cfmongodb/test/package-frame.html
  44. +217 −0 doc/api/cfmongodb/test/package-summary.html
  45. +42 −0 doc/api/index.html
  46. +66 −0 doc/api/overview-frame.html
  47. +178 −0 doc/api/overview-summary.html
  48. BIN doc/api/resources/inherit.gif
  49. +29 −0 doc/api/stylesheet.css
  50. +34 −0 doc/docs/allclasses-frame.html
  51. +42 −0 doc/docs/index.html
  52. +51 −0 doc/docs/overview-frame.html
  53. +158 −0 doc/docs/overview-summary.html
  54. BIN doc/docs/resources/inherit.gif
  55. +29 −0 doc/docs/stylesheet.css
  56. +39 −0 doc/resources/static/index.html
  57. BIN doc/resources/static/resources/inherit.gif
  58. +29 −0 doc/resources/static/stylesheet.css
  59. +35 −0 doc/resources/templates/allclasses-frame.html
  60. +548 −0 doc/resources/templates/class.html
  61. +65 −0 doc/resources/templates/inc/nav.html
  62. +40 −0 doc/resources/templates/index.html
  63. +52 −0 doc/resources/templates/overview-frame.html
  64. +70 −0 doc/resources/templates/overview-summary.html
  65. +37 −0 doc/resources/templates/package-frame.html
  66. +75 −0 doc/resources/templates/package-summary.html
  67. +13 −0 doc/run.cfm
  68. +223 −0 javaloader/JavaLoader.cfc
  69. +354 −0 javaloader/JavaProxy.cfc
  70. BIN javaloader/lib/classloader-20080514084644.jar
  71. BIN javaloader/lib/classloader-src.zip
  72. +213 −0 javaloader/licence.txt
  73. +69 −0 javaloader/readme.txt
  74. BIN lib/mongo-java-driver-1.2.jar
  75. +5 −0 test/BaseTest.cfc
  76. +25 −0 test/CollectionEachIteratorTest.cfc
  77. +9 −0 test/DatabaseTest.cfc
  78. +19 −0 test/DocumentFactoryModelTest.cfc
  79. +135 −0 test/DocumentTest.cfc
  80. +329 −0 test/ExpressionBuilderTest.cfc
  81. +17 −0 test/InheritedDocumentTest.cfc
  82. +36 −0 test/ModelTest.cfc
  83. +142 −0 test/MongoDBTest.cfc
  84. +9 −0 test/MongoSmokeTest.cfc
  85. +18 −0 test/NewDocumentTest.cfc
  86. +115 −0 test/SearchMongoTest.cfc
  87. +22 −0 test/SomeDoc.cfc
  88. +13 −0 test/TestSuiteTest.cfc
  89. +19 −0 test/fixture/MyMongoDocument.cfc
  90. +27 −0 test/fixture/MyMongoModel.cfc
View
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>cfmongo</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+</projectDescription>
View
@@ -0,0 +1,11 @@
+<cfcomponent output="false" hint="Convenience wrapper for MongoDB. @see components.MongoDB for wrapper details">
+
+<cfscript>
+ mongodb = createObject('component','components.MongoDB');
+ function init(){
+ return createObject('component','components.MongoDB');
+ }
+</cfscript>
+
+
+</cfcomponent>
@@ -0,0 +1,8 @@
+<cfcomponent output="false" hint="Represents a Mongo Collection">
+<!---
+Operations on Collections:
+
+
+--->
+<cffunction name="init" hint="Constructor"></cffunction>
+</cfcomponent>
View
@@ -0,0 +1,56 @@
+<cfcomponent output="false">
+<!---
+Operations on Databases:
+
+set port
+set server
+
+ --->
+<cfscript>
+//This maybe should be a config object
+config = {
+ server_name = 'localhost',
+ server_port = 27017,
+ db_name = 'default_db',
+ };
+
+ mongo = createObject('java', 'com.mongodb.Mongo').init( variables.config.server_name , variables.config.server_port );
+
+ function getDB(name){
+ return mongo.getDB(name);
+ }
+</cfscript>
+
+<!---
+
+getAddress public com.mongodb.DBAddress com.mongodb.DBTCP.getAddress()
+debugString public java.lang.String com.mongodb.DBTCP.debugString()
+requestStart public void com.mongodb.DBTCP.requestStart()
+requestDone public void com.mongodb.DBTCP.requestDone()
+requestEnsureConnection public void com.mongodb.DBTCP.requestEnsureConnection()
+getConnectPoint public java.lang.String com.mongodb.DBTCP.getConnectPoint()
+getCollectionFromFull public com.mongodb.DBApiLayer$MyCollection com.mongodb.DBApiLayer.getCollectionFromFull(java.lang.String)
+getCollectionFromFull public com.mongodb.DBCollection com.mongodb.DBApiLayer.getCollectionFromFull(java.lang.String)
+getCollectionNames public java.util.Set com.mongodb.DBApiLayer.getCollectionNames() throws com.mongodb.MongoException
+toString public java.lang.String com.mongodb.DB.toString()
+getName public java.lang.String com.mongodb.DB.getName()
+setReadOnly public void com.mongodb.DB.setReadOnly(java.lang.Boolean)
+command public com.mongodb.DBObject com.mongodb.DB.command(com.mongodb.DBObject) throws com.mongodb.MongoException
+eval public java.lang.Object com.mongodb.DB.eval(java.lang.String,java.lang.Object[]) throws com.mongodb.MongoException
+authenticate public boolean com.mongodb.DB.authenticate(java.lang.String,char[]) throws com.mongodb.MongoException
+getCollection public final com.mongodb.DBCollection com.mongodb.DB.getCollection(java.lang.String)
+createCollection public final com.mongodb.DBCollection com.mongodb.DB.createCollection(java.lang.String,com.mongodb.DBObject)
+dropDatabase public void com.mongodb.DB.dropDatabase() throws com.mongodb.MongoException
+getCollectionFromString public com.mongodb.DBCollection com.mongodb.DB.getCollectionFromString(java.lang.String)
+doEval public com.mongodb.DBObject com.mongodb.DB.doEval(java.lang.String,java.lang.Object[]) throws com.mongodb.MongoException
+resetIndexCache public void com.mongodb.DB.resetIndexCache()
+getLastError public com.mongodb.DBObject com.mongodb.DB.getLastError() throws com.mongodb.MongoException
+setWriteConcern public void com.mongodb.DB.setWriteConcern(com.mongodb.DB$WriteConcern)
+getWriteConcern public com.mongodb.DB$WriteConcern com.mongodb.DB.getWriteConcern()
+addUser public void com.mongodb.DB.addUser(java.lang.String,char[])
+getPreviousError public com.mongodb.DBObject com.mongodb.DB.getPreviousError() throws com.mongodb.MongoException
+resetError public void com.mongodb.DB.resetError() throws com.mongodb.MongoException
+forceError public void com.mongodb.DB.forceError() throws com.mongodb.MongoException
+ --->
+
+</cfcomponent>
View
@@ -0,0 +1,67 @@
+<cfcomponent output="false" implements="IDocument" hint="Default implementation of IDocument and used by the Mongo class to generate a document.">
+
+<cfset this.__props__ = structNew() />
+<cfset variables.mongo = createObject('component', 'MongoDB') />
+
+
+<cffunction name="init" hint="Constructor. Creates an instance of a MongoDocument.">
+ <cfargument name="collection_name" type="string" required="true" hint="The name of the collection to which this document is bound." />
+ <cfargument name="_mongo" type="any" required="false" default="#variables.mongo#" hint="The instance of the Mongo wrapper to which the document is bound." />
+ <cfset variables.mongo.collection(collection_name) />
+ <cfset variables.mongo = _mongo />
+ <cfreturn this />
+</cffunction>
+
+
+<cffunction name="setCollection">
+</cffunction>
+
+
+<cffunction name="set" hint="Sets a property for the Document" returntype="void">
+ <cfargument name="property" type="String" />
+ <cfargument name="value" type="Any" />
+ <cfset structInsert(this.__props__, arguments.property, arguments.value) />
+</cffunction>
+
+
+<cffunction name="get" hint="Fetches the value of the given property. Returns null if not found." returntype="Any">
+ <cfargument name="property" />
+ <cfset var ret_val = javacast('null', '') />
+ <cftry>
+ <cfset ret_val = this.__props__[arguments.property] />
+ <cfcatch type="Expression">
+ <!--- want to return null --->
+ </cfcatch>
+ </cftry>
+ <cfreturn ret_val />
+</cffunction>
+
+<cffunction name="remove" returntype="void" hint="Removes a property form a Document. **NOT IMPLEMENTED**">
+ <cfargument name="property" hint="Removes the given property if it exists." />
+ <cfthrow type="NotImplementedException" message="To Do.">
+</cffunction>
+
+
+
+<cffunction name="save" returntype="String">
+ <cfreturn mongo.put(this.__props__) />
+</cffunction>
+
+
+<cffunction name="delete" returntype="void" hint="Deletes this Document from the Collection">
+ <cfset mongo.deleteById(this.__props__['_id']) />
+</cffunction>
+
+
+<cffunction name="update" hint="Performs in-place update of the the value for 'property'. NOT IMPLEMENTED">
+ <cfargument name="property">
+ <cfargument name="value">
+ <cfthrow type="NotImplementedException" message="To Do.">
+</cffunction>
+
+
+<cffunction name="validate" hint="Should be called before save() to perform any required validation. NOT IMPLEMENTED" returntype="void">
+ <cfthrow type="NotImplementedException" message="To Do.">
+</cffunction>
+
+</cfcomponent>
@@ -0,0 +1,191 @@
+<cfcomponent>
+<cfscript>
+
+ /*---------------------------------------------------------------------
+
+ DSL for MongoDB searches:
+
+ mongo.expressionBuilder().
+
+ results = mongo.startsWith('name','foo'). //string
+ endsWith('title','bar'). //string
+ exists('field','value'). //string
+ regex('field','value'). //string
+ eq('field','value'). //numeric
+ lt('field','value'). //numeric
+ gt('field','value'). //numeric
+ gte('field','value'). //numeric
+ lte('field','value'). //numeric
+ in('field','value'). //array
+ nin('field','value'). //array
+ mod('field','value'). //numeric
+ size('field','value'). //numeric
+ after('field','value'). //date
+ before('field','value'). //date
+ search('title,author,date', limit, start);
+
+ search(keys=[keys_to_return],limit=num,start=num);
+
+
+
+
+-------------------------------------------------------------------------------------*/
+
+builder = createObject('java', 'com.mongodb.BasicDBObjectBuilder').start();
+pattern = createObject('java', 'java.util.regex.Pattern');
+
+function startsWith(element, val){
+ var regex = val & '.*';
+ builder.add( element, pattern.compile(regex) );
+ return this;
+}
+
+function endsWith(element, val){
+ var regex = '.*' & val;
+ builder.add( element, pattern.compile(regex) );
+ return this;
+}
+
+
+function exists(element, val){
+ var regex = '.*' & val & '.*';
+ builder.add( element, pattern.compile(regex) );
+ return this;
+}
+
+
+function regex(element, val){
+ var regex = val;
+ builder.add( element, pattern.compile(regex) );
+ return this;
+}
+
+
+function builder(){
+ return builder;
+}
+
+function start(){
+ builder.start();
+ return this;
+}
+
+function get(){
+ return builder.get();
+}
+
+
+//May need at least some exception handling
+function where( js_expression ){
+ builder.add( '$where', js_expression );
+ return this;
+}
+
+function inArray(element, val){
+ builder.add( element, val );
+ return this;
+}
+
+ //vals should be list or array
+function $in(element,vals){
+ if(isArray(vals)) return addArrayCriteria(element,vals,'$in');
+ return addArrayCriteria(element, listToArray(vals),'$in');
+}
+
+function $nin(element,vals){
+ if(isArray(vals)) return addArrayCriteria(element,vals,'$nin');
+ return addArrayCriteria(element, listToArray(vals),'$nin');
+}
+
+
+function $eq(element,val){
+ builder.add( element, val );
+ return this;
+}
+
+
+function $ne(element,val){
+ return addNumericCriteria(element,val,'$ne');
+}
+
+
+function $lt(element,val){
+ return addNumericCriteria(element,val,'$lt');
+}
+
+
+function $lte(element,val){
+ return addNumericCriteria(element,val,'$lte');
+}
+
+
+function $gt(element,val){
+ return addNumericCriteria(element,val,'$gt');
+}
+
+
+function $gte(element,val){
+ return addNumericCriteria(element,val,'$gte');
+}
+
+</cfscript>
+
+<cffunction name="before">
+ <cfargument name="element" type="string" />
+ <cfargument name="val" type="date" />
+ <cfscript>
+ var exp = {};
+ var date = parseDateTime(val);
+ exp['$lte'] = date;
+ builder.add( element, exp );
+ return this;
+ </cfscript>
+</cffunction>
+
+
+<cffunction name="after">
+ <cfargument name="element" type="string" />
+ <cfargument name="val" type="date" />
+ <cfscript>
+ var exp = {};
+ var date = parseDateTime(val);
+ exp['$gte'] = date;
+ builder.add( element, exp );
+ return this;
+ </cfscript>
+</cffunction>
+
+<!---
+Note to self: Using cffunction here because of the ability/need to cast
+arbitrary numeric data to java without using JavaCast. CFARGUMENT takes care
+of that. CF9 might too, but most folks are still < CF9.
+
+But, this also proved to be a very good refactor.
+ --->
+
+<cffunction name="addNumericCriteria" hint="refactored $expressions for numerics">
+ <cfargument name="element" type="string" hint="The element in the document we're searching"/>
+ <cfargument name="val" type="numeric" hint="The comparative value of the element" />
+ <cfargument name="type" type="string" hint="$gt,$lt,etc. The operators - <><=>= ..." />
+ <cfscript>
+ var exp = {};
+ exp[type] = val;
+ builder.add( element, exp );
+ return this;
+ </cfscript>
+</cffunction>
+
+<cffunction name="addArrayCriteria" hint="refactored $expressions for numerics">
+ <cfargument name="element" type="string" hint="The array element in the document we're searching"/>
+ <cfargument name="val" type="array" hint="The value(s) of an element in the array" />
+ <cfargument name="type" type="string" hint="$in,$nin,etc." />
+ <cfscript>
+ var exp = {};
+ exp[type] = val;
+ builder.add( element, exp );
+ return this;
+ </cfscript>
+</cffunction>
+
+
+</cfcomponent>
View
@@ -0,0 +1,27 @@
+<cfinterface displayName="IDocument" hint="All MongoDB Documents should implement this interface. Basic ColdFusion structures can also be saved to the datastore. But from an OO design perspective, it's a good practice to implement this interface">
+
+<cffunction name="setCollection" hint="Sets the collection to which this Document instance belongs. This should be called prior to any other operations. If not, the default Collection, if any, will be the container for this Document."></cffunction>
+
+<cffunction name="set" hint="Sets a property for the Document" returntype="void">
+ <cfargument name="property" type="String" />
+ <cfargument name="value" type="Any" />
+</cffunction>
+
+<cffunction name="get" hint="Fetches the value of the given property. Returns null if not found." returntype="Any">
+ <cfargument name="property" />
+</cffunction>
+
+<cffunction name="remove" returntype="void">
+ <cfargument name="property" hint="Removes the given property if it exists." />
+</cffunction>
+
+<cffunction name="save" hint="Commits this Document instance to the datastore and returns an ID" returntype="String"></cffunction>
+
+<cffunction name="update" hint="Performs in-place updating - Instead of retrieving and updating every item within a document, this method is more efficient, allowing for 'Cherry Picking' of specific data elements to update. ">
+ <cfargument name="property">
+<cfargument name="value">
+</cffunction>
+
+<cffunction name="validate" hint="Should be called before save()" returntype="void"></cffunction>
+
+</cfinterface>
View
@@ -0,0 +1,13 @@
+<cfcomponent output="false" hint="Main configuration information for MongoDb connections. Defaults are provided, but should be changed as needed. ">
+<cfscript>
+
+ //Default values
+ this.defaults = {
+ server_name = 'localhost',
+ server_port = 27017,
+ db_name = 'default_db',
+ collection_name = 'default_collection'
+ };
+
+</cfscript>
+</cfcomponent>
Oops, something went wrong.

0 comments on commit ecf4451

Please sign in to comment.