当前位置: 首页>>代码示例>>Java>>正文


Java Database.getTable方法代码示例

本文整理汇总了Java中org.apache.ddlutils.model.Database.getTable方法的典型用法代码示例。如果您正苦于以下问题:Java Database.getTable方法的具体用法?Java Database.getTable怎么用?Java Database.getTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ddlutils.model.Database的用法示例。


在下文中一共展示了Database.getTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dropTable

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Outputs the DDL required to drop the given table. This method also
 * drops foreign keys to the table.
 * 
 * @param database The database
 * @param table    The table
 */
public void dropTable(Database database, Table table) throws IOException
{
    // we're dropping the foreignkeys to the table first
    for (int idx = database.getTableCount() - 1; idx >= 0; idx--)
    {
        Table        otherTable = database.getTable(idx);
        ForeignKey[] fks        = otherTable.getForeignKeys();

        for (int fkIdx = 0; (fks != null) && (fkIdx < fks.length); fkIdx++)
        {
            if (fks[fkIdx].getForeignTable().equals(table))
            {
                dropForeignKey(otherTable, fks[fkIdx]);
            }
        }
    }
    // and the foreign keys from the table
    dropForeignKeys(table);

    writeTableComment(table);
    dropTable(table);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:30,代码来源:SqlBuilder.java

示例2: apply

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void apply(Database database, boolean caseSensitive)
{
    // we only need to replace the table in the model, as there can't be a
    // foreign key from or to it when these kind of changes are created
    for (int tableIdx = 0; tableIdx < database.getTableCount(); tableIdx++)
    {
        Table curTable = database.getTable(tableIdx);

        if ((caseSensitive  && curTable.getQualifiedName().equals(getChangedTable())) ||
            (!caseSensitive && curTable.getQualifiedName().equalsIgnoreCase(getChangedTable())))
        {
            database.removeTable(tableIdx);
            database.addTable(tableIdx, new CloneHelper().clone(_targetTable, true, false, database, caseSensitive));
            break;
        }
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:21,代码来源:RecreateTableChange.java

示例3: compareModels

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Compares the given source and target models and creates change objects to get from
 * the source to the target one. These changes will be applied to the given
 * intermediate model (the other two won't be changed), so that it will be equal to
 * the target model after this model has finished.
 * 
 * @param sourceModel       The source model
 * @param intermediateModel The intermediate model to apply the changes to
 * @param targetModel       The target model
 * @return The changes
 */
protected List compareModels(Database sourceModel,
                             Database intermediateModel,
                             Database targetModel)
{
    ArrayList changes = new ArrayList();

    changes.addAll(checkForRemovedForeignKeys(sourceModel, intermediateModel, targetModel));
    changes.addAll(checkForRemovedTables(sourceModel, intermediateModel, targetModel));

    for (int tableIdx = 0; tableIdx < intermediateModel.getTableCount(); tableIdx++)
    {
        Table intermediateTable = intermediateModel.getTable(tableIdx);
        Table sourceTable       = sourceModel.findTable(intermediateTable.getQualifiedName(), _caseSensitive);
        Table targetTable       = targetModel.findTable(intermediateTable.getQualifiedName(), _caseSensitive);
        List  tableChanges      = compareTables(sourceModel, sourceTable,
                                                intermediateModel, intermediateTable,
                                                targetModel, targetTable);

        changes.addAll(tableChanges);
    }

    changes.addAll(checkForAddedTables(sourceModel, intermediateModel, targetModel));
    changes.addAll(checkForAddedForeignKeys(sourceModel, intermediateModel, targetModel));
    return changes;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:37,代码来源:ModelComparator.java

示例4: getFilteredParameters

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Filters the parameters for the given model and platform.
 * 
 * @param model           The database model
 * @param platformName    The name of the platform
 * @param isCaseSensitive Whether case is relevant when comparing names of tables
 * @return The filtered parameters
 */
protected CreationParameters getFilteredParameters(Database model, String platformName, boolean isCaseSensitive)
{
    CreationParameters parameters = new CreationParameters();

    for (Iterator it = _parameters.iterator(); it.hasNext();)
    {
        TableSpecificParameter param = (TableSpecificParameter)it.next();

        if (param.isForPlatform(platformName))
        {
            for (int idx = 0; idx < model.getTableCount(); idx++)
            {
                Table table = model.getTable(idx);

                if (param.isForTable(table, isCaseSensitive))
                {
                    parameters.addParameter(table, param.getName(), param.getValue());
                }
            }
        }
    }
    return parameters;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:32,代码来源:DatabaseCommandWithCreationParameters.java

示例5: testToColumnValues

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Test the toColumnValues method.
 */
public void testToColumnValues()
{
    final String schema =
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='ddlutils'>\n"+
        "  <table name='TestTable'>\n"+
        "    <column name='id' autoIncrement='true' type='INTEGER' primaryKey='true'/>\n"+
        "    <column name='name' type='VARCHAR' size='15'/>\n"+
        "  </table>\n"+
        "</database>";

    Database         database = parseDatabaseFromString(schema);
    PlatformImplBase platform = new TestPlatform();
    Table            table    = database.getTable(0);
    SqlDynaClass     clz      = SqlDynaClass.newInstance(table);
    DynaBean         db       = new SqlDynaBean(SqlDynaClass.newInstance(table));

    db.set("name", "name");

    Map map = platform.toColumnValues(clz.getSqlDynaProperties(), db);

    assertEquals("name",
                 map.get("name"));
    assertTrue(map.containsKey("id"));
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:TestPlatformImplBase.java

示例6: testColumnWithDefault

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Tests a database model with a table with a column with a default.
 */
public void testColumnWithDefault() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='SomeTable'\n" +
        "         description='Some table'>\n" +
        "    <column name='ID'\n" +
        "            type='VARCHAR'\n" +
        "            size='32'\n" +
        "            default='Test string'/>\n" +
        "  </table>\n" +
        "</database>");

    assertEquals("test", model.getName());
    assertEquals(1, model.getTableCount());
    
    Table table = model.getTable(0);

    assertEquals("SomeTable", "Some table", 1, 0, 0, 0, 0,
                 table);
    assertEquals("ID", Types.VARCHAR, 32, 0, "Test string", null, null, false, false, false,
                 table.getColumn(0));

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" +
        "  <table name=\"SomeTable\" description=\"Some table\">\n" +
        "    <column name=\"ID\" primaryKey=\"false\" required=\"false\" type=\"VARCHAR\" size=\"32\" default=\"Test string\" autoIncrement=\"false\" />\n" +
        "  </table>\n" +
        "</database>\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:36,代码来源:TestDatabaseIO.java

示例7: checkForAddedForeignKeys

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
protected List checkForAddedForeignKeys(Database sourceModel,
                                        Database intermediateModel,
                                        Database targetModel)
{
    List changes           = super.checkForAddedForeignKeys(sourceModel, intermediateModel, targetModel);
    List additionalChanges = new ArrayList();

    // re-adding all foreign keys that are maintained and that use a changed column
    for (int tableIdx = 0; tableIdx < targetModel.getTableCount(); tableIdx++)
    {
        Table targetTable       = targetModel.getTable(tableIdx);
        Table sourceTable       = sourceModel.findTable(targetTable.getName(), isCaseSensitive());
        Table intermediateTable = intermediateModel.findTable(targetTable.getName(), isCaseSensitive());

        if (sourceTable != null)
        {
            for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)
            {
                ForeignKey targetFk       = targetTable.getForeignKey(fkIdx);
                ForeignKey sourceFk       = findCorrespondingForeignKey(sourceTable, targetFk);
                ForeignKey intermediateFk = findCorrespondingForeignKey(intermediateTable, targetFk);

                if ((sourceFk != null) && (intermediateFk == null))
                {
                    additionalChanges.add(new AddForeignKeyChange(intermediateTable.getName(), targetFk));
                }
            }
        }
    }
    for (Iterator changeIt = additionalChanges.iterator(); changeIt.hasNext();)
    {
        ((AddForeignKeyChange)changeIt.next()).apply(intermediateModel, isCaseSensitive());
    }
    changes.addAll(additionalChanges);
    return changes;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:40,代码来源:MSSqlModelComparator.java

示例8: testColumnWithSize2

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Tests a database model with a table with a column with a size spec.
 */
public void testColumnWithSize2() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='SomeTable'\n" +
        "         description='Some table'>\n" +
        "    <column name='ID'\n" +
        "            type='DECIMAL'\n" +
        "            size='10,3'/>\n" +
        "  </table>\n" +
        "</database>");

    assertEquals("test", model.getName());
    assertEquals(1, model.getTableCount());
    
    Table table = model.getTable(0);

    assertEquals("SomeTable", "Some table", 1, 0, 0, 0, 0,
                 table);
    assertEquals("ID", Types.DECIMAL, 10, 3, null, null, null, false, false, false,
                 table.getColumn(0));

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" +
        "  <table name=\"SomeTable\" description=\"Some table\">\n" +
        "    <column name=\"ID\" primaryKey=\"false\" required=\"false\" type=\"DECIMAL\" size=\"10,3\" autoIncrement=\"false\" />\n" +
        "  </table>\n" +
        "</database>\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:35,代码来源:TestDatabaseIO.java

示例9: checkForAddedForeignKeys

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Creates change objects for foreign keys that are not present in the given source model but are in the target
 * model, and applies them to the given intermediate model.
 * 
 * @param sourceModel       The source model
 * @param intermediateModel The intermediate model to apply the changes to
 * @param targetModel       The target model
 * @return The changes
 */
protected List checkForAddedForeignKeys(Database sourceModel,
                                        Database intermediateModel,
                                        Database targetModel)
{
    List changes = new ArrayList();

    for (int tableIdx = 0; tableIdx < targetModel.getTableCount(); tableIdx++)
    {
        Table targetTable       = targetModel.getTable(tableIdx);
        Table intermediateTable = intermediateModel.findTable(targetTable.getQualifiedName(), _caseSensitive);

        for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)
        {
            ForeignKey targetFk       = targetTable.getForeignKey(fkIdx);
            ForeignKey intermediateFk = findCorrespondingForeignKey(intermediateTable, targetFk);

            if (intermediateFk == null)
            {
                if (_log.isInfoEnabled())
                {
                    _log.info("Foreign key " + targetFk + " needs to be added to table " + intermediateTable.getQualifiedName());
                }

                intermediateFk = _cloneHelper.clone(targetFk, intermediateTable, intermediateModel, _caseSensitive);

                AddForeignKeyChange fkChange = new AddForeignKeyChange(intermediateTable.getQualifiedName(), intermediateFk);

                changes.add(fkChange);
                fkChange.apply(intermediateModel, _caseSensitive);
            }
        }
    }
    return changes;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:44,代码来源:ModelComparator.java

示例10: writeAddIdentityUsingAlterTable

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
protected void writeAddIdentityUsingAlterTable(Platform platform,
    Database model) throws DataSinkException {
  // if identity column has to be set using alter table then
  // do it after loading the data
  if (_addIdentityUsingAlterTable && platform.getPlatformInfo()
          .isAddingIdentityUsingAlterTableSupported()) {
    StringWriter buffer = new StringWriter();
  
    SqlBuilder builder = platform.getSqlBuilder();
    builder.setWriter(buffer);
    for (int index = 0; index < model.getTableCount(); index++) {
      Table table = model.getTable(index);
      for (int col = 0; col < table.getColumnCount(); col++) {
        Column column = table.getColumn(col);
        if (column.isAutoIncrement()) {
          try {
            builder.writeAddIdentityColumnUsingAlterTable(table, column);
          } catch (IOException ioe) {
            throw new DataSinkException(ioe);
          }
        }
      }
    }
    String sql = buffer.toString();
    platform.evaluateBatch(sql, false);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:28,代码来源:WriteDataToDatabaseCommand.java

示例11: testColumnWithDescription

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Tests a database model with a table with a column with a description.
 */
public void testColumnWithDescription() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='SomeTable'\n" +
        "         description='Some table'>\n" +
        "    <column name='ID'\n" +
        "            type='INTEGER'\n" +
        "            description='Foo'/>\n" +
        "  </table>\n" +
        "</database>");

    assertEquals("test", model.getName());
    assertEquals(1, model.getTableCount());
    
    Table table = model.getTable(0);

    assertEquals("SomeTable", "Some table", 1, 0, 0, 0, 0,
                 table);
    assertEquals("ID", Types.INTEGER, 0, 0, null, "Foo", null, false, false, false,
                 table.getColumn(0));

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" +
        "  <table name=\"SomeTable\" description=\"Some table\">\n" +
        "    <column name=\"ID\" primaryKey=\"false\" required=\"false\" type=\"INTEGER\" autoIncrement=\"false\" description=\"Foo\" />\n" +
        "  </table>\n" +
        "</database>\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:35,代码来源:TestDatabaseIO.java

示例12: testColumnWithJavaName

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Tests a database model with a table with a column with a java name.
 */
public void testColumnWithJavaName() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='SomeTable'\n" +
        "         description='Some table'>\n" +
        "    <column name='ID'\n" +
        "            type='DOUBLE'\n" +
        "            javaName='testString'/>\n" +
        "  </table>\n" +
        "</database>");

    assertEquals("test", model.getName());
    assertEquals(1, model.getTableCount());
    
    Table table = model.getTable(0);

    assertEquals("SomeTable", "Some table", 1, 0, 0, 0, 0,
                 table);
    assertEquals("ID", Types.DOUBLE, 0, 0, null, null, "testString", false, false, false,
                 table.getColumn(0));

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" +
        "  <table name=\"SomeTable\" description=\"Some table\">\n" +
        "    <column name=\"ID\" primaryKey=\"false\" required=\"false\" type=\"DOUBLE\" autoIncrement=\"false\" javaName=\"testString\" />\n" +
        "  </table>\n" +
        "</database>\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:35,代码来源:TestDatabaseIO.java

示例13: testSingleColumn

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Tests a database model with a table with a single column.
 */
public void testSingleColumn() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='SomeTable'\n" +
        "         description='Some table'>\n" +
        "    <column name='ID'\n" +
        "            type='INTEGER'/>\n" +
        "  </table>\n" +
        "</database>");

    assertEquals("test", model.getName());
    assertEquals(1, model.getTableCount());
    
    Table table = model.getTable(0);

    assertEquals("SomeTable", "Some table", 1, 0, 0, 0, 0,
                 table);
    assertEquals("ID", Types.INTEGER, 0, 0, null, null, null, false, false, false,
                 table.getColumn(0));

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" +
        "  <table name=\"SomeTable\" description=\"Some table\">\n" +
        "    <column name=\"ID\" primaryKey=\"false\" required=\"false\" type=\"INTEGER\" autoIncrement=\"false\" />\n" +
        "  </table>\n" +
        "</database>\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:34,代码来源:TestDatabaseIO.java

示例14: testRequiredColumn

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Tests a database model with a table with a required column.
 */
public void testRequiredColumn() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='SomeTable'\n" +
        "         description='Some table'>\n" +
        "    <column name='ID'\n" +
        "            type='INTEGER'\n" +
        "            required='true'/>\n" +
        "  </table>\n" +
        "</database>");

    assertEquals("test", model.getName());
    assertEquals(1, model.getTableCount());
    
    Table table = model.getTable(0);

    assertEquals("SomeTable", "Some table", 1, 0, 0, 0, 0,
                 table);
    assertEquals("ID", Types.INTEGER, 0, 0, null, null, null, false, true, false,
                 table.getColumn(0));

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" +
        "  <table name=\"SomeTable\" description=\"Some table\">\n" +
        "    <column name=\"ID\" primaryKey=\"false\" required=\"true\" type=\"INTEGER\" autoIncrement=\"false\" />\n" +
        "  </table>\n" +
        "</database>\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:35,代码来源:TestDatabaseIO.java

示例15: testUniqueIndexWithName

import org.apache.ddlutils.model.Database; //导入方法依赖的package包/类
/**
 * Tests a database model with an unique index with a name.
 */
public void testUniqueIndexWithName() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='TableWithIndex'>\n" +
        "    <column name='id'\n" +
        "            type='DOUBLE'\n" +
        "            primaryKey='true'\n" +
        "            required='true'/>\n" +
        "    <column name='value'\n" +
        "            type='SMALLINT'\n" +
        "            default='1'/>\n" +
        "    <unique name='The Index'>\n" +
        "      <unique-column name='value'/>\n" +
        "    </unique>\n" +
        "  </table>\n" +
        "</database>");

    assertEquals("test", model.getName());
    assertEquals(1, model.getTableCount());
    
    Table table = model.getTable(0);

    assertEquals("TableWithIndex", null, 2, 1, 0, 0, 1,
                 table);
    assertEquals("id", Types.DOUBLE, 0, 0, null, null, null, true, true, false,
                 table.getColumn(0));
    assertEquals("value", Types.SMALLINT, 0, 0, "1", null, null, false, false, false,
                 table.getColumn(1));

    Index index = table.getIndex(0);

    assertEquals("The Index", true, 1, index);
    assertEquals(table.getColumn(1), null, index.getColumn(0));

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" +
        "  <table name=\"TableWithIndex\">\n" +
        "    <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\" />\n" +
        "    <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\" />\n" +
        "    <unique name=\"The Index\">\n" +
        "      <unique-column name=\"value\" />\n" +
        "    </unique>\n" +
        "  </table>\n" +
        "</database>\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:52,代码来源:TestDatabaseIO.java


注:本文中的org.apache.ddlutils.model.Database.getTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。