cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1420311 - in /cxf/trunk/rt/rs/extensions/search/src: main/java/org/apache/cxf/jaxrs/ext/search/ main/java/org/apache/cxf/jaxrs/ext/search/jpa/ main/java/org/apache/cxf/jaxrs/ext/search/ldap/ main/java/org/apache/cxf/jaxrs/ext/search/lucene...
Date Tue, 11 Dec 2012 18:03:38 GMT
Author: sergeyb
Date: Tue Dec 11 18:03:36 2012
New Revision: 1420311

URL: http://svn.apache.org/viewvc?rev=1420311&view=rev
Log:
[CXF-4693] Making the String based converters thread-safe ready when needed

Added:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
      - copied, changed from r1419367, cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
  (with props)
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/LocalVisitorState.java
  (with props)
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/SBThreadLocalVisitorState.java
  (with props)
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/ThreadLocalVisitorState.java
  (with props)
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/VisitorState.java
  (with props)
Removed:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java
Modified:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java?rev=1420311&r1=1420310&r2=1420311&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
Tue Dec 11 18:03:36 2012
@@ -35,11 +35,11 @@ import javax.persistence.criteria.Path;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
-import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.ConditionType;
 import org.apache.cxf.jaxrs.ext.search.OrSearchCondition;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.visitor.AbstractSearchConditionVisitor;
 
 public abstract class AbstractJPATypedQueryVisitor<T, T1, E> 
     extends AbstractSearchConditionVisitor<T, E> {
@@ -239,5 +239,4 @@ public abstract class AbstractJPATypedQu
         return joinProperties == null ? false : joinProperties.contains(prop);
     }
     
-    
 }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java?rev=1420311&r1=1420310&r2=1420311&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
Tue Dec 11 18:03:36 2012
@@ -21,17 +21,15 @@ package org.apache.cxf.jaxrs.ext.search.
 import java.util.Collections;
 import java.util.Map;
 
-import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.ConditionType;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.visitor.AbstractUntypedSearchConditionVisitor;
 /**
  * Initial Implementation of http://tools.ietf.org/html/rfc4515
  */
-public class LdapQueryVisitor<T> extends AbstractSearchConditionVisitor<T, String>
{
+public class LdapQueryVisitor<T> extends AbstractUntypedSearchConditionVisitor<T,
String> {
 
-    private StringBuilder sb = new StringBuilder();
-    
     public LdapQueryVisitor() {
         this(Collections.<String, String>emptyMap());
     }
@@ -41,6 +39,11 @@ public class LdapQueryVisitor<T> extends
     }
     
     public void visit(SearchCondition<T> sc) {
+    
+        StringBuilder sb = getStringBuilder();
+        if (sb == null) {
+            sb = new StringBuilder();
+        }
         
         PrimitiveStatement statement = sc.getStatement();
         if (statement != null) {
@@ -67,15 +70,15 @@ public class LdapQueryVisitor<T> extends
             }
             
             for (SearchCondition<T> condition : sc.getSearchConditions()) {
+                saveStringBuilder(sb);
                 condition.accept(this);
+                sb = getStringBuilder();
             }
             sb.append(")");
         }
+        saveStringBuilder(sb);
     }
     
-    public String getQuery() {
-        return sb.toString();
-    }
     
     public static String conditionTypeToLdapOperator(ConditionType ct) {
         String op;

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java?rev=1420311&r1=1420310&r2=1420311&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
Tue Dec 11 18:03:36 2012
@@ -25,10 +25,10 @@ import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 
-import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.ConditionType;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.visitor.AbstractSearchConditionVisitor;
 import org.apache.lucene.document.DateTools;
 import org.apache.lucene.document.DateTools.Resolution;
 import org.apache.lucene.index.Term;

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java?rev=1420311&r1=1420310&r2=1420311&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
Tue Dec 11 18:03:36 2012
@@ -23,15 +23,14 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionVisitor;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
 import org.apache.cxf.jaxrs.ext.search.SearchUtils;
+import org.apache.cxf.jaxrs.ext.search.visitor.AbstractUntypedSearchConditionVisitor;
 
 
-public class SQLPrinterVisitor<T> extends AbstractSearchConditionVisitor<T, String>
{
+public class SQLPrinterVisitor<T> extends AbstractUntypedSearchConditionVisitor<T,
String> {
 
-    private StringBuilder sb;
     private String table;
     private String tableAlias;
     private List<String> columns;
@@ -56,19 +55,14 @@ public class SQLPrinterVisitor<T> extend
                              String tableAlias,
                              List<String> columns) {
         super(fieldMap);
+        
         this.columns = columns;
         this.table = table;
         this.tableAlias = tableAlias;
     }
     
     public void visit(SearchCondition<T> sc) {
-        
-        if (sb == null) {
-            sb = new StringBuilder();
-            if (table != null) {
-                SearchUtils.startSqlQuery(sb, table, tableAlias, columns);
-            }
-        }
+        StringBuilder sb = getStringBuilder();
         
         PrimitiveStatement statement = sc.getStatement();
         if (statement != null) {
@@ -93,19 +87,27 @@ public class SQLPrinterVisitor<T> extend
                     first = false;
                 }
                 sb.append("(");
+                saveStringBuilder(sb);
                 condition.accept(this);
+                sb = getStringBuilder();
                 sb.append(")");
             }
         }
+        
+        saveStringBuilder(sb);
     }
     
-
-    @Deprecated
-    public String getResult() {
-        return getQuery();
+    protected StringBuilder getStringBuilder() {
+        StringBuilder sb = super.getStringBuilder();
+        if (sb == null) {
+            sb = new StringBuilder();
+            if (table != null) {
+                SearchUtils.startSqlQuery(sb, table, tableAlias, columns);
+            }
+        }
+        return sb;
     }
     
-    public String getQuery() {
-        return sb == null ? null : sb.toString();
-    }
+    
+    
 }

Copied: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
(from r1419367, cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java?p2=cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java&p1=cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java&r1=1419367&r2=1420311&rev=1420311&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
Tue Dec 11 18:03:36 2012
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.cxf.jaxrs.ext.search;
+package org.apache.cxf.jaxrs.ext.search.visitor;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.cxf.jaxrs.ext.search.SearchConditionVisitor;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 
 

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java?rev=1420311&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
Tue Dec 11 18:03:36 2012
@@ -0,0 +1,56 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.ext.search.visitor;
+
+import java.util.Map;
+
+public abstract class AbstractUntypedSearchConditionVisitor<T, E> extends AbstractSearchConditionVisitor<T,
String> {
+
+    private VisitorState<StringBuilder> state = new LocalVisitorState<StringBuilder>();
+    
+    protected AbstractUntypedSearchConditionVisitor(Map<String, String> fieldMap) {
+        super(fieldMap);
+    }
+    
+    public void setVisitorState(VisitorState<StringBuilder> s) {
+        this.state = s;
+    }
+    
+    public VisitorState<StringBuilder> getVisitorState() {
+        return this.state;
+    }
+    
+    protected StringBuilder getStringBuilder() {
+        return getVisitorState().get();
+    }
+    
+    protected StringBuilder removeStringBuilder() {
+        return getVisitorState().remove();
+    }
+    
+    protected void saveStringBuilder(StringBuilder sb) {
+        getVisitorState().set(sb);
+    }
+    
+    public String getQuery() {
+        StringBuilder sb = removeStringBuilder();
+        return sb == null ? null : sb.toString();
+    }
+    
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/LocalVisitorState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/LocalVisitorState.java?rev=1420311&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/LocalVisitorState.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/LocalVisitorState.java
Tue Dec 11 18:03:36 2012
@@ -0,0 +1,46 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.ext.search.visitor;
+
+
+/**
+ * Simple thread local storage implementation for helping
+ * search condition visitors to access its state across multiple
+ * visit calls when a given visitor is not created on per-request basis.
+ */
+public class LocalVisitorState<T> implements VisitorState<T> {
+    private T value;
+    
+    public LocalVisitorState() {
+    }
+    
+    public T get() {
+        return value;
+    }
+
+    public T remove() {
+        T oldValue = get();
+        value = null;
+        return oldValue;
+    }
+
+    public void set(T v) {
+        this.value = v;
+    }    
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/LocalVisitorState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/LocalVisitorState.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/SBThreadLocalVisitorState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/SBThreadLocalVisitorState.java?rev=1420311&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/SBThreadLocalVisitorState.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/SBThreadLocalVisitorState.java
Tue Dec 11 18:03:36 2012
@@ -0,0 +1,28 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.ext.search.visitor;
+
+
+/**
+ * Simple thread local storage implementation for helping
+ * search condition visitors to access its state across multiple
+ * visit calls when a given visitor is not created on per-request basis.
+ */
+public class SBThreadLocalVisitorState extends ThreadLocalVisitorState<StringBuilder>
{
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/SBThreadLocalVisitorState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/SBThreadLocalVisitorState.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/ThreadLocalVisitorState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/ThreadLocalVisitorState.java?rev=1420311&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/ThreadLocalVisitorState.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/ThreadLocalVisitorState.java
Tue Dec 11 18:03:36 2012
@@ -0,0 +1,43 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.ext.search.visitor;
+
+
+/**
+ * Simple thread local storage implementation for helping
+ * search condition visitors to access its state across multiple
+ * visit calls when a given visitor is not created on per-request basis.
+ */
+public class ThreadLocalVisitorState<T> implements VisitorState<T> {
+    private ThreadLocal<T> state = new ThreadLocal<T>();
+    
+    public T get() {
+        return state.get();
+    }
+
+    public T remove() {
+        T value = get();
+        state.remove();
+        return value;
+    }
+
+    public void set(T value) {
+        state.set(value);
+    }    
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/ThreadLocalVisitorState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/ThreadLocalVisitorState.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/VisitorState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/VisitorState.java?rev=1420311&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/VisitorState.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/VisitorState.java
Tue Dec 11 18:03:36 2012
@@ -0,0 +1,32 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.jaxrs.ext.search.visitor;
+
+/**
+ * Simple thread local storage implementation for helping
+ * search condition visitors to access its state across multiple
+ * visit calls when a given visitor is not created on per-request basis.
+ */
+public interface VisitorState<T> {
+    T get();
+
+    T remove();
+
+    void set(T value);
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/VisitorState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/VisitorState.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java?rev=1420311&r1=1420310&r2=1420311&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
Tue Dec 11 18:03:36 2012
@@ -25,6 +25,7 @@ import org.apache.cxf.jaxrs.ext.search.S
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
 import org.apache.cxf.jaxrs.ext.search.SearchParseException;
 import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
+import org.apache.cxf.jaxrs.ext.search.visitor.SBThreadLocalVisitorState;
 
 import org.junit.Assert;
 import org.junit.Ignore;
@@ -105,6 +106,20 @@ public class SQLPrinterVisitorTest exten
     }
     
     @Test
+    public void testSQL4WithTLStateAndSingleThread() throws SearchParseException {
+        SearchCondition<Condition> filter = parser.parse("(name==test,level==18);(name==test1,level!=19)");
+        SQLPrinterVisitor<Condition> visitor = new SQLPrinterVisitor<Condition>("table");
+        visitor.setVisitorState(new SBThreadLocalVisitorState());
+        
+        filter.accept(visitor);
+        String sql = visitor.getQuery();
+        assertTrue(("SELECT * FROM table WHERE ((name = 'test') OR (level = '18'))"
+                   + " AND ((name = 'test1') OR (level <> '19'))").equals(sql)
+                   || ("SELECT * FROM table WHERE ((name = 'test1') OR (level <> '19'))"
+                   + " AND ((name = 'test') OR (level = '18'))").equals(sql));
+    }
+    
+    @Test
     public void testSQL5() throws SearchParseException {
         SearchCondition<Condition> filter = parser.parse("name==test");
         SQLPrinterVisitor<Condition> visitor = new SQLPrinterVisitor<Condition>("table");



Mime
View raw message