You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by am...@apache.org on 2016/02/05 09:43:40 UTC
[3/3] lens git commit: LENS-791 : Fix CLI output to print yaml
representation of entity
LENS-791 : Fix CLI output to print yaml representation of entity
Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/b805ee98
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/b805ee98
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/b805ee98
Branch: refs/heads/master
Commit: b805ee989188c5889e6472b48572d126b6515414
Parents: 58d8636
Author: Rajat Khandelwal <pr...@apache.org>
Authored: Fri Feb 5 14:12:29 2016 +0530
Committer: Amareshwari Sriramadasu <am...@apache.org>
Committed: Fri Feb 5 14:12:29 2016 +0530
----------------------------------------------------------------------
lens-api/pom.xml | 7 +
.../java/org/apache/lens/api/APIResult.java | 33 +-
.../main/java/org/apache/lens/api/DateTime.java | 2 +-
.../main/java/org/apache/lens/api/LensConf.java | 6 +-
.../org/apache/lens/api/LensSessionHandle.java | 47 +--
.../java/org/apache/lens/api/ToXMLString.java | 73 ++++
.../java/org/apache/lens/api/ToYAMLString.java | 121 ++++++
.../apache/lens/api/jaxb/LensJAXBContext.java | 47 ++-
.../lens/api/jaxb/YAMLToStringStrategy.java | 389 +++++++++++++++++++
.../lens/api/query/InMemoryQueryResult.java | 5 +
.../lens/api/query/LensPreparedQuery.java | 4 +-
.../org/apache/lens/api/query/LensQuery.java | 3 +-
.../org/apache/lens/api/query/QueryHandle.java | 10 -
.../lens/api/query/QueryPrepareHandle.java | 10 -
.../org/apache/lens/api/query/QueryResult.java | 3 +-
.../lens/api/query/QueryResultSetMetadata.java | 4 +-
.../org/apache/lens/api/query/QueryStatus.java | 42 +-
.../lens/api/query/QuerySubmitResult.java | 3 +-
.../apache/lens/api/query/SchedulerJobInfo.java | 2 +
.../org/apache/lens/api/result/QueryCostTO.java | 1 -
.../lens/api/jaxb/YAMLToStringStrategyTest.java | 166 ++++++++
.../toString/org.apache.lens.api.DateTime.xml | 24 ++
.../toString/org.apache.lens.api.DateTime.yaml | 16 +
.../toString/org.apache.lens.api.LensConf.xml | 33 ++
.../toString/org.apache.lens.api.LensConf.yaml | 17 +
...pache.lens.api.query.InMemoryQueryResult.xml | 49 +++
...ache.lens.api.query.InMemoryQueryResult.yaml | 17 +
....apache.lens.api.query.LensPreparedQuery.xml | 43 ++
...apache.lens.api.query.LensPreparedQuery.yaml | 24 ++
.../org.apache.lens.api.query.LensQuery.xml | 67 ++++
.../org.apache.lens.api.query.LensQuery.yaml | 42 ++
...che.lens.api.query.PersistentQueryResult.xml | 27 ++
...he.lens.api.query.PersistentQueryResult.yaml | 19 +
.../org.apache.lens.api.query.QueryHandle.xml | 24 ++
.../org.apache.lens.api.query.QueryHandle.yaml | 16 +
....lens.api.query.QueryHandleWithResultSet.xml | 26 ++
...lens.api.query.QueryHandleWithResultSet.yaml | 16 +
.../org.apache.lens.api.query.QueryPlan.xml | 43 ++
.../org.apache.lens.api.query.QueryPlan.yaml | 29 ++
...apache.lens.api.query.QueryPrepareHandle.xml | 24 ++
...pache.lens.api.query.QueryPrepareHandle.yaml | 16 +
...he.lens.api.query.QueryResultSetMetadata.xml | 33 ++
...e.lens.api.query.QueryResultSetMetadata.yaml | 17 +
.../org.apache.lens.api.query.QueryStatus.xml | 35 ++
.../org.apache.lens.api.query.QueryStatus.yaml | 22 ++
.../org.apache.lens.api.query.ResultRow.xml | 33 ++
.../org.apache.lens.api.query.ResultRow.yaml | 16 +
...apache.lens.api.query.SchedulerJobHandle.xml | 24 ++
...pache.lens.api.query.SchedulerJobHandle.yaml | 16 +
.../org.apache.lens.api.result.QueryCostTO.xml | 26 ++
.../org.apache.lens.api.result.QueryCostTO.yaml | 18 +
.../lens/cli/commands/BaseLensCommand.java | 37 +-
.../lens/cli/commands/LensCRUDCommand.java | 7 +-
.../cli/commands/LensConnectionCommands.java | 26 +-
.../cli/commands/LensDimensionCommands.java | 7 +-
.../lens/cli/commands/LensQueryCommands.java | 6 +-
.../cli/commands/LogicalTableCrudCommand.java | 13 +-
.../apache/lens/cli/LensCliApplicationTest.java | 3 +-
.../apache/lens/cli/TestLensCubeCommands.java | 5 +-
.../lens/cli/TestLensDimensionCommands.java | 4 +-
.../cli/TestLensDimensionTableCommands.java | 6 +-
.../apache/lens/cli/TestLensFactCommands.java | 4 +-
.../lens/cli/TestLensStorageCommands.java | 4 +-
.../java/org/apache/lens/client/LensClient.java | 1 +
.../apache/lens/client/LensMetadataClient.java | 26 +-
.../org/apache/lens/client/LensStatement.java | 2 +-
.../src/main/resources/lens-client-default.xml | 5 +
lens-examples/pom.xml | 16 +-
.../apache/lens/examples/SampleMetastore.java | 5 +-
.../src/main/resources/example-job.xml | 5 +-
.../examples/ExampleSchemaToStringTest.java | 45 +++
.../test/resources/yaml/city-local-part.yaml | 20 +
lens-examples/src/test/resources/yaml/city.yaml | 23 ++
.../src/test/resources/yaml/city_subset.yaml | 30 ++
.../src/test/resources/yaml/city_table.yaml | 36 ++
.../resources/yaml/customer-local-part.yaml | 20 +
.../src/test/resources/yaml/customer.yaml | 38 ++
.../src/test/resources/yaml/customer_table.yaml | 45 +++
.../src/test/resources/yaml/db-storage.yaml | 19 +
.../test/resources/yaml/dim1-local-part.yaml | 20 +
.../test/resources/yaml/dim2-local-part.yaml | 20 +
.../test/resources/yaml/dim4-local-part.yaml | 20 +
.../src/test/resources/yaml/dim_table.yaml | 35 ++
.../src/test/resources/yaml/dim_table2.yaml | 34 ++
.../src/test/resources/yaml/dim_table3.yaml | 34 ++
.../src/test/resources/yaml/dim_table4.yaml | 43 ++
.../src/test/resources/yaml/example-job.yaml | 39 ++
.../test/resources/yaml/fact1-local-part1.yaml | 20 +
.../test/resources/yaml/fact1-local-part2.yaml | 20 +
.../test/resources/yaml/fact1-local-part3.yaml | 20 +
.../src/test/resources/yaml/fact1.yaml | 35 ++
.../test/resources/yaml/fact2-local-part1.yaml | 20 +
.../test/resources/yaml/fact2-local-part2.yaml | 20 +
.../test/resources/yaml/fact2-local-part3.yaml | 20 +
.../src/test/resources/yaml/fact2.yaml | 36 ++
.../resources/yaml/local-cluster-storage.yaml | 19 +
.../src/test/resources/yaml/local-storage.yaml | 19 +
.../resources/yaml/product-local-parts.yaml | 48 +++
.../src/test/resources/yaml/product.yaml | 36 ++
.../test/resources/yaml/product_db_table.yaml | 36 ++
.../src/test/resources/yaml/product_table.yaml | 39 ++
.../test/resources/yaml/raw-local-part1.yaml | 20 +
.../test/resources/yaml/raw-local-part2.yaml | 20 +
.../test/resources/yaml/raw-local-part3.yaml | 20 +
.../test/resources/yaml/raw-local-part4.yaml | 20 +
.../test/resources/yaml/raw-local-part5.yaml | 20 +
.../test/resources/yaml/raw-local-part6.yaml | 20 +
.../src/test/resources/yaml/rawfact.yaml | 38 ++
.../yaml/sales-aggr-continuous-fact.yaml | 45 +++
.../yaml/sales-aggr-fact1-local-parts.yaml | 40 ++
.../yaml/sales-aggr-fact1-mydb-parts.yaml | 24 ++
.../test/resources/yaml/sales-aggr-fact1.yaml | 60 +++
.../yaml/sales-aggr-fact2-local-parts.yaml | 40 ++
.../yaml/sales-aggr-fact2-mydb-parts.yaml | 24 ++
.../test/resources/yaml/sales-aggr-fact2.yaml | 56 +++
.../src/test/resources/yaml/sales-cube.yaml | 110 ++++++
.../src/test/resources/yaml/sales-raw-fact.yaml | 50 +++
.../resources/yaml/sales-raw-local-parts.yaml | 32 ++
.../src/test/resources/yaml/sample-cube.yaml | 47 +++
.../yaml/sample-db-only-dimension.yaml | 32 ++
.../test/resources/yaml/sample-dimension.yaml | 32 ++
.../test/resources/yaml/sample-dimension2.yaml | 24 ++
.../org/apache/lens/server/LensJerseyTest.java | 2 +-
.../apache/lens/server/LensServerTestUtil.java | 9 +-
pom.xml | 1 +
src/site/apt/user/client-config.apt | 14 +-
126 files changed, 3432 insertions(+), 249 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/pom.xml
----------------------------------------------------------------------
diff --git a/lens-api/pom.xml b/lens-api/pom.xml
index e4a89ff..9b5e5f8 100644
--- a/lens-api/pom.xml
+++ b/lens-api/pom.xml
@@ -93,8 +93,10 @@
<arg>-extension</arg>
<arg>-Xinheritance</arg>
<arg>-XtoString</arg>
+ <arg>-XtoString-toStringStrategyClass=org.apache.lens.api.jaxb.YAMLToStringStrategy</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
+ <arg>-Xfluent-api</arg>
</args>
<plugins>
<plugin>
@@ -102,6 +104,11 @@
<artifactId>jaxb2-basics</artifactId>
<version>${jaxb2.basics.plugin.version}</version>
</plugin>
+ <plugin>
+ <groupId>org.jvnet.jaxb2_commons</groupId>
+ <artifactId>jaxb2-fluent-api</artifactId>
+ <version>${jaxb2.fluent.plugin.version}</version>
+ </plugin>
</plugins>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/APIResult.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/APIResult.java b/lens-api/src/main/java/org/apache/lens/api/APIResult.java
index f50d3ea..26e9926 100644
--- a/lens-api/src/main/java/org/apache/lens/api/APIResult.java
+++ b/lens-api/src/main/java/org/apache/lens/api/APIResult.java
@@ -18,15 +18,8 @@
*/
package org.apache.lens.api;
-import java.io.StringWriter;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.*;
-import org.apache.lens.api.jaxb.LensJAXBContext;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -45,7 +38,7 @@ import lombok.NoArgsConstructor;
* Instantiates a new API result.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public class APIResult {
+public class APIResult extends ToYAMLString {
/**
* The status.
*/
@@ -61,19 +54,6 @@ public class APIResult {
private String message;
/**
- * The Constant JAXB_CONTEXT.
- */
- private static final JAXBContext JAXB_CONTEXT;
-
- static {
- try {
- JAXB_CONTEXT = new LensJAXBContext(APIResult.class);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
* API Result status.
*/
@XmlType
@@ -94,17 +74,6 @@ public class APIResult {
FAILED
}
- @Override
- public String toString() {
- try {
- StringWriter stringWriter = new StringWriter();
- Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
- marshaller.marshal(this, stringWriter);
- return stringWriter.toString();
- } catch (JAXBException e) {
- return e.getMessage();
- }
- }
private static final APIResult SUCCESS = new APIResult(Status.SUCCEEDED, "");
public static APIResult partial(int actual, int expected) {
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/DateTime.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/DateTime.java b/lens-api/src/main/java/org/apache/lens/api/DateTime.java
index 3f89fdd..cd88a57 100644
--- a/lens-api/src/main/java/org/apache/lens/api/DateTime.java
+++ b/lens-api/src/main/java/org/apache/lens/api/DateTime.java
@@ -42,7 +42,7 @@ import lombok.*;
* Instantiates a new date.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public class DateTime {
+public class DateTime extends ToYAMLString {
/**
* The Date.
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/LensConf.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/LensConf.java b/lens-api/src/main/java/org/apache/lens/api/LensConf.java
index 67d6461..86504c7 100644
--- a/lens-api/src/main/java/org/apache/lens/api/LensConf.java
+++ b/lens-api/src/main/java/org/apache/lens/api/LensConf.java
@@ -39,7 +39,7 @@ import lombok.NoArgsConstructor;
* Instantiates a new lens conf.
*/
@NoArgsConstructor
-public class LensConf implements Serializable {
+public class LensConf extends ToYAMLString implements Serializable {
/**
* The Constant serialVersionUID.
@@ -75,4 +75,8 @@ public class LensConf implements Serializable {
public void addProperties(Map<String, String> props) {
properties.putAll(props);
}
+
+ public String getProperty(Object key) {
+ return properties.get(key);
+ }
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/LensSessionHandle.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/LensSessionHandle.java b/lens-api/src/main/java/org/apache/lens/api/LensSessionHandle.java
index dc9142d..74725e3 100644
--- a/lens-api/src/main/java/org/apache/lens/api/LensSessionHandle.java
+++ b/lens-api/src/main/java/org/apache/lens/api/LensSessionHandle.java
@@ -21,20 +21,12 @@
*/
package org.apache.lens.api;
-import java.io.StringReader;
-import java.io.StringWriter;
import java.util.UUID;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import org.apache.lens.api.jaxb.LensJAXBContext;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -57,7 +49,7 @@ import lombok.NoArgsConstructor;
* Instantiates a new lens session handle.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public class LensSessionHandle {
+public class LensSessionHandle extends ToXMLString {
/**
* The public id.
@@ -76,47 +68,12 @@ public class LensSessionHandle {
private UUID secretId;
/**
- * The Constant JAXB_CONTEXT.
- */
- private static final JAXBContext JAXB_CONTEXT;
-
- static {
- try {
- JAXB_CONTEXT = new LensJAXBContext(LensSessionHandle.class);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
* Value of.
*
* @param sessionStr the session str
* @return the lens session handle
*/
public static LensSessionHandle valueOf(String sessionStr) {
- try {
- Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
- return (LensSessionHandle) unmarshaller.unmarshal(new StringReader(sessionStr));
- } catch (JAXBException e) {
- return null;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- try {
- StringWriter stringWriter = new StringWriter();
- Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
- marshaller.marshal(this, stringWriter);
- return stringWriter.toString();
- } catch (JAXBException e) {
- return "";
- }
+ return valueOf(sessionStr, LensSessionHandle.class);
}
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/ToXMLString.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/ToXMLString.java b/lens-api/src/main/java/org/apache/lens/api/ToXMLString.java
new file mode 100644
index 0000000..fca56a8
--- /dev/null
+++ b/lens-api/src/main/java/org/apache/lens/api/ToXMLString.java
@@ -0,0 +1,73 @@
+/**
+ * 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.lens.api;
+
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.lens.api.jaxb.LensJAXBContext;
+
+public abstract class ToXMLString {
+ protected static final Map<Class<?>, JAXBContext> JAXB_CONTEXTS = new HashMap<>();
+
+
+ @Override
+ public String toString() {
+ return toString(this);
+ }
+
+ public static String toString(Object o) {
+ try {
+ StringWriter stringWriter = new StringWriter();
+ Marshaller marshaller = getLensJAXBContext(o.getClass()).createMarshaller();
+ marshaller.marshal(o, stringWriter);
+ return stringWriter.toString();
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static JAXBContext getLensJAXBContext(Class<?> clazz) {
+ if (!JAXB_CONTEXTS.containsKey(clazz)) {
+ try {
+ JAXB_CONTEXTS.put(clazz, new LensJAXBContext(clazz));
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return JAXB_CONTEXTS.get(clazz);
+ }
+
+ public static <T> T valueOf(String sessionStr, Class<T> tClass) {
+ try {
+ Unmarshaller unmarshaller = getLensJAXBContext(tClass).createUnmarshaller();
+ return (T) unmarshaller.unmarshal(new StringReader(sessionStr));
+ } catch (JAXBException e) {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/ToYAMLString.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/ToYAMLString.java b/lens-api/src/main/java/org/apache/lens/api/ToYAMLString.java
new file mode 100644
index 0000000..65a0c44
--- /dev/null
+++ b/lens-api/src/main/java/org/apache/lens/api/ToYAMLString.java
@@ -0,0 +1,121 @@
+/**
+ * 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.lens.api;
+
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.lens.api.jaxb.YAMLToStringStrategy;
+
+import org.jvnet.jaxb2_commons.lang.ToString;
+import org.jvnet.jaxb2_commons.lang.ToStringStrategy;
+import org.jvnet.jaxb2_commons.locator.ObjectLocator;
+
+import com.google.common.collect.Lists;
+import lombok.Data;
+
+public abstract class ToYAMLString implements ToString {
+ @Data(staticConstructor = "of")
+ public static class FieldNameAndValue {
+ final String name;
+ final Object value;
+ }
+
+ public String toString() {
+ final ToStringStrategy strategy = new YAMLToStringStrategy();
+ final StringBuilder buffer = new StringBuilder();
+ append(null, buffer, strategy);
+ return buffer.toString();
+ }
+
+ public StringBuilder append(ObjectLocator locator, StringBuilder buffer, ToStringStrategy strategy) {
+ if (getFieldsToAppend().size() == 1) {
+ Object field = getFieldsToAppend().iterator().next().getValue();
+ strategy.append(locator, buffer, field);
+ return buffer;
+ }
+ strategy.appendStart(locator, this, buffer);
+ appendFields(locator, buffer, strategy);
+ strategy.appendEnd(locator, this, buffer);
+ return buffer;
+ }
+
+ Collection<FieldNameAndValue> fieldsToAppend = null;
+
+ public Collection<FieldNameAndValue> getFieldsToAppend() {
+ if (fieldsToAppend == null) {
+ List<FieldNameAndValue> fieldNameAndValueList = Lists.newArrayList();
+ for (Field field : this.getClass().getDeclaredFields()) {
+ try {
+ Method getter = getGetter(field);
+ fieldNameAndValueList.add(new FieldNameAndValue(getReadableName(getter), getter.invoke(this)));
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchMethodException e) {
+ //pass. The field doesn't have getter.
+ }
+ }
+ fieldsToAppend = fieldNameAndValueList;
+ }
+ return fieldsToAppend;
+ }
+
+ @Override
+ public StringBuilder appendFields(ObjectLocator objectLocator, StringBuilder stringBuilder, ToStringStrategy
+ toStringStrategy) {
+ for (FieldNameAndValue fieldNameAndValue : fieldsToAppend) {
+ toStringStrategy.appendField(objectLocator, this, fieldNameAndValue.getName(), stringBuilder,
+ fieldNameAndValue.getValue());
+ }
+ return stringBuilder;
+ }
+
+ private String getReadableName(Method method) {
+ return method.getName().replaceAll("^get", "").replaceAll("^is", "Is").replaceAll("([a-z])(?=[A-Z])", "$1 ");
+ }
+
+ private Method getGetter(Field field) throws NoSuchMethodException {
+ String getterName;
+ if (field.getType().isAssignableFrom(Boolean.class) || field.getType().equals(Boolean.TYPE)) {
+ getterName = field.getName();
+ if (!getterName.startsWith("is")) {
+ getterName = "is" + toPascalCase(getterName);
+ }
+ } else {
+ getterName = "get" + toPascalCase(field.getName());
+ }
+ return this.getClass().getDeclaredMethod(getterName);
+ }
+
+ private String toPascalCase(String str) {
+ return str.substring(0, 1).toUpperCase() + str.substring(1);
+ }
+
+ public String toXMLString() {
+ return ToXMLString.toString(this);
+ }
+
+ public static <T> T fromXMLString(String xml, Class<? extends T> clazz) {
+ return ToXMLString.valueOf(xml, clazz);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/jaxb/LensJAXBContext.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/jaxb/LensJAXBContext.java b/lens-api/src/main/java/org/apache/lens/api/jaxb/LensJAXBContext.java
index 85a47ec..e517c92 100644
--- a/lens-api/src/main/java/org/apache/lens/api/jaxb/LensJAXBContext.java
+++ b/lens-api/src/main/java/org/apache/lens/api/jaxb/LensJAXBContext.java
@@ -21,12 +21,16 @@
*/
package org.apache.lens.api.jaxb;
-import java.net.URL;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import javax.xml.XMLConstants;
import javax.xml.bind.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.util.ValidationEventCollector;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
@@ -38,6 +42,18 @@ import lombok.extern.slf4j.Slf4j;
public class LensJAXBContext extends JAXBContext {
private final JAXBContext jaxbContext;
private final boolean hasTopLevelClass;
+ private static final LensJAXBContext INSTANCE;
+ private static final Unmarshaller UNMARSHALLER;
+
+ static {
+ try {
+ INSTANCE = new LensJAXBContext(org.apache.lens.api.metastore.ObjectFactory.class,
+ org.apache.lens.api.scheduler.ObjectFactory.class);
+ UNMARSHALLER = INSTANCE.createUnmarshaller();
+ } catch (JAXBException e) {
+ throw new RuntimeException("Couldn't create instance of lens jaxb context", e);
+ }
+ }
public LensJAXBContext(Class... classesToBeBoundArray) throws JAXBException {
jaxbContext = JAXBContext.newInstance(classesToBeBoundArray);
@@ -55,11 +71,12 @@ public class LensJAXBContext extends JAXBContext {
public Unmarshaller createUnmarshaller() throws JAXBException {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
if (!hasTopLevelClass) {
- ClassLoader classLoader = LensJAXBContext.class.getClassLoader();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try {
- URL resource = classLoader.getResource("cube-0.1.xsd");
- Schema schema = sf.newSchema(resource);
+ Schema schema = sf.newSchema(new Source[]{
+ new StreamSource(getClass().getResourceAsStream("/scheduler-job-0.1.xsd")),
+ new StreamSource(getClass().getResourceAsStream("/cube-0.1.xsd")),
+ });
unmarshaller.setSchema(schema);
} catch (SAXException e) {
throw new JAXBException(e);
@@ -88,4 +105,26 @@ public class LensJAXBContext extends JAXBContext {
return true;
}
}
+
+ public LensJAXBContext getInstance() {
+ return INSTANCE;
+ }
+
+ public Unmarshaller getUnmarshaller() {
+ return UNMARSHALLER;
+ }
+
+ public static <T> T unmarshallFromFile(String filename) throws JAXBException, IOException {
+ File file = new File(filename);
+ if (file.exists()) {
+ return ((JAXBElement<T>) UNMARSHALLER.unmarshal(file)).getValue();
+ } else {
+ // load from classpath
+ InputStream stream = LensJAXBContext.class.getResourceAsStream(filename);
+ if (stream == null) {
+ throw new IOException("File not found:" + filename);
+ }
+ return ((JAXBElement<T>) UNMARSHALLER.unmarshal(stream)).getValue();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/jaxb/YAMLToStringStrategy.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/jaxb/YAMLToStringStrategy.java b/lens-api/src/main/java/org/apache/lens/api/jaxb/YAMLToStringStrategy.java
new file mode 100644
index 0000000..f5af1c6
--- /dev/null
+++ b/lens-api/src/main/java/org/apache/lens/api/jaxb/YAMLToStringStrategy.java
@@ -0,0 +1,389 @@
+/**
+ * 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.lens.api.jaxb;
+
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.*;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.lens.api.metastore.*;
+import org.apache.lens.api.query.QueryHandle;
+import org.apache.lens.api.query.QueryPrepareHandle;
+import org.apache.lens.api.query.ResultColumn;
+
+import org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy;
+import org.jvnet.jaxb2_commons.lang.ToString;
+import org.jvnet.jaxb2_commons.lang.ToStringStrategy;
+import org.jvnet.jaxb2_commons.locator.ObjectLocator;
+
+import com.google.common.collect.Sets;
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class YAMLToStringStrategy extends JAXBToStringStrategy {
+ public static final ToStringStrategy INSTANCE = new YAMLToStringStrategy();
+ private int indentationValue = -1;
+ public static final String INDENTATION_STRING = " ";
+ private boolean insideArray = false;
+ private Stack<Boolean> insideArrayStack = new Stack<>();
+ public static final Set<Class<?>> WRAPPER_TYPES = Sets.newHashSet(Boolean.class, Character.class, Byte.class,
+ Short.class, Integer.class, Long.class, Float.class, Double.class, Void.class, XMLGregorianCalendar.class,
+ UUID.class, String.class, Enum.class, QueryHandle.class, QueryPrepareHandle.class, java.util.Date.class);
+
+ {
+ insideArrayStack.push(false);
+ }
+
+ public StringBuilder indent(StringBuilder buffer) {
+ for (int i = 0; i < indentationValue; i++) {
+ buffer.append(INDENTATION_STRING);
+ }
+ return buffer;
+ }
+
+ public static String objectToString(ToString object) {
+ final StringBuilder buffer = new StringBuilder();
+ object.append(null, buffer, INSTANCE);
+ return buffer.toString();
+ }
+
+ @Override
+ public StringBuilder appendStart(ObjectLocator parentLocator, Object object, StringBuilder buffer) {
+ indentationValue++;
+ return buffer;
+ }
+
+ @Override
+ public StringBuilder appendEnd(ObjectLocator parentLocator, Object parent, StringBuilder buffer) {
+ indentationValue--;
+ return buffer;
+ }
+
+ protected void appendFieldStart(ObjectLocator parentLocator, Object parent, String fieldName, StringBuilder buffer) {
+ if (fieldName != null) {
+ indent(buffer).append(fieldName).append(": ");
+ }
+ }
+
+ interface NameableContext {
+ String getHeading();
+
+ void close();
+
+ String getDetails();
+ }
+
+ @Data
+ class XFieldNameableContext implements NameableContext {
+ final XField field;
+ private String displayString;
+ private String description;
+ private String name;
+ private String heading;
+
+ @Override
+ public String getHeading() {
+ StringBuilder singleLineHeading = new StringBuilder();
+ if (isNotBlank(field.getDisplayString())) {
+ singleLineHeading.append(field.getDisplayString()).append("(").append(field.getName()).append(")");
+ } else {
+ singleLineHeading.append(field.getName());
+ }
+ if (isNotBlank(field.getDescription())) {
+ singleLineHeading.append(" [").append(field.getDescription()).append("]");
+ }
+ this.name = field.getName();
+ this.description = field.getDescription();
+ this.displayString = field.getDisplayString();
+ field.setName(null);
+ field.setDescription(null);
+ field.setDisplayString(null);
+ this.heading = singleLineHeading.toString();
+ return singleLineHeading.toString() + ":";
+ }
+
+ @Override
+ public void close() {
+ field.setName(this.name);
+ field.setDisplayString(this.displayString);
+ field.setDescription(this.description);
+ }
+
+ @Override
+ public String getDetails() {
+ try {
+ String fieldDetails = YAMLToStringStrategy.super.appendInternal(null, new StringBuilder(), field).toString();
+ if (field instanceof XJoinChain) {
+ return "\n" + fieldDetails;
+ }
+ String singleLineDetails = fieldDetails.replaceAll("\\s+$", "").replaceAll("\n\\s+", ", ").trim();
+ if (singleLineDetails.length() < 100 && !singleLineDetails.contains("-")) {
+ return singleLineDetails;
+ }
+ return "\n" + fieldDetails;
+ } finally {
+ close();
+ }
+ }
+ }
+
+ @Data
+ class ReflectiveNameableContext implements NameableContext {
+ private final Object value;
+ private final Method getter, setter;
+ private String name;
+
+ @Override
+ public String getHeading() {
+ try {
+ name = (String) getter.invoke(value);
+ setter.invoke(value, new Object[]{null});
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ return "-";
+ }
+ if (isBlank(name)) {
+ return "-";
+ }
+ return name + ":";
+ }
+
+ @Override
+ public void close() {
+ try {
+ setter.invoke(value, new Object[]{name});
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ return;
+ }
+ }
+
+ @Override
+ public String getDetails() {
+ try {
+ String fieldDetails = YAMLToStringStrategy.super.appendInternal(null, new StringBuilder(), value).toString();
+ String singleLineDetails = fieldDetails.replaceAll("\\s+$", "").replaceAll("\n\\s+", ", ").trim();
+ if (singleLineDetails.length() < 100 && !singleLineDetails.contains("-")) {
+ return singleLineDetails;
+ }
+ return "\n" + fieldDetails;
+ } finally {
+ close();
+ }
+ }
+ }
+
+ public NameableContext getNameableContext(Object value) {
+ if (value instanceof XField) {
+ return new XFieldNameableContext((XField) value);
+ }
+ try {
+ if (value.getClass().getMethod("getName") != null) {
+ return new ReflectiveNameableContext(value, value.getClass().getMethod("getName"),
+ value.getClass().getMethod("setName", String.class));
+ }
+ } catch (NoSuchMethodException e) {
+ try {
+ if (value.getClass().getMethod("getStorageName") != null) {
+ return new ReflectiveNameableContext(value, value.getClass().getMethod("getStorageName"),
+ value.getClass().getMethod("setStorageName", String.class));
+ }
+ } catch (NoSuchMethodException e1) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected StringBuilder appendInternal(ObjectLocator locator, StringBuilder stringBuilder, Object value) {
+ insideArray = insideArrayStack.peek();
+ insideArrayStack.push(false);
+ try {
+ if (value instanceof String && ((String) value).isEmpty()) {
+ appendNullText(stringBuilder);
+ return stringBuilder;
+ }
+ if (!canBeInlinedWithOtherArrayElements(value)) {
+ appendNewLine(stringBuilder);
+ }
+ if (value instanceof Map) {
+ indentationValue++;
+ for (Object key : ((Map) value).keySet()) {
+ appendNewLine(indent(stringBuilder).append(key).append(": ").append(((Map) value).get(key)));
+ }
+ indentationValue--;
+ return stringBuilder;
+ }
+ if (value instanceof XProperty || value instanceof XPartSpecElement || value instanceof XTimePartSpecElement
+ || value instanceof ResultColumn) {
+ removeLastArrayStart(stringBuilder);
+ if (value instanceof ResultColumn) {
+ ResultColumn column = (ResultColumn) value;
+ indent(stringBuilder).append(column.getName()).append(": ").append(column.getType());
+ }
+ if (value instanceof XProperty) {
+ XProperty property = (XProperty) value;
+ indent(stringBuilder).append(property.getName()).append(": ").append(property.getValue());
+ }
+ if (value instanceof XPartSpecElement) {
+ XPartSpecElement partSpecElement = (XPartSpecElement) value;
+ indent(stringBuilder).append(partSpecElement.getKey()).append(": ").append(partSpecElement.getValue());
+ }
+ if (value instanceof XTimePartSpecElement) {
+ XTimePartSpecElement partSpecElement = (XTimePartSpecElement) value;
+ indent(stringBuilder).append(partSpecElement.getKey()).append(": ").append(partSpecElement.getValue());
+ }
+ return appendNewLine(stringBuilder);
+ }
+
+ if (value instanceof XJoinEdge) {
+ XJoinEdge edge = (XJoinEdge) value;
+ XTableReference from = edge.getFrom();
+ XTableReference to = edge.getTo();
+ stringBuilder.setLength(stringBuilder.length() - 2);
+ stringBuilder
+ .append(from.getTable()).append(".").append(from.getColumn()).append(from.isMapsToMany() ? "(many)" : "")
+ .append("=")
+ .append(to.getTable()).append(".").append(to.getColumn()).append(to.isMapsToMany() ? "(many)" : "");
+ return appendNewLine(stringBuilder);
+ }
+ NameableContext context = getNameableContext(value);
+ if (context != null) {
+ String heading = context.getHeading();
+ if (isBlank(heading)) {
+ heading = "-";
+ }
+ if (insideArray) {
+ stringBuilder.setLength(stringBuilder.length() - 2);
+ }
+ String details = context.getDetails();
+ stringBuilder.append(heading);
+ if (details.charAt(0) != '\n') {
+ stringBuilder.append(" ");
+ }
+ stringBuilder.append(details);
+ return appendNewLine(stringBuilder);
+ }
+ // some other way of getting heading
+ if (value instanceof Collection) {
+ Collection collection = (Collection) value;
+ // try inline
+ StringBuilder allElements = super.appendInternal(locator, new StringBuilder(), value);
+ if (collection.size() != 0 && canBeInlinedWithOtherArrayElements((collection.iterator().next()))
+ && allElements.length() < 120) {
+ stringBuilder.setLength(stringBuilder.length() - 1);
+ String sep = " ";
+ for (Object singleElement : collection) {
+ stringBuilder.append(sep);
+ appendInternal(locator, stringBuilder, singleElement);
+ sep = ", ";
+ }
+ return stringBuilder;
+ } else {
+ return stringBuilder.append(allElements);
+ }
+ }
+ // If this class is just a wrapper over a another object
+ Field[] fields = value.getClass().getDeclaredFields();
+ int nonStaticFields = 0;
+ String fieldName = null;
+ for (Field field : fields) {
+ if (!Modifier.isStatic(field.getModifiers())) {
+ nonStaticFields++;
+ fieldName = field.getName();
+ }
+ }
+ if (nonStaticFields == 1) {
+ try {
+ Object wrappedValue = value.getClass().getDeclaredMethod("get" + fieldName.substring(0, 1).toUpperCase()
+ + fieldName.substring(1)).invoke(value);
+ return appendNewLine(appendInternal(locator, stringBuilder, wrappedValue));
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ log.error("getter access failed. Going the usual way");
+ }
+ }
+ return super.appendInternal(locator, stringBuilder, value);
+ } finally {
+ insideArrayStack.pop();
+ }
+ }
+
+ private boolean canBeInlinedWithOtherArrayElements(Object value) {
+ if (value.getClass().isPrimitive()) {
+ return true;
+ }
+ for (Class<?> clazz : WRAPPER_TYPES) {
+ if (clazz.isAssignableFrom(value.getClass())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void removeLastArrayStart(StringBuilder stringBuilder) {
+ stringBuilder.setLength(stringBuilder.length() - ((indentationValue + 1) * INDENTATION_STRING.length()));
+ }
+
+ @Override
+ protected void appendFieldEnd(ObjectLocator parentLocator, Object parent, String fieldName, StringBuilder buffer) {
+ appendNewLine(buffer);
+ }
+
+ private StringBuilder appendNewLine(StringBuilder buffer) {
+ if (buffer.length() != 0 && buffer.charAt(buffer.length() - 1) != '\n') {
+ while (buffer.charAt(buffer.length() - 1) == ' ') {
+ buffer.setLength(buffer.length() - 1);
+ }
+ buffer.append("\n");
+ }
+ return buffer;
+ }
+
+ @Override
+ protected void appendArrayStart(StringBuilder buffer) {
+ indentationValue++;
+ insideArrayStack.push(true);
+ appendArraySeparator(buffer);
+ }
+
+ @Override
+ protected void appendArrayEnd(StringBuilder buffer) {
+ // start takes care
+ indentationValue--;
+ insideArrayStack.pop();
+ }
+
+ @Override
+ protected void appendArraySeparator(StringBuilder buffer) {
+ indent(buffer).append("-");
+ }
+
+ @Override
+ protected void appendNullText(StringBuilder buffer) {
+ buffer.setLength(buffer.lastIndexOf("\n") + 1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/InMemoryQueryResult.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/InMemoryQueryResult.java b/lens-api/src/main/java/org/apache/lens/api/query/InMemoryQueryResult.java
index 36d0ba0..b7013a0 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/InMemoryQueryResult.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/InMemoryQueryResult.java
@@ -67,4 +67,9 @@ public class InMemoryQueryResult extends QueryResult {
b.append(numRows).append(" rows ");
return b.toString();
}
+
+ @Override
+ public String toString() {
+ return super.toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/LensPreparedQuery.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/LensPreparedQuery.java b/lens-api/src/main/java/org/apache/lens/api/query/LensPreparedQuery.java
index f5bc35d..2d100b6 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/LensPreparedQuery.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/LensPreparedQuery.java
@@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.lens.api.LensConf;
+import org.apache.lens.api.ToYAMLString;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
@@ -62,7 +63,7 @@ import lombok.NoArgsConstructor;
* Instantiates a new lens prepared query.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public class LensPreparedQuery {
+public class LensPreparedQuery extends ToYAMLString {
/**
* The prepare handle.
@@ -112,4 +113,5 @@ public class LensPreparedQuery {
@XmlElement
@Getter
private LensConf conf;
+
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/LensQuery.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/LensQuery.java b/lens-api/src/main/java/org/apache/lens/api/query/LensQuery.java
index 23c4dec..e0ee761 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/LensQuery.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/LensQuery.java
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.apache.lens.api.LensConf;
import org.apache.lens.api.Priority;
+import org.apache.lens.api.ToYAMLString;
import lombok.*;
@@ -79,7 +80,7 @@ import lombok.*;
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode
-public class LensQuery {
+public class LensQuery extends ToYAMLString {
/**
* The query handle.
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/QueryHandle.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/QueryHandle.java b/lens-api/src/main/java/org/apache/lens/api/query/QueryHandle.java
index 2d4c706..88e4b0f 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/QueryHandle.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/QueryHandle.java
@@ -86,14 +86,4 @@ public class QueryHandle extends QuerySubmitResult implements Serializable {
}
return handleId.toString();
}
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return getHandleIdString();
- }
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/QueryPrepareHandle.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/QueryPrepareHandle.java b/lens-api/src/main/java/org/apache/lens/api/query/QueryPrepareHandle.java
index 38e87b1..24b0e9a 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/QueryPrepareHandle.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/QueryPrepareHandle.java
@@ -72,16 +72,6 @@ public class QueryPrepareHandle extends QuerySubmitResult {
return new QueryPrepareHandle(UUID.fromString(handle));
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return getQueryHandleString();
- }
-
public String getQueryHandleString() {
return prepareHandleId.toString();
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/QueryResult.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/QueryResult.java b/lens-api/src/main/java/org/apache/lens/api/query/QueryResult.java
index 3bc7cc7..db91e41 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/QueryResult.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/QueryResult.java
@@ -24,6 +24,7 @@ package org.apache.lens.api.query;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
+import org.apache.lens.api.ToYAMLString;
import org.apache.lens.api.result.PrettyPrintable;
import lombok.AccessLevel;
@@ -38,5 +39,5 @@ import lombok.NoArgsConstructor;
* Instantiates a new query result.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public abstract class QueryResult implements PrettyPrintable {
+public abstract class QueryResult extends ToYAMLString implements PrettyPrintable {
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/QueryResultSetMetadata.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/QueryResultSetMetadata.java b/lens-api/src/main/java/org/apache/lens/api/query/QueryResultSetMetadata.java
index 22c61cf..dbdc677 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/QueryResultSetMetadata.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/QueryResultSetMetadata.java
@@ -27,6 +27,8 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.lens.api.ToYAMLString;
+
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -47,7 +49,7 @@ import lombok.NoArgsConstructor;
* Instantiates a new query result set metadata.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public class QueryResultSetMetadata {
+public class QueryResultSetMetadata extends ToYAMLString {
/**
* The columns.
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/QueryStatus.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/QueryStatus.java b/lens-api/src/main/java/org/apache/lens/api/query/QueryStatus.java
index 40e5d87..7a9ada1 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/QueryStatus.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/QueryStatus.java
@@ -11,7 +11,7 @@
*
* 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
+ * "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.
@@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
+import org.apache.lens.api.ToYAMLString;
import org.apache.lens.api.result.LensErrorTO;
import lombok.*;
@@ -59,7 +60,7 @@ import lombok.*;
* Instantiates a new query status.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public class QueryStatus implements Serializable {
+public class QueryStatus extends ToYAMLString implements Serializable {
/**
* The Constant serialVersionUID.
@@ -171,43 +172,6 @@ public class QueryStatus implements Serializable {
@XmlElement
private LensErrorTO lensErrorTO;
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
-
- StringBuilder str = new StringBuilder(" Status : ").append(status.toString()).append("\n");
- if (statusMessage != null) {
- str.append(" Message : ").append(statusMessage).append("\n");
- }
-
- str.append(" Progress : ").append(progress).append("\n");
- if (progressMessage != null) {
- str.append(" Progress Message : ").append(progressMessage).append("\n");
- }
-
- if (queueNumber != null) {
- str.append(" Position in queue : ").append(queueNumber).append("\n");
- }
-
- if (errorMessage != null) {
- str.append(" Error : ").append(errorMessage).append("\n");
- }
-
- if (status.equals(Status.SUCCESSFUL)) {
- if (isResultSetAvailable) {
- str.append(" Result Available");
- } else {
- str.append(" Result Not Available");
- }
- }
-
- return str.toString();
- }
-
public boolean finished() {
return status.equals(Status.SUCCESSFUL) || status.equals(Status.FAILED) || status.equals(Status.CANCELED);
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/QuerySubmitResult.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/QuerySubmitResult.java b/lens-api/src/main/java/org/apache/lens/api/query/QuerySubmitResult.java
index f3fb6db..93d7e0a 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/QuerySubmitResult.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/QuerySubmitResult.java
@@ -24,6 +24,7 @@ package org.apache.lens.api.query;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
+import org.apache.lens.api.ToYAMLString;
import org.apache.lens.api.result.QueryCostTO;
/**
@@ -32,6 +33,6 @@ import org.apache.lens.api.result.QueryCostTO;
@XmlRootElement
@XmlSeeAlso({QueryHandle.class, QueryPrepareHandle.class, QueryHandleWithResultSet.class,
QueryPlan.class, QueryCostTO.class})
-public abstract class QuerySubmitResult {
+public abstract class QuerySubmitResult extends ToYAMLString {
}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/query/SchedulerJobInfo.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/query/SchedulerJobInfo.java b/lens-api/src/main/java/org/apache/lens/api/query/SchedulerJobInfo.java
index 1ae7894..92260b5 100644
--- a/lens-api/src/main/java/org/apache/lens/api/query/SchedulerJobInfo.java
+++ b/lens-api/src/main/java/org/apache/lens/api/query/SchedulerJobInfo.java
@@ -20,11 +20,13 @@ package org.apache.lens.api.query;
import org.apache.lens.api.scheduler.XJob;
+import lombok.AllArgsConstructor;
import lombok.Data;
/**
* POJO to represent the <code>job</code> table in the database.
*/
@Data
+@AllArgsConstructor
public class SchedulerJobInfo {
/**
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/main/java/org/apache/lens/api/result/QueryCostTO.java
----------------------------------------------------------------------
diff --git a/lens-api/src/main/java/org/apache/lens/api/result/QueryCostTO.java b/lens-api/src/main/java/org/apache/lens/api/result/QueryCostTO.java
index 266a4b7..25ab336 100644
--- a/lens-api/src/main/java/org/apache/lens/api/result/QueryCostTO.java
+++ b/lens-api/src/main/java/org/apache/lens/api/result/QueryCostTO.java
@@ -48,7 +48,6 @@ import lombok.*;
* Instantiates a new query cost.
*/
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-@ToString
public class QueryCostTO extends QuerySubmitResult implements Serializable {
/**
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/java/org/apache/lens/api/jaxb/YAMLToStringStrategyTest.java
----------------------------------------------------------------------
diff --git a/lens-api/src/test/java/org/apache/lens/api/jaxb/YAMLToStringStrategyTest.java b/lens-api/src/test/java/org/apache/lens/api/jaxb/YAMLToStringStrategyTest.java
new file mode 100644
index 0000000..3a784f8
--- /dev/null
+++ b/lens-api/src/test/java/org/apache/lens/api/jaxb/YAMLToStringStrategyTest.java
@@ -0,0 +1,166 @@
+/**
+ * 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.lens.api.jaxb;
+
+import java.io.*;
+import java.util.Collection;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.apache.lens.api.ToXMLString;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Lists;
+import lombok.Data;
+
+public class YAMLToStringStrategyTest {
+ String timeZone;
+ public static final String XML_LICENSE_HEADER = "<!--\n"
+ + "\n"
+ + " Licensed to the Apache Software Foundation (ASF) under one\n"
+ + " or more contributor license agreements. See the NOTICE file\n"
+ + " distributed with this work for additional information\n"
+ + " regarding copyright ownership. The ASF licenses this file\n"
+ + " to you under the Apache License, Version 2.0 (the\n"
+ + " \"License\"); you may not use this file except in compliance\n"
+ + " with the License. You may obtain a copy of the License at\n"
+ + "\n"
+ + " http://www.apache.org/licenses/LICENSE-2.0\n"
+ + "\n"
+ + " Unless required by applicable law or agreed to in writing,\n"
+ + " software distributed under the License is distributed on an\n"
+ + " \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n"
+ + " KIND, either express or implied. See the License for the\n"
+ + " specific language governing permissions and limitations\n"
+ + " under the License.\n"
+ + "\n"
+ + "-->\n";
+
+ public static final String YAML_HEADER = "# Licensed to the Apache Software Foundation (ASF) under one\n"
+ + "# or more contributor license agreements. See the NOTICE file\n"
+ + "# distributed with this work for additional information\n"
+ + "# regarding copyright ownership. The ASF licenses this file\n"
+ + "# to you under the Apache License, Version 2.0 (the\n"
+ + "# \"License\"); you may not use this file except in compliance\n"
+ + "# with the License. You may obtain a copy of the License at\n"
+ + "#\n"
+ + "# http://www.apache.org/licenses/LICENSE-2.0\n"
+ + "#\n"
+ + "# Unless required by applicable law or agreed to in writing, software\n"
+ + "# distributed under the License is distributed on an \"AS IS\" BASIS,\n"
+ + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
+ + "# See the License for the specific language governing permissions and\n"
+ + "# limitations under the License.\n";
+
+ @BeforeClass
+ public void setTimeZone() throws IOException {
+ timeZone = System.getProperty("user.timezone");
+ System.setProperty("user.timezone", "GMT");
+ TimeZone.setDefault(null);
+ write();
+ }
+
+ private void write() throws IOException {
+ for (Object object : getNewObjectsForYAML()) {
+ BufferedWriter xmlWriter = new BufferedWriter(new FileWriter(new File("src/test/resources/toString/"
+ + object.getClass().getName() + ".xml")));
+ BufferedWriter toStringWriter = new BufferedWriter(new FileWriter(new File("src/test/resources/toString/"
+ + object.getClass().getName() + ".yaml")));
+ xmlWriter.write(XML_LICENSE_HEADER);
+ xmlWriter.write(ToXMLString.toString(object));
+ xmlWriter.close();
+
+ toStringWriter.write(YAML_HEADER);
+ toStringWriter.write(object.toString());
+ toStringWriter.close();
+ }
+ }
+
+ private Collection<Object> getNewObjectsForYAML() {
+ return Lists.newArrayList();
+ }
+
+ @AfterClass
+ public void reSetTimeZone() {
+ System.setProperty("user.timezone", timeZone);
+ TimeZone.setDefault(null);
+ }
+
+ @Data
+ public static class ToStringTestData {
+ private final String name;
+ private final Object object;
+ private final String toString;
+
+ public void verify() {
+ Assert.assertEquals(object.toString().trim(), toString.trim(), "toString didn't match for " + name);
+ }
+ }
+
+ @DataProvider
+ public Object[][] toStringDataProvider() throws Exception {
+ Collection<ToStringTestData> dataCollection = provideData();
+ Object[][] array = new Object[dataCollection.size()][1];
+ int i = 0;
+ for (ToStringTestData data : dataCollection) {
+ array[i++][0] = data;
+ }
+ return array;
+ }
+
+ protected Collection<ToStringTestData> provideData() throws Exception {
+ List<ToStringTestData> dataList = Lists.newArrayList();
+ for (String fn : new File(getClass().getResource("/toString").toURI()).list(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith("xml");
+ }
+ })) {
+ Class<?> clazz = Class.forName(fn.substring(0, fn.length() - 4));
+ Object unmarshalled = clazz.cast(new LensJAXBContext(clazz)
+ .createUnmarshaller().unmarshal(getClass().getResourceAsStream("/toString/" + fn)));
+ String toString = readYAML("/toString/" + fn.replaceAll("xml$", "yaml"));
+ dataList.add(new ToStringTestData(fn, unmarshalled, toString));
+ }
+ return dataList;
+ }
+
+ @Test(dataProvider = "toStringDataProvider")
+ public void testToString(ToStringTestData testData) {
+ testData.verify();
+ }
+
+ protected String readYAML(String s) throws IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(s)));
+ String line = br.readLine();
+ StringBuilder sb = new StringBuilder();
+ while (line != null) {
+ if (!line.startsWith("#")) {
+ sb.append(line).append("\n");
+ }
+ line = br.readLine();
+ }
+ return sb.toString().trim();
+ }
+}
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.xml
new file mode 100644
index 0000000..2527018
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<dateTime>
+ <date>2016-02-02T19:17:34.893</date>
+</dateTime>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.yaml
new file mode 100644
index 0000000..24f89aa
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.DateTime.yaml
@@ -0,0 +1,16 @@
+# 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.
+Tue Feb 02 19:17:34 GMT 2016
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.xml
new file mode 100644
index 0000000..41fc022
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<conf>
+ <properties>
+ <entry>
+ <key>key2</key>
+ <value>value2</value>
+ </entry>
+ <entry>
+ <key>key1</key>
+ <value>value1</value>
+ </entry>
+ </properties>
+</conf>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.yaml
new file mode 100644
index 0000000..82548fd
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.LensConf.yaml
@@ -0,0 +1,17 @@
+# 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.
+key2: value2
+key1: value1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.xml
new file mode 100644
index 0000000..2d7b5a2
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<inMemoryQueryResult>
+ <rows>
+ <rows>
+ <values>
+ <values xsi:type="xs:int" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1</values>
+ <values xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">name</values>
+ <values xsi:type="xs:double" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">3.5</values>
+ <values xsi:type="xs:boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">true</values>
+ </values>
+ </rows>
+ <rows>
+ <values>
+ <values xsi:type="xs:int" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">2</values>
+ <values xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">home</values>
+ <values xsi:type="xs:double" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">9.5</values>
+ <values xsi:type="xs:boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">false</values>
+ </values>
+ </rows>
+ </rows>
+</inMemoryQueryResult>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.yaml
new file mode 100644
index 0000000..a6f4739
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.InMemoryQueryResult.yaml
@@ -0,0 +1,17 @@
+# 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.
+- 1, name, 3.5, true
+- 2, home, 9.5, false
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.xml
new file mode 100644
index 0000000..1276b61
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<lensPreparedQuery>
+ <prepareHandle>
+ <prepareHandleId>42d071c5-15d2-4836-982c-4e434ce651b5</prepareHandleId>
+ </prepareHandle>
+ <userQuery>cube select blah</userQuery>
+ <preparedTime>2016-02-02T19:17:34.894+05:30</preparedTime>
+ <preparedUser>user</preparedUser>
+ <selectedDriverName>selected-driver</selectedDriverName>
+ <driverQuery>select blah from driver table</driverQuery>
+ <conf>
+ <properties>
+ <entry>
+ <key>key2</key>
+ <value>value2</value>
+ </entry>
+ <entry>
+ <key>key1</key>
+ <value>value1</value>
+ </entry>
+ </properties>
+ </conf>
+</lensPreparedQuery>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.yaml
new file mode 100644
index 0000000..7893ec0
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensPreparedQuery.yaml
@@ -0,0 +1,24 @@
+# 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.
+Prepare Handle: 42d071c5-15d2-4836-982c-4e434ce651b5
+User Query: cube select blah
+Prepared Time: Tue Feb 02 13:47:34 GMT 2016
+Prepared User: user
+Selected Driver Name: selected-driver
+Driver Query: select blah from driver table
+Conf:
+ key2: value2
+ key1: value1
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.xml
new file mode 100644
index 0000000..4f84433
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<lensQuery>
+ <queryHandle>
+ <handleId>28be0bb7-f675-4065-9de4-0c0be6e39068</handleId>
+ </queryHandle>
+ <userQuery>cube select blah blah</userQuery>
+ <submittedUser>user</submittedUser>
+ <priority>HIGH</priority>
+ <isPersistent>true</isPersistent>
+ <selectedDriverName>selected-driver</selectedDriverName>
+ <driverQuery>select blah from driver table</driverQuery>
+ <status>
+ <progress>10.0</progress>
+ <status>RUNNING</status>
+ <statusMessage>query running</statusMessage>
+ <isResultSetAvailable>false</isResultSetAvailable>
+ <lensErrorTO>
+ <code>9999</code>
+ <message>error message</message>
+ <stackTrace>random stack trace</stackTrace>
+ </lensErrorTO>
+ <errorMessage>error message</errorMessage>
+ <progressMessage>progress message</progressMessage>
+ <queueNumber>11</queueNumber>
+ </status>
+ <resultSetPath>/path/to/result</resultSetPath>
+ <driverOpHandle>a6f6fb20-cd1b-44dc-819c-36eb8c99e72c</driverOpHandle>
+ <queryConf>
+ <properties>
+ <entry>
+ <key>key2</key>
+ <value>value2</value>
+ </entry>
+ <entry>
+ <key>key1</key>
+ <value>value1</value>
+ </entry>
+ </properties>
+ </queryConf>
+ <submissionTime>1454420854897</submissionTime>
+ <launchTime>1454420854897</launchTime>
+ <driverStartTime>1454420854897</driverStartTime>
+ <driverFinishTime>1454420854897</driverFinishTime>
+ <finishTime>1454420854897</finishTime>
+ <closedTime>1454420854897</closedTime>
+ <queryName>query name</queryName>
+</lensQuery>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.yaml
new file mode 100644
index 0000000..ee8af96
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.LensQuery.yaml
@@ -0,0 +1,42 @@
+# 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.
+Query Handle: 28be0bb7-f675-4065-9de4-0c0be6e39068
+User Query: cube select blah blah
+Submitted User: user
+Priority: HIGH
+Is Persistent: true
+Selected Driver Name: selected-driver
+Driver Query: select blah from driver table
+Status:
+ Progress: 10.0
+ Queue Number: 11
+ Status: RUNNING
+ Status Message: query running
+ Is Result Set Available: false
+ Progress Message: progress message
+ Error Message: error message
+Result Set Path: /path/to/result
+Driver Op Handle: a6f6fb20-cd1b-44dc-819c-36eb8c99e72c
+Query Conf:
+ key2: value2
+ key1: value1
+Submission Time: 1454420854897
+Launch Time: 1454420854897
+Driver Start Time: 1454420854897
+Driver Finish Time: 1454420854897
+Finish Time: 1454420854897
+Closed Time: 1454420854897
+Query Name: query name
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.xml
new file mode 100644
index 0000000..6228730
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<persistentQueryResult>
+ <persistedURI>hdfs://a.zip</persistedURI>
+ <numRows>100</numRows>
+ <fileSize>9878</fileSize>
+ <httpResultUrl>http://query/result/a</httpResultUrl>
+</persistentQueryResult>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.yaml
new file mode 100644
index 0000000..746f411
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.PersistentQueryResult.yaml
@@ -0,0 +1,19 @@
+# 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.
+Persisted URI: hdfs://a.zip
+Num Rows: 100
+File Size: 9878
+Http Result Url: http://query/result/a
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.xml
new file mode 100644
index 0000000..35fce9c
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<queryHandle>
+ <handleId>28be0bb7-f675-4065-9de4-0c0be6e39068</handleId>
+</queryHandle>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.yaml
new file mode 100644
index 0000000..1715af3
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandle.yaml
@@ -0,0 +1,16 @@
+# 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.
+28be0bb7-f675-4065-9de4-0c0be6e39068
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.xml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.xml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.xml
new file mode 100644
index 0000000..57111fc
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+
+-->
+<queryHandleWithResultSet>
+ <queryHandle>
+ <handleId>28be0bb7-f675-4065-9de4-0c0be6e39068</handleId>
+ </queryHandle>
+</queryHandleWithResultSet>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lens/blob/b805ee98/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.yaml
----------------------------------------------------------------------
diff --git a/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.yaml b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.yaml
new file mode 100644
index 0000000..dfa33d2
--- /dev/null
+++ b/lens-api/src/test/resources/toString/org.apache.lens.api.query.QueryHandleWithResultSet.yaml
@@ -0,0 +1,16 @@
+# 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.
+Query Handle: 28be0bb7-f675-4065-9de4-0c0be6e39068