alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lift Framework example source code file (DBRecord.scala)

This example Lift Framework source code file (DBRecord.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lift Framework tags/keywords

boolean, boolean, box, connectionidentifier, dbrecord, dbrecord, full, if, if, mytype, mytype, partialfunction, record, sql

The Lift Framework DBRecord.scala source code

/*
 * Copyright 2007-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 record 

import common._
import db.{ConnectionIdentifier, DB}
import util._
import scala.xml._

@deprecated("This was never fully implemented. If you're looking for a SQL implementation of Record, please see Squeryl-Record. If you have any questions, please bring them up on the mailing list.")
trait DBRecord[MyType <: DBRecord[MyType]] extends Record[MyType] {
  self: MyType =>

  /**
   * Was this instance deleted from backing store?
   */
  private var was_deleted_? = false

  /**
   * The meta record (the object that contains the meta result for this type)
   */
  def meta: DBMetaRecord[MyType]

  /**
   * Save the instance and return the instance
   */
  def save(): MyType = {
    runSafe {
      meta.save(this)
    }
    this
  }


 /**
  * Save the instance and return the instance
  */
  override def saveTheRecord(): Box[MyType] = {save(); Full(this)}

  /**
   * Delete the instance from backing store
   */
  def delete_! : Boolean = {
    if (!can_delete_?) false else
    runSafe {
      was_deleted_? = meta.delete_!(this)
      was_deleted_?
    }
  }

  /**
   * Can this model object be deleted?
   */
  def can_delete_? : Boolean =  meta.saved_?(this) && !was_deleted_?

  private var dbConnectionIdentifier: Box[ConnectionIdentifier] = Empty

  def connectionIdentifier = dbConnectionIdentifier openOr calcDbId

  def dbCalculateConnectionIdentifier: PartialFunction[MyType, ConnectionIdentifier] = Map.empty

  private def calcDbId = if (dbCalculateConnectionIdentifier.isDefinedAt(this)) dbCalculateConnectionIdentifier(this)
                         else meta.dbDefaultConnectionIdentifier

  /**
   * Append a function to perform after the commit happens
   * @param func - the function to perform after the commit happens
   */
  def doPostCommit(func: () => Unit) {
    DB.appendPostFunc(connectionIdentifier, func)
  }
}

Other Lift Framework examples (source code examples)

Here is a short list of links related to this Lift Framework DBRecord.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.