Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je;
  
 import java.util.List;
 
The configuration properties of a SecondaryDatabase extend those of a primary Database. The secondary database configuration is specified when calling Environment.openSecondaryDatabase(com.sleepycat.je.Transaction,java.lang.String,com.sleepycat.je.Database,com.sleepycat.je.SecondaryConfig).

To create a configuration object with default attributes:

     SecondaryConfig config = new SecondaryConfig();
 

To set custom attributes:

     SecondaryConfig config = new SecondaryConfig();
     config.setAllowCreate(true);
     config.setSortedDuplicates(true);
     config.setKeyCreator(new MyKeyCreator());
 

 
 public class SecondaryConfig extends DatabaseConfig {
 
     /*
      * For internal use, to allow null as a valid value for the config
      * parameter.
      */
     public static final SecondaryConfig DEFAULT = new SecondaryConfig();
 
     private boolean allowPopulate;
     private SecondaryKeyCreator keyCreator;
     private Database foreignKeyDatabase;
             .;
     private boolean immutableSecondaryKey;

    
Creates an instance with the system's default settings.
 
     public SecondaryConfig() {
     }

    
Specifies the user-supplied object used for creating single-valued secondary keys.

Unless the primary database is read-only, a key creator is required when opening a secondary database. Either a KeyCreator or MultiKeyCreator must be specified, but both may not be specified.

Unless the primary database is read-only, a key creator is required when opening a secondary database.

WARNING: Key creator instances are shared by multiple threads and key creator methods are called without any special synchronization. Therefore, key creators must be thread safe. In general no shared state should be used and any caching of computed values must be done with proper synchronization.

Parameters:
keyCreator the user-supplied object used for creating single-valued secondary keys.
Returns:
this
 
     public SecondaryConfig setKeyCreator(SecondaryKeyCreator keyCreator) {
         setKeyCreatorVoid(keyCreator);
         return this;
     }
    
    

Hidden:
The void return setter for use by Bean editors.
 
     public void setKeyCreatorVoid(SecondaryKeyCreator keyCreator) {
         this. = keyCreator;
     }

    
Returns the user-supplied object used for creating single-valued secondary keys.

Returns:
the user-supplied object used for creating single-valued secondary keys.
See also:
setKeyCreator(com.sleepycat.je.SecondaryKeyCreator)
        return ;
    }

    
Specifies the user-supplied object used for creating multi-valued secondary keys.

Unless the primary database is read-only, a key creator is required when opening a secondary database. Either a KeyCreator or MultiKeyCreator must be specified, but both may not be specified.

WARNING: Key creator instances are shared by multiple threads and key creator methods are called without any special synchronization. Therefore, key creators must be thread safe. In general no shared state should be used and any caching of computed values must be done with proper synchronization.

Parameters:
multiKeyCreator the user-supplied object used for creating multi-valued secondary keys.
Returns:
this
    public SecondaryConfig
        setMultiKeyCreator(SecondaryMultiKeyCreator multiKeyCreator) {
        setMultiKeyCreatorVoid(multiKeyCreator);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void 
        setMultiKeyCreatorVoid(SecondaryMultiKeyCreator multiKeyCreator) {
        this. = multiKeyCreator;
    }

    
Returns the user-supplied object used for creating multi-valued secondary keys.

Returns:
the user-supplied object used for creating multi-valued secondary keys.
See also:
setKeyCreator(com.sleepycat.je.SecondaryKeyCreator)
        return ;
    }

    
Specifies whether automatic population of the secondary is allowed.

If automatic population is allowed, when the secondary database is opened it is checked to see if it is empty. If it is empty, the primary database is read in its entirety and keys are added to the secondary database using the information read from the primary.

If this property is set to true and the database is transactional, the population of the secondary will be done within the explicit or auto-commit transaction that is used to open the database.

