[ 
https://issues.apache.org/jira/browse/TOMEE-1537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14392952#comment-14392952
 ] 

Romain Manni-Bucau commented on TOMEE-1537:
-------------------------------------------

well there are several things you can have a look:

1) properties-provider, it is a recent solution allowing you to read properties 
from an external source: https://issues.apache.org/jira/browse/TOMEE-1289
2) ormal way to create a resource is:

{code}
        final ResourceInfo serviceInfo = new ResourceInfo();
        serviceInfo.id = "someid";
        serviceInfo.properties = new Properties();
        serviceInfo.properties.put("JdbcDriver", "xxxx");
        serviceInfo.properties.put("JdbcUrl", "xxxx");
        serviceInfo.properties.put("UserName", "xxxx");
        serviceInfo.properties.put("Password", "xxxx");
        serviceInfo.properties.put("JtaManaged", "true");
        serviceInfo.properties.put("Definition", ""); /// empty!
        serviceInfo.types = new 
ArrayList<String>(asList(DataSource.class.getName()));
        serviceInfo.service = "Resource";
        serviceInfo.className = DataSourceFactory.class.getName();
        serviceInfo.factoryMethod = "create";
        serviceInfo.constructorArgs.addAll(asList("ServiceId", "JtaManaged", 
"JdbcDriver", "Definition", "MaxWaitTime", "TimeBetweenEvictionRuns", 
"MinEvictableIdleTime"));
        
SystemInstance.get().getComponent(Assembler.class).createResource(serviceInfo);
{code}

Not this will create properly your resource but you need to destroy it as well 
if it is not a global resource. Can be done with:

{code}
Reflections.invokeByReflection(
                assembler, "destroyResource",
                new Class<?>[]{String.class, String.class, Object.class},
                new Object[]{
                        theId, DataSource.class.getName(), 
SystemInstance.get().getComponent(ContainerSystem.class)
                        .getJNDIContext().lookup("openejb:Resource/" + theId)
                });
{code}

> DataSourceFactory.create method removes the single backslash from MS SQL 
> Server jdbcUrl string that contains SQL Server instance name that causes 
> dataSoruce.getConnection() to throw SQLServerException.
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: TOMEE-1537
>                 URL: https://issues.apache.org/jira/browse/TOMEE-1537
>             Project: TomEE
>          Issue Type: Bug
>    Affects Versions: 1.7.1
>         Environment: Windows, Sql Server 2012, MS Sql Server JDBC Driver 4
>            Reporter: John Pratt
>            Priority: Critical
>
> If you pass in a valid connection string to the DataSourceFactory.create 
> method that contains a single backslash i.e., 
> jdbcUrl=jdbc:sqlserver://IN08268\SQLEXPRESS. The DataSource factory 
> implementation parses the “definition” String as java.util.Properties. 
> Parsing the string as java.util.Properties removes the single backslash 
> character that cause JDBC driver to fail.
> There is a workaround you could do to replace the single backslash with 
> double backslash in the jdbcUrl property (but this is an invalid conection 
> url for sql server). 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to