Re: [Dev] How to get a connection from the carbon datasources

2016-09-28 Thread Kishanthan Thangarajah
Hi Niranda,

What you have given is mostly used when accessing datasources within
webapps. This is where using JNDI lookup will be helpful. But if this is
within an OSGi component that you want to access datasources, then best way
is to use relevant OSGi services as mentioned by Rajith above.

Thanks,
Kishanthan.

On Tue, Sep 27, 2016 at 9:29 AM, Rajith Vitharana  wrote:

> Hi Niranda,
>
> Since we use jndi, IMO this approach is also ok. Other than that, you can
> also get carbon datasource using Ndatasource component as well. Sample will
> be as below
>
> CarbonDataSource cds = dataSourceService.getDataSource("datasourceName");
>
> You will need to get the datasourceService[2] as osgi service.
>
> AFAIR you need to mention datasource name from "name" tag [1]
>
> [1] - 
> WSO2_CARBON_DB
> [2] - org.wso2.carbon.ndatasource.core.DataSourceService
>
> Thanks,
>
>
> On 27 September 2016 at 08:03, Niranda Perera  wrote:
>
>> Hi all,
>>
>> I want to use a jdbc connection provided by a carbon-datasource.
>>
>> I found the following blog from Kishanthan [1], which was done in 2013.
>>
>> it uses the org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory as
>> follows
>>
>> Hashtable environment = new Hashtable();
>>  environment.put("java.naming.factory.initialoorg.wso2.carbo
>> n.tomcat.jndi.CarbonJavaURLContextFactory");
>> Context initContext = new InitialContext(environment);
>> Object result = initContext.lookup("jdbc/MyCarbonDataSource");
>> if (result != null) {
>> // Do your work here
>> } else {
>> System.out.println(“Cannot find MyCarbonDataSource”);
>> }
>>
>> My question is, is there a better way of doing this now (a util method
>> may be?) or is this method still applicable?
>>
>> Best
>>
>> [1] https://kishanthan.wordpress.com/2013/02/11/access-
>> cabon-data-sources-within-webapps-in-wso2-application-server/
>>
>> --
>> *Niranda Perera*
>> Software Engineer, WSO2 Inc.
>> Mobile: +94-71-554-8430
>> Twitter: @n1r44 
>> https://pythagoreanscript.wordpress.com/
>>
>> ___
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Rajith Vitharana
>
> Senior Software Engineer,
> WSO2 Inc. : wso2.com
> Mobile : +94715883223
> Blog : http://lankavitharana.blogspot.com/
> 
>



-- 
*Kishanthan Thangarajah*
Technical Lead,
Platform Technologies Team,
WSO2, Inc.
lean.enterprise.middleware

Mobile - +94773426635
Blog - *http://kishanthan.wordpress.com *
Twitter - *http://twitter.com/kishanthan *
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] How to get a connection from the carbon datasources

2016-09-26 Thread Chanaka Cooray
Hi Niranda,

In c5, you can fetch a datasource object using the data source service or
using the jndi context manager. [1]

[1] https://github.com/wso2/carbon-datasources

Thanks,
Chanaka.

On Tuesday, September 27, 2016, Niranda Perera > wrote:

> Hi all,
>
> I want to use a jdbc connection provided by a carbon-datasource.
>
> I found the following blog from Kishanthan [1], which was done in 2013.
>
> it uses the org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory as
> follows
>
> Hashtable environment = new Hashtable();
>  environment.put("java.naming.factory.initialoorg.wso2.carbo
> n.tomcat.jndi.CarbonJavaURLContextFactory");
> Context initContext = new InitialContext(environment);
> Object result = initContext.lookup("jdbc/MyCarbonDataSource");
> if (result != null) {
> // Do your work here
> } else {
> System.out.println(“Cannot find MyCarbonDataSource”);
> }
>
> My question is, is there a better way of doing this now (a util method may
> be?) or is this method still applicable?
>
> Best
>
> [1] https://kishanthan.wordpress.com/2013/02/11/access-
> cabon-data-sources-within-webapps-in-wso2-application-server/
>
> --
> *Niranda Perera*
> Software Engineer, WSO2 Inc.
> Mobile: +94-71-554-8430
> Twitter: @n1r44 
> https://pythagoreanscript.wordpress.com/
>


-- 
Chanaka Cooray
Software Engineer, WSO2 Inc. http://wso2.com
Email: chana...@wso2.com
Mobile: +94713149860

___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] How to get a connection from the carbon datasources

2016-09-26 Thread Rajith Vitharana
Hi Niranda,

