Project

General

Profile

6129b-6816-2.patch

Radu Apetrii, 01/13/2023 06:21 AM

Download (5.32 KB)

View differences:

new/src/com/goldencode/p2j/persist/SortCriterion.java 2023-01-13 11:07:14 +0000
98 98
**     AL2 20220706          Added isCompatible to filter out the sort clauses not belonging to the buffer.
99 99
**     OM  20220727          FieldId and PropertyId are different for denormalized extent fields.
100 100
**     OM  20221103          New class names for FQLPreprocessor, FQLExpression, FQLBundle, and FQLCache.
101
**     RAA 20230110          Reduced the number of iterations (for parsing the text) in constructor. Made 
102
**                           all non-final fields final. 
101 103
*/
102 104

  
103 105
/*
......
253 255
   private final String originalName;
254 256
   
255 257
   /** Sort property name, usually qualified */
256
   private String name;
258
   private final String name;
257 259
   
258 260
   /** Subscript value, if any */
259
   private int subscript = -1;
261
   private final int subscript;
260 262
   
261 263
   /** SQL dialect which used this sort criterion; used for rtrim calls on character properties */
262
   private Dialect dialect = null;
264
   private final Dialect dialect;
263 265
   
264 266
   /**
265 267
    * Constructor which parses original sort component text, deriving the property name, sort
......
344 346
      this.dialect = dialect;
345 347
      this.dmoClass = dmoInfo.getImplementationClass();
346 348
      
347
      // parse the test and extract alias, property and optional extent
348
      int spacePos = text.indexOf(' ');
349
      String rawName = ((spacePos != -1) ? text.substring(0, spacePos) : text).trim();
350
      name = rawName;
351
      originalName = internStrings ? rawName.intern() : rawName;
352
      int bracketPos = rawName.indexOf("[");
353
      int endPos = -1;
354
      if (bracketPos >= 0)
349
      char[] src = text.toCharArray();
350
      boolean extentMode = false;
351
      int spacePos = -1;
352
      int dotPos = -1;
353
      int bracketPos = -1;
354
      boolean reachedBracket = false;
355
      int subscriptBuilder = 0;
356
      
357
      for (int i = 0; i < src.length; i++)
355 358
      {
356
         endPos = rawName.indexOf("]");
357
         if (endPos < 0)
359
         switch (src[i])
358 360
         {
359
            throw new PersistenceException("Malformed subscript text:  " + text);
361
            case '[':
362
            {
363
               extentMode = true;
364
               reachedBracket = true;
365
               bracketPos = i;
366
               break;
367
            }
368
            case ']':
369
            {
370
               extentMode = false;
371
               break;
372
            }
373
            case '.':
374
            {
375
               dotPos = i;
376
               break;
377
            }
378
            case ' ':
379
            {
380
               spacePos = i;
381
               break;
382
            }
360 383
         }
361 384
         
362
         // extract base name
363
         name = rawName.substring(0, bracketPos);
364
      }
365
      
366
      int dotPos = name.lastIndexOf(".");
367
      if (dotPos < 0)
368
      {
369
         throw new PersistenceException("Sort property may not be unqualified:  " + rawName);
370
      }
371
      
372
      String propName = name.substring(dotPos + 1);
373
      String alias = name.substring(0, dotPos);
385
         if (extentMode && src[i] != '[')
386
         {
387
            subscriptBuilder = subscriptBuilder * 10 + (src[i] - '0');
388
         }
389
      }
390
      
391
      originalName = internStrings ? new String(src, 0, spacePos).intern() :
392
                                     new String(src, 0, spacePos);
393
      int length = (reachedBracket ? Math.min(bracketPos, spacePos) : spacePos) - dotPos - 1;
394
      propertyName = internStrings ? 
395
                     new String(src, dotPos + 1, length).intern() : 
396
                     new String(src, dotPos + 1, length);
397
      alias = internStrings ? new String(src, 0, dotPos).intern() : 
398
                              new String(src, 0, dotPos);
399
      name = internStrings ? new String(src, 0, dotPos + propertyName.length() + 1).intern() : 
400
                             new String(src, 0, dotPos + propertyName.length() + 1);
401
      ascending = src[spacePos + 1] == 'a' ? true : false;
402
      subscript = reachedBracket ? subscriptBuilder : -1;
403
      
374 404
      DmoMeta dmoMeta = DmoMetadataManager.getDmoInfo(dmoClass);
375
      Property propMeta = dmoMeta.getFieldInfo(propName);
376
      this.propertyName = propMeta.name; // already interned, anyway
377
      this.alias = internStrings ? alias.intern() : alias;
378
      
379
      if (bracketPos >= 0)
380
      {
381
         int extent = propMeta.index > 0 ? 0 : propMeta.extent;
382
         if (extent > 0)
383
         {
384
            // extract subscript
385
            String sub = rawName.substring(bracketPos + 1, endPos);
386
            try
387
            {
388
               subscript = Integer.parseInt(sub);
389
            }
390
            catch (NumberFormatException exc)
391
            {
392
               throw new PersistenceException("Unsupported subscript:  " + sub);
393
            }
394
            
395
            name = alias + "." + propertyName;
396
         }
397
      }
398
      
399
      if (internStrings)
400
      {
401
         name = name.intern();
402
      }
403
      
404
      // determine sort direction
405
      ascending = (spacePos == -1 || !"desc".equalsIgnoreCase(text.substring(spacePos + 1).trim()));
405
      Property propMeta = dmoMeta.getFieldInfo(propertyName);
406 406
      
407 407
      // get backing getter method
408 408
      if (propMeta.propId == ReservedProperty.ID_MULTIPLEX)