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

Scala example source code file (Relation.scala)

This example Scala source code file (Relation.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 - Scala tags/keywords

boolean, boolean, datatype,datatype, list, pair, relation, relation, statement, string, string, unit, untyped, untyped

The Scala Relation.scala source code

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |                                         **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */



package scala.dbc
package statement;


/** A statement that returns a relation. */
@deprecated(DbcIsDeprecated, "2.9.0") abstract class Relation extends Statement {
  
  def isCompatibleType: (DataType,DataType)=>Boolean =
    ((dt,wdt)=>dt.isSubtypeOf(wdt));

  def typeCheck (relation: result.Relation): Unit = {
      val sameType: Boolean = (
        relation.metadata.length == fieldTypes.length &&
        (relation.metadata.zip(fieldTypes).forall({case Pair(field,expectedType) =>
          isCompatibleType(field.datatype, expectedType)}))
      );
      if (!sameType)
        throw new exception.IncompatibleSchema(fieldTypes,relation.metadata.map(field=>field.datatype));
  }

  def fieldTypes: List[DataType];
  
  def sqlTypeString: String =
    if (fieldTypes.isEmpty)
      "UNTYPED"
    else
      fieldTypes.map(dt=>dt.sqlString).mkString("RELATION (",", ",")");
  
  /** A SQL-99 compliant string representation of the statement. */
  def sqlString: String;
  
  /** A SQL-99 compliant string representation of the relation sub-
   * statement. This only has a meaning inside another statement. */
  def sqlInnerString: String;
  
  /** Executes the statement on the given database. */
  def execute (database: scala.dbc.Database): scala.dbc.result.Relation = {
    database.executeStatement(this);
  }
  
  def execute (database:scala.dbc.Database, debug:Boolean): scala.dbc.result.Relation = {
    database.executeStatement(this,debug);
  }
  
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Relation.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.