teiid SVN: r4380 - trunk/engine/src/test/java/org/teiid/query/validator.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-08-28 16:03:45 -0400 (Tue, 28 Aug 2012)
New Revision: 4380
Modified:
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-2141 correcting unit test
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2012-08-28 20:02:39 UTC (rev 4379)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2012-08-28 20:03:45 UTC (rev 4380)
@@ -1603,7 +1603,7 @@
}
@Test public void testObjectTableScript() {
- helpValidate("select * from objecttable('this. is not valid' columns c integer 'row') as x", new String[] {"OBJECTTABLE('this is not valid' COLUMNS c integer 'row') AS x"}, RealMetadataFactory.example1Cached());
+ helpValidate("select * from objecttable('this. is not valid' columns c integer 'row') as x", new String[] {"OBJECTTABLE('this. is not valid' COLUMNS c integer 'row') AS x"}, RealMetadataFactory.example1Cached());
}
@Test public void testXMLQueryPassingContextType() {
12 years, 4 months
teiid SVN: r4379 - in trunk/engine/src/main/java/org/teiid: common/buffer/impl and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-08-28 16:02:39 -0400 (Tue, 28 Aug 2012)
New Revision: 4379
Modified:
trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java
trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java
trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java
trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareEvaluator.java
Log:
TEIID-2171 lazily associating the cleanup and proactively removing also ensuring iterators are created for common iterations
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/AutoCleanupUtil.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -55,10 +55,20 @@
private static ReferenceQueue<Object> QUEUE = new ReferenceQueue<Object>();
private static final Set<PhantomReference<Object>> REFERENCES = Collections.synchronizedSet(Collections.newSetFromMap(new IdentityHashMap<PhantomReference<Object>, Boolean>()));
- public static void setCleanupReference(Object o, Removable r) {
- REFERENCES.add(new PhantomCleanupReference(o, r));
+ public static PhantomReference<Object> setCleanupReference(Object o, Removable r) {
+ PhantomCleanupReference ref = new PhantomCleanupReference(o, r);
+ REFERENCES.add(ref);
doCleanup();
+ return ref;
}
+
+ public static void removeCleanupReference(PhantomReference<Object> ref) {
+ if (ref == null) {
+ return;
+ }
+ REFERENCES.remove(ref);
+ ref.clear();
+ }
public static void doCleanup() {
for (int i = 0; i < 10; i++) {
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/FileStoreInputStreamFactory.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -28,6 +28,7 @@
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
+import java.lang.ref.PhantomReference;
import java.nio.charset.Charset;
import org.teiid.common.buffer.FileStore.FileStoreOutputStream;
@@ -39,11 +40,12 @@
private final FileStore lobBuffer;
private FileStoreOutputStream fsos;
private String encoding;
+ private PhantomReference<Object> cleanup;
public FileStoreInputStreamFactory(FileStore lobBuffer, String encoding) {
this.encoding = encoding;
this.lobBuffer = lobBuffer;
- AutoCleanupUtil.setCleanupReference(this, lobBuffer);
+ cleanup = AutoCleanupUtil.setCleanupReference(this, lobBuffer);
}
@Override
@@ -100,6 +102,8 @@
public void free() {
fsos = null;
lobBuffer.remove();
+ AutoCleanupUtil.removeCleanupReference(cleanup);
+ cleanup = null;
}
@Override
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/LobManager.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -189,7 +189,7 @@
public void persist() throws TeiidComponentException {
// stream the contents of lob into file store.
byte[] bytes = new byte[1 << 14];
-
+ AutoCleanupUtil.setCleanupReference(this, lobStore);
for (Map.Entry<String, LobHolder> entry : this.lobReferences.entrySet()) {
entry.getValue().lob = detachLob(entry.getValue().lob, lobStore, bytes);
}
@@ -294,5 +294,6 @@
public void remove() {
this.lobReferences.clear();
+ //we don't remove the filestore as there could be local connection references to the lob objects
}
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBuffer.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -127,15 +127,16 @@
*/
public void addTupleBatch(TupleBatch batch, boolean save) throws TeiidComponentException {
setRowCount(batch.getBeginRow() - 1);
+ List<List<?>> tuples = batch.getTuples();
if (save) {
- for (List<?> tuple : batch.getTuples()) {
- addTuple(tuple);
+ for (int i = 0; i < batch.getRowCount(); i++) {
+ addTuple(tuples.get(i));
}
} else {
//add the lob references only, since they may still be referenced later
if (isLobs()) {
- for (List<?> tuple : batch.getTuples()) {
- lobManager.updateReferences(tuple, ReferenceMode.CREATE);
+ for (int i = 0; i < batch.getRowCount(); i++) {
+ lobManager.updateReferences(tuples.get(i), ReferenceMode.CREATE);
}
}
}
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -30,6 +30,7 @@
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
+import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
@@ -126,7 +127,22 @@
}
}
}
+
+ private final class Remover implements Removable {
+ private Long id;
+ private AtomicBoolean prefersMemory;
+
+ public Remover(Long id, AtomicBoolean prefersMemory) {
+ this.id = id;
+ this.prefersMemory = prefersMemory;
+ }
+ @Override
+ public void remove() {
+ removeCacheGroup(id, prefersMemory.get());
+ }
+ }
+
/**
* This estimate is based upon adding the value to 2/3 maps and having CacheEntry/PhysicalInfo keys
*/
@@ -136,6 +152,7 @@
final Long id;
SizeUtility sizeUtility;
private WeakReference<BatchManagerImpl> ref = new WeakReference<BatchManagerImpl>(this);
+ private PhantomReference<Object> cleanup;
AtomicBoolean prefersMemory = new AtomicBoolean();
String[] types;
private LobManager lobManager;
@@ -147,7 +164,6 @@
for (int i = 0; i < types.length; i++) {
this.types[i] = DataTypeManager.getDataTypeName(types[i]);
}
- cache.createCacheGroup(newID);
}
@Override
@@ -189,6 +205,10 @@
public Long createManagedBatch(List<? extends List<?>> batch,
Long previous, boolean removeOld)
throws TeiidComponentException {
+ if (cleanup == null) {
+ cache.createCacheGroup(id);
+ cleanup = AutoCleanupUtil.setCleanupReference(this, new Remover(id, prefersMemory));
+ }
int sizeEstimate = getSizeEstimate(batch);
Long oid = batchAdded.getAndIncrement();
CacheEntry old = null;
@@ -216,9 +236,9 @@
throws IOException, ClassNotFoundException {
List<? extends List<?>> batch = BatchSerializer.readBatch(ois, types);
if (lobManager != null) {
- for (List<?> list : batch) {
+ for (int i = batch.size() - 1; i >= 0; i--) {
try {
- lobManager.updateReferences(list, ReferenceMode.ATTACH);
+ lobManager.updateReferences(batch.get(i), ReferenceMode.ATTACH);
} catch (TeiidComponentException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30052, e);
}
@@ -297,7 +317,11 @@
@Override
public void remove() {
- removeCacheGroup(id, prefersMemory.get());
+ if (cleanup != null) {
+ removeCacheGroup(id, prefersMemory.get());
+ AutoCleanupUtil.removeCleanupReference(cleanup);
+ cleanup = null;
+ }
}
@Override
@@ -468,7 +492,6 @@
if (lobIndexes != null) {
FileStore lobStore = createFileStore(newID + "_lobs"); //$NON-NLS-1$
lobManager = new LobManager(lobIndexes, lobStore);
- AutoCleanupUtil.setCleanupReference(lobManager, lobStore);
batchManager.setLobManager(lobManager);
}
TupleBuffer tupleBuffer = new TupleBuffer(batchManager, String.valueOf(newID), elements, lobManager, getProcessorBatchSize(elements));
@@ -510,16 +533,7 @@
}
private BatchManagerImpl createBatchManager(final Long newID, Class<?>[] types) {
- BatchManagerImpl bm = new BatchManagerImpl(newID, types);
- final AtomicBoolean prefersMemory = bm.prefersMemory;
- AutoCleanupUtil.setCleanupReference(bm, new Removable() {
-
- @Override
- public void remove() {
- BufferManagerImpl.this.removeCacheGroup(newID, prefersMemory.get());
- }
- });
- return bm;
+ return new BatchManagerImpl(newID, types);
}
@Override
@@ -860,9 +874,11 @@
long overhead = vals.size() * BATCH_OVERHEAD;
maxReserveBytes.addAndGet(overhead);
reserveBatchBytes.addAndGet(overhead);
- for (Long val : vals) {
- //TODO: we will unnecessarily call remove on the cache, but that should be low cost
- fastGet(val, prefersMemory, false);
+ if (!vals.isEmpty()) {
+ for (Long val : vals) {
+ //TODO: we will unnecessarily call remove on the cache, but that should be low cost
+ fastGet(val, prefersMemory, false);
+ }
}
}
@@ -885,8 +901,8 @@
private int[] getSizeEstimates(List<? extends Expression> elements) {
int total = 0;
boolean isValueCacheEnabled = DataTypeManager.isValueCacheEnabled();
- for (Expression element : elements) {
- Class<?> type = element.getType();
+ for (int i = elements.size() - 1; i >= 0; i--) {
+ Class<?> type = elements.get(i).getType();
total += SizeUtility.getSize(isValueCacheEnabled, type);
}
//assume 64-bit
@@ -1027,9 +1043,9 @@
String[] types = (String[])in.readObject();
List<ElementSymbol> schema = new ArrayList<ElementSymbol>(types.length);
- for (String type : types) {
+ for (int i = 0; i < types.length; i++) {
ElementSymbol es = new ElementSymbol("x"); //$NON-NLS-1$
- es.setType(DataTypeManager.getDataTypeClass(type));
+ es.setType(DataTypeManager.getDataTypeClass(types[i]));
schema.add(es);
}
TupleBuffer buffer = createTupleBuffer(schema, "cached", TupleSourceType.FINAL); //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/SplittableStorageManager.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -140,10 +140,9 @@
}
public synchronized void removeDirect() {
- for (FileStore info : storageFiles) {
- info.remove();
+ for (int i = storageFiles.size() - 1; i >= 0; i--) {
+ this.storageFiles.remove(i).remove();
}
- storageFiles.clear();
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -600,7 +600,7 @@
return this.data.estimateNodeCardinality;
}
- private ProcessingState getProcessingState() {
+ private final ProcessingState getProcessingState() {
//construct lazily since not all tests call initialize
if (this.processingState == null) {
this.processingState = new ProcessingState();
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareEvaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareEvaluator.java 2012-08-28 19:41:34 UTC (rev 4378)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareEvaluator.java 2012-08-28 20:02:39 UTC (rev 4379)
@@ -82,10 +82,12 @@
@Override
public void clear() {
- for (TupleBuffer buffer : values()) {
- buffer.remove();
+ if (!isEmpty()) {
+ for (TupleBuffer buffer : values()) {
+ buffer.remove();
+ }
+ super.clear();
}
- super.clear();
}
}
12 years, 4 months
teiid SVN: r4378 - in trunk/engine/src: main/java/org/teiid/query/eval and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-08-28 15:41:34 -0400 (Tue, 28 Aug 2012)
New Revision: 4378
Added:
trunk/engine/src/main/java/org/teiid/query/eval/TeiidScriptEngine.java
Modified:
trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/ObjectTable.java
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-2141 adding teiid_script
Modified: trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-08-28 18:31:49 UTC (rev 4377)
+++ trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-08-28 19:41:34 UTC (rev 4378)
@@ -528,5 +528,6 @@
TEIID31108, //datasource not available
TEIID31109, //invalid scripting language
TEIID31110, //invalid script
+ TEIID31111, //invalid teiid script
}
}
Added: trunk/engine/src/main/java/org/teiid/query/eval/TeiidScriptEngine.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/eval/TeiidScriptEngine.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/eval/TeiidScriptEngine.java 2012-08-28 19:41:34 UTC (rev 4378)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.eval;
+
+import java.beans.BeanInfo;
+import java.beans.IndexedPropertyDescriptor;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.MethodDescriptor;
+import java.beans.PropertyDescriptor;
+import java.io.IOException;
+import java.io.Reader;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.regex.Pattern;
+
+import javax.script.AbstractScriptEngine;
+import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+
+import org.teiid.core.util.LRUCache;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.query.QueryPlugin;
+
+/**
+ * A simplistic script engine that supports root variable access and 0-ary methods on the subsequent objects.
+ */
+public final class TeiidScriptEngine extends AbstractScriptEngine implements Compilable {
+ private static Map<ClassLoader, Map<Class<?>, Map<String, Method>>> properties = new WeakHashMap<ClassLoader, Map<Class<?>, Map<String, Method>>>(100);
+ private static Pattern splitter = Pattern.compile("\\."); //$NON-NLS-1$
+
+ @Override
+ public Bindings createBindings() {
+ return new SimpleBindings();
+ }
+
+ @Override
+ public CompiledScript compile(String script) throws ScriptException {
+ final String[] parts = splitter.split(script);
+ for (int i = 1; i < parts.length; i++) {
+ String string = parts[i];
+ for (int j = 0; j < string.length(); j++) {
+ if (!Character.isJavaIdentifierPart(string.charAt(j))) {
+ throw new ScriptException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30431,string, string.charAt(j)));
+ }
+ }
+ }
+ return new CompiledScript() {
+
+ @Override
+ public ScriptEngine getEngine() {
+ return TeiidScriptEngine.this;
+ }
+
+ @Override
+ public Object eval(ScriptContext sc) throws ScriptException {
+ if (sc == null) {
+ throw new NullPointerException();
+ }
+ Object obj = null;
+ if (parts.length > 0) {
+ obj = sc.getAttribute(parts[0]);
+ }
+ if (obj == null) {
+ return null;
+ }
+ for (int i = 1; i < parts.length; i++) {
+ String part = parts[i];
+ Map<String, Method> methodMap = getMethodMap(obj.getClass());
+ Method m = methodMap.get(part);
+ if (m == null) {
+ throw new ScriptException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31111, part, obj.getClass()));
+ }
+ try {
+ obj = m.invoke(obj);
+ } catch (IllegalAccessException e) {
+ throw new ScriptException(e);
+ } catch (InvocationTargetException e) {
+ if (e.getCause() instanceof Exception) {
+ throw new ScriptException((Exception) e.getCause());
+ }
+ throw new ScriptException(e);
+ }
+ }
+ return obj;
+ }
+ };
+ }
+
+ private Map<String, Method> getMethodMap(Class<?> clazz) throws ScriptException {
+ Map<Class<?>, Map<String, Method>> clazzMaps = null;
+ synchronized (properties) {
+ clazzMaps = properties.get(clazz.getClassLoader());
+ if (clazzMaps == null) {
+ clazzMaps = Collections.synchronizedMap(new LRUCache<Class<?>, Map<String, Method>>(100));
+ properties.put(clazz.getClassLoader(), clazzMaps);
+ }
+ }
+ Map<String, Method> methodMap = clazzMaps.get(clazz);
+ if (methodMap == null) {
+ try {
+ BeanInfo info = Introspector.getBeanInfo(clazz);
+ PropertyDescriptor[] pds = info.getPropertyDescriptors();
+ methodMap = new HashMap<String, Method>();
+ if (pds != null) {
+ for (int j = 0; j < pds.length; j++) {
+ PropertyDescriptor pd = pds[j];
+ if (pd.getReadMethod() == null || pd instanceof IndexedPropertyDescriptor) {
+ continue;
+ }
+ String name = pd.getName();
+ Method m = pd.getReadMethod();
+ methodMap.put(name, m);
+ }
+ }
+ MethodDescriptor[] mds = info.getMethodDescriptors();
+ if (pds != null) {
+ for (int j = 0; j < mds.length; j++) {
+ MethodDescriptor md = mds[j];
+ if (md.getMethod() == null || md.getMethod().getParameterTypes().length > 0 || md.getMethod().getReturnType() == Void.class) {
+ continue;
+ }
+ String name = md.getName();
+ Method m = md.getMethod();
+ methodMap.put(name, m);
+ }
+ }
+ clazzMaps.put(clazz, methodMap);
+ } catch (IntrospectionException e) {
+ throw new ScriptException(e);
+ }
+ }
+ return methodMap;
+ }
+
+ @Override
+ public CompiledScript compile(Reader script) throws ScriptException {
+ try {
+ return compile(ObjectConverterUtil.convertToString(script));
+ } catch (IOException e) {
+ throw new ScriptException(e);
+ }
+ }
+
+ @Override
+ public ScriptEngineFactory getFactory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object eval(Reader reader, ScriptContext sc)
+ throws ScriptException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object eval(String script, ScriptContext sc)
+ throws ScriptException {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/query/eval/TeiidScriptEngine.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2012-08-28 18:31:49 UTC (rev 4377)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2012-08-28 19:41:34 UTC (rev 4378)
@@ -60,6 +60,7 @@
import org.teiid.metadata.Column.SearchType;
import org.teiid.metadata.ProcedureParameter.Type;
import org.teiid.query.QueryPlugin;
+import org.teiid.query.eval.TeiidScriptEngine;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.function.FunctionTree;
import org.teiid.query.mapping.relational.QueryNode;
@@ -1119,8 +1120,8 @@
if (this.scriptEngineManager == null) {
this.scriptEngineManager = new ScriptEngineManager();
}
- if (language == null) {
- language = ObjectTable.DEFAULT_LANGUAGE;
+ if (language == null || ObjectTable.DEFAULT_LANGUAGE.equals(language)) {
+ return new TeiidScriptEngine();
}
ScriptEngine engine = null;
if (allowedLanguages == null || allowedLanguages.contains(language)) {
@@ -1147,6 +1148,7 @@
if (allowedLanguages != null) {
names.retainAll(allowedLanguages);
}
+ names.add(ObjectTable.DEFAULT_LANGUAGE);
throw new TeiidProcessingException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31109, language, names));
}
this.scriptEngineFactories.put(language, engine.getFactory());
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java 2012-08-28 18:31:49 UTC (rev 4377)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/ObjectTableNode.java 2012-08-28 19:41:34 UTC (rev 4378)
@@ -22,6 +22,7 @@
package org.teiid.query.processor.relational;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -36,15 +37,18 @@
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.TupleBatch;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.QueryPlugin;
import org.teiid.query.eval.Evaluator;
import org.teiid.query.function.FunctionDescriptor;
+import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.ObjectTable;
import org.teiid.query.sql.lang.ObjectTable.ObjectColumn;
+import org.teiid.query.util.CommandContext;
/**
* Handles object table processing.
@@ -69,17 +73,33 @@
}
@Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
+ this.scriptContext = new SimpleScriptContext();
+ }
+
+ @Override
public void open() throws TeiidComponentException, TeiidProcessingException {
super.open();
if (table.getScriptEngine() == null) {
table.setScriptEngine(getContext().getMetadata().getScriptEngine(table.getScriptingLanguage()));
}
- scriptContext = new SimpleScriptContext();
this.scriptContext.setAttribute(TEIID_CONTEXT, this.getContext(), ScriptContext.ENGINE_SCOPE);
}
@Override
public synchronized void closeDirect() {
+ if (this.scriptContext != null) {
+ try {
+ this.scriptContext.getErrorWriter().flush();
+ } catch (IOException e) {
+ }
+ try {
+ this.scriptContext.getWriter().flush();
+ } catch (IOException e) {
+ }
+ }
super.closeDirect();
reset();
}
@@ -90,7 +110,9 @@
item = null;
result = null;
rowCount = 0;
- this.scriptContext = null;
+ if (this.scriptContext != null) {
+ this.scriptContext.getBindings(ScriptContext.ENGINE_SCOPE).clear();
+ }
}
public void setTable(ObjectTable table) {
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/ObjectTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/ObjectTable.java 2012-08-28 18:31:49 UTC (rev 4377)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/ObjectTable.java 2012-08-28 19:41:34 UTC (rev 4378)
@@ -35,7 +35,7 @@
public class ObjectTable extends TableFunctionReference {
- public static final String DEFAULT_LANGUAGE = "javascript"; //$NON-NLS-1$
+ public static final String DEFAULT_LANGUAGE = "teiid_script"; //$NON-NLS-1$
public static class ObjectColumn extends ProjectedColumn {
private String path;
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-08-28 18:31:49 UTC (rev 4377)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-08-28 19:41:34 UTC (rev 4378)
@@ -40,7 +40,7 @@
TEIID30011=The function "{0}" will not be added because a function with the same name and signature already exists.
TEIID30389=Unexpected exception while loading "{1}.{2}" for UDF "{0}"
TEIID30387=Could not load UDF "{0}", since its invocation class "{1}" could not be found.
-TEIID30388=UDF "{0}" could not loaded, since no method on class "{1}" with name "{2}" has a matching type signature.
+TEIID30388=UDF "{0}" could not be loaded, since no method on class "{1}" with name "{2}" has a matching type signature.
TEIID30424=Unable to represent average value from {0} / {1}
TEIID30425=Unable to compute aggregate function {0} on data of type {1}
TEIID30429={0} must be non-null.
@@ -1025,7 +1025,8 @@
TEIID31106=Duplicate parameter {1} defined on {0}
TEIID31107=Procedure {0} can only have 1 RESULT/return value
TEIID31109=Invalid language {0}. Supported and allowed language names are {1}.
-TEIID31110=Invalid script {0}. Scrpting engine reported: {1}.
+TEIID31110=Invalid script {0}. Scrpting engine reported: {1}
+TEIID31111=No such accessible property/method {0} on {1}.
SQLParser.proc_type_conflict=Result type {1} conflicts with return type {2} for procedure {0}
SQLParser.param_out=Procedure {0} RESULT param {1} must be of type OUT.
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2012-08-28 18:31:49 UTC (rev 4377)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2012-08-28 19:41:34 UTC (rev 4378)
@@ -1603,7 +1603,7 @@
}
@Test public void testObjectTableScript() {
- helpValidate("select * from objecttable('this is not valid' columns c integer 'row') as x", new String[] {"OBJECTTABLE('this is not valid' COLUMNS c integer 'row') AS x"}, RealMetadataFactory.example1Cached());
+ helpValidate("select * from objecttable('this. is not valid' columns c integer 'row') as x", new String[] {"OBJECTTABLE('this is not valid' COLUMNS c integer 'row') AS x"}, RealMetadataFactory.example1Cached());
}
@Test public void testXMLQueryPassingContextType() {
12 years, 4 months
teiid SVN: r4377 - trunk/jboss-integration/src/main/java/org/teiid/jboss/rest.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-08-28 14:31:49 -0400 (Tue, 28 Aug 2012)
New Revision: 4377
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
Log:
TEIID-2158: Fixing the issue with hardcoded model name
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java 2012-08-28 12:16:57 UTC (rev 4376)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java 2012-08-28 18:31:49 UTC (rev 4377)
@@ -288,8 +288,8 @@
}
}
- buildQueryProcedure(vdbName, vdbVersion, "xml", cw, passthroughAuth);
- buildQueryProcedure(vdbName, vdbVersion, "json", cw, passthroughAuth);
+ buildQueryProcedure(vdbName, vdbVersion, modelName, "xml", cw, passthroughAuth);
+ buildQueryProcedure(vdbName, vdbVersion, modelName, "json", cw, passthroughAuth);
cw.visitEnd();
@@ -451,7 +451,7 @@
}
}
- private void buildQueryProcedure(String vdbName, int vdbVersion, String context, ClassWriter cw, boolean passthroughAuth) {
+ private void buildQueryProcedure(String vdbName, int vdbVersion, String modelName, String context, ClassWriter cw, boolean passthroughAuth) {
MethodVisitor mv;
{
AnnotationVisitor av0;
@@ -491,7 +491,7 @@
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(context.equals("xml")?ICONST_0:ICONST_1);
mv.visitInsn(passthroughAuth?ICONST_1:ICONST_0);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/View", "executeQuery", "(Ljava/lang/String;ILjava/lang/String;ZZ)Ljava/io/InputStream;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/"+modelName, "executeQuery", "(Ljava/lang/String;ILjava/lang/String;ZZ)Ljava/io/InputStream;");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
12 years, 4 months
teiid SVN: r4376 - trunk/build/kits/jboss-as7/docs/teiid.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-08-28 08:16:57 -0400 (Tue, 28 Aug 2012)
New Revision: 4376
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
Log:
TEIID-2141 adding a release note
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-08-28 02:42:57 UTC (rev 4375)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-08-28 12:16:57 UTC (rev 4376)
@@ -30,7 +30,8 @@
<li>TEIID-2148 <b>Streaming Improvements</b> - the ws translator invoke/invokeHttp procedures now accept a "stream"" parameter to indicate that the result should be streamed directly without an intermediate copy being created.
Also intermediate document/blob copies are made concurrently with reading to reduce latency.
<li>TEIID-2158 <b>Rest Services</b> - when required extension metadata defined on the virtual procedure, a REST based service on that procedure is automatically generated and deployed upon VDB deployment.
- <li>TEIID-2163 <b>Binary XMLSERIALIZE</b> - XMLSERIALIZE now supports blob/varbinary and the encoding/version and XMLDECLARATION options.
+ <li>TEIID-2163 <b>Binary XMLSERIALIZE</b> - XMLSERIALIZE now supports blob/varbinary and the encoding/version and XMLDECLARATION options.
+ <li>TEIID-2141 <b>OBJECTTABLE</b> - was added to extract values from objects using arbitrary scripts. See the Reference for usage.
</ul>
<h2><a name="Compatibility">Compatibility Issues</a></h2>
12 years, 4 months
teiid SVN: r4375 - in trunk/admin/src: main/resources/org/teiid/adminapi and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-08-27 22:42:57 -0400 (Mon, 27 Aug 2012)
New Revision: 4375
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
trunk/admin/src/main/resources/org/teiid/adminapi/i18n.properties
trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
trunk/admin/src/test/resources/parser-test-vdb.xml
trunk/admin/src/test/resources/vdb-describe.txt
Log:
TEIID-2141 rounding out support in the vdb.xml
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java 2012-08-28 00:49:56 UTC (rev 4374)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataMapper.java 2012-08-28 02:42:57 UTC (rev 4375)
@@ -882,6 +882,7 @@
private static final String ALLOW_READ = "allow-read"; //$NON-NLS-1$
private static final String ALLOW_EXECUTE = "allow-execute"; //$NON-NLS-1$
private static final String ALLOW_ALTER = "allow-alter"; //$NON-NLS-1$
+ private static final String ALLOW_LANGUAGE = "allow-language"; //$NON-NLS-1$
public static PermissionMetaDataMapper INSTANCE = new PermissionMetaDataMapper();
@@ -891,6 +892,10 @@
}
node.get(RESOURCE_NAME).set(permission.getResourceName());
+ if(permission.getAllowLanguage() != null) {
+ node.get(ALLOW_LANGUAGE).set(permission.getAllowLanguage().booleanValue());
+ return node;
+ }
if (permission.getAllowCreate() != null) {
node.get(ALLOW_CREATE).set(permission.getAllowCreate().booleanValue());
}
@@ -921,6 +926,10 @@
if (node.get(RESOURCE_NAME) != null) {
permission.setResourceName(node.get(RESOURCE_NAME).asString());
}
+ if (node.has(ALLOW_LANGUAGE)) {
+ permission.setAllowLanguage(node.get(ALLOW_LANGUAGE).asBoolean());
+ return permission;
+ }
if (node.has(ALLOW_CREATE)) {
permission.setAllowCreate(node.get(ALLOW_CREATE).asBoolean());
}
@@ -949,6 +958,7 @@
addAttribute(node, ALLOW_READ, ModelType.BOOLEAN, false);
addAttribute(node, ALLOW_EXECUTE, ModelType.BOOLEAN, false);
addAttribute(node, ALLOW_ALTER, ModelType.BOOLEAN, false);
+ addAttribute(node, ALLOW_LANGUAGE, ModelType.BOOLEAN, false);
return node;
}
}
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-08-28 00:49:56 UTC (rev 4374)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetadataParser.java 2012-08-28 02:42:57 UTC (rev 4375)
@@ -502,7 +502,7 @@
writeElement(writer, Element.ALLOW_ALTER, permission.getAllowAlter().toString());
}
if (permission.getAllowLanguage() != null) {
- writeElement(writer, Element.ALLOW_LANGUAGE, permission.getAllowCreate().toString());
+ writeElement(writer, Element.ALLOW_LANGUAGE, permission.getAllowLanguage().toString());
}
writer.writeEndElement();
}
Modified: trunk/admin/src/main/resources/org/teiid/adminapi/i18n.properties
===================================================================
--- trunk/admin/src/main/resources/org/teiid/adminapi/i18n.properties 2012-08-28 00:49:56 UTC (rev 4374)
+++ trunk/admin/src/main/resources/org/teiid/adminapi/i18n.properties 2012-08-28 02:42:57 UTC (rev 4375)
@@ -78,6 +78,7 @@
allow-delete.describe = delete allowed
allow-execute.describe = execute allowed
allow-alter.describe = alter allowed
+allow-language.describe = language allowed
TEIID70051=The controller is not available at {0}:{1}
TEIID70000=Failed to resolve host '{0}' due to : {1}
Modified: trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
--- trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2012-08-28 00:49:56 UTC (rev 4374)
+++ trunk/admin/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2012-08-28 02:42:57 UTC (rev 4375)
@@ -117,9 +117,16 @@
assertTrue(role.getMappedRoleNames().contains("ROLE2")); //$NON-NLS-1$
List<DataPolicy.DataPermission> permissions = role.getPermissions();
- assertEquals(2, permissions.size());
+ assertEquals(3, permissions.size());
+ boolean lang = false;
for (DataPolicy.DataPermission p: permissions) {
+ if (p.getAllowLanguage() != null) {
+ assertTrue(p.getAllowLanguage());
+ assertEquals("javascript", p.getResourceName());
+ lang = true;
+ continue;
+ }
if (p.getResourceName().equalsIgnoreCase("myTable.T1")) { //$NON-NLS-1$
assertTrue(p.getAllowRead());
assertNull(p.getAllowDelete());
@@ -129,6 +136,7 @@
assertTrue(p.getAllowDelete());
}
}
+ assertTrue(lang);
}
private VDBMetaData buildVDB() {
@@ -191,6 +199,11 @@
perm2.setAllowDelete(true);
roleOne.addPermission(perm2);
+ PermissionMetaData perm3 = new PermissionMetaData();
+ perm3.setResourceName("javascript"); //$NON-NLS-1$
+ perm3.setAllowLanguage(true);
+ roleOne.addPermission(perm3);
+
roleOne.setMappedRoleNames(Arrays.asList("ROLE1", "ROLE2")); //$NON-NLS-1$ //$NON-NLS-2$
vdb.addDataPolicy(roleOne);
Modified: trunk/admin/src/test/resources/parser-test-vdb.xml
===================================================================
--- trunk/admin/src/test/resources/parser-test-vdb.xml 2012-08-28 00:49:56 UTC (rev 4374)
+++ trunk/admin/src/test/resources/parser-test-vdb.xml 2012-08-28 02:42:57 UTC (rev 4375)
@@ -33,6 +33,10 @@
<allow-execute>true</allow-execute>
<allow-alter>true</allow-alter>
</permission>
+ <permission>
+ <resource-name>javascript</resource-name>
+ <allow-language>true</allow-language>
+ </permission>
<mapped-role-name>ROLE1</mapped-role-name>
<mapped-role-name>ROLE2</mapped-role-name>
</data-role>
Modified: trunk/admin/src/test/resources/vdb-describe.txt
===================================================================
--- trunk/admin/src/test/resources/vdb-describe.txt 2012-08-28 00:49:56 UTC (rev 4374)
+++ trunk/admin/src/test/resources/vdb-describe.txt 2012-08-28 02:42:57 UTC (rev 4375)
@@ -378,6 +378,13 @@
},
"description" : "alter allowed",
"required" : false
+ },
+ "allow-language" : {
+ "type" : {
+ "TYPE_MODEL_VALUE" : "BOOLEAN"
+ },
+ "description" : "language allowed",
+ "required" : false
}
}
},
12 years, 4 months
teiid SVN: r4374 - trunk/admin/src/main/java/org/teiid/adminapi/impl.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-08-27 20:49:56 -0400 (Mon, 27 Aug 2012)
New Revision: 4374
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
Log:
TEIID-2164 minor optimizations to permission logic
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2012-08-27 23:07:08 UTC (rev 4373)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/DataPolicyMetadata.java 2012-08-28 00:49:56 UTC (rev 4374)
@@ -72,17 +72,17 @@
public void setPermissions(List<DataPermission> permissions) {
this.permissions.clear();
for (DataPermission permission:permissions) {
- addPermission((PermissionMetaData)permission);
+ addPermissionMetadata((PermissionMetaData)permission);
}
}
public void addPermission(PermissionMetaData... perms) {
for (PermissionMetaData permission:perms) {
- addPermission(permission);
+ addPermissionMetadata(permission);
}
}
- private void addPermission(PermissionMetaData permission) {
+ private void addPermissionMetadata(PermissionMetaData permission) {
PermissionMetaData previous = null;
if (permission.getAllowLanguage() != null) {
previous = this.languagePermissions.put(permission.getResourceName(), permission);
12 years, 4 months
teiid SVN: r4373 - in trunk/jboss-integration/src/main/java/org/teiid/jboss: rest and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-08-27 19:07:08 -0400 (Mon, 27 Aug 2012)
New Revision: 4373
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
Log:
TEIID-2158: Fixing the issue with undeploy of VDB not correctly doing the un-deployment of the dependent war file.
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-08-27 22:38:00 UTC (rev 4372)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-08-27 23:07:08 UTC (rev 4373)
@@ -103,6 +103,7 @@
protected final InjectedValue<ModelController> controllerValue = new InjectedValue<ModelController>();
private VDBLifeCycleListener vdbListener;
+ private VDBLifeCycleListener restEasyListener;
private LinkedHashMap<String, Resource> visibilityMap;
public VDBService(VDBMetaData metadata, LinkedHashMap<String, Resource> visibilityMap) {
@@ -171,7 +172,9 @@
};
getVDBRepository().addListener(this.vdbListener);
- getVDBRepository().addListener(new ResteasyEnabler(controllerValue.getValue(), executorInjector.getValue()));
+
+ this.restEasyListener = new ResteasyEnabler(controllerValue.getValue(), executorInjector.getValue());
+ getVDBRepository().addListener(this.restEasyListener);
MetadataStore store = new MetadataStore();
@@ -265,8 +268,9 @@
GlobalTableStore gts = vdb.getAttachment(GlobalTableStore.class);
this.objectReplicatorInjector.getValue().stop(gts);
}
+ getVDBRepository().removeVDB(this.vdb.getName(), this.vdb.getVersion());
getVDBRepository().removeListener(this.vdbListener);
- getVDBRepository().removeVDB(this.vdb.getName(), this.vdb.getVersion());
+ getVDBRepository().removeListener(this.restEasyListener);
final ServiceController<?> controller = context.getController().getServiceContainer().getService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(), vdb.getVersion()));
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java 2012-08-27 22:38:00 UTC (rev 4372)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java 2012-08-27 23:07:08 UTC (rev 4373)
@@ -90,7 +90,7 @@
@Override
public void removed(String name, int version, CompositeVDB cvdb) {
VDBMetaData vdb = cvdb.getVDB();
- String generate = vdb.getPropertyValue("auto-generate-rest-war"); //$NON-NLS-1$
+ String generate = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"auto-generate"); //$NON-NLS-1$
final String warName = buildName(vdb);
if (generate != null && Boolean.parseBoolean(generate)
&& ((AdminImpl) this.admin).getDeployments().contains(warName)) {
12 years, 4 months
teiid SVN: r4372 - in trunk: jboss-integration/src/main/resources/rest-war and 2 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-08-27 18:38:00 -0400 (Mon, 27 Aug 2012)
New Revision: 4372
Added:
trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java
trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml
trunk/jboss-integration/src/main/resources/rest-war/web.xml
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java
trunk/test-integration/common/src/test/resources/sample-vdb.xml
Log:
TEIID-2158: Adding the HTTPBasic security, with option to use pass-through-authentication and ad-hoc query based rest service
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java 2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java 2012-08-27 22:38:00 UTC (rev 4372)
@@ -56,8 +56,8 @@
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Procedure;
import org.teiid.metadata.ProcedureParameter;
+import org.teiid.metadata.ProcedureParameter.Type;
import org.teiid.metadata.Schema;
-import org.teiid.metadata.ProcedureParameter.Type;
import org.teiid.query.metadata.TransformationMetadata;
@@ -74,6 +74,29 @@
props.setProperty("${vdb-name}", vdb.getName());
props.setProperty("${vdb-version}", String.valueOf(vdb.getVersion()));
+ boolean passthroughAuth = false;
+ String securityType = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-type");
+ String securityDomain = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-domain");
+ String securityRole = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-role");
+ String passthoughAuthStr = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"passthrough-auth");
+ if (passthoughAuthStr != null) {
+ passthroughAuth = Boolean.parseBoolean(passthoughAuthStr);
+ }
+
+ props.setProperty("${security-role}", ((securityRole == null)?"rest":securityRole));
+ props.setProperty("${security-domain}", ((securityDomain == null)?"teiid-security":securityDomain));
+
+ if (securityType == null) {
+ securityType = "httpbasic";
+ }
+
+ if (securityType.equalsIgnoreCase("none")) {
+ props.setProperty("${security-content}", "");
+ }
+ else if (securityType.equalsIgnoreCase("httpbasic")) {
+ props.setProperty("${security-content}", replaceTemplates(getFileContents("rest-war/httpbasic.xml"), props));
+ }
+
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ZipOutputStream out = new ZipOutputStream(byteStream);
writeEntry("WEB-INF/web.xml", out, replaceTemplates(getFileContents("rest-war/web.xml"), props).getBytes());
@@ -82,7 +105,7 @@
ArrayList<String> applicationViews = new ArrayList<String>();
for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
Schema schema = metadataStore.getSchema(model.getName());
- byte[] viewContents = getViewClass(vdb.getName(), vdb.getVersion(), model.getName(), schema);
+ byte[] viewContents = getViewClass(vdb.getName(), vdb.getVersion(), model.getName(), schema, passthroughAuth);
if (viewContents != null) {
writeEntry("WEB-INF/classes/org/teiid/jboss/rest/"+model.getName()+".class", out, viewContents);
applicationViews.add(schema.getName());
@@ -205,7 +228,7 @@
return cw.toByteArray();
}
- private byte[] getViewClass(String vdbName, int vdbVersion, String modelName, Schema schema) {
+ private byte[] getViewClass(String vdbName, int vdbVersion, String modelName, Schema schema, boolean passthroughAuth) {
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
MethodVisitor mv;
@@ -237,11 +260,13 @@
String method = procedure.getProperty(ResteasyEnabler.REST_NAMESPACE+"METHOD", false);
String contentType = procedure.getProperty(ResteasyEnabler.REST_NAMESPACE+"PRODUCES", false);
String charSet = procedure.getProperty(ResteasyEnabler.REST_NAMESPACE+"CHARSET", false);
- if (getPathParameters(uri).size() != procedure.getParameters().size()) {
- LogManager.logWarning(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50091, procedure.getFullName()));
- continue;
- }
+
if (uri != null && method != null) {
+ if (method.equalsIgnoreCase("GET") && getPathParameters(uri).size() != procedure.getParameters().size()) {
+ LogManager.logWarning(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50091, procedure.getFullName()));
+ continue;
+ }
+
if (contentType == null) {
contentType = findContentType(procedure);
}
@@ -257,14 +282,14 @@
else if (contentType.equals("plain")) {
contentType = "text/plain";
}
- buildRestService(vdbName, vdbVersion, modelName, procedure, method, uri, cw, contentType, charSet);
+ buildRestService(vdbName, vdbVersion, modelName, procedure, method, uri, cw, contentType, charSet, passthroughAuth);
hasValidProcedures = true;
}
}
}
-// buildQueryProcedure(vdbName, vdbVersion, "xml", cw);
-// buildQueryProcedure(vdbName, vdbVersion, "json", cw);
+ buildQueryProcedure(vdbName, vdbVersion, "xml", cw, passthroughAuth);
+ buildQueryProcedure(vdbName, vdbVersion, "json", cw, passthroughAuth);
cw.visitEnd();
@@ -303,7 +328,7 @@
private void buildRestService(String vdbName, int vdbVersion, String modelName, Procedure procedure,
String method, String uri, ClassWriter cw, String contentType,
- String charSet) {
+ String charSet, boolean passthroughAuth) {
List<ProcedureParameter> params = new ArrayList<ProcedureParameter>(procedure.getParameters().size());
boolean usingReturn = false;
@@ -350,9 +375,15 @@
av0.visitEnd();
}
+ // post only accepts Form inputs, not path params
+ String paramType = "Ljavax/ws/rs/PathParam;";
+ if (method.toUpperCase().equals("POST")) {
+ paramType = "Ljavax/ws/rs/FormParam;";
+ }
+
for (int i = 0; i < paramsSize; i++)
{
- av0 = mv.visitParameterAnnotation(i, "Ljavax/ws/rs/PathParam;", true);
+ av0 = mv.visitParameterAnnotation(i, paramType, true);
av0.visit("value", params.get(i).getName());
av0.visitEnd();
}
@@ -402,8 +433,8 @@
mv.visitVarInsn(ALOAD, paramsSize+1);
mv.visitLdcInsn(charSet==null?"":charSet);
-
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/"+modelName, "execute", "(Ljava/lang/String;ILjava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;)Ljava/io/InputStream;");
+ mv.visitInsn(passthroughAuth?ICONST_1:ICONST_0);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/"+modelName, "execute", "(Ljava/lang/String;ILjava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;Z)Ljava/io/InputStream;");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
@@ -415,12 +446,12 @@
mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;");
mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V");
mv.visitInsn(ATHROW);
- mv.visitMaxs(6, paramsSize+2);
+ mv.visitMaxs(7, paramsSize+2);
mv.visitEnd();
}
}
- private void buildQueryProcedure(String vdbName, int vdbVersion, String context, ClassWriter cw) {
+ private void buildQueryProcedure(String vdbName, int vdbVersion, String context, ClassWriter cw, boolean passthroughAuth) {
MethodVisitor mv;
{
AnnotationVisitor av0;
@@ -459,7 +490,8 @@
mv.visitIntInsn(BIPUSH, vdbVersion);
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(context.equals("xml")?ICONST_0:ICONST_1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/View", "executeQuery", "(Ljava/lang/String;ILjava/lang/String;Z)Ljava/io/InputStream;");
+ mv.visitInsn(passthroughAuth?ICONST_1:ICONST_0);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/View", "executeQuery", "(Ljava/lang/String;ILjava/lang/String;ZZ)Ljava/io/InputStream;");
mv.visitLabel(l1);
mv.visitInsn(ARETURN);
mv.visitLabel(l2);
@@ -471,7 +503,7 @@
mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;");
mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V");
mv.visitInsn(ATHROW);
- mv.visitMaxs(5, 3);
+ mv.visitMaxs(6, 3);
mv.visitEnd();
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java 2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java 2012-08-27 22:38:00 UTC (rev 4372)
@@ -61,7 +61,7 @@
public void finishedDeployment(String name, int version, CompositeVDB cvdb) {
final VDBMetaData vdb = cvdb.getVDB();
- String generate = vdb.getPropertyValue("auto-generate-rest-war"); //$NON-NLS-1$
+ String generate = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"auto-generate"); //$NON-NLS-1$
final String warName = buildName(vdb);
if (generate != null && Boolean.parseBoolean(generate)
@@ -112,6 +112,11 @@
}
private boolean hasRestMetadata(VDBMetaData vdb) {
+ String securityType = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-type"); //$NON-NLS-1$
+ if (securityType != null && !securityType.equalsIgnoreCase("none") && !securityType.equalsIgnoreCase("httpbasic")) { //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
+ }
+
MetadataStore metadataStore = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
for (ModelMetaData model: vdb.getModelMetaDatas().values()) {
Schema schema = metadataStore.getSchema(model.getName());
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java 2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java 2012-08-27 22:38:00 UTC (rev 4372)
@@ -31,6 +31,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLXML;
+import java.sql.Statement;
import java.util.LinkedHashMap;
import org.teiid.core.types.BlobType;
@@ -45,7 +46,7 @@
public abstract class TeiidRSProvider {
public InputStream execute(String vdbName, int version, String procedureSignature,
- LinkedHashMap<String, String> parameters, String charSet) throws SQLException {
+ LinkedHashMap<String, String> parameters, String charSet, boolean passthroughAuth) throws SQLException {
Object result = null;
//the generated code sends a empty string rather than null.
@@ -53,7 +54,7 @@
charSet = null;
}
- Connection conn = getConnection(vdbName, version);
+ Connection conn = getConnection(vdbName, version, passthroughAuth);
boolean usingReturn = procedureSignature.startsWith("{ ?"); //$NON-NLS-1$
try {
//TODO: an alternative strategy would be to set the parameters based upon name
@@ -84,32 +85,7 @@
result = statement.getObject(1);
}
statement.close();
- if (result == null) {
- return null; //or should this be an empty result?
- }
-
- if (result instanceof SQLXML) {
- if (charSet != null) {
- XMLSerialize serialize = new XMLSerialize();
- serialize.setTypeString("blob"); //$NON-NLS-1$
- serialize.setDeclaration(true);
- serialize.setEncoding(charSet);
- serialize.setDocument(true);
- try {
- return ((BlobType)XMLSystemFunctions.serialize(serialize, (XMLType)result)).getBinaryStream();
- } catch (TransformationException e) {
- throw new SQLException(e);
- }
- }
- return ((SQLXML)result).getBinaryStream();
- }
- else if (result instanceof Blob) {
- return ((Blob)result).getBinaryStream();
- }
- else if (result instanceof Clob) {
- return new ReaderInputStream(((Clob)result).getCharacterStream(), charSet==null?Charset.defaultCharset():Charset.forName(charSet));
- }
- return new ByteArrayInputStream(result.toString().getBytes(charSet==null?Charset.defaultCharset():Charset.forName(charSet)));
+ return handleResult(charSet, result);
} finally {
if (conn != null) {
try {
@@ -119,10 +95,65 @@
}
}
}
+
+ private InputStream handleResult(String charSet, Object result) throws SQLException {
+ if (result == null) {
+ return null; //or should this be an empty result?
+ }
+
+ if (result instanceof SQLXML) {
+ if (charSet != null) {
+ XMLSerialize serialize = new XMLSerialize();
+ serialize.setTypeString("blob"); //$NON-NLS-1$
+ serialize.setDeclaration(true);
+ serialize.setEncoding(charSet);
+ serialize.setDocument(true);
+ try {
+ return ((BlobType)XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML)result))).getBinaryStream();
+ } catch (TransformationException e) {
+ throw new SQLException(e);
+ }
+ }
+ return ((SQLXML)result).getBinaryStream();
+ }
+ else if (result instanceof Blob) {
+ return ((Blob)result).getBinaryStream();
+ }
+ else if (result instanceof Clob) {
+ return new ReaderInputStream(((Clob)result).getCharacterStream(), charSet==null?Charset.defaultCharset():Charset.forName(charSet));
+ }
+ return new ByteArrayInputStream(result.toString().getBytes(charSet==null?Charset.defaultCharset():Charset.forName(charSet)));
+ }
- private Connection getConnection(String vdbName, int version) throws SQLException {
+ public InputStream executeQuery(String vdbName, int vdbVersion, String sql, boolean json, boolean passthroughAuth) throws SQLException {
+ Connection conn = getConnection(vdbName, vdbVersion, passthroughAuth);
+ Object result = null;
+ try {
+ Statement statement = conn.createStatement();
+ final boolean hasResultSet = statement.execute(sql);
+ if (hasResultSet) {
+ ResultSet rs = statement.getResultSet();
+ if (rs.next()) {
+ result = rs.getObject(1);
+ } else {
+ throw new SQLException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50092));
+ }
+ rs.close();
+ }
+ statement.close();
+ return handleResult(Charset.defaultCharset().name(), result);
+ } finally {
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+ }
+
+ private Connection getConnection(String vdbName, int version, boolean passthough) throws SQLException {
TeiidDriver driver = new TeiidDriver();
- return driver.connect("jdbc:teiid:"+vdbName+"."+version, null);
+ return driver.connect("jdbc:teiid:"+vdbName+"."+version+(passthough?"PassthroughAuthentication=true":""), null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
-
}
Added: trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml
===================================================================
--- trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml (rev 0)
+++ trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml 2012-08-27 22:38:00 UTC (rev 4372)
@@ -0,0 +1,20 @@
+ <security-role>
+ <description>security role</description>
+ <role-name>${security-role}</role-name>
+ </security-role>
+
+ <security-constraint>
+ <display-name>require valid user</display-name>
+ <web-resource-collection>
+ <web-resource-name>Teiid Rest Application</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>${security-role}</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>yourdomain.com</realm-name>
+ </login-config>
\ No newline at end of file
Property changes on: trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml
===================================================================
--- trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml 2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml 2012-08-27 22:38:00 UTC (rev 4372)
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
- <security-domain>java:/jaas/teiid-security</security-domain>
+ <security-domain>java:/jaas/${security-domain}</security-domain>
</jboss-web>
\ No newline at end of file
Modified: trunk/jboss-integration/src/main/resources/rest-war/web.xml
===================================================================
--- trunk/jboss-integration/src/main/resources/rest-war/web.xml 2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/resources/rest-war/web.xml 2012-08-27 22:38:00 UTC (rev 4372)
@@ -16,26 +16,7 @@
<servlet-name>RestDataservice</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
- <!--
- <security-role>
- <description>security role</description>
- <role-name>example-role</role-name>
- </security-role>
-
- <security-constraint>
- <display-name>require valid user</display-name>
- <web-resource-collection>
- <web-resource-name>Teiid rest application</web-resource-name>
- <url-pattern>/*</url-pattern>
- </web-resource-collection>
- <auth-constraint>
- <role-name>example-role</role-name>
- </auth-constraint>
- </security-constraint>
- <login-config>
- <auth-method>BASIC</auth-method>
- <realm-name>yourdomain.com</realm-name>
- </login-config>
- -->
+${security-content}
+
</web-app>
\ No newline at end of file
Modified: trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java 2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java 2012-08-27 22:38:00 UTC (rev 4372)
@@ -22,13 +22,16 @@
package org.teiid.arquillian;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.net.URLEncoder;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.After;
@@ -61,7 +64,7 @@
}
@Test
- public void testReuse() throws Exception {
+ public void testGetOperation() throws Exception {
admin.deploy("sample-vdb.xml",new FileInputStream(UnitTestUtil.getTestDataFile("sample-vdb.xml")));
assertTrue(AdminUtil.waitForVDBLoad(admin, "sample", 1, 3));
@@ -73,15 +76,49 @@
assertTrue(((AdminImpl)admin).getDeployments().contains("sample_1.war"));
- String response = httpCall("http://localhost:8080/sample_1/view/g1/123", "GET");
- assertEquals("<sample.g1Table.p1 p1=\"123\"><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></sample.g1Table.p1>", response);
+ // get based call
+ String response = httpCall("http://localhost:8080/sample_1/view/g1/123", "GET", null);
+ assertEquals("<rows p1=\"123\"><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></rows>", response);
}
- private String httpCall(String url, String method) throws Exception {
+ @Test
+ public void testPostOperation() throws Exception {
+ admin.deploy("sample-vdb.xml",new FileInputStream(UnitTestUtil.getTestDataFile("sample-vdb.xml")));
+
+ assertTrue(AdminUtil.waitForVDBLoad(admin, "sample", 1, 3));
+
+ this.internalConnection = TeiidDriver.getInstance().connect("jdbc:teiid:sample@mm://localhost:31000;user=user;password=user", null);
+
+ execute("SELECT * FROM Txns.G1"); //$NON-NLS-1$
+ this.internalResultSet.next();
+
+ assertTrue(((AdminImpl)admin).getDeployments().contains("sample_1.war"));
+
+ String params = URLEncoder.encode("p1", "UTF-8") + "=" + URLEncoder.encode("456", "UTF-8");
+
+ // post based call
+ String response = httpCall("http://localhost:8080/sample_1/view/g1post", "POST", params);
+ assertEquals("<rows p1=\"456\"><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></rows>", response);
+
+ // ad-hoc procedure
+ params = URLEncoder.encode("sql", "UTF-8") + "=" + URLEncoder.encode("SELECT XMLELEMENT(NAME \"rows\", XMLAGG(XMLELEMENT(NAME \"row\", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1", "UTF-8");
+ response = httpCall("http://localhost:8080/sample_1/view/query", "POST", params);
+ assertEquals("<rows><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></rows>", response);
+ }
+
+
+ private String httpCall(String url, String method, String params) throws Exception {
StringBuffer buff = new StringBuffer();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod(method);
connection.setDoOutput(true);
+
+ if (method.equalsIgnoreCase("post")) {
+ OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
+ wr.write(params);
+ wr.flush();
+ }
+
BufferedReader serverResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = serverResponse.readLine()) != null) {
Modified: trunk/test-integration/common/src/test/resources/sample-vdb.xml
===================================================================
--- trunk/test-integration/common/src/test/resources/sample-vdb.xml 2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/test-integration/common/src/test/resources/sample-vdb.xml 2012-08-27 22:38:00 UTC (rev 4372)
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vdb name="sample" version="1">
<property name="UseConnectorMetadata" value="true" />
- <property name="auto-generate-rest-war" value="true"/>
+ <property name="{http://teiid.org/rest}auto-generate" value="true"/>
+ <property name="{http://teiid.org/rest}security-type" value="none"/>
+ <property name="{http://teiid.org/rest}security-domain" value="teiid-security"/>
+ <property name="{http://teiid.org/rest}security-role" value="example-role"/>
<model name="Txns">
<source name="text-connector" translator-name="loopback" />
@@ -16,13 +19,18 @@
CREATE VIRTUAL PROCEDURE g1Table(IN p1 integer) RETURNS TABLE (xml_out xml) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'GET', "REST:URI" 'g1/{p1}')
AS
BEGIN
- SELECT XMLELEMENT(NAME sample.g1Table.p1, XMLATTRIBUTES (g1Table.p1 as p1), XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1;
+ SELECT XMLELEMENT(NAME "rows", XMLATTRIBUTES (g1Table.p1 as p1), XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1;
END
CREATE VIRTUAL PROCEDURE g2Table() RETURNS TABLE (xml_out string) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'GET', "REST:URI" 'g2')
AS
BEGIN
SELECT '{ "age":100, "name":test,messages:["msg1","msg2","msg3"]}' as xml_out;
- END
+ END
+ CREATE VIRTUAL PROCEDURE g1TablePost(IN p1 integer) RETURNS TABLE (xml_out xml) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'POST', "REST:URI" 'g1post')
+ AS
+ BEGIN
+ SELECT XMLELEMENT(NAME "rows", XMLATTRIBUTES (g1TablePost.p1 as p1), XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1;
+ END
]]> </metadata>
</model>
12 years, 4 months
teiid SVN: r4371 - in branches/7.7.x: engine/src/main/java/org/teiid/query/processor/relational and 1 other directories.
by teiid-commits@lists.jboss.org
Author: jolee
Date: 2012-08-27 16:43:50 -0400 (Mon, 27 Aug 2012)
New Revision: 4371
Modified:
branches/7.7.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
Log:
TEIID-2112 addressing pre-gregorian cutoff values
Modified: branches/7.7.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java
===================================================================
--- branches/7.7.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java 2012-08-27 20:43:40 UTC (rev 4370)
+++ branches/7.7.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java 2012-08-27 20:43:50 UTC (rev 4371)
@@ -22,6 +22,8 @@
package org.teiid.core.util;
+import static org.junit.Assert.*;
+
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
@@ -29,28 +31,20 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.GregorianCalendar;
import java.util.TimeZone;
-import org.teiid.core.util.TimestampWithTimezone;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-import junit.framework.TestCase;
+public class TestTimestampWithTimezone {
-public class TestTimestampWithTimezone extends TestCase {
-
- /**
- * Constructor for TestTimestampWithTimezone.
- *
- * @param name
- */
- public TestTimestampWithTimezone(String name) {
- super(name);
- }
-
- public void setUp() {
+ @Before public void setUp() {
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("America/Chicago")); //$NON-NLS-1$
}
- public void tearDown() {
+ @After public void tearDown() {
TimestampWithTimezone.resetCalendar(null);
}
@@ -117,7 +111,7 @@
return ts;
}
- public void testDST() {
+ @Test public void testDST() {
helpTestSame("2005-10-30 02:39:10", 1, "America/Chicago", //$NON-NLS-1$ //$NON-NLS-2$
"GMT-05:00"); //$NON-NLS-1$
@@ -137,32 +131,32 @@
}
- public void testTimezone() {
+ @Test public void testTimezone() {
helpTestSame("2004-06-29 15:39:10", 1, "GMT-06:00", //$NON-NLS-1$ //$NON-NLS-2$
"GMT-05:00"); //$NON-NLS-1$
}
- public void testTimezone2() {
+ @Test public void testTimezone2() {
helpTestSame("2004-06-29 15:39:10", 1, "GMT-08:00", //$NON-NLS-1$ //$NON-NLS-2$
"GMT-06:00"); //$NON-NLS-1$
}
- public void testTimezone3() {
+ @Test public void testTimezone3() {
helpTestSame("2004-08-31 18:25:54", 1, "Europe/London", //$NON-NLS-1$ //$NON-NLS-2$
"GMT"); //$NON-NLS-1$
}
- public void testTimezoneOverMidnight() {
+ @Test public void testTimezoneOverMidnight() {
helpTestSame("2004-06-30 23:39:10", 1, "America/Los_Angeles", //$NON-NLS-1$ //$NON-NLS-2$
"America/Chicago"); //$NON-NLS-1$
}
- public void testCase2852() {
+ @Test public void testCase2852() {
helpTestSame("2005-05-17 22:35:33", 508659, "GMT", //$NON-NLS-1$ //$NON-NLS-2$
"America/New_York"); //$NON-NLS-1$
}
- public void testCreateDate() {
+ @Test public void testCreateDate() {
Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201"); //$NON-NLS-1$
Date date = TimestampWithTimezone.createDate(t);
@@ -179,7 +173,7 @@
assertEquals(cal.get(Calendar.DATE), 30);
}
- public void testCreateTime() {
+ @Test public void testCreateTime() {
Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201"); //$NON-NLS-1$
Time date = TimestampWithTimezone.createTime(t);
@@ -199,14 +193,14 @@
/**
* Even though the id of the timezones are different, this should not change the result
*/
- public void testDateToDateConversion() {
+ @Test public void testDateToDateConversion() {
Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
Date converted = TimestampWithTimezone.createDate(t, TimeZone.getTimeZone("America/Chicago"), Calendar.getInstance(TimeZone.getTimeZone("US/Central"))); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(t.getTime(), converted.getTime());
}
- public void testDateToDateConversion1() {
+ @Test public void testDateToDateConversion1() {
Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
Date converted = TimestampWithTimezone.createDate(t, TimeZone.getTimeZone("America/Chicago"), Calendar.getInstance(TimeZone.getTimeZone("GMT"))); //$NON-NLS-1$ //$NON-NLS-2$
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2012-08-27 20:43:40 UTC (rev 4370)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2012-08-27 20:43:50 UTC (rev 4371)
@@ -22,15 +22,14 @@
package org.teiid.query.processor.relational;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.TimeZone;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
@@ -56,7 +55,6 @@
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.XMLType;
-import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.query.QueryPlugin;
import org.teiid.query.eval.Evaluator;
import org.teiid.query.function.FunctionDescriptor;
@@ -310,10 +308,11 @@
if (value instanceof CalendarValue) {
CalendarValue cv = (CalendarValue)value;
if (!cv.hasTimezone()) {
+ int tzMin = getContext().getServerTimeZone().getRawOffset()/60000;
+ cv.setTimezoneInMinutes(tzMin);
Calendar cal = cv.getCalendar();
- Date d = cal.getTime();
- cal.setTimeZone(getContext().getServerTimeZone());
- return TimestampWithTimezone.createTimestamp(d, TimeZone.getTimeZone("GMT"), cal);
+
+ return new Timestamp(cal.getTime().getTime());
}
}
return Value.convertToJava(value);
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2012-08-27 20:43:40 UTC (rev 4370)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2012-08-27 20:43:50 UTC (rev 4371)
@@ -194,10 +194,10 @@
}
@Test public void testXmlTableDateTime() throws Exception {
- String sql = "select * from xmltable('/a' passing convert('<a dt=\"2011-11-17T07:38:49\" dtz=\"2011-11-17T07:38:49Z\" t=\"13:23:14\" d=\"2010-04-05\" />', xml) columns x timestamp path '@dt', x1 timestamp path '@dtz', y date path '@d', z time path '@t') as x"; //$NON-NLS-1$
+ String sql = "select * from xmltable('/a' passing convert('<a dt=\"0001-11-17T07:38:49\" dtz=\"2011-11-17T07:38:49Z\" t=\"13:23:14\" d=\"2010-04-05\" />', xml) columns x timestamp path '@dt', x1 timestamp path '@dtz', y date path '@d', z time path '@t') as x"; //$NON-NLS-1$
List<?>[] expected = new List<?>[] {
- Arrays.asList(TimestampUtil.createTimestamp(111, 10, 17, 7, 38, 49, 0), TimestampUtil.createTimestamp(111, 10, 17, 1, 38, 49, 0), TimestampUtil.createDate(110, 3, 5), TimestampUtil.createTime(13, 23, 14))
+ Arrays.asList(TimestampUtil.createTimestamp(-1899, 10, 19, 7, 38, 49, 0), TimestampUtil.createTimestamp(111, 10, 17, 1, 38, 49, 0), TimestampUtil.createDate(110, 3, 5), TimestampUtil.createTime(13, 23, 14))
};
process(sql, expected);
12 years, 4 months