Since we use jndi, IMO this approach is also ok. Other than that, you can
also get carbon datasource using Ndatasource component as well. Sample will
be as below

CarbonDataSource cds = dataSourceService.getDataSource("datasourceName");

You will need to get the datasourceService[2] as osgi service.

AFAIR you need to mention datasource name from "name" tag [1]

[1] - 
WSO2_CARBON_DB
[2] - org.wso2.carbon.ndatasource.core.DataSourceService

Thanks,


On 27 September 2016 at 08:03, Niranda Perera  wrote:

> Hi all,
>
> I want to use a jdbc connection provided by a carbon-datasource.
>
> I found the following blog from Kishanthan [1], which was done in 2013.
>
> it uses the org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory as
> follows
>
> Hashtable environment = new Hashtable();
>  environment.put("java.naming.factory.initialoorg.wso2.carbon.tomcat.jndi.
> CarbonJavaURLContextFactory");
> Context initContext = new InitialContext(environment);
> Object result = initContext.lookup("jdbc/MyCarbonDataSource");
> if (result != null) {
> // Do your work here
> } else {
> System.out.println(“Cannot find MyCarbonDataSource”);
> }
>
> My question is, is there a better way of doing this now (a util method may
> be?) or is this method still applicable?
>
> Best
>
> [1] https://kishanthan.wordpress.com/2013/02/11/access-cabon-data-sources-
> within-webapps-in-wso2-application-server/
>
> --
> *Niranda Perera*
> Software Engineer, WSO2 Inc.
> Mobile: +94-71-554-8430
> Twitter: @n1r44 
> https://pythagoreanscript.wordpress.com/
>
> ___
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Rajith Vitharana

Senior Software Engineer,
WSO2 Inc. : wso2.com
Mobile : +94715883223
Blog : http://lankavitharana.blogspot.com/

___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] How to get a connection from the carbon datasources

2016-09-26 Thread Supun Sethunga
Similar approach is used in ml [1] too.

[1]
https://github.com/wso2/carbon-ml/blob/master/components/ml/org.wso2.carbon.ml.database/src/main/java/org/wso2/carbon/ml/database/internal/MLDataSource.java#L30

Regards,

On Tue, Sep 27, 2016 at 8:03 AM, Niranda Perera  wrote:

> Hi all,
>
> I want to use a jdbc connection provided by a carbon-datasource.
>
> I found the following blog from Kishanthan [1], which was done in 2013.
>
> it uses the org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory as
> follows
>
> Hashtable environment = new Hashtable();
>  environment.put("java.naming.factory.initialoorg.wso2.carbon.tomcat.jndi.
> CarbonJavaURLContextFactory");
> Context initContext = new InitialContext(environment);
> Object result = initContext.lookup("jdbc/MyCarbonDataSource");
> if (result != null) {
> // Do your work here
> } else {
> System.out.println(“Cannot find MyCarbonDataSource”);
> }
>
> My question is, is there a better way of doing this now (a util method may
> be?) or is this method still applicable?
>
> Best
>
> [1] https://kishanthan.wordpress.com/2013/02/11/access-cabon-data-sources-
> within-webapps-in-wso2-application-server/
>
> --
> *Niranda Perera*
> Software Engineer, WSO2 Inc.
> Mobile: +94-71-554-8430
> Twitter: @n1r44 
> https://pythagoreanscript.wordpress.com/
>
> ___
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
*Supun Sethunga*
Senior Software Engineer
WSO2, Inc.
http://wso2.com/
lean | enterprise | middleware
Mobile : +94 716546324
Blog: http://supunsetunga.blogspot.com
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[Dev] How to get a connection from the carbon datasources

2016-09-26 Thread Niranda Perera
Hi all,

I want to use a jdbc connection provided by a carbon-datasource.

I found the following blog from Kishanthan [1], which was done in 2013.

it uses the org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory as
follows

Hashtable environment = new Hashtable();
 
environment.put("java.naming.factory.initialoorg.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory");
Context initContext = new InitialContext(environment);
Object result = initContext.lookup("jdbc/MyCarbonDataSource");
if (result != null) {
// Do your work here
} else {
System.out.println(“Cannot find MyCarbonDataSource”);
}

My question is, is there a better way of doing this now (a util method may
be?) or is this method still applicable?

Best

[1]
https://kishanthan.wordpress.com/2013/02/11/access-cabon-data-sources-within-webapps-in-wso2-application-server/

-- 
*Niranda Perera*
Software Engineer, WSO2 Inc.
Mobile: +94-71-554-8430
Twitter: @n1r44 
https://pythagoreanscript.wordpress.com/
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev