dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38609
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19667: use static thread-safe JodaTime DateTimeFormatter for node serializers (except Jackson2 which hav...
------------------------------------------------------------
revno: 19667
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-07-16 13:27:31 +0700
message:
use static thread-safe JodaTime DateTimeFormatter for node serializers (except Jackson2 which have its own), gives about 10% speed improvements for non-JSON payloads
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/CsvNodeSerializer.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/PdfNodeSerializer.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 2015-07-16 06:27:31 +0000
@@ -28,19 +28,24 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.OutputStream;
-
import org.hisp.dhis.node.config.Config;
import org.hisp.dhis.node.types.CollectionNode;
import org.hisp.dhis.node.types.ComplexNode;
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.node.types.SimpleNode;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+import java.io.OutputStream;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public abstract class AbstractNodeSerializer implements NodeSerializer
{
+ protected static final DateTimeFormatter DT_FORMATTER = DateTimeFormat.forPattern( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
+ .withZoneUTC();
+
protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception
{
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/CsvNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/CsvNodeSerializer.java 2015-02-22 20:02:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/CsvNodeSerializer.java 2015-07-16 06:27:31 +0000
@@ -39,15 +39,14 @@
import org.hisp.dhis.node.types.ComplexNode;
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.node.types.SimpleNode;
+import org.joda.time.DateTime;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import java.io.OutputStream;
-import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
-import java.util.TimeZone;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -145,9 +144,8 @@
if ( Date.class.isAssignableFrom( simpleNode.getValue().getClass() ) )
{
- SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
- dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
- value = dateFormat.format( (Date) simpleNode.getValue() );
+ DateTime dateTime = new DateTime( simpleNode.getValue() );
+ value = DT_FORMATTER.print( dateTime );
}
csvGenerator.writeObjectField( simpleNode.getName(), value );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.java 2015-02-22 20:02:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.java 2015-07-16 06:27:31 +0000
@@ -45,6 +45,7 @@
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.node.types.SimpleNode;
import org.hisp.dhis.schema.PropertyType;
+import org.joda.time.DateTime;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
@@ -189,9 +190,8 @@
if ( Date.class.isAssignableFrom( simpleNode.getValue().getClass() ) )
{
- SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
- dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
- value = dateFormat.format( (Date) simpleNode.getValue() );
+ DateTime dateTime = new DateTime( simpleNode.getValue() );
+ value = DT_FORMATTER.print( dateTime );
}
return value;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/PdfNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/PdfNodeSerializer.java 2015-02-22 20:02:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/PdfNodeSerializer.java 2015-07-16 06:27:31 +0000
@@ -38,6 +38,7 @@
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.node.types.SimpleNode;
import org.hisp.dhis.system.util.PDFUtils;
+import org.joda.time.DateTime;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
@@ -131,9 +132,8 @@
if ( Date.class.isAssignableFrom( simpleNode.getValue().getClass() ) )
{
- SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
- dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
- value = dateFormat.format( (Date) simpleNode.getValue() );
+ DateTime dateTime = new DateTime( simpleNode.getValue() );
+ value = DT_FORMATTER.print( dateTime );
}
return value;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 2015-07-16 06:27:31 +0000
@@ -35,6 +35,7 @@
import org.hisp.dhis.node.types.ComplexNode;
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.node.types.SimpleNode;
+import org.joda.time.DateTime;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
@@ -44,10 +45,8 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.OutputStream;
-import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
-import java.util.TimeZone;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -113,9 +112,8 @@
if ( simpleNode.getValue() != null && Date.class.isAssignableFrom( simpleNode.getValue().getClass() ) )
{
- SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
- dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
- value = dateFormat.format( (Date) simpleNode.getValue() );
+ DateTime dateTime = new DateTime( simpleNode.getValue() );
+ value = DT_FORMATTER.print( dateTime );
}
else
{