Package com.sleepycat.je

Examples of com.sleepycat.je.SecondaryConfig


  {
   //*-- open the environment
   if (env == null)  { openEnv(DBDIR, false); if (env == null) return false; }

   //*-- create the primary database handle
   SecondaryConfig secdbconfig = new SecondaryConfig();
   secdbconfig.setSortedDuplicates(true);
   secdbconfig.setAllowCreate(true);
   secdbconfig.setAllowPopulate(true);       //*-- allow auto-populate
   secdbconfig.setReadOnly(readOnly);      //*-- set r/w status of the database
   secdbconfig.setKeyCreator(skc);
   setSecDB( env.openSecondaryDatabase(null, secDbname, getCurrentDB(), secdbconfig) );
  }
  catch (DatabaseException dbe)
  { logger.error("Failed to create Sec. DB " + secDbname + " " + dbe.getMessage() ); return false; }

View Full Code Here


   //*-- open the environment
   if (env != null) { openEnv(DBDIR, readOnly); if (env == null) return false; }

   //*-- create the primary database handle
   SecondaryConfig secdbconfig = new SecondaryConfig();
   secdbconfig.setAllowPopulate(true);        //*-- recreate secondary from primary
   secdbconfig.setSortedDuplicates(true);       //*-- allow dups
   secdbconfig.setExclusiveCreate(readOnly);     //*-- allow opening of an existing database
   secdbconfig.setReadOnly(readOnly);        //*-- set r/w status of the database
   secdbconfig.setKeyCreator(skc);

   //secdbconfig.setTransactional(true);
   setSecDB( env.openSecondaryDatabase(null, dbname, getCurrentDB(), secdbconfig) );
  }
  catch (DatabaseException dbe)
View Full Code Here

            currentTxn =
                CurrentTransaction.getInstanceInternal(db.getEnvironment());
            DatabaseConfig dbConfig;
            if (db instanceof SecondaryDatabase) {
                secDb = (SecondaryDatabase) database;
                SecondaryConfig secConfig = secDb.getSecondaryConfig();
                secKeyCreator = secConfig.getKeyCreator();
                dbConfig = secConfig;
            } else {
                dbConfig = db.getConfig();
            }
            ordered = !DbCompat.isTypeHash(dbConfig);
View Full Code Here

                           PrimaryOpenState priOpenState)
        throws DatabaseException {

        assert !secIndexMap.containsKey(secName);
        String[] fileAndDbNames = parseDbName(storePrefix + dbSecName);
        SecondaryConfig config =
            getSecondaryConfig(secName, entityMeta, keyClassName, secKeyMeta);
        Database priDb = primaryIndex.getDatabase();
        DatabaseConfig priConfig = priDb.getConfig();

        String relatedClsName = secKeyMeta.getRelatedEntity();
        if (relatedClsName != null) {
            PrimaryIndex relatedIndex = getRelatedIndex(relatedClsName);
            config.setForeignKeyDatabase(relatedIndex.getDatabase());
        }

        if (config.getTransactional() != priConfig.getTransactional() ||
            DbCompat.getDeferredWrite(config) !=
            DbCompat.getDeferredWrite(priConfig) ||
            config.getReadOnly() != priConfig.getReadOnly()) {
            throw new IllegalArgumentException
                ("One of these properties was changed to be inconsistent" +
                 " with the associated primary database: " +
                 " Transactional, DeferredWrite, ReadOnly");
        }
View Full Code Here

    private SecondaryConfig getSecondaryConfig(String secName,
                                               EntityMetadata entityMeta,
                                               String keyClassName,
                                               SecondaryKeyMetadata
                                               secKeyMeta) {
        SecondaryConfig config = secConfigMap.get(secName);
        if (config == null) {
            /* Set common properties to match the primary DB. */
            DatabaseConfig priConfig = getPrimaryConfig(entityMeta);
            config = new SecondaryConfig();
            config.setTransactional(priConfig.getTransactional());
            config.setAllowCreate(!priConfig.getReadOnly());
            config.setReadOnly(priConfig.getReadOnly());
            DbCompat.setTypeBtree(config);
            /* <!-- begin JE only --> */
            DbInternal.setReplicated(config,
                                     DbInternal.getReplicated(priConfig));
            config.setTemporary(priConfig.getTemporary());
            config.setDeferredWrite(priConfig.getDeferredWrite());
            config.setOverrideBtreeComparator(true);
            config.setOverrideDuplicateComparator(true);
            /* <!-- end JE only --> */
            /* Set secondary properties based on metadata. */
            config.setAllowPopulate(true);
            Relationship rel = secKeyMeta.getRelationship();
            config.setSortedDuplicates(rel == Relationship.MANY_TO_ONE ||
                                       rel == Relationship.MANY_TO_MANY);
            setBtreeComparator(config, keyClassName);
            config.setDuplicateComparator(priConfig.getBtreeComparator());
            PersistKeyCreator keyCreator = new PersistKeyCreator
                (catalog, entityMeta, keyClassName, secKeyMeta, rawAccess);
            if (rel == Relationship.ONE_TO_MANY ||
                rel == Relationship.MANY_TO_MANY) {
                config.setMultiKeyCreator(keyCreator);
            } else {
                config.setKeyCreator(keyCreator);
            }
            DeleteAction deleteAction = secKeyMeta.getDeleteAction();
            if (deleteAction != null) {
                ForeignKeyDeleteAction baseDeleteAction;
                switch (deleteAction) {
                case ABORT:
                    baseDeleteAction = ForeignKeyDeleteAction.ABORT;
                    break;
                case CASCADE:
                    baseDeleteAction = ForeignKeyDeleteAction.CASCADE;
                    break;
                case NULLIFY:
                    baseDeleteAction = ForeignKeyDeleteAction.NULLIFY;
                    break;
                default:
                    throw DbCompat.unexpectedState(deleteAction.toString());
                }
                config.setForeignKeyDeleteAction(baseDeleteAction);
                if (deleteAction == DeleteAction.NULLIFY) {
                    config.setForeignMultiKeyNullifier(keyCreator);
                }
            }
            secConfigMap.put(secName, config);
        }
        return config;
View Full Code Here

        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.getExclusiveCreate() ||
            config.getAllowCreate() == config.getReadOnly() ||
            config.getSortedDuplicates() != dbConfig.getSortedDuplicates() ||
            config.getBtreeComparator() != dbConfig.getBtreeComparator() ||
            config.getDuplicateComparator() != null ||
            /* <!-- begin JE only --> */
            config.getTemporary() != dbConfig.getTemporary() ||
            /* <!-- end JE only --> */
            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: " +
                 " AllowCreate, ExclusiveCreate, SortedDuplicates," +
                 " BtreeComparator, DuplicateComparator, Temporary," +
View Full Code Here

    keyBinding = new SerialBinding<IMetaData[]>(classCatalog, IMetaData[].class);
    dataBinding = new SerialBinding<ICache>(classCatalog, ICache.class);
    dbMain = env.openDatabase(null, DATABASE_MAIN_NAME, dbConfig);

    // 单个关键字索引表允许重复的记录
    SecondaryConfig config = new SecondaryConfig();
    config.setAllowCreate(true);
    config.setTransactional(true);
    config.setSortedDuplicates(true);
    config.setKeyCreator(new SecondaryKeyCreator() {

      public boolean createSecondaryKey(SecondaryDatabase secondary,
          DatabaseEntry key, DatabaseEntry data, DatabaseEntry result)
          throws DatabaseException {
        String name = secondary.getDatabaseName();
View Full Code Here

    private SecondaryDatabase openSecondary(Database priDb, String dbName,
                                            boolean dups, int keyId)
        throws DatabaseException {

        SecondaryConfig dbConfig = new SecondaryConfig();
        dbConfig.setTransactional(isTransactional);
        dbConfig.setAllowCreate(true);
        dbConfig.setSortedDuplicates(dups);
        dbConfig.setKeyCreator(new MyKeyCreator(keyId));

        Transaction txn = txnBegin();
        try {
            return env.openSecondaryDatabase(txn, dbName, priDb, dbConfig);
        } finally {
View Full Code Here

     */
    private SecondaryDatabase openSecondary(Database priDb, String dbName,
                                            boolean allowDuplicates)
        throws DatabaseException {

        SecondaryConfig dbConfig = new SecondaryConfig();
        dbConfig.setTransactional(isTransactional);
        dbConfig.setAllowCreate(true);
        dbConfig.setSortedDuplicates(allowDuplicates);
        dbConfig.setKeyCreator(new MyKeyCreator());
        Transaction txn = txnBegin();
        SecondaryDatabase secDb;
        try {
            secDb = env.openSecondaryDatabase(txn, dbName, priDb, dbConfig);
        } finally {
View Full Code Here

            env.openSecondaryDatabase(txn, "xxx", priDb, null);
            fail();
        } catch (NullPointerException expected) { }
        try {
            env.openSecondaryDatabase(txn, "xxx", priDb,
                                      new SecondaryConfig());
            fail();
        } catch (NullPointerException expected) { }
       
        /* Database operations. */

 
View Full Code Here

TOP

Related Classes of com.sleepycat.je.SecondaryConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.