Created
December 6, 2011 09:29
-
-
Save eiennohito/1437537 to your computer and use it in GitHub Desktop.
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
package org.eiennohito.scot.db | |
import net.liftweb.util.Props | |
import net.liftweb.mongodb.{MongoMeta, MongoIdentifier} | |
/** | |
* @author eiennohito | |
* @since 17.11.11 | |
*/ | |
object DbId extends MongoIdentifier { | |
val dbName = Props.get("db.name", "scot_db") | |
def jndiName = dbName | |
} | |
trait NamedDatabase { self: MongoMeta[_] => | |
override def mongoIdentifier = DbId | |
} |
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
package org.eiennohito.scot.db | |
import net.liftweb.mongodb.MongoDB | |
import com.mongodb.{ServerAddress, Mongo} | |
import net.liftweb.util.Props | |
/** | |
* @author eiennohito | |
* @since 17.11.11 | |
*/ | |
object DbInitializer { | |
var inited = false | |
def init() { | |
if (!inited) { | |
val sa = new ServerAddress(Props.get("db.server").get, Props.getInt("db.port", ServerAddress.defaultPort())) | |
MongoDB.defineDb(DbId, new Mongo(sa), Props.get("db.name").get) | |
inited = true; | |
} | |
} | |
} |
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
package org.eiennohito.scot.model | |
import org.eiennohito.scot.db.NamedDatabase | |
import net.liftweb.mongodb.record.field.{DateField, LongPk} | |
import net.liftweb.mongodb.record.{MongoMetaRecord, MongoRecord} | |
import net.liftweb.record.field.{LongField, StringField} | |
/** | |
* @author eiennohito | |
* @since 17.11.11 | |
*/ | |
class LogEntry private() extends MongoRecord[LogEntry] with LongPk[LogEntry] { | |
def meta = LogEntry | |
object content extends StringField(this, 2500) | |
object nick extends StringField(this, 250) | |
object time extends DateField(this) | |
object conf extends LongField(this) | |
object who extends LongField(this) | |
} | |
object LogEntry extends LogEntry with MongoMetaRecord[LogEntry] with NamedDatabase | |
class Participant private() extends MongoRecord[Participant] with LongPk[Participant] { | |
def meta = Participant | |
object conf extends LongField(this) | |
object nick extends StringField(this, 250) | |
object jid extends StringField(this, 250) | |
} | |
object Participant extends Participant with MongoMetaRecord[Participant] with NamedDatabase | |
class ChangeNickEvent private() extends MongoRecord[ChangeNickEvent] with LongPk[ChangeNickEvent] { | |
def meta = ChangeNickEvent | |
object who extends LongField(this, 250) | |
object from extends StringField(this, 250) | |
object to extends StringField(this, 250) | |
object when extends DateField(this) | |
def participant = Participant.find(who.is) | |
} | |
object ChangeNickEvent extends ChangeNickEvent with MongoMetaRecord[ChangeNickEvent] with NamedDatabase | |
class OnlineTime private() extends MongoRecord[OnlineTime] with LongPk[OnlineTime] { | |
def meta = OnlineTime | |
object who extends LongField(this) | |
object cameOnline extends DateField(this) | |
object wentOffline extends DateField(this) { | |
override def optional_? = true | |
} | |
} | |
object OnlineTime extends OnlineTime with MongoMetaRecord[OnlineTime] with NamedDatabase |
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
def registerNickChange(participant: Participant, newNick: String, date: Date) { | |
val old = participant.nick.valueBox | |
ChangeNickEvent.createRecord | |
.from(old).to(newNick).who(participant.id.is).when(date).save | |
participant.nick(newNick).save | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment