From user-return-7760-apmail-geronimo-user-archive=geronimo.apache.org@geronimo.apache.org Thu Sep 27 04:47:15 2007 Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 86293 invoked from network); 27 Sep 2007 04:47:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Sep 2007 04:47:14 -0000 Received: (qmail 59090 invoked by uid 500); 27 Sep 2007 04:46:56 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 59064 invoked by uid 500); 27 Sep 2007 04:46:56 -0000 Mailing-List: contact user-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: user@geronimo.apache.org List-Id: Delivered-To: mailing list user@geronimo.apache.org Received: (qmail 59047 invoked by uid 99); 27 Sep 2007 04:46:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Sep 2007 21:46:56 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [193.110.102.5] (HELO linuxap01e.dmc.de) (193.110.102.5) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Sep 2007 04:46:53 +0000 Received: from [127.0.0.1] (helo=localhost) by linuxap01e.dmc.de with esmtp (Exim 4.63) (envelope-from ) id 1IalGh-0002tc-BA for user@geronimo.apache.org; Thu, 27 Sep 2007 06:46:31 +0200 X-Virus-Scanned: amavisd-new at dmc.de Received: from linuxap01e.dmc.de ([127.0.0.1]) by localhost (linux-ap01e.dmc.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8NzhO62ZTXI0 for ; Thu, 27 Sep 2007 06:46:29 +0200 (CEST) Received: from [193.110.102.2] (helo=dmc-l01-mx01.dmc.local) by linuxap01e.dmc.de with esmtp (Exim 4.63) (envelope-from ) id 1IalGf-0002tS-OC for user@geronimo.apache.org; Thu, 27 Sep 2007 06:46:29 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: AW: How to register a Datasource in GlobalJNDI Namespace? Date: Thu, 27 Sep 2007 06:46:29 +0200 Message-ID: <5EF9ADF93DC4DA46ACD21782C13680CF12BF3C@dmc-l01-mx01.dmc.local> In-Reply-To: <3D94D1D5-6FF9-4BBD-84D3-83C6786A88B7@yahoo.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: How to register a Datasource in GlobalJNDI Namespace? Thread-Index: AcgAR8dwxuie2eusSUW2A8ebZGWnOwAeVw1A From: =?iso-8859-1?Q?Kristian_K=F6hler?= To: X-Virus-Checked: Checked by ClamAV on apache.org Thanks David and Tomasz! Works great. :-) Kristian > -----Urspr=FCngliche Nachricht----- > Von: David Jencks [mailto:david_jencks@yahoo.com] > Gesendet: Mittwoch, 26. September 2007 16:15 > An: user@geronimo.apache.org > Betreff: Re: How to register a Datasource in GlobalJNDI Namespace? >=20 >=20 >=20 > On Sep 26, 2007, at 3:33 AM, Kristian K=F6hler wrote: >=20 > > Hi > > > > i use a custom deployment mechanism to install my application into =20 > > Geronimo 2.0.1. I have no special deployment plan for that kind of =20 > > application. One component out of my application wants to access =20 > > the DataSource registered within Geronimo Application server. The =20 > > component tries to lookup the db via a JNDI lookup call. > > > > My idea is to register the DB within the Global JNDI Namespace and =20 > > that access it from within my application. I configured the pool =20 > > via deployment plan and registered a GBeanBinding GBean for the =20 > > registration in the Global Namespace. > > > > My problem is: What's the name of the DBPool to access/ to link to =20 > > with the GBeanBinding? Is this a passable way to do this? >=20 > You can but its a pain. You need to find the =20 > ManagedConnectionFactoryWrapper for your pool and call=20 > $getResource() =20 > on it to get the datasource. >=20 > Instead you might try the more specific connection factory binder =20 > dain wrote a long time ago that has been languishing in the=20 > sandbox. =20 > This will let you get the actual datasource out of jndi. I haven't =20 > tested it but someone has recently got something similar and a =20 > related class for admin objects to work. >=20 > thanks > david jencks >=20 > /* > * Licensed to the Apache Software Foundation (ASF) under one > * or more contributor license agreements. See the NOTICE file > * distributed with this work for additional information > * regarding copyright ownership. The ASF licenses this file > * to you 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. > */ >=20 >=20 > package org.apache.geronimo.connector.globaljndi; >=20 > import org.apache.geronimo.connector.outbound.ConnectionFactorySource; > import org.apache.geronimo.gbean.AbstractName; > import org.apache.geronimo.gbean.AbstractNameQuery; > import org.apache.geronimo.gbean.GBeanInfo; > import org.apache.geronimo.gbean.GBeanInfoBuilder; > import org.apache.geronimo.gbean.GBeanLifecycle; > import org.apache.geronimo.gjndi.KernelContextGBean; > import org.apache.geronimo.kernel.Kernel; >=20 > import javax.naming.Name; > import javax.naming.NameParser; > import javax.naming.NamingException; > import javax.resource.ResourceException; >=20 > import java.util.Collections; > import java.util.Map; >=20 > /** > * @version $Rev$ $Date$ > */ > public class ResourceBindings extends KernelContextGBean implements =20 > GBeanLifecycle { > private final Class type; >=20 > public ResourceBindings(Kernel kernel, String nameInNamespace, =20 > Class type) throws NamingException { > super(nameInNamespace, new AbstractNameQuery(null, =20 > Collections.EMPTY_MAP, ConnectionFactorySource.class.getName()), =20 > kernel); > this.type =3D type; > } >=20 > public ResourceBindings(Kernel kernel, String nameInNamespace, =20 > ClassLoader classLoader, String type) throws NamingException, =20 > ClassNotFoundException { > super(nameInNamespace, new AbstractNameQuery(null, =20 > Collections.EMPTY_MAP, ConnectionFactorySource.class.getName()), =20 > kernel); > this.type =3D classLoader.loadClass(type); > } >=20 > protected Map createBindings(AbstractName abstractName, Object =20 > value) throws NamingException { > if (value instanceof ConnectionFactorySource) { > ConnectionFactorySource connectionFactorySource =3D =20 > (ConnectionFactorySource) value; >=20 > String name =3D (String)=20 > abstractName.getName().get("name"); > if (name =3D=3D null) return null; >=20 > Object resource =3D null; > try { > resource =3D connectionFactorySource.$getResource(); > } catch (ResourceException e) { > throw (NamingException)new NamingException("Could =20 > not obtain connection factory from gbean").initCause(e); > } > if (!type.isInstance(resource)) return null; >=20 > NameParser parser =3D getNameParser(); > Name jndiName =3D parser.parse(name); >=20 > return Collections.singletonMap(jndiName, resource); > } > throw new NamingException("value is not a =20 > ConnectionFactorySource: abstractName=3D" + abstractName + " =20 > valueType=3D" + value.getClass().getName()); > } >=20 > public static final GBeanInfo GBEAN_INFO; >=20 > public static GBeanInfo getGBeanInfo() { > return ResourceBindings.GBEAN_INFO; > } >=20 > static { > GBeanInfoBuilder builder =3D GBeanInfoBuilder.createStatic=20 > (ResourceBindings.class, "JdbcBindings"); > builder.addAttribute("type", String.class, true); > builder.setConstructor(new String[]{"kernel", =20 > "nameInNamespace", "classLoader", "type"}); > GBEAN_INFO =3D builder.getBeanInfo(); > } > } >=20 --- http://gaswerk.sourceforge.net