@@ -91,12 +91,20 @@ public class Console {
9191 private long transactionBatchSize = 0L ;
9292 protected long currentOperationsInBatch = 0L ;
9393 private RemoteServer remoteServer ;
94+ private boolean batchMode = false ;
95+ private boolean failAtEnd = false ;
9496
9597 public Console (final DatabaseInternal database ) throws IOException {
9698 this ();
9799 this .databaseProxy = database ;
98100 }
99101
102+ public Console (boolean batchMode , boolean failAtEnd ) throws IOException {
103+ this ();
104+ this .batchMode = batchMode ;
105+ this .failAtEnd = failAtEnd ;
106+ }
107+
100108 public Console () throws IOException {
101109 IntegrationUtils .setRootPath (configuration );
102110 databaseDirectory = configuration .getValueAsString (GlobalConfiguration .SERVER_DATABASE_DIRECTORY );
@@ -185,11 +193,11 @@ public static void execute(final String[] args) throws IOException {
185193 }
186194 }
187195
188- final Console console = new Console ();
196+ final Console console = new Console (batchMode , failAtEnd );
189197
190198 try {
191199 if (batchMode ) {
192- console .parse (commands .toString (), true , batchMode , failAtEnd );
200+ console .parse (commands .toString (), true );
193201 console .parse ("exit" , true );
194202 } else {
195203 // INTERACTIVE MODE
@@ -298,10 +306,12 @@ private void executeSet(final String line) {
298306 final String key = parts [0 ].trim ();
299307 final String value = parts [1 ].trim ();
300308
301- if ("limit" .equalsIgnoreCase (key )) {
309+ switch (key .toLowerCase ()) {
310+ case "limit" -> {
302311 limit = Integer .parseInt (value );
303312 outputLine (3 , "Set new limit to %d" , limit );
304- } else if ("asyncMode" .equalsIgnoreCase (key )) {
313+ }
314+ case "asyncmode" -> {
305315 asyncMode = Boolean .parseBoolean (value );
306316 if (asyncMode ) {
307317 // ENABLE ASYNCHRONOUS PARALLEL MODE
@@ -314,39 +324,47 @@ private void executeSet(final String line) {
314324 });
315325 }
316326 outputLine (3 , "Set asyncMode to %s" , asyncMode );
317- } else if ("transactionBatchSize" .equalsIgnoreCase (key )) {
327+ }
328+ case "transactionbatchsize" -> {
318329 transactionBatchSize = Integer .parseInt (value );
319330 outputLine (3 , "Set new transactionBatch to %d" , transactionBatchSize );
320- } else if ("language" .equalsIgnoreCase (key )) {
331+ }
332+ case "language" -> {
321333 language = value ;
322334 outputLine (3 , "Set language to %s" , language );
323- } else if ("expandResultSet" .equalsIgnoreCase (key )) {
335+ }
336+ case "expandresultset" -> {
324337 expandResultSet = value .equalsIgnoreCase ("true" );
325338 outputLine (3 , "Set expanded result set to %s" , expandResultSet );
326- } else if ("maxMultiValueEntries" .equalsIgnoreCase (key )) {
339+ }
340+ case "maxmultivalueentries" -> {
327341 maxMultiValueEntries = Integer .parseInt (value );
328342 outputLine (3 , "Set maximum multi value entries to %d" , maxMultiValueEntries );
329- } else if ("verbose" .equalsIgnoreCase (key )) {
343+ }
344+ case "verbose" -> {
330345 verboseLevel = Integer .parseInt (value );
331346 outputLine (3 , "Set verbose level to %d" , verboseLevel );
332- } else if ("maxWidth" .equalsIgnoreCase (key )) {
347+ }
348+ case "maxwidth" -> {
333349 maxWidth = Integer .parseInt (value );
334350 outputLine (3 , "Set maximum width to %d" , maxWidth );
335- } else {
351+ }
352+ default -> {
336353 if (!setGlobalConfiguration (key , value , false ))
337354 outputLine (3 , "Setting '%s' is not supported by the console" , key );
338355 }
356+ }
339357
340358 flushOutput ();
341359 }
342360
343361 private void executeTransactionStatus () {
344362 checkDatabaseIsOpen ();
345363
346- if (databaseProxy instanceof DatabaseInternal ) {
347- final TransactionContext tx = (( DatabaseInternal ) databaseProxy ) .getTransaction ();
364+ if (databaseProxy instanceof DatabaseInternal db ) {
365+ final TransactionContext tx = db .getTransaction ();
348366 if (tx .isActive ()) {
349- final ResultInternal row = new ResultInternal (( Database ) databaseProxy );
367+ final ResultInternal row = new ResultInternal (db );
350368 row .setPropertiesFromMap (tx .getStats ());
351369 printRecord (row );
352370
@@ -561,15 +579,14 @@ else if (rec != null)
561579
562580 final List <TableFormatter .TableRow > resultSet = new ArrayList <>();
563581
564- Object value ;
565582 for (final String fieldName : currentRecord .getPropertyNames ()) {
566- value = currentRecord .getProperty (fieldName );
567- if (value instanceof byte [])
568- value = "byte[" + (( byte []) value ) .length + "]" ;
569- else if (value instanceof Iterator <?>) {
583+ Object value = currentRecord .getProperty (fieldName );
584+ if (value instanceof byte [] bytes )
585+ value = "byte[" + bytes .length + "]" ;
586+ else if (value instanceof Iterator <?> iterator ) {
570587 final List <Object > coll = new ArrayList <>();
571- while ((( Iterator <?>) value ) .hasNext ())
572- coll .add ((( Iterator <?>) value ) .next ());
588+ while (iterator .hasNext ())
589+ coll .add (iterator .next ());
573590 value = coll ;
574591 } else if (MultiValue .isMultiValue (value )) {
575592 value = TableFormatter .getPrettyFieldMultiValue (MultiValue .getMultiValueIterator (value ), maxMultiValueEntries );
@@ -608,14 +625,17 @@ public void onError(Exception exception) {
608625 outputError (exception );
609626 }
610627 });
611- } else
628+ } else {
612629 try {
613630 resultSet = databaseProxy .command (language , line );
614631 } catch (Exception e ) {
615- // outputError(e);
616- // return;
617- throw e ;
632+ if (batchMode && !failAtEnd )
633+ throw e ;
634+ else
635+ outputError (e );
636+ return ;
618637 }
638+ }
619639
620640 if (transactionBatchSize > 0 ) {
621641 ++currentOperationsInBatch ;
@@ -736,16 +756,11 @@ private void executeLoad(final String fileName) throws IOException {
736756 flushOutput ();
737757 }
738758
739- public boolean parse (final String line ) throws IOException , RuntimeException {
759+ public boolean parse (final String line ) throws IOException {
740760 return parse (line , false );
741761 }
742762
743- public boolean parse (final String line , final boolean printCommand ) throws IOException , RuntimeException {
744- return parse (line , printCommand , false , false );
745- }
746-
747- public boolean parse (final String line , final boolean printCommand , final boolean batchMode , boolean failAtEnd )
748- throws IOException , RuntimeException {
763+ public boolean parse (final String line , final boolean printCommand ) throws IOException {
749764
750765 final ParsedLine parsedLine = parser .parse (line , 0 );
751766
@@ -765,14 +780,8 @@ public boolean parse(final String line, final boolean printCommand, final boolea
765780 throw e ;
766781 }
767782 } else {
768- try {
769783 if (!execute (w ))
770784 return false ;
771- } catch (final Exception e ) {
772- return true ;
773-
774- // throw e;
775- }
776785
777786 }
778787 }
0 commit comments