wu-sheng closed pull request #11: Add copyFrom method for complex data type.
URL: https://github.com/apache/incubator-skywalking-oal-tool/pull/11
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/oal-parser/src/main/resources/code-templates/IndicatorImplementor.ftl 
b/oal-parser/src/main/resources/code-templates/IndicatorImplementor.ftl
index 6f8240e..3245422 100644
--- a/oal-parser/src/main/resources/code-templates/IndicatorImplementor.ftl
+++ b/oal-parser/src/main/resources/code-templates/IndicatorImplementor.ftl
@@ -178,15 +178,26 @@ public class ${metricName}Indicator extends 
${indicatorClassName} implements Ala
     @Override
     public Indicator toHour() {
         ${metricName}Indicator indicator = new ${metricName}Indicator();
-        indicator.setTimeBucket(toTimeBucketInHour());
 <#list fieldsFromSource as field>
-    <#if field.columnName != "time_bucket">
+    <#if field.columnName == "time_bucket">
+        indicator.setTimeBucket(toTimeBucketInHour());
+    <#elseif field.typeName == "java.lang.String" || field.typeName == "long" 
|| field.typeName == "int" || field.typeName == "double" || field.typeName == 
"float">
         indicator.${field.fieldSetter}(this.${field.fieldGetter}());
+    <#else>
+        ${field.typeName} newValue = new ${field.typeName}();
+        newValue.copyFrom(this.${field.fieldGetter}());
+        indicator.${field.fieldSetter}(newValue);
     </#if>
 </#list>
 <#list persistentFields as field>
-    <#if field.columnName != "time_bucket">
+    <#if field.columnName == "time_bucket">
+        indicator.setTimeBucket(toTimeBucketInHour());
+    <#elseif field.typeName == "java.lang.String" || field.typeName == "long" 
|| field.typeName == "int" || field.typeName == "double" || field.typeName == 
"float">
         indicator.${field.fieldSetter}(this.${field.fieldGetter}());
+    <#else>
+        ${field.typeName} newValue = new ${field.typeName}();
+        newValue.copyFrom(this.${field.fieldGetter}());
+        indicator.${field.fieldSetter}(newValue);
     </#if>
 </#list>
         return indicator;
@@ -195,15 +206,26 @@ public class ${metricName}Indicator extends 
${indicatorClassName} implements Ala
     @Override
     public Indicator toDay() {
         ${metricName}Indicator indicator = new ${metricName}Indicator();
-        indicator.setTimeBucket(toTimeBucketInDay());
 <#list fieldsFromSource as field>
-    <#if field.columnName != "time_bucket">
+    <#if field.columnName == "time_bucket">
+        indicator.setTimeBucket(toTimeBucketInDay());
+    <#elseif field.typeName == "java.lang.String" || field.typeName == "long" 
|| field.typeName == "int" || field.typeName == "double" || field.typeName == 
"float">
         indicator.${field.fieldSetter}(this.${field.fieldGetter}());
+    <#else>
+        ${field.typeName} newValue = new ${field.typeName}();
+        newValue.copyFrom(this.${field.fieldGetter}());
+        indicator.${field.fieldSetter}(newValue);
     </#if>
 </#list>
 <#list persistentFields as field>
-    <#if field.columnName != "time_bucket">
+    <#if field.columnName == "time_bucket">
+        indicator.setTimeBucket(toTimeBucketInDay());
+    <#elseif field.typeName == "java.lang.String" || field.typeName == "long" 
|| field.typeName == "int" || field.typeName == "double" || field.typeName == 
"float">
         indicator.${field.fieldSetter}(this.${field.fieldGetter}());
+    <#else>
+        ${field.typeName} newValue = new ${field.typeName}();
+        newValue.copyFrom(this.${field.fieldGetter}());
+        indicator.${field.fieldSetter}(newValue);
     </#if>
 </#list>
         return indicator;
@@ -212,15 +234,26 @@ public class ${metricName}Indicator extends 
${indicatorClassName} implements Ala
     @Override
     public Indicator toMonth() {
         ${metricName}Indicator indicator = new ${metricName}Indicator();
-        indicator.setTimeBucket(toTimeBucketInMonth());
 <#list fieldsFromSource as field>
-    <#if field.columnName != "time_bucket">
+    <#if field.columnName == "time_bucket">
+        indicator.setTimeBucket(toTimeBucketInMonth());
+    <#elseif field.typeName == "java.lang.String" || field.typeName == "long" 
|| field.typeName == "int" || field.typeName == "double" || field.typeName == 
"float">
         indicator.${field.fieldSetter}(this.${field.fieldGetter}());
+    <#else>
+        ${field.typeName} newValue = new ${field.typeName}();
+        newValue.copyFrom(this.${field.fieldGetter}());
+        indicator.${field.fieldSetter}(newValue);
     </#if>
 </#list>
 <#list persistentFields as field>
-    <#if field.columnName != "time_bucket">
+    <#if field.columnName == "time_bucket">
+        indicator.setTimeBucket(toTimeBucketInMonth());
+    <#elseif field.typeName == "java.lang.String" || field.typeName == "long" 
|| field.typeName == "int" || field.typeName == "double" || field.typeName == 
"float">
         indicator.${field.fieldSetter}(this.${field.fieldGetter}());
+    <#else>
+        ${field.typeName} newValue = new ${field.typeName}();
+        newValue.copyFrom(this.${field.fieldGetter}());
+        indicator.${field.fieldSetter}(newValue);
     </#if>
 </#list>
         return indicator;
diff --git 
a/oal-parser/src/test/resources/expectedFiles/IndicatorImplementorExpected.java 
b/oal-parser/src/test/resources/expectedFiles/IndicatorImplementorExpected.java
index 76cf7c7..b4554c4 100644
--- 
a/oal-parser/src/test/resources/expectedFiles/IndicatorImplementorExpected.java
+++ 
b/oal-parser/src/test/resources/expectedFiles/IndicatorImplementorExpected.java
@@ -116,11 +116,11 @@
     @Override
     public Indicator toHour() {
         ServiceAvgIndicator indicator = new ServiceAvgIndicator();
-        indicator.setTimeBucket(toTimeBucketInHour());
         indicator.setEntityId(this.getEntityId());
         indicator.setSummation(this.getSummation());
         indicator.setCount(this.getCount());
         indicator.setValue(this.getValue());
+        indicator.setTimeBucket(toTimeBucketInHour());
         indicator.setStringField(this.getStringField());
         return indicator;
     }
@@ -128,11 +128,11 @@ public Indicator toHour() {
     @Override
     public Indicator toDay() {
         ServiceAvgIndicator indicator = new ServiceAvgIndicator();
-        indicator.setTimeBucket(toTimeBucketInDay());
         indicator.setEntityId(this.getEntityId());
         indicator.setSummation(this.getSummation());
         indicator.setCount(this.getCount());
         indicator.setValue(this.getValue());
+        indicator.setTimeBucket(toTimeBucketInDay());
         indicator.setStringField(this.getStringField());
         return indicator;
     }
@@ -140,11 +140,11 @@ public Indicator toDay() {
     @Override
     public Indicator toMonth() {
         ServiceAvgIndicator indicator = new ServiceAvgIndicator();
-        indicator.setTimeBucket(toTimeBucketInMonth());
         indicator.setEntityId(this.getEntityId());
         indicator.setSummation(this.getSummation());
         indicator.setCount(this.getCount());
         indicator.setValue(this.getValue());
+        indicator.setTimeBucket(toTimeBucketInMonth());
         indicator.setStringField(this.getStringField());
         return indicator;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to