File: dbObjectId.R

package info (click to toggle)
r-cran-rpostgresql 0.7-7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 720 kB
  • sloc: sh: 3,070; ansic: 3,054; makefile: 7
file content (58 lines) | stat: -rw-r--r-- 2,107 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
## Class: dbObjectId
## $Id$

## This package was developed as a part of Summer of Code program organized by Google.
## Thanks to David A. James & Saikat DebRoy, the authors of RMySQL package.
## Code from RMySQL package was reused with the permission from the authors.
## Also Thanks to my GSoC mentor Dirk Eddelbuettel for helping me in the development.


##
## This mixin helper class is NOT part of the database interface definition,
## but it is extended by the Oracle, MySQL,PostgreSQL and SQLite implementations
## to allow us to conviniently (and portably)
## implement all database foreign objects methods (i.e., methods for show(),
## print() format() the dbManger, dbConnection, dbResultSet, etc.)
## A dbObjectId is an  identifier into an actual remote database objects.
## This class and its derived classes <driver-manager>Object need to
## be VIRTUAL to avoid coercion (green book, p.293) during method dispatching.

setClass("dbObjectId", representation(Id = "integer", "VIRTUAL"))

## coercion methods
setAs("dbObjectId", "integer",
      def = function(from) as(slot(from,"Id"), "integer")
      )
setAs("dbObjectId", "numeric",
      def = function(from) as(slot(from, "Id"), "integer")
      )
setAs("dbObjectId", "character",
      def = function(from) as(slot(from, "Id"), "character")
      )

## formating, showing, printing,...
setMethod("format", "dbObjectId",
          def = function(x, ...) {
              paste("(", paste(as(x, "integer"), collapse=","), ")", sep="")
          },
          valueClass = "character"
          )

setMethod("show", "dbObjectId", def = function(object) print(object))

setMethod("print", "dbObjectId",
          def = function(x, ...){
              expired <- if(isPostgresqlIdCurrent(x)) "" else "Expired "
              str <- paste("<", expired, class(x), ":", format(x), ">", sep="")
              cat(str, "\n")
              invisible(NULL)
          }
          )

## verify that obj refers to a currently open/loaded database
isPostgresqlIdCurrent <- function(obj) {
    obj <- as(obj, "integer")
    .Call(RS_DBI_validHandle, obj)
}