summaryrefslogtreecommitdiff
path: root/src/dbc
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-04-19 17:59:46 +0000
committermichelou <michelou@epfl.ch>2007-04-19 17:59:46 +0000
commit5cc62b4e5cfe4f37b7b30ae9d2cadcdbb406987e (patch)
tree6e6b95195d1582f69d4e56a85f90d3d5530608fe /src/dbc
parented8f3f0b9b31e75b14933e889d6aa105d2c0f0b7 (diff)
downloadscala-5cc62b4e5cfe4f37b7b30ae9d2cadcdbb406987e.tar.gz
scala-5cc62b4e5cfe4f37b7b30ae9d2cadcdbb406987e.tar.bz2
scala-5cc62b4e5cfe4f37b7b30ae9d2cadcdbb406987e.zip
updated tests for productElement/-Arity
Diffstat (limited to 'src/dbc')
-rw-r--r--src/dbc/scala/dbc/Database.scala64
-rw-r--r--src/dbc/scala/dbc/result/Relation.scala42
2 files changed, 54 insertions, 52 deletions
diff --git a/src/dbc/scala/dbc/Database.scala b/src/dbc/scala/dbc/Database.scala
index 3167c30c71..f10d73f8a0 100644
--- a/src/dbc/scala/dbc/Database.scala
+++ b/src/dbc/scala/dbc/Database.scala
@@ -1,7 +1,7 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
@@ -9,30 +9,32 @@
// $Id:Database.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
-package scala.dbc;
+package scala.dbc
-import java.sql._;
+import java.sql._
/** A link to a database. The <code>Database</code> abstract class must
- * be specialised for every different DBMS.
- * @author Gilles Dubochet **/
+ * be specialised for every different DBMS.
+ *
+ * @author Gilles Dubochet
+ */
case class Database(dbms: Vendor) {
class Closed extends Exception {}
/** A lock used for operations that need to be atomic for this database
* instance. */
- private val lock: scala.concurrent.Lock = new scala.concurrent.Lock();
+ private val lock: scala.concurrent.Lock = new scala.concurrent.Lock()
/** The vendor of the DBMS that contains this database. */
- private val vendor: Vendor = dbms;
+ private val vendor: Vendor = dbms
/** The Database connections available to use. */
- private var availableConnections: List[Connection] = Nil;
+ private var availableConnections: List[Connection] = Nil
/** The connections that are currently in use. */
- private var usedConnections: List[Connection] = Nil;
+ private var usedConnections: List[Connection] = Nil
/** Whether the database no longer accepts new connections. */
private var closing: Boolean = false;
@@ -40,7 +42,7 @@ case class Database(dbms: Vendor) {
/** Retrieves a connection from the available connection pool or creates
* a new one.
*
- * @returns A connection that can be used to access the database.
+ * @return A connection that can be used to access the database.
*/
private def getConnection: Connection = {
if (closing) {
@@ -72,23 +74,23 @@ case class Database(dbms: Vendor) {
*/
private def closeConnection(connection: Connection): Unit = {
if (closing) {
- connection.close();
+ connection.close()
} else {
- lock.acquire;
+ lock.acquire
usedConnections = usedConnections.remove(e => (e.equals(connection)));
if (availableConnections.length < vendor.retainedConnections)
availableConnections = connection :: availableConnections
else
- connection.close();
- lock.release;
+ connection.close()
+ lock.release
}
}
/** ..
*/
- def close: Unit = {
- closing = true;
- for (val conn <- availableConnections) conn.close();
+ def close {
+ closing = true
+ for (conn <- availableConnections) conn.close()
}
/** Executes a statement that returns a relation on this database.
@@ -108,12 +110,12 @@ case class Database(dbms: Vendor) {
def executeStatement(relationStatement: statement.Relation,
debug: Boolean): result.Relation =
new scala.dbc.result.Relation {
- val statement = relationStatement;
- if (debug) Console.println("## " + statement.sqlString);
- private val connection = getConnection;
- val sqlResult = connection.createStatement().executeQuery(statement.sqlString);
- closeConnection(connection);
- statement.typeCheck(this);
+ val statement = relationStatement
+ if (debug) Console.println("## " + statement.sqlString)
+ private val connection = getConnection
+ val sqlResult = connection.createStatement().executeQuery(statement.sqlString)
+ closeConnection(connection)
+ statement.typeCheck(this)
}
/** Executes a statement that updates the state of the database.
@@ -159,10 +161,10 @@ case class Database(dbms: Vendor) {
*/
def executeStatement[ResultType](transactionStatement: statement.Transaction[ResultType], debug: Boolean): result.Status[ResultType] = {
new scala.dbc.result.Status[ResultType] {
- val touchedCount = None;
- val statement = transactionStatement;
- private val connection = getConnection;
- connection.setAutoCommit(false);
+ val touchedCount = None
+ val statement = transactionStatement
+ private val connection = getConnection
+ connection.setAutoCommit(false)
val jdbcStatement: java.sql.Statement = connection.createStatement();
if (debug) Console.println("## " + transactionStatement.sqlStartString);
jdbcStatement.execute(transactionStatement.sqlStartString);
@@ -175,11 +177,11 @@ case class Database(dbms: Vendor) {
case e: Throwable => {
if (debug) Console.println("## " + transactionStatement.sqlAbortString);
jdbcStatement.execute(transactionStatement.sqlAbortString);
- throw e;
+ throw e
}
}
- connection.setAutoCommit(true);
- closeConnection(connection);
+ connection.setAutoCommit(true)
+ closeConnection(connection)
}
}
diff --git a/src/dbc/scala/dbc/result/Relation.scala b/src/dbc/scala/dbc/result/Relation.scala
index 5ffc387a87..6388c5594c 100644
--- a/src/dbc/scala/dbc/result/Relation.scala
+++ b/src/dbc/scala/dbc/result/Relation.scala
@@ -1,7 +1,7 @@
/* __ *\
** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
@@ -9,7 +9,7 @@
// $Id:Relation.scala 6853 2006-03-20 16:58:47 +0100 (Mon, 20 Mar 2006) dubochet $
-package scala.dbc.result;
+package scala.dbc.result
/** An ISO-9075:2003 (SQL) table. This is equivalent to a relation in the
@@ -17,24 +17,24 @@ package scala.dbc.result;
abstract class Relation extends AnyRef with Iterable[Tuple] {
/** The statement that generated this relation. */
- def statement: scala.dbc.statement.Relation;
+ def statement: scala.dbc.statement.Relation
/** A JDBC result containing this relation. */
- protected def sqlResult: java.sql.ResultSet;
+ protected def sqlResult: java.sql.ResultSet
/** A JDBC metadata object attached to the relation. */
- protected def sqlMetadata: java.sql.ResultSetMetaData = sqlResult.getMetaData();
+ protected def sqlMetadata: java.sql.ResultSetMetaData = sqlResult.getMetaData()
/** Metadata about all fields in a tuple of the relation. */
def metadata: List[FieldMetadata] =
- for (val count <- List.range(1, sqlMetadata.getColumnCount()+1)) yield
+ for (count <- List.range(1, sqlMetadata.getColumnCount()+1)) yield
new FieldMetadata {
- val name: String = sqlMetadata.getColumnName(count);
- val index: Int = count;
- val datatype: DataType = dbc.datatype.Factory.create(sqlMetadata,count);
- val catalog: String = sqlMetadata.getCatalogName(count);
- val schema: String = sqlMetadata.getSchemaName(count);
- val table: String = sqlMetadata.getTableName(count);
+ val name: String = sqlMetadata.getColumnName(count)
+ val index: Int = count
+ val datatype: DataType = dbc.datatype.Factory.create(sqlMetadata,count)
+ val catalog: String = sqlMetadata.getCatalogName(count)
+ val schema: String = sqlMetadata.getSchemaName(count)
+ val table: String = sqlMetadata.getTableName(count)
}
/** Metadata about the field at the given index. If there is no such
@@ -52,18 +52,18 @@ abstract class Relation extends AnyRef with Iterable[Tuple] {
* in DBMS. This means that if this method is called multiple times, all returned
* iterators will share the same state. */
def elements: Iterator[Tuple] = new Iterator[Tuple] {
- protected val result: java.sql.ResultSet = Relation.this.sqlResult;
- def hasNext: Boolean = !(result.isLast());
+ protected val result: java.sql.ResultSet = Relation.this.sqlResult
+ def hasNext: Boolean = !(result.isLast())
def next: Tuple = {
if (result.next()) {
new Tuple {
- val me = this;
- val originatingRelation = Relation.this;
- val fields: List[Field] = for (val fieldMetadata <- metadata) yield
+ val me = this
+ val originatingRelation = Relation.this
+ val fields: List[Field] = for (fieldMetadata <- metadata) yield
new Field {
- val metadata = fieldMetadata;
- val content = dbc.value.Factory.create(result,metadata.index,metadata.datatype);
- val originatingTuple = me;
+ val metadata = fieldMetadata
+ val content = dbc.value.Factory.create(result,metadata.index,metadata.datatype)
+ val originatingTuple = me
}
}
} else error("next on empty iterator")