Parameters:
allowPopulate whether automatic population of the secondary is allowed.
Returns:
this
    public SecondaryConfig setAllowPopulate(boolean allowPopulate) {
        setAllowPopulateVoid(allowPopulate);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setAllowPopulateVoid(boolean allowPopulate) {
        this. = allowPopulate;
    }

    
Returns whether automatic population of the secondary is allowed. If setAllowPopulate(boolean) has not been called, this method returns false.

Returns:
whether automatic population of the secondary is allowed.
See also:
setAllowPopulate(boolean)
    public boolean getAllowPopulate() {
        return ;
    }

    
Defines a foreign key integrity constraint for a given foreign key database.

If this property is non-null, a record must be present in the specified foreign database for every record in the secondary database, where the secondary key value is equal to the foreign database key value. Whenever a record is to be added to the secondary database, the secondary key is used as a lookup key in the foreign database. If the key is not found in the foreign database, a ForeignConstraintException is thrown.

The foreign database must not have duplicates allowed. If duplicates are allowed, an IllegalArgumentException will be thrown when the secondary database is opened.

Parameters:
foreignKeyDatabase the database used to check the foreign key integrity constraint, or null if no foreign key constraint should be checked.
Returns:
this
    public SecondaryConfig setForeignKeyDatabase(Database foreignKeyDatabase) {
        setForeignKeyDatabaseVoid(foreignKeyDatabase);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setForeignKeyDatabaseVoid(Database foreignKeyDatabase) {
        this. = foreignKeyDatabase;
    }

    
Returns the database used to check the foreign key integrity constraint, or null if no foreign key constraint will be checked.

Returns:
the foreign key database, or null.
See also:
setForeignKeyDatabase(com.sleepycat.je.Database)
    public Database getForeignKeyDatabase() {
        return ;
    }

    
Specifies the action taken when a referenced record in the foreign key database is deleted.

This property is ignored if the foreign key database property is null.

Parameters:
foreignKeyDeleteAction the action taken when a referenced record in the foreign key database is deleted.
Returns:
this
See also:
ForeignKeyDeleteAction @see .setForeignKeyDatabase
        (ForeignKeyDeleteAction foreignKeyDeleteAction) {
        setForeignKeyDeleteActionVoid(foreignKeyDeleteAction);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setForeignKeyDeleteActionVoid
        (ForeignKeyDeleteAction foreignKeyDeleteAction) {
        DatabaseUtil.checkForNullParam(foreignKeyDeleteAction,
                                       "foreignKeyDeleteAction");
        this. = foreignKeyDeleteAction;
    }

    
Returns the action taken when a referenced record in the foreign key database is deleted.

Returns:
the action taken when a referenced record in the foreign key database is deleted.
See also:
setForeignKeyDeleteAction(com.sleepycat.je.ForeignKeyDeleteAction)
        return ;
    }

    
Specifies the user-supplied object used for setting single-valued foreign keys to null.

This method may not be used along with setMultiKeyCreator(com.sleepycat.je.SecondaryMultiKeyCreator). When using a multi-key creator, use setForeignMultiKeyNullifier(com.sleepycat.je.ForeignMultiKeyNullifier) instead.

If the foreign key database property is non-null and the foreign key delete action is NULLIFY, this property is required to be non-null; otherwise, this property is ignored.

WARNING: Key nullifier instances are shared by multiple threads and key nullifier methods are called without any special synchronization. Therefore, key creators must be thread safe. In general no shared state should be used and any caching of computed values must be done with proper synchronization.

Parameters:
foreignKeyNullifier the user-supplied object used for setting single-valued foreign keys to null.
Returns:
this
See also:
ForeignKeyNullifier @see ForeignKeyDeleteAction.NULLIFY @see .setForeignKeyDatabase
    public SecondaryConfig
        setForeignKeyNullifier(ForeignKeyNullifier foreignKeyNullifier) {
        setForeignKeyNullifierVoid(foreignKeyNullifier);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void 
        setForeignKeyNullifierVoid(ForeignKeyNullifier foreignKeyNullifier) {
        this. = foreignKeyNullifier;
    }

    
Returns the user-supplied object used for setting single-valued foreign keys to null.

Returns:
the user-supplied object used for setting single-valued foreign keys to null.
See also:
setForeignKeyNullifier(com.sleepycat.je.ForeignKeyNullifier)
        return ;
    }

    
Specifies the user-supplied object used for setting multi-valued foreign keys to null.

If the foreign key database property is non-null and the foreign key delete action is NULLIFY, this property is required to be non-null; otherwise, this property is ignored.

WARNING: Key nullifier instances are shared by multiple threads and key nullifier methods are called without any special synchronization. Therefore, key creators must be thread safe. In general no shared state should be used and any caching of computed values must be done with proper synchronization.

Parameters:
foreignMultiKeyNullifier the user-supplied object used for setting multi-valued foreign keys to null.
Returns:
this
See also:
ForeignMultiKeyNullifier @see ForeignKeyDeleteAction.NULLIFY @see .setForeignKeyDatabase
        (ForeignMultiKeyNullifier foreignMultiKeyNullifier) {
        setForeignMultiKeyNullifierVoid(foreignMultiKeyNullifier);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
        (ForeignMultiKeyNullifier foreignMultiKeyNullifier) {
        this. = foreignMultiKeyNullifier;
    }

    
Returns the user-supplied object used for setting multi-valued foreign keys to null.

Returns:
the user-supplied object used for setting multi-valued foreign keys to null.
See also:
setForeignMultiKeyNullifier(com.sleepycat.je.ForeignMultiKeyNullifier)
        return ;
    }

    
Specifies whether the secondary key is immutable.

Specifying that a secondary key is immutable can be used to optimize updates when the secondary key in a primary record will never be changed after that primary record is inserted. For immutable secondary keys, a best effort is made to avoid calling SecondaryKeyCreator.createSecondaryKey when a primary record is updated. This optimization may reduce the overhead of an update operation significantly if the createSecondaryKey operation is expensive.

Be sure to set this property to true only if the secondary key in the primary record is never changed. If this rule is violated, the secondary index will become corrupted, that is, it will become out of sync with the primary.

Parameters:
immutableSecondaryKey whether the secondary key is immutable.
Returns:
this
    public SecondaryConfig
        setImmutableSecondaryKey(boolean immutableSecondaryKey) {
        setImmutableSecondaryKeyVoid(immutableSecondaryKey);
        return this;
    }
    
    

Hidden:
The void return setter for use by Bean editors.
    public void setImmutableSecondaryKeyVoid(boolean immutableSecondaryKey) {
        this. = immutableSecondaryKey;
    }

    
Returns whether the secondary key is immutable. If setImmutableSecondaryKey(boolean) has not been called, this method returns false.

Returns:
whether the secondary key is immutable.
See also:
setImmutableSecondaryKey(boolean)
    public boolean getImmutableSecondaryKey() {
        return ;
    }

    
Returns a copy of this configuration object.
    @Override
    public SecondaryConfig clone() {
        return (SecondaryConfigsuper.clone();
    }

    
For JCA Database handle caching.

Throws:
java.lang.IllegalArgumentException via JEConnection.openSecondaryDatabase.
    @Override
    void validate(DatabaseConfig configArg)
        throws DatabaseException {
        super.validate(configArg);
        if (configArg == null ||
            !(configArg instanceof SecondaryConfig)) {
            throw new IllegalArgumentException
                ("The SecondaryConfig argument is null.");
        }
        SecondaryConfig config = (SecondaryConfigconfigArg;
        boolean kcMatch = equalOrBothNull
            (config.getKeyCreator(), );
        boolean mkcMatch = equalOrBothNull
            (config.getMultiKeyCreator(), );
        boolean fkdMatch =
            (config.getForeignKeyDatabase() == );
        boolean fkdaMatch =
            (config.getForeignKeyDeleteAction() == );
        boolean fknMatch = equalOrBothNull
            (config.getForeignKeyNullifier(), );
        boolean fmknMatch = equalOrBothNull
            (config.getForeignMultiKeyNullifier(), );
        boolean imskMatch =
            (config.getImmutableSecondaryKey() == );
        if (kcMatch &&
            mkcMatch &&
            fkdMatch &&
            fkdaMatch &&
            fknMatch &&
            fmknMatch &&
            imskMatch) {
            return;
        }
        String message =
            genSecondaryConfigMismatchMessage(
                configkcMatchmkcMatchfkdMatchfkdaMatch,
                fknMatchfmknMatchimskMatch);
        throw new IllegalArgumentException(message);
    }
    
    

Hidden:
For internal use only.
    @Override
    public DatabaseConfig setTriggers(List<Triggertriggers) {
        if ((triggers == null) || (triggers.size() == 0)) {
            return this;
        }
        throw new IllegalArgumentException
            ("Triggers may only be associated with a Primary database");
    }

    

Hidden:
For internal use only.
    @Override
                                              boolean override) {
        throw new IllegalArgumentException
            ("Triggers may only be associated with a Primary database");
    }
    
    private boolean equalOrBothNull(Object o1Object o2) {
        return (o1 != null) ? o1.equals(o2) : (o2 == null);
    }
                                             boolean kcMatch,
                                             boolean mkcMatch,
                                             boolean fkdMatch,
                                             boolean fkdaMatch,
                                             boolean fknMatch,
                                             boolean fmknMatch,
                                             boolean imskMatch) {
        StringBuilder ret = new StringBuilder
            ("The following SecondaryConfig parameters for the\n" +
             "cached Database do not match the parameters for the\n" +
             "requested Database:\n");
        if (!kcMatch) {
            ret.append(" SecondaryKeyCreator\n");
        }
        if (!mkcMatch) {
            ret.append(" SecondaryMultiKeyCreator\n");
        }
        if (!fkdMatch) {
            ret.append(" ForeignKeyDelete\n");
        }
        if (!fkdaMatch) {
            ret.append(" ForeignKeyDeleteAction\n");
        }
        if (!fknMatch) {
            ret.append(" ForeignKeyNullifier\n");
        }
        if (!fknMatch) {
            ret.append(" ForeignMultiKeyNullifier\n");
        }
        if (!imskMatch) {
            ret.append(" ImmutableSecondaryKey\n");
        }
        return ret.toString();
    }

    
Returns the values for each configuration attribute.

Returns:
the values for each configuration attribute.
    @Override
    public String toString() {
        return "keyCreator=" +  +
            "\nmultiKeyCreator=" +  +
            "\nallowPopulate=" +  +
            "\nforeignKeyDatabase=" +  +
            "\nforeignKeyDeleteAction=" +  +
            "\nforeignKeyNullifier=" +  +
            "\nforeignMultiKeyNullifier=" +  +
            "\nimmutableSecondaryKey=" +  +
            "\n";
    }
New to GrepCode? Check out our FAQ X