Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 Erik Bengtson and others. All rights reserved. Licensed 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. Contributors: ... /
 
 package org.datanucleus.store.json;
 
 import java.net.URL;
 import java.util.Map;
 
 
Implementation of a ConnectionFactory for JSON. The connections are only created and they are not managed. All operations besides getConnection are no-op.
 
 {
     // TODO Where is this defined ? Persistence property ? If so then should not have "org."
     public static final String STORE_JSON_URL = "org.datanucleus.store.json.url";

    
Constructor.

Parameters:
storeMgr Store Manager
resourceType Type of resource (tx, nontx)
 
     public ConnectionFactoryImpl(StoreManager storeMgrString resourceType)
     {
         super(storeMgrresourceType);
     }

    
Obtain a connection from the Factory. The connection will be enlisted within the org.datanucleus.Transaction associated to the poolKey if "enlist" is set to true.

Parameters:
poolKey the pool that is bound the connection during its lifecycle (or null)
options Any options for then creating the connection
Returns:
the org.datanucleus.store.connection.ManagedConnection
 
     public ManagedConnection createManagedConnection(Object poolKeyMap options)
     {
         return new ManagedConnectionImpl(options);
     }

    
Implementation of a ManagedConnection for JSON.
 
     public class ManagedConnectionImpl extends AbstractManagedConnection
     {
         Map options;
 
         public ManagedConnectionImpl(Map options)
         {
             this. = options;
         }
 
         public void close()
         {
             // TODO Auto-generated method stub
         }
 
         public Object getConnection()
         {
             String urlStr = .getConnectionURL();
             urlStr = urlStr.substring(urlStr.indexOf(.getStoreManagerKey()+":") +
                 .getStoreManagerKey().length()+1);
             if (.containsKey())
             {
                 if(urlStr.endsWith("/") && .get().toString().startsWith("/"))
                 {
                     urlStr += .get().toString().substring(1);
                 }
                 else if(!urlStr.endsWith("/") && !.get().toString().startsWith("/"))
                 {
                     urlStr += "/"+.get().toString();
                 }
                 else
                 {
                     urlStr += .get().toString();
                 }
            }
            URL url;
            try
            {
                url = new URL(urlStr);
                return url.openConnection();
            }
            catch (MalformedURLException e)
            {
                throw new NucleusDataStoreException(e.getMessage(),e);
            }
            catch (IOException e)
            {
                throw new NucleusDataStoreException(e.getMessage(),e);
            }
        }
        public XAResource getXAResource()
        {
            return null;
        }
    }
New to GrepCode? Check out our FAQ X