Permalink
Browse files

major refactor

  • Loading branch information...
1 parent 2ac61cb commit f30229cff0b0528dd78d1d2dff2e28ed80f4e0d1 billy committed Dec 11, 2009
View
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>cfmongodb</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- </buildSpec>
- <natures>
- <nature>org.cfeclipse.cfml.CFENature</nature>
- </natures>
-</projectDescription>
View
@@ -1,19 +0,0 @@
-<cfcomponent output="false">
-<cfscript>
-this.id = '';
-this.title = '';
-this.body = '';
-this.tags = [];
-this.author = '';
-this.pub_date = now();
-this.comments = arrayNew(1);
-
-this.comment = {
-comment_author = 'Coward',
-comment_email = '',
-comment_www = '',
-comment_text = ''};
-
-this.comments[1] = this.comment;
-</cfscript>
-</cfcomponent>
View
@@ -1,33 +0,0 @@
-<cfcomponent output="false">
-<cfscript>
-mongo = createObject('component','MongoDB');
-</cfscript>
-
-
-<cffunction name="createBlogPost" access="remote">
- <cfargument name="title" />
- <cfargument name="author" />
- <cfargument name="tags" />
- <cfargument name="text" />
- <cfscript>
- blog = createObject('component','Blog');
- blog.title = arguments.title;
- blog.author = arguments.author;
- blog.tags = listToArray(arguments.tags);
- blog.text = arguments.text;
- mongo.put(blog);
- </cfscript>
-
-</cffunction>
-
-
-<cffunction name="getBlogPosts" access="remote">
- <cfreturn mongo.find() />
-</cffunction>
-
-<cffunction name="deletePost" access="remote">
- <cfargument name="id" type="string" />
- <cfset mongo.deleteById(id) />
-</cffunction>
-
-</cfcomponent>
File renamed without changes.
View
@@ -1,48 +0,0 @@
-<cfcomponent output="false" extends="mxunit.framework.TestCase">
-<cfscript>
- mongo = createObject('component', 'MongoDB');
- blog = createObject('component', 'Blog');
-
-
- blog.title = 'Title 1';
- blog.text = 'Text 1';
- blog.author = 'bill-1';
- mongo.put(blog);
-
- blog.title = 'Title 2';
- blog.text = 'Text 2';
- blog.author = 'bill-2';
- mongo.put(blog);
-
- blog.title = 'Title 3';
- blog.text = 'Text 3';
- blog.author = 'bill-3';
- mongo.put(blog);
-
- /* weird. setUp appears to not be called in Railo? */
-
- function _tearDown(){
- items = mongo.findAll();
- for(i=1; i<=arrayLen(items);i++){
- o = items[i];
- mongo.deleteById( o['_id'].toString() );
- debug( o['_id'].toString() );
- }
- }
-
-
- function testFindIterator(){
- items = mongo.findAll();
- assertEquals(3,items.size());
- }
-
-
-
- function setUp(){
-
- }
-
-
-
-</cfscript>
-</cfcomponent>
View
@@ -1,96 +0,0 @@
-<cfcomponent output="false">
-
-<cfscript>
-//This is configurable.
-server_name = 'localhost';
-server_port = 27017;
-db_name = 'default_db';
-collection_name = 'default_collection';
-
-//maybe this goes in super class?
-mongo = createObject('java', 'com.mongodb.Mongo').init( variables.server_name , variables.server_port );
-db = mongo.getDb(db_name);
-collection = db.getCollection(collection_name);
-
-
-//------------------------------------------------------------------------//
-function add(key,value,o){
- //add key value pair to object ... todo
-}
-
-
-function put(o){
- var doc = createObject('java', 'com.mongodb.BasicDBObject').init();
- var id = chr(0);
- doc.putAll(o);
- id = collection.insert(doc).get("_id");
- o._id = id; //add the _id object to the struct
- return id;
-}//end function
-
-
-
-function get(field,value){
- var q = createObject('java', 'com.mongodb.BasicDBObject').init(field,value);
- var cursor = collection.find(q);
- return cursor.next();
-} //end function
-
-
-//when only a string id is available
-function getById(id){
- var objId = createObject('java','com.mongodb.ObjectId').init(id);
- return get("_id", objId);
- } //en
-
-
-function count(){
- return collection.getCount();
-}
-
-
-function findOne(){
- return collection.findOne();
-} //
-
-
-function findAll(){
- var sort = {pub_date = -1};
- var sort_spec = createObject('java', 'com.mongodb.BasicDBObject').init(sort);
- return collection.find().sort( sort_spec ).toArray();
-} //end function
-
-
-function delete(o){
- var obj = get("_id", o._id);
- return collection.remove(obj); //id's of deleted items
-} //end function
-
-
-//Note the ObjectId object. This creates an ObjectId from
-//the string representation of
-
-function deleteById(id){
- var objId = createObject('java','com.mongodb.ObjectId').init(id);
- var obj = get("_id", objId);
- return collection.remove(obj); //id's of deleted items
-} //en
-
-
-function update(o){
- var obj = get("_id", o._id);
- var new_object = createObject('java', 'com.mongodb.BasicDBObject').init(o);
- return collection.update(obj, new_object, false, false);
-
-} //end function
-
-
-
-//not tested ...
-function switchCollection(collection_name){
- collection = db.getCollection(collection_name);
-}
-
-</cfscript>
-
-</cfcomponent>
View
@@ -1,108 +0,0 @@
-<cfcomponent output="false" extends="mxunit.framework.TestCase">
-<cfscript>
-
- friend = {
- name="f",
- email = 'f@f.org',
- address = {
- street = '123 f st',
- city = 'f',
- state = 'f',
- zip = '12345',
- country = 'usa'
- }
- };
-
- person = {
- name="bill",
- email = 'bill@mxunit.org',
- address = {
- street = '123 main st',
- city = 'anytown',
- state = 'here',
- zip = '12345',
- country = 'usa'
- },
- friend=friend
- };
-
-
-function testSerializeJSONThis(){
- var p = createObject('component','Blog');
- var j = serializeJSON(p);
- debug(j);
- mongo = createObject('component','MongoDB');
- id = mongo.put(p);
- o = mongo.get('_id',id);
- debug(o);
- mongo.delete(p);
-}
-
-function $endToEndSyntax(){
- mongo = createObject('component','MongoDB');
- id = mongo.put(person); //name/value or struct
- the_guy = mongo.get('_id',id);
- debug(id.toString());
- debug( mongo.count() );
- assert(1==mongo.count());
- mongo.delete(person);
-
-}
-
-function $testFindSame(){
- return;
- mongo = createObject('component','MongoDB');
- //id = mongo.put(person); //name/value or struct
- person.name = 'ed';
- newperson = mongo.findSame(person);
- debug(person);
- debug(newperson);
- mongo.delete(person);
- assertEquals(newperson.name,'ed');
-}
-
-function $updatePerson(){
- mongo = createObject('component','MongoDB');
- mongo.put(person); //name/value or struct
- person.name = 'ed';
- newperson = mongo.update(person);
- //debug(newperson.hashCode());
- debug(newperson);
-
- mongo.delete(person);
-
-
-}
-
-
-
- person ={
- name='bill',
- email='bill@bill.com'
- };
-
- function getByStringIdTest(){
- var localp ={
- name='shmoopy',
- email='shmoopy@bshmoopy.com'
- };
- var id = mongo.put(localp);
- var fetched_from_db_person = mongo.getById( id.toString() );
- debug(fetched_from_db_person);
- mongo.deleteById(id.toString());
- assertEquals(fetched_from_db_person.name,'shmoopy');
-
- }
-
-
- function setUp(){
- mongo = createObject('component','MongoDB');
- }
-
- function tearDown(){
-
- }
-
-
-</cfscript>
-</cfcomponent>
View
46 README
@@ -1,46 +0,0 @@
-10.18.2009
-bill shelton
-
-This is simple proof of concept of using ColdFusion and MongoDB.
-
-Conclusion: sweet
-
-Description: Inserts CFML structs into MongoDB
-Basic Usage:
-
-mongo = createObject('component','MongoDB');
-
-person = {
- name="bill",
- email = 'bill@mxunit.org',
- address = {
- street = '123 main st',
- city = 'anytown',
- state = 'here',
- zip = '12345',
- country = 'usa'
- },
- };
-
-id = mongo.put(person);
-person.city = 'some other town';
-mongo.update(person);
-fetched_person = mongo.get
-
-mongo.delete(person);
-
-Installation:
-
-1. Download and install MongoDB: http://www.mongodb.org/
-2. Make sure mongod is running. The examples use MongoDB's defaults:
- server_name = 'localhost', server_port = 27017
-3. Download the MongoDB Java Driver: http://github.com/mongodb/mongo-java-driver/downloads
-4. Place the Java MongoDB Driver in your CF Server's classpath (some /lib somewhere)
-5. Copy the CFMongoDB files to your web root; e.g, /cfmongo.
-6. Start the server and point your browser to http://localhost:8888/cfmongo/demo.cfm
-
-Notes: This was built and tested on Railo 3.1.1 Express and Ubuntu 9.04. Would like to
-test this in other environments.
-
-
-
File renamed without changes.
Oops, something went wrong.

0 comments on commit f30229c

Please sign in to comment.