예제 #1
0
파일: Store.java 프로젝트: nologic/nabs
 public synchronized void setSecondaryConfig(
     Class entityClass, String keyName, SecondaryConfig config) {
   checkOpen();
   String entityClsName = entityClass.getName();
   EntityMetadata entityMeta = checkEntityClass(entityClsName);
   SecondaryKeyMetadata secKeyMeta = checkSecKey(entityMeta, keyName);
   String keyClassName = getSecKeyClass(secKeyMeta);
   String secName = makeSecName(entityClass.getName(), keyName);
   if (secIndexMap.containsKey(secName)) {
     throw new IllegalStateException("Cannot set config after DB is open");
   }
   SecondaryConfig dbConfig = getSecondaryConfig(secName, entityMeta, keyClassName, secKeyMeta);
   if (config.getSortedDuplicates() != dbConfig.getSortedDuplicates()
       || config.getBtreeComparator() != dbConfig.getBtreeComparator()
       || config.getDuplicateComparator() != null
       || config.getAllowPopulate() != dbConfig.getAllowPopulate()
       || config.getKeyCreator() != dbConfig.getKeyCreator()
       || config.getMultiKeyCreator() != dbConfig.getMultiKeyCreator()
       || config.getForeignKeyNullifier() != dbConfig.getForeignKeyNullifier()
       || config.getForeignMultiKeyNullifier() != dbConfig.getForeignMultiKeyNullifier()
       || config.getForeignKeyDeleteAction() != dbConfig.getForeignKeyDeleteAction()
       || config.getForeignKeyDatabase() != null) {
     throw new IllegalArgumentException(
         "One of these properties was illegally changed: "
             + " SortedDuplicates, BtreeComparator, DuplicateComparator,"
             + " AllowPopulate, KeyCreator, MultiKeyCreator,"
             + " ForeignKeyNullifer, ForeignMultiKeyNullifier,"
             + " ForeignKeyDeleteAction, ForeignKeyDatabase");
   }
   secConfigMap.put(secName, config);
 }
예제 #2
0
  private SecondaryDatabase openSecondary(
      Database priDb,
      boolean allowDuplicates,
      String dbName,
      boolean allowPopulate,
      boolean readOnly)
      throws DatabaseException {

    List secListBefore = priDb.getSecondaryDatabases();
    SecondaryConfig dbConfig = new SecondaryConfig();
    dbConfig.setTransactional(isTransactional);
    dbConfig.setAllowCreate(true);
    dbConfig.setSortedDuplicates(allowDuplicates);
    dbConfig.setReadOnly(readOnly);
    dbConfig.setAllowPopulate(allowPopulate);
    if (!readOnly) {
      if (useMultiKey) {
        dbConfig.setMultiKeyCreator(new SimpleMultiKeyCreator(new MyKeyCreator()));
      } else {
        dbConfig.setKeyCreator(new MyKeyCreator());
      }
    }
    Transaction txn = txnBegin();
    SecondaryDatabase secDb;
    try {
      secDb = env.openSecondaryDatabase(txn, dbName, priDb, dbConfig);
    } finally {
      txnCommit(txn);
    }
    assertNotNull(secDb);

    /* Check configuration. */
    assertSame(priDb, secDb.getPrimaryDatabase());
    SecondaryConfig config2 = secDb.getSecondaryConfig();
    assertEquals(allowPopulate, config2.getAllowPopulate());
    assertEquals(dbConfig.getKeyCreator(), config2.getKeyCreator());

    /* Make sure the new secondary is added to the primary's list. */
    List secListAfter = priDb.getSecondaryDatabases();
    assertTrue(secListAfter.remove(secDb));
    assertEquals(secListBefore, secListAfter);

    return secDb;
  }