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


Java Database类代码示例

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


Database类属于org.apache.ddlutils.model包,在下文中一共展示了Database类的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: readTableElements

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Reads table elements from the XML stream reader and adds them to the given
 * database model.
 * 
 * @param xmlReader The reader
 * @param model     The database model to add the table objects to
 */
private void readTableElements(XMLStreamReader xmlReader, Database model) throws XMLStreamException, IOException
{
    int eventType = XMLStreamReader.START_ELEMENT;

    while (eventType != XMLStreamReader.END_ELEMENT)
    {
        eventType = xmlReader.next();
        if (eventType == XMLStreamReader.START_ELEMENT)
        {
            if (isSameAs(xmlReader.getName(), QNAME_ELEMENT_TABLE)) {
                model.addTable(readTableElement(xmlReader));
            }
            else {
                readOverElement(xmlReader);
            }
        }
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:26,代码来源:DatabaseIO.java

示例3: getCreateModelSql

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public String getCreateModelSql(Database model, CreationParameters params, boolean dropTablesFirst, boolean continueOnError)
{
    String sql = null;

    try
    {
        StringWriter buffer = new StringWriter();

        getSqlBuilder().setWriter(buffer);
        getSqlBuilder().createTables(model, params, dropTablesFirst);
        sql = buffer.toString();
    }
    catch (IOException e)
    {
        // won't happen because we're using a string writer
    }
    return sql;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:PlatformImplBase.java

示例4: createTables

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Outputs the DDL required to drop (if requested) and (re)create all tables in the database model.
 * 
 * @param database   The database
 * @param params     The parameters used in the creation
 * @param dropTables Whether to drop tables before creating them
 */
public void createTables(Database database, CreationParameters params, boolean dropTables) throws IOException
{
    if (dropTables)
    {
        dropTables(database);
    }

    for (int idx = 0; idx < database.getTableCount(); idx++)
    {
        Table table = database.getTable(idx);

        writeTableComment(table);
        createTable(database,
                    table,
                    params == null ? null : params.getParametersFor(table));
    }

    // we're writing the external foreignkeys last to ensure that all referenced tables are already defined
    createForeignKeys(database);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:28,代码来源:SqlBuilder.java

示例5: testNoTables

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Tests a database model without tables.
 */
public void testNoTables() throws Exception
{
    Database model = readModel(
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "</database>");

    assertEquals("test",
                 model.getName());
    assertEquals(0,
                 model.getTableCount());

    assertEquals(
        "<?xml version='1.0' encoding='UTF-8'?>\n" +
        "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\" />\n",
        model);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:20,代码来源:TestDatabaseIO.java

示例6: testSingleTablesWithSelfReferencingFK

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Tests the removal of a table with a self-referencing foreign key. 
 */
public void testSingleTablesWithSelfReferencingFK()
{
    final String modelXml = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='avalue' type='INTEGER'/>\n"+
        "    <foreign-key foreignTable='roundtrip'>\n"+
        "      <reference local='avalue' foreign='pk'/>\n"+
        "    </foreign-key>\n"+
        "  </table>\n"+
        "</database>";

    createDatabase(modelXml);

    DatabaseToDdlTask task = getDatabaseToDdlTaskInstance();

    task.addDropTables(new DropTablesCommand());
    task.execute();

    assertEquals(new Database("roundtriptest"),
                 readModelFromDatabase("roundtriptest"),
                 false);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:TestDropTablesCommand.java

示例7: testSameDefaultValueExpressedDifferently

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Tests that shows that the same default value expressed differently does not
 * result in a change.
 */
public void testSameDefaultValueExpressedDifferently()
{
    final String MODEL1 = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='TableA'>\n" +
        "    <column name='ColPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
        "    <column name='Col' type='DOUBLE' default='10'/>\n" +
        "  </table>\n" +
        "</database>";
    final String MODEL2 = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='TABLEA'>\n" +
        "    <column name='COLPK' type='INTEGER' primaryKey='true' required='true'/>\n" +
        "    <column name='COL' type='DOUBLE' default='1e+1'/>\n" +
        "  </table>\n" +
        "</database>";

    Database model1  = parseDatabaseFromString(MODEL1);
    Database model2  = parseDatabaseFromString(MODEL2);
    List     changes = getPlatform(false).getChanges(model1, model2);

    assertTrue(changes.isEmpty());
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:30,代码来源:TestTableComparison.java

示例8: testColumnNameShortAndValueLong

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Tests the reader & writer behavior when a column name is a normal valid tag,
 * and the column name is shorter than 255 characters but the value is longer.
 */
public void testColumnNameShortAndValueLong() throws Exception
{
    Database model = readModel(
        "<?xml version='1.0' encoding='UTF-8'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='test'>\n"+
        "    <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='value' type='VARCHAR' size='400' required='true'/>\n"+
        "  </table>\n"+
        "</database>");
    String testedValue = StringUtils.repeat("Some Text", 40);

    SqlDynaBean bean = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <value>" + testedValue + "</value>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:30,代码来源:TestDataReaderAndWriter.java

示例9: readDatabaseElement

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Reads a database element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The database object
 */
private Database readDatabaseElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Database model = new Database();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            model.setName(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT_ID_METHOD))
        {
            model.setIdMethod(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_VERSION))
        {
            model.setVersion(xmlReader.getAttributeValue(idx));
        }
    }
    readTableElements(xmlReader, model);
    consumeRestOfElement(xmlReader);
    return model;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:32,代码来源:DatabaseIO.java

示例10: getDropModelSql

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public String getDropModelSql(Database model) 
{
    String sql = null;

    try
    {
        StringWriter buffer = new StringWriter();

        getSqlBuilder().setWriter(buffer);
        getSqlBuilder().dropTables(model);
        sql = buffer.toString();
    }
    catch (IOException e)
    {
        // won't happen because we're using a string writer
    }
    return sql;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:PlatformImplBase.java

示例11: getConfiguredDataReader

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
     * Returns a data reader instance configured for the given platform (which needs to
     * be connected to a live database) and model.
     * 
     * @param platform The database
     * @param model    The model
     * @return The data reader
     */
    public DataReader getConfiguredDataReader(Platform platform, Database model) throws DdlUtilsException
    {
        DataToDatabaseSink sink     = new DataToDatabaseSink(platform, model);
        DataReader         reader   = new DataReader();

        sink.setHaltOnErrors(_failOnError);
        sink.setEnsureForeignKeyOrder(_ensureFKOrder);
        sink.setUseBatchMode(_useBatchMode);
        if (_batchSize != null)
        {
            sink.setBatchSize(_batchSize.intValue());
        }
        
        reader.setModel(model);
// GemStone changes BEGIN
        reader.setCaseSensitive(platform.isDelimitedIdentifierModeOn());
// GemStone changes END
        reader.setSink(sink);
        registerConverters(reader.getConverterConfiguration());
        return reader;
    }
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:30,代码来源:DatabaseDataIO.java

示例12: 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

示例13: testZDeleteClient

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Test which copies a client, then deletes it, and then tests that the foreign keys are still
 * activated
 */
@Test
public void testZDeleteClient() {
  Platform platform = SystemService.getInstance().getPlatform();
  ExcludeFilter excludeFilter = DBSMOBUtil.getInstance().getExcludeFilter(
      new File(OBPropertiesProvider.getInstance().getOpenbravoProperties()
          .getProperty("source.path")));
  Database dbBefore = platform.loadTablesFromDatabase(excludeFilter);
  String newClientId = exportImport(QA_TEST_CLIENT_ID);
  Client client = OBDal.getInstance().get(Client.class, newClientId);

  SystemService.getInstance().deleteClient(client);
  Database dbAfter = platform.loadTablesFromDatabase(excludeFilter);
  for (int i = 0; i < dbBefore.getTableCount(); i++) {
    Table table1 = dbBefore.getTable(i);
    Table table2 = dbAfter.getTable(i);
    for (int j = 0; j < table1.getForeignKeyCount(); j++) {
      assertTrue(table1.getForeignKey(j).equals(table2.getForeignKey(j)));
    }
  }
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:25,代码来源:ClientExportImportTest.java

示例14: testColumnNameIsBase64

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Tests the reader & writer behavior when a column name is 'base64'.
 */
public void testColumnNameIsBase64() throws Exception
{
    Database model = readModel(
        "<?xml version='1.0' encoding='UTF-8'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='test'>\n"+
        "    <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='" + DatabaseIO.BASE64_ATTR_NAME + "' type='VARCHAR' size='50' required='true'/>\n"+
        "  </table>\n"+
        "</database>");
    String testedValue = "Some Text";

    SqlDynaBean bean = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));

    bean.set("id", new Integer(1));
    bean.set(DatabaseIO.BASE64_ATTR_NAME, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column column-name=\"" + DatabaseIO.BASE64_ATTR_NAME + "\">" + testedValue + "</column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:TestDataReaderAndWriter.java

示例15: performConstraintsTest

import org.apache.ddlutils.model.Database; //导入依赖的package包/类
/**
 * Tests a nullable column. Basically we're creating the test database
 * and then read it back and compare the original with the read one.
 * In addition we can also check that DdlUtils does not try to alter the new
 * database when using the <code>alterTables</code>/<code>getAlterTablesSql</code>
 * methods of the {@link org.apache.ddlutils.Platform} with the read-back model.
 * 
 * @param modelXml        The model to be tested in XML form
 * @param checkAlteration Whether to also check the alter tables sql
 */
protected void performConstraintsTest(String modelXml, boolean checkAlteration)
{
    createDatabase(modelXml);

    Database modelFromDb = readModelFromDatabase("roundtriptest");
    
    assertEquals(getAdjustedModel(),
    		     modelFromDb);

    if (checkAlteration)
    {
     String alterTablesSql = getAlterTablesSql(modelFromDb).trim();
	
     assertTrue(alterTablesSql.length() == 0);
    }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:27,代码来源:TestConstraints.java


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