forked from lift/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Tim Nelson
committed
Oct 3, 2011
1 parent
f4b8461
commit 7805a44
Showing
7 changed files
with
158 additions
and
52 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
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
84 changes: 84 additions & 0 deletions
84
...ce/mongodb-record/src/main/scala/net/liftweb/mongodb/record/field/MongoRefListField.scala
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,84 @@ | ||
/* | ||
* Copyright 2011 WorldWide Conferencing, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.liftweb | ||
package mongodb | ||
package record | ||
package field | ||
|
||
import common._ | ||
import http.{S, SHtml} | ||
import net.liftweb.record.{Field, MandatoryTypedField, TypedField} | ||
|
||
import java.util.UUID | ||
|
||
import org.bson.types.ObjectId | ||
|
||
/* | ||
* Trait for creating a Field for storing a list of "foreign keys". Caches the | ||
* items after fetching. Implementations are available for ObjectId, UUID, String, | ||
* Int, and Long, but you can extend this. | ||
* | ||
* toForm produces a multi-select form element. You just need to supply the | ||
* options by overriding the options method. | ||
*/ | ||
abstract class MongoRefListField[OwnerType <: BsonRecord[OwnerType], RefType <: MongoRecord[RefType], MyType] | ||
(rec: OwnerType)(implicit mf: Manifest[MyType]) extends MongoListField[OwnerType, MyType](rec) { | ||
|
||
/** The MongoMetaRecord of the referenced object **/ | ||
def refMeta: MongoMetaRecord[RefType] | ||
|
||
/* | ||
* get the referenced objects | ||
*/ | ||
def objs = synchronized { | ||
if (!_calcedObjs) { | ||
_calcedObjs = true | ||
this._objs = refMeta.findAllByList(this.value) | ||
} | ||
_objs | ||
} | ||
|
||
def cached_? : Boolean = synchronized { _calcedObjs } | ||
|
||
def primeObjs(objs: List[RefType]) = synchronized { | ||
_objs = objs | ||
_calcedObjs = true | ||
} | ||
|
||
private var _objs: List[RefType] = Nil | ||
private var _calcedObjs = false | ||
} | ||
|
||
class ObjectIdRefListField[OwnerType <: BsonRecord[OwnerType], RefType <: MongoRecord[RefType]]( | ||
rec: OwnerType, val refMeta: MongoMetaRecord[RefType] | ||
) extends MongoRefListField[OwnerType, RefType, ObjectId](rec) {} | ||
|
||
class UUIDRefListField[OwnerType <: BsonRecord[OwnerType], RefType <: MongoRecord[RefType]]( | ||
rec: OwnerType, val refMeta: MongoMetaRecord[RefType] | ||
) extends MongoRefListField[OwnerType, RefType, UUID](rec) {} | ||
|
||
class StringRefListField[OwnerType <: BsonRecord[OwnerType], RefType <: MongoRecord[RefType]]( | ||
rec: OwnerType, val refMeta: MongoMetaRecord[RefType] | ||
) extends MongoRefListField[OwnerType, RefType, String](rec) {} | ||
|
||
class IntRefListField[OwnerType <: BsonRecord[OwnerType], RefType <: MongoRecord[RefType]]( | ||
rec: OwnerType, val refMeta: MongoMetaRecord[RefType] | ||
) extends MongoRefListField[OwnerType, RefType, Int](rec) {} | ||
|
||
class LongRefListField[OwnerType <: BsonRecord[OwnerType], RefType <: MongoRecord[RefType]]( | ||
rec: OwnerType, val refMeta: MongoMetaRecord[RefType] | ||
) extends MongoRefListField[OwnerType, RefType, Long](rec) {} |
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