66package  org .hibernate .reactive ;
77
88import  java .math .BigDecimal ;
9+ import  java .math .RoundingMode ;
910import  java .util .ArrayList ;
1011import  java .util .List ;
1112import  java .util .concurrent .CompletionStage ;
1213import  javax .persistence .Entity ;
1314import  javax .persistence .Id ;
1415
1516import  org .hibernate .cfg .Configuration ;
16- import  org .hibernate .reactive .containers .DatabaseConfiguration ;
1717import  org .hibernate .reactive .pool .ReactiveConnection ;
18- import  org .hibernate .reactive .testing .DatabaseSelectionRule ;
18+ import  org .hibernate .reactive .pool .impl .PostgresParameters ;
19+ import  org .hibernate .reactive .pool .impl .SQLServerParameters ;
1920
2021import  org .junit .After ;
21- import  org .junit .Rule ;
2222import  org .junit .Test ;
2323
2424import  io .vertx .ext .unit .TestContext ;
2727
2828public  class  BatchQueryOnConnectionTest  extends  BaseReactiveTest  {
2929
30- 	@ Rule  // Not supported at the moment 
31- 	public  DatabaseSelectionRule  skip  = DatabaseSelectionRule .skipTestsFor ( DatabaseConfiguration .DBType .SQLSERVER  );
32- 
3330	private  static  final  int  BATCH_SIZE  = 20 ;
3431
3532	@ After 
@@ -67,10 +64,7 @@ public void testBatchInsertUpdateSizeGtMultiple(TestContext context) {
6764	}
6865
6966	public  List <List <Object []>> doBatchInserts (TestContext  context , int  nEntities , int  nEntitiesMultiple ) {
70- 		final  String  insertSql  = "insert into DataPoint (description, x, y, id) values " ;
71- 		final  String  sql  = dbType ().requiresDollarSyntax ()
72- 				? insertSql  + "($1, $2, $3, $4)" 
73- 				: insertSql  + "(?, ?, ?, ?)" ;
67+ 		final  String  insertSql  = process ( "insert into DataPoint (description, x, y, id) values (?, ?, ?, ?)"  );
7468
7569		List <List <Object []>> paramsBatches  = new  ArrayList <>();
7670		List <Object []> paramsBatch  = new  ArrayList <>( BATCH_SIZE  );
@@ -79,8 +73,8 @@ public List<List<Object[]>> doBatchInserts(TestContext context, int nEntities, i
7973
8074			DataPoint  dp  = new  DataPoint (i );
8175			dp .description  = "#"  + i ;
82- 			dp .setX (new  BigDecimal (i  * 0.1d ).setScale (19 , BigDecimal . ROUND_DOWN ) );
83- 			dp .setY (new  BigDecimal (dp .getX ().doubleValue ()* Math .PI ).setScale (19 , BigDecimal . ROUND_DOWN ) );
76+ 			dp .setX (  new  BigDecimal (  i  * 0.1d   ).setScale (  19 , RoundingMode . DOWN  )  );
77+ 			dp .setY (  new  BigDecimal (  dp .getX ().doubleValue () *  Math .PI   ).setScale (  19 , RoundingMode . DOWN  )  );
8478			//uncomment to expose bug in DB2 client: 
8579//			dp.setY(new BigDecimal(Math.cos(dp.getX().doubleValue())).setScale(19, BigDecimal.ROUND_DOWN)); 
8680
@@ -98,7 +92,7 @@ public List<List<Object[]>> doBatchInserts(TestContext context, int nEntities, i
9892
9993		CompletionStage <ReactiveConnection > stage  = connection ();
10094		for  ( List <Object []> batch  : paramsBatches  ) {
101- 			stage  = stage .thenCompose ( connection  -> connection .update ( sql , batch  )
95+ 			stage  = stage .thenCompose ( connection  -> connection .update ( insertSql , batch  )
10296					.thenApply ( updateCounts  -> {
10397						context .assertEquals ( batch .size (), updateCounts .length  );
10498						for  ( int  updateCount  : updateCounts  ) {
@@ -123,6 +117,17 @@ public List<List<Object[]>> doBatchInserts(TestContext context, int nEntities, i
123117		return  paramsBatches ;
124118	}
125119
120+ 	private  String  process (String  sql ) {
121+ 		switch  ( dbType () ) {
122+ 			case  POSTGRESQL :
123+ 			case  COCKROACHDB :
124+ 				return  PostgresParameters .INSTANCE .process ( sql  );
125+ 			case  SQLSERVER :
126+ 				return  SQLServerParameters .INSTANCE .process ( sql  );
127+ 		}
128+ 		return  sql ;
129+ 	}
130+ 
126131	protected  Configuration  constructConfiguration () {
127132		Configuration  configuration  = super .constructConfiguration ();
128133		configuration .addAnnotatedClass ( DataPoint .class  );
0 commit comments