Java Code Examples for com.sleepycat.je.Environment#getDatabaseNames()

The following examples show how to use com.sleepycat.je.Environment#getDatabaseNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Migrator.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
/**
 * 扫描指定环境中的实体名称与仓储名称的映射
 * 
 * @param environment
 * @return 实体名称与仓储名称的映射
 */
private Map<String, String> scanEntityStoreNameMap(Environment environment) {
    final Map<String, String> entityStoreNameMap = new HashMap<String, String>();
    for (String databaseName : environment.getDatabaseNames()) {
        // 检测数据库名称是否符合EntityStore的名称规范(persist#STORE_NAME#ENTITY_CLASS)
        if (databaseName.startsWith(PERSIST_PREFIX) && !databaseName.endsWith(FORMAT_SUFFIX) && !databaseName.endsWith(SEQUENCE_SUFFIX)) {
            final String[] databasePartNames = databaseName.split("#");
            // 防止重复构建RawStore
            if (databasePartNames.length == 3) {
                if (entityStoreNameMap.containsKey(databasePartNames[2])) {
                    throw new RuntimeException("实体名称冲突");
                } else {
                    entityStoreNameMap.put(databasePartNames[2], databasePartNames[1]);
                }
            }
        }
    }
    return entityStoreNameMap;
}
 
Example 2
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void renameDatabases(Environment environment, Transaction transaction)
{
    List<String> databases = environment.getDatabaseNames();
    String[] oldDatabases = { OLD_META_DATA_DB_NAME, OLD_BRIDGES_DB_NAME, OLD_LINKS_DB_NAME };
    String[] newDatabases = { NEW_METADATA_DB_NAME, NEW_BRIDGES_DB_NAME, NEW_LINKS_DB_NAME };

    for (int i = 0; i < oldDatabases.length; i++)
    {
        String oldName = oldDatabases[i];
        String newName = newDatabases[i];
        if (databases.contains(oldName))
        {
            LOGGER.info("Renaming " + oldName + " into " + newName);
            environment.renameDatabase(transaction, oldName, newName);
        }
    }
}
 
Example 3
Source File: UpgraderTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyDatabaseUpgradeDoesNothing() throws Exception
{
    File nonExistentStoreLocation = new File(TMP_FOLDER, getTestName());
    deleteDirectoryIfExists(nonExistentStoreLocation);

    nonExistentStoreLocation.mkdir();
    Environment emptyEnvironment = createEnvironment(nonExistentStoreLocation);
    try
    {
        _upgrader = new Upgrader(emptyEnvironment, getVirtualHost());
        _upgrader.upgradeIfNecessary();

        List<String> databaseNames = emptyEnvironment.getDatabaseNames();
        List<String> expectedDatabases = new ArrayList<String>();
        expectedDatabases.add(Upgrader.VERSION_DB_NAME);
        assertEquals("Expectedonly VERSION table in initially empty store after upgrade: ", expectedDatabases, databaseNames);
        assertEquals("Unexpected store version", BDBConfigurationStore.VERSION, getStoreVersion(emptyEnvironment));

    }
    finally
    {
        emptyEnvironment.close();
        nonExistentStoreLocation.delete();
    }
}
 
Example 4
Source File: Migrator.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/**
 * 获取环境所有的实体名称
 * 
 * @param environment
 * @return 实体名称的集合
 */
private Collection<String> getAllEntityNames(Environment environment) {
    final Collection<String> entityStoreSet = new HashSet<String>();
    for (String databaseName : environment.getDatabaseNames()) {
        // 检测数据库名称是否符合EntityStore的名称规范(persist#STORE_NAME#ENTITY_CLASS)
        if (databaseName.startsWith(PERSIST_PREFIX) && !databaseName.endsWith(FORMAT_SUFFIX) && !databaseName.endsWith(SEQUENCE_SUFFIX)) {
            final String[] databasePartNames = databaseName.split("#");
            entityStoreSet.add(databasePartNames[2]);
        }
    }
    return entityStoreSet;
}
 
Example 5
Source File: Migrator.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/**
 * 构建新数据库环境
 * 
 * @param databaseConfiguration
 */
public void buildNewEnvironment(BerkeleyAccessor accessorFactory) {
    // 删除准备迁移的仓储
    final EnvironmentConfig environmentConfiguration = new EnvironmentConfig(environmentProperties);
    final Environment environment = new Environment(this.newDatabaseDirectory, environmentConfiguration);

    for (String databaseName : environment.getDatabaseNames()) {
        // 检测数据库名称是否符合EntityStore的名称规范(persist#STORE_NAME#ENTITY_CLASS)
        if (databaseName.startsWith(PERSIST_PREFIX)) {
            final String[] databasePartNames = databaseName.split("#");
            logger.debug("扫描数据库[{}]", databaseName);
            if (this.migrateStroreNames.contains(databasePartNames[1])) {
                environment.removeDatabase(null, databaseName);
                logger.debug("删除数据库[{}]", databaseName);
            }
        }
    }

    environment.close();

    // 让环境自动构建迁移的实体数据表
    // final ClassPathXmlApplicationContext applicationContext = new
    // ClassPathXmlApplicationContext(new String[] { databaseConfiguration });
    // BerkeleyAccessor accessorFactory =
    // applicationContext.getBean(BerkeleyAccessor.class);
    // applicationContext.close();
    // while (accessorFactory.getState() != BerkeleyState.STOPPED) {
    // Thread.yield();
    // }
    accessorFactory.start();
    accessorFactory.stop();
}
 
Example 6
Source File: AbstractStoreUpgrade.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private void reportDatabaseRowCount(Environment environment)
{
    List<String> databases = environment.getDatabaseNames();
    for (String database : databases)
    {
        LOGGER.debug("    " + getRowCount(database, environment)  + " rows in " + database);
    }
}
 
Example 7
Source File: UpgradeFrom4To5.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
/**
 * For all databases which haven't been otherwise upgraded, we still need to
 * rename them from _v4 to _v5
 */
private void renameRemainingDatabases(final Environment environment, final UpgradeInteractionHandler handler,
        Transaction transaction)
{
    for (String dbName : environment.getDatabaseNames())
    {
        if (dbName.endsWith("_v4"))
        {
            String newName = dbName.substring(0, dbName.length() - 3) + "_v5";
            LOGGER.info("Renaming " + dbName + " into " + newName);
            environment.renameDatabase(transaction, dbName, newName);
        }
    }

}