1
1
/*
2
- * Copyright 2014-2018 the original author or authors.
2
+ * Copyright 2014-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -532,7 +532,8 @@ private void insertSessionAttributes(JdbcSession session, List<String> attribute
532
532
public void setValues (PreparedStatement ps , int i ) throws SQLException {
533
533
String attributeName = attributeNames .get (i );
534
534
ps .setString (1 , attributeName );
535
- setObjectAsBlob (ps , 2 , session .getAttribute (attributeName ));
535
+ getLobHandler ().getLobCreator ().setBlobAsBytes (ps , 2 ,
536
+ serialize (session .getAttribute (attributeName )));
536
537
ps .setString (3 , session .getId ());
537
538
}
538
539
@@ -547,7 +548,8 @@ public int getBatchSize() {
547
548
this .jdbcOperations .update (this .createSessionAttributeQuery , (ps ) -> {
548
549
String attributeName = attributeNames .get (0 );
549
550
ps .setString (1 , attributeName );
550
- setObjectAsBlob (ps , 2 , session .getAttribute (attributeName ));
551
+ getLobHandler ().getLobCreator ().setBlobAsBytes (ps , 2 ,
552
+ serialize (session .getAttribute (attributeName )));
551
553
ps .setString (3 , session .getId ());
552
554
});
553
555
}
@@ -561,7 +563,8 @@ private void updateSessionAttributes(JdbcSession session, List<String> attribute
561
563
@ Override
562
564
public void setValues (PreparedStatement ps , int i ) throws SQLException {
563
565
String attributeName = attributeNames .get (i );
564
- setObjectAsBlob (ps , 1 , session .getAttribute (attributeName ));
566
+ getLobHandler ().getLobCreator ().setBlobAsBytes (ps , 1 ,
567
+ serialize (session .getAttribute (attributeName )));
565
568
ps .setString (2 , session .primaryKey );
566
569
ps .setString (3 , attributeName );
567
570
}
@@ -576,7 +579,8 @@ public int getBatchSize() {
576
579
else {
577
580
this .jdbcOperations .update (this .updateSessionAttributeQuery , (ps ) -> {
578
581
String attributeName = attributeNames .get (0 );
579
- setObjectAsBlob (ps , 1 , session .getAttribute (attributeName ));
582
+ getLobHandler ().getLobCreator ().setBlobAsBytes (ps , 1 ,
583
+ serialize (session .getAttribute (attributeName )));
580
584
ps .setString (2 , session .primaryKey );
581
585
ps .setString (3 , attributeName );
582
586
});
@@ -659,16 +663,17 @@ private void prepareQueries() {
659
663
getQuery (DELETE_SESSIONS_BY_EXPIRY_TIME_QUERY );
660
664
}
661
665
662
- private void setObjectAsBlob (PreparedStatement ps , int paramIndex , Object object )
663
- throws SQLException {
664
- byte [] bytes = (byte []) this .conversionService .convert (object ,
666
+ private LobHandler getLobHandler () {
667
+ return this .lobHandler ;
668
+ }
669
+
670
+ private byte [] serialize (Object object ) {
671
+ return (byte []) this .conversionService .convert (object ,
665
672
TypeDescriptor .valueOf (Object .class ),
666
673
TypeDescriptor .valueOf (byte [].class ));
667
- this .lobHandler .getLobCreator ().setBlobAsBytes (ps , paramIndex , bytes );
668
674
}
669
675
670
- private Object getBlobAsObject (ResultSet rs , String columnName ) throws SQLException {
671
- byte [] bytes = this .lobHandler .getBlobAsBytes (rs , columnName );
676
+ private Object deserialize (byte [] bytes ) {
672
677
return this .conversionService .convert (bytes , TypeDescriptor .valueOf (byte [].class ),
673
678
TypeDescriptor .valueOf (Object .class ));
674
679
}
@@ -898,8 +903,9 @@ public List<JdbcSession> extractData(ResultSet rs) throws SQLException, DataAcce
898
903
}
899
904
String attributeName = rs .getString ("ATTRIBUTE_NAME" );
900
905
if (attributeName != null ) {
901
- Object attributeValue = getBlobAsObject (rs , "ATTRIBUTE_BYTES" );
902
- session .delegate .setAttribute (attributeName , lazily (() -> attributeValue ));
906
+ byte [] bytes = getLobHandler ().getBlobAsBytes (rs , "ATTRIBUTE_BYTES" );
907
+ session .delegate .setAttribute (attributeName ,
908
+ lazily (() -> deserialize (bytes )));
903
909
}
904
910
sessions .add (session );
905
911
}
0 commit comments