# HG changeset patch # User Tomas Zeman # Date 1334903182 -7200 # Node ID b6584386027440ff10f07a7237c7262b209ce51e # Parent e2a2e2045c0ec3b8269cf0f36ca0cd29563e23d3 Trackable entity: created/updated fields diff -r e2a2e2045c0e -r b65843860274 db/db-schema.sql --- a/db/db-schema.sql Fri Apr 20 08:26:22 2012 +0200 +++ b/db/db-schema.sql Fri Apr 20 08:26:22 2012 +0200 @@ -4,6 +4,7 @@ "l1" bigint not null, "i18n" boolean not null, "name" varchar(100) not null, + "updated_at" timestamp not null, "ol2" bigint, "s3" varchar(200) not null, "id" bigint primary key not null, @@ -20,10 +21,13 @@ "s1" varchar(200) not null, "note" varchar(10240), "os2" varchar(200), + "created_at" timestamp not null, + "created_by" bigint, "i2" integer not null, "oi3" integer, "l2" bigint not null, "ol3" bigint, + "updated_by" bigint, "os3" varchar(200), "deleted" boolean not null ); @@ -32,9 +36,13 @@ create index "code_list_item_code_list_idx" on "code_list_item" ("code_list"); create table "user" ( "name" varchar(100) not null, + "updated_at" timestamp not null, "id" bigint primary key not null, "note" varchar(10240), + "created_at" timestamp not null, + "created_by" bigint, "login" varchar(40) not null, + "updated_by" bigint, "deleted" boolean not null, "active" boolean not null, "password" varchar(128) not null @@ -44,9 +52,13 @@ create index "user_login_idx" on "user" ("login"); create table "city" ( "name" varchar(100) not null, + "updated_at" timestamp not null, "id" bigint primary key not null, "country_id" bigint not null, - "note" varchar(10240) + "note" varchar(10240), + "created_at" timestamp not null, + "created_by" bigint, + "updated_by" bigint ); create sequence "s_city_id"; create table "address" ( @@ -60,13 +72,18 @@ create table "country" ( "iso3" varchar(3) not null, "name" varchar(100) not null, + "updated_at" timestamp not null, "id" bigint primary key not null, "iso2" varchar(2) not null, - "note" varchar(10240) + "note" varchar(10240), + "created_at" timestamp not null, + "created_by" bigint, + "updated_by" bigint ); create sequence "s_country_id"; create table "contact" ( "name" varchar(100) not null, + "updated_at" timestamp not null, "id" bigint primary key not null, "work_mobile" varchar(40) not null, "private_mail" varchar(256), @@ -75,9 +92,12 @@ "first_name" varchar(80) not null, "fax" varchar(40), "note" varchar(10240), + "created_at" timestamp not null, + "created_by" bigint, "other_mail" varchar(256), "position" varchar(40), "other_mobile" varchar(40), + "updated_by" bigint, "private_mobile" varchar(40), "private_phone" varchar(40), "work_phone" varchar(40) @@ -85,11 +105,15 @@ create sequence "contact_id_seq"; create table "company" ( "name" varchar(100) not null, + "updated_at" timestamp not null, "id" bigint primary key not null, "partner" integer not null, "ico" varchar(40) not null, "note" varchar(10240), + "created_at" timestamp not null, + "created_by" bigint, "corresp_address_id" bigint, + "updated_by" bigint, "pin" integer not null, "address_id" bigint not null ); diff -r e2a2e2045c0e -r b65843860274 src/main/scala/fis/aaa/model/AaaSchema.scala --- a/src/main/scala/fis/aaa/model/AaaSchema.scala Fri Apr 20 08:26:22 2012 +0200 +++ b/src/main/scala/fis/aaa/model/AaaSchema.scala Fri Apr 20 08:26:22 2012 +0200 @@ -28,7 +28,7 @@ columns(t.deleted, t.active) are(indexed("user_deleted_active_idx")) )) - User.byId.default.set(UserCrud.get _) + UserVendors.byId.default.set(UserCrud.get _) /** All existing (undeleted) users. */ val usersF = () => from(userT)(u => diff -r e2a2e2045c0e -r b65843860274 src/main/scala/fis/aaa/model/User.scala --- a/src/main/scala/fis/aaa/model/User.scala Fri Apr 20 08:26:22 2012 +0200 +++ b/src/main/scala/fis/aaa/model/User.scala Fri Apr 20 08:26:22 2012 +0200 @@ -42,16 +42,20 @@ */ object User extends User with MetaRecord[User] with Factory { - object cur extends FactoryMaker[Box[User]](Empty) - - object byId extends Inject[Long => Box[User]]({id: Long => Empty}) {} - /** * Returns current logged in user. */ - def get: Box[User] = cur() - + def get: Box[User] = UserVendors.cur() } +/** + * User vendors. + * Must be separate from User due to initialization errors + * in Entity (recursive defs). + */ +object UserVendors extends Factory { + object cur extends FactoryMaker[Box[User]](Empty) + object byId extends Inject[Long => Box[User]]({id: Long => Empty}) {} +} // vim: set ts=2 sw=2 et: diff -r e2a2e2045c0e -r b65843860274 src/main/scala/fis/aaa/model/UserField.scala --- a/src/main/scala/fis/aaa/model/UserField.scala Fri Apr 20 08:26:22 2012 +0200 +++ b/src/main/scala/fis/aaa/model/UserField.scala Fri Apr 20 08:26:22 2012 +0200 @@ -92,8 +92,8 @@ val updatedBy = new UpdatedByField(this.asInstanceOf[T], curUserVendor, getUserVendor) - protected def curUserVendor: Vendor[Box[User]] = User.cur - protected def getUserVendor: Vendor[Long => Box[User]] = User.byId + protected def curUserVendor: Vendor[Box[User]] = UserVendors.cur + protected def getUserVendor: Vendor[Long => Box[User]] = UserVendors.byId } /** diff -r e2a2e2045c0e -r b65843860274 src/main/scala/fis/base/model/Entity.scala --- a/src/main/scala/fis/base/model/Entity.scala Fri Apr 20 08:26:22 2012 +0200 +++ b/src/main/scala/fis/base/model/Entity.scala Fri Apr 20 08:26:22 2012 +0200 @@ -15,16 +15,21 @@ */ package fis.base.model +import fis.aaa.model.{CreatedByField, UpdatedByField, User, UserVendors} +import net.liftweb.common._ +import net.liftweb.http.Factory import net.liftweb.record.{MetaRecord, Record} import net.liftweb.record.field._ import net.liftweb.squerylrecord.KeyedRecord -import net.tz.lift.model.{FieldLabel, OptionalFieldDisplay} +import net.liftweb.util._ +import net.tz.lift.model.{CreatedField, FieldLabel, OptionalFieldDisplay, UpdatedField} import org.squeryl.annotations.Column /** * Base data/model entity trait, common for all FIS entities. */ trait Entity[OwnerType <: Record[OwnerType]] extends KeyedRecord[Long] { + @Column(name="id") val idField = new LongField(this.asInstanceOf[OwnerType]) val name = new StringField(this.asInstanceOf[OwnerType], "") with FieldLabel @@ -33,6 +38,17 @@ /** Display representation of this entity. */ def linkName = name.get + + /* Can't mixin traits directly - must be implemented here. */ + val createdAt = new CreatedField(this.asInstanceOf[OwnerType]) + val updatedAt = new UpdatedField(this.asInstanceOf[OwnerType]) + val createdBy = new CreatedByField(this.asInstanceOf[OwnerType], + curUserVendor, getUserVendor) + val updatedBy = new UpdatedByField(this.asInstanceOf[OwnerType], + curUserVendor, getUserVendor) + + protected def curUserVendor: Vendor[Box[User]] = UserVendors.cur + protected def getUserVendor: Vendor[Long => Box[User]] = UserVendors.byId } import net.liftweb.common.Box