Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 127 lines (91 sloc) 2.965 kb
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
use v6;

class java::sql::Driver { ... };
class java::sql::Connection { ... };

use java::sql::DriverManager;

class DBDI::DriverManager does java::sql::DriverManager {

    my %drivers;

    method registerDriver ( java::sql::Driver $driver ) {
        say "registerDriver($driver)";
        %drivers{$driver} = $driver;
    } # throws java.sql.SQLException


    multi method getConnection (
        Str $url,
    --> java::sql::Connection
    ) {
        return self.getConnection($url, { });
    }


    multi method getConnection (
        Str $url,
        Str $user,
        Str $pass,
    --> java::sql::Connection
    ) {
        my Hash $info .= new;
        $info.<user> = $user;
        $info.<password> = $pass;

        return self.getConnection($url, $info);
    }


    multi method getConnection (
        Str $url,
        Hash $info,
    --> java::sql::Connection
    ) {
        say "> getConnection($url, { $info.perl })";

        my $con;
        for %drivers.values -> $driver {
            $con = $driver.connect($url, $info);
            last if $con;
        }
        die "Unable to find a driver to handle $url" if not $con;

        if (1) {
            my sub log-calls($obj, Role $r) {
                my $wrapper = RoleHOW.new;
                # XXX add caching of log-wrapped variants of roles
                for $r.^methods -> $m {
                    $wrapper.^add_method($m.name, method (|$c) {
                        warn ">> $m\n";
                        nextsame;
                        # XXX ideally should be
                        # my |$retval = callsame;
                        # warn "< $m";
                        # return |$retval;

                        # XXX introspect return type and, if appropriate, add a call
                        # to wrap the returned object with a logging wrapper
                        # so logging gets automatically applied to other types
                    });
                }
                $obj does $wrapper.^compose();
            }
            log-calls($con, java::sql::Connection);
        }

        say "< getConnection $con";
        return $con;
    } # throws java.sql.SQLException


    method deregisterDriver (
        java::sql::Driver $v1, # java.sql.Driver
    ) { ... } # throws java.sql.SQLException


    method getDriver (
        Str $v1, # java.lang.String
    --> java::sql::Driver # java.sql.Driver
    ) { ... } # throws java.sql.SQLException


    method getDrivers (
    --> Iterable # java.util.Enumeration
    ) { ... }


    method getLogWriter (
    --> IO # java.io.PrintWriter
    ) { ... }


    method getLoginTimeout (
    --> Int # int
    ) { ... }


    method initialize (
    ) { ... }


    method println (
        Str $v1, # java.lang.String
    ) { ... }


    method setLogWriter (
        IO $v1, # java.io.PrintWriter
    ) { ... }


    method setLoginTimeout (
        Int $v1, # int
    ) { ... }

}
Something went wrong with that request. Please try again.