Project

General

Profile

dbrestrictions.diff

Igor Skornyakov, 11/28/2022 11:35 AM

Download (5.18 KB)

View differences:

src/com/goldencode/p2j/persist/ConnectionManager.java 2022-11-28 15:53:09 +0000
154 154
**     IAS 20220311          Fix recursive call of the OptionsParser
155 155
**     IAS 20220713          Do not lock database on SET-CLIENT. 
156 156
**     CA  20220426          Added DBCODEPAGE builtin function stubs.
157
**     IAS 20221128          Re-worked DB-RESTRICTIONS support.
157 158
*/
158 159

  
159 160
/*
......
1242 1243
    */
1243 1244
   public static character dbRestrictions(int index)
1244 1245
   {
1245
      return dbRestrictions(index, (String) null);
1246
      return get().dbRestrictionsImpl(null, index, null);
1246 1247
   }
1247 1248
   
1248 1249
   /**
......
1265 1266
         return (new character());
1266 1267
      }
1267 1268
      
1268
      return dbRestrictions(index.intValue(), (String) null);
1269
      return get().dbRestrictionsImpl(null, index.intValue(), null);
1269 1270
   }
1270 1271
   
1271 1272
   /**
......
1288 1289
         return (new character());
1289 1290
      }
1290 1291
      
1291
      return dbRestrictions(index.intValue(), table);
1292
      return get().dbRestrictionsImpl(null, index.intValue(), null);
1292 1293
   }
1293 1294
   
1294 1295
   /**
......
1306 1307
    */
1307 1308
   public static character dbRestrictions(int index, character table)
1308 1309
   {
1309
      return dbRestrictions(index, (String) null);
1310
      return get().dbRestrictionsImpl(null, index, null);
1310 1311
   }
1311 1312
   
1312 1313
   /**
......
1329 1330
         return (new character());
1330 1331
      }
1331 1332
      
1332
      return (new character(""));
1333
      return get().dbRestrictionsImpl(null, index, null);
1333 1334
   }
1334 1335
   
1335 1336
   /**
......
1344 1345
    */
1345 1346
   public static character dbRestrictions(character name)
1346 1347
   {
1347
      return dbRestrictions(name, (String) null);
1348
      return dbRestrictions(name, (character) null);
1348 1349
   }
1349 1350
   
1350 1351
   /**
......
1359 1360
    */
1360 1361
   public static character dbRestrictions(String name)
1361 1362
   {
1362
      return dbRestrictions(name, (String) null);
1363
      return get().dbRestrictionsImpl(name, 0, null);
1363 1364
   }
1364 1365
   
1365 1366
   /**
......
1377 1378
    */
1378 1379
   public static character dbRestrictions(character name, character table)
1379 1380
   {
1380
      if (name.isUnknown())
1381
      if (name == null || name.isUnknown())
1381 1382
      {
1382
         return (new character());
1383
         return new character();
1383 1384
      }
1384 1385
      
1385
      return dbRestrictions(name.toStringMessage(), table.toStringMessage());
1386
      character ret = get().dbRestrictionsImpl(name.toStringMessage(), 0, null);
1387
      ret.setCaseSensitive(name.isCaseSensitive());
1388
      return ret;
1386 1389
   }
1387 1390
   
1388 1391
   /**
......
1400 1403
    */
1401 1404
   public static character dbRestrictions(character name, String table)
1402 1405
   {
1403
      if (name.isUnknown())
1404
      {
1405
         return (new character());
1406
      }
1407
      
1408
      return dbRestrictions(name.toStringMessage(), table);
1406
      return dbRestrictions(name, new character(table));
1409 1407
   }
1410 1408
   
1411 1409
   /**
......
1423 1421
    */
1424 1422
   public static character dbRestrictions(String name, character table)
1425 1423
   {
1426
      return dbRestrictions(name, (String) null);
1424
      return dbRestrictions(new character(name), table);
1427 1425
   }
1428 1426
   
1429 1427
   /**
......
1441 1439
    */
1442 1440
   public static character dbRestrictions(String name, String table)
1443 1441
   {
1444
      String ldb = get().getLDBName(name);
1445
      if (ldb == null)
1442
      if (name == null)
1446 1443
      {
1447
         return (new character());
1444
         return new character();
1448 1445
      }
1449 1446
      
1450
      return (new character(""));
1447
      return get().dbRestrictionsImpl(name, 0, null);
1451 1448
   }
1452 1449
   
1453 1450
   /**
......
3906 3903
   }
3907 3904
   
3908 3905
   /**
3906
    * Get a description of restrictions for the table in the connected database with a specified 
3907
    * alias or at the specified index.  Currently, <code>table</code> is ignored.
3908
    *
3909
    * @param   nameOrAlias
3910
    *          Logical database name or alias.
3911
    *
3912
    * @param   index
3913
    *          One-based index of the alias (aliases are stored in the order
3914
    *          in which they were created).
3915
    * @param   table
3916
    *          table name (currently ignored)
3917
    * 
3918
    * @return  a description of restrictions for the table in the connected database
3919
    */
3920
   private character dbRestrictionsImpl(String nameOrAlias, int index, String table)
3921
   {
3922
      if (nameOrAlias == null)
3923
      {
3924
         nameOrAlias = iterateToIndex(connected.keySet(), index);
3925
         if (nameOrAlias == null)
3926
         {
3927
            return new character(); // returning unknown value
3928
         }
3929
      }
3930
      
3931
      // Get the logical DB name.
3932
      String ldb = getLDBName(nameOrAlias);
3933
      ConnectInfo info = connected.get(ldb);
3934
      
3935
      if (info == null)
3936
      {
3937
         return new character();
3938
      }
3939
      
3940
      List<Map.Entry<ConnectOption, ConnectOptionValue>> opts = info.opts;
3941
      if (opts != null)
3942
      {
3943
         boolean readOnly = opts.stream().map(Map.Entry::getKey).
3944
                                filter(co -> co == ConnectOption.READ_ONLY_DB).
3945
                                findFirst().isPresent();
3946
         return readOnly ? new character("READ-ONLY") : new character("");
3947
      }
3948
      return new character();
3949
   }
3950
   /**
3909 3951
    * Convert CONNECT options to a DBPARAM string.
3910 3952
    * 
3911 3953
    * @param   opts