Hi Jody,
 
Thanks for your answer. Let me explain it a bit more. 
I found Functions very useful and I wanted to use a function to do a lookup in 
another Oracle table with a query because I cannot get a Join working.
Because a lookup is executed for each table-row I want to initialize the 
Connection only once.
 
Here are fragments of my code:
 
 
public class MyFunctionFactory implements FunctionFactory {    
    private ArrayList<FunctionName> functionList;
    private static FunctionName LOOKUP = new FunctionNameImpl("lookup", 
"datasource", "query");
    private Connection m_conn = null;

    public Function function(Name name, List<Expression> args, Literal 
fallback) {
         if(new NameImpl("lookup").equals(name)){
            return new AbstractFunction(LOOKUP, args, fallback){
                public String evaluate(Object object) {
                    try {
                        String strDatasourceName = eval(object, 0, 
String.class);
                        String strQuery = eval(object, 1, String.class);
 
                        if (m_conn == null) {
                            InitialContext context = 
GeoTools.getInitialContext(GeoTools.getDefaultHints());
                            GeoTools.init(context);
                            DataSource ds = 
(DataSource)context.lookup("java:/comp/env/jdbc/" + strDatasourceName);
                            m_conn = ds.getConnection();
                            m_strDatasourceName = strDatasourceName;
                        }
                        m_strPrevQuery = strQuery;
                        m_strPrevResult = "";
                        return getStringFromQuery(m_conn, strQuery);
                    } catch (Exception e) {
                        return "";
                    }
                }
            };
        }
        return null; // we do not implement that function
    }

Will this work when may threads are calling the lookup function and use the 
same Connection in MyFunctionFactory?
 
Thanks.
Ron
 
  

________________________________
 From: Jody Garnett <[email protected]>
To: Ron Lindhoudt <[email protected]> 
Cc: Andrea Aime <[email protected]>; 
"[email protected]" 
<[email protected]> 
Sent: Friday, March 15, 2013 4:39 AM
Subject: Re: [Geotools-gt2-users] FunctionFactory threadsafe?
  

The FunctionFactoryFinder(s) keep the registry of FunctionFactory instances 
thread safe (so we do not create two accidentally). Beyond that your factory 
could be used by multiple threads. 

The Function's returned are placed into a Filter or Expression data structure 
which is generally immutable, allowing it to be called from multiple threads 
efficiently.

You have confused me a bit from switching your question from FunctionFactory 
(single object in a register) to Function (many copies). 


-- 
Jody Garnett

 
On Friday, 15 March 2013 at 1:25 AM, Ron Lindhoudt wrote: 
So this means that when I set a non-static private variable in a function of 
FunctionFactory that this variable does not change during the execution of this 
function by another call?
> 
>Ron
>
> 
>From: Andrea Aime <[email protected]>
>To: Ron Lindhoudt <[email protected]> 
>Cc: "[email protected]" 
><[email protected]> 
>Sent: Thursday, March 14, 2013 3:12 PM
>Subject: Re: [Geotools-gt2-users] FunctionFactory threadsafe?
>  
>
>On Thu, Mar 14, 2013 at 3:07 PM, Ron Lindhoudt <[email protected]> wrote:
>
>Hey,
>>
>>I created a new FunctionFactory and registered this in services.
>>I want to know if FunctionFactory is threadsafe 
>
>
>It has to be thread safe, yes
>
>
>Cheers
>Andrea
>
>
>-- 
>
>==
>Our support, Your Success! Visit http://opensdi.geo-solutions.it/ for more 
>information. 
>==
>
>
>Ing. Andrea Aime 
>@geowolf
>Technical Lead
>
>
>GeoSolutions S.A.S.
>Via Poggio alle Viti 1187
>55054  Massarosa (LU)
>Italy 
>phone: +39 0584 962313
>fax: +39 0584 1660272
>mob: +39  339 8844549
>
>
>http://www.geo-solutions.it/
>http://twitter.com/geosolutions_it 
>
>
>------------------------------------------------------- 
>
>  
>------------------------------------------------------------------------------
>Everyone hates slow websites. So do we.
>Make your web apps faster with AppDynamics
>Download AppDynamics Lite for free today:
>http://p.sf.net/sfu/appdyn_d2d_mar
>_______________________________________________
>GeoTools-GT2-Users mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users  
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to