hbase - 如何在不删除表的情况下更改表结构

发布于 2024-12-02 17:47:05 字数 760 浏览 2 评论 0原文

我使用 grails-1.3.2 和 gorm-hbase-0.2.4 插件。

有时我需要更改表结构(添加新表或列)。 我已经创建了汽车表:

class Car{
    static belongsTo = [user:User]

    String color
    String model
    //.....

    static constraints = {
    }
}

但是当我想创建汽车对象时:

def create = {
        Car car = new Car()
        car.properties = params
        car.save(flush: true)        
 }

出现以下异常:

ERROR gorm.SavePersistentMethod  - APP_CAR
org.apache.hadoop.hbase.TableNotFoundException: APP_CAR

在我使用 create-drop 运行应用程序后,一切都开始正常工作。 但我不能在每次更改后删除所有数据, 我认为插件必须执行所有更新

,因此,我正在寻找某种方法,在更改表结构后继续运行应用程序而不删除表。

如果有人知道解决方案,请提供帮助。

i use grails-1.3.2 and gorm-hbase-0.2.4 plugin.

Sometimes i need to change tables structure(add new tables or columns).
I have created Car table:

class Car{
    static belongsTo = [user:User]

    String color
    String model
    //.....

    static constraints = {
    }
}

but when i want to create car object:

def create = {
        Car car = new Car()
        car.properties = params
        car.save(flush: true)        
 }

I got the following exception:

ERROR gorm.SavePersistentMethod  - APP_CAR
org.apache.hadoop.hbase.TableNotFoundException: APP_CAR

After i run application with create-drop, everithing starts work good..
but i can not after every changes delete all data,
i thought plugin have to do all updates

so, i am looking some way after changind tables structure continue to run application without drop tables..

If anybody know solution please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走走停停 2024-12-09 17:47:05

Grails 不会自动更新您的表,如果它自动删除生产中的列怎么办?也许这不是你想要的。

有一个数据库迁移插件可以执行此操作,这里有一个很棒的链接 这解释了它。请注意,您需要使用 grails prod 而不是直接在链接中使用那些,否则它将仅在开发模式下运行。该链接在其命令中不显示 prod。

官方链接位于此处,有关此的 Spring 源博客为 此处

Grails will NOT do automatic updates to your tables, what if it drops a column in production automatically? Maybe that is not what you wanted.

There is a database migration plugin to do this and here is an excellent link that explains it. Note that you need to use grails prod instead of using the ones directly in the link, otherwise it will run in development mode only. The link does not show prod in its commands.

The official links are here and the spring source blog about this is here.

蓦然回首 2024-12-09 17:47:05

数据库迁移插件将不起作用,因为它仅适用于 hibernate。
您需要对插件源进行一些更改。 HBasePluginSupport.grovy

static doWithApplicationContext = {ApplicationContext applicationContext ->
    LOG.debug("Closure HBasePluginSupport.doWithApplicationContext{} invoked with arg $applicationContext")

    assert !PluginManagerHolder.getPluginManager().hasGrailsPlugin("hibernate"),"hibernate plug-in conflicts with gorm-hbase plug-in"

    // Read data source configuration, setting defaults as required
    def dataSource = application.config.dataSource
    // TODO write tests for this <--- Even maybe figure out if this is ever invoked
    if (!dataSource) dataSource = new HBaseDefaults()

    def dbCreate = dataSource?.dbCreate
    if (!dbCreate) dbCreate = "create-drop"
    LOG.debug("Data Source configured with dbCreate set to $dbCreate")

    // TODO Complete dbCreate related processing
    if (dbCreate?.toUpperCase()?.equals("CREATE-DROP")) {
        def createIndexedTables = dataSource?.indexed
        LOG.debug ("Flag createIndexedTables set to $createIndexedTables")
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")

        tableManager.createSequenceTable()
        tableManager.createReferenceTable()

        application.domainClasses.each {domainClass ->
            LOG.debug("Adding table for Domain Class $domainClass")
            tableManager.createDomainTable(domainClass, createIndexedTables)
        }

        LOG.debug("List of all store found :")
        tableManager.getTableNames().each {tn ->
            LOG.debug("- $tn")
        }
    } else if (dbCreate?.toUpperCase()?.equals("UPDATE")) {
        def createIndexedTables = dataSource?.indexed
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")
        def existingTables = tableManager.getTableNames();

        application.domainClasses.each {domainClass ->
            LOG.debug("Domain Class $domainClass")
            def tableDesc = new HTableDescriptor(HBaseNameUtils.getDomainTableName(domainClass))
            if (!existingTables.contains(tableDesc.getNameAsString())) {
                tableManager.createDomainTable(domainClass, createIndexedTables)
                LOG.debug("Adding table for Domain Class $domainClass")
            }
        }
    }

    application.domainClasses.each {domainClass ->
        LOG.debug("Adding dbms related methods to Domain Class $domainClass")
        def domainClassManager = new HBaseDomainClassManager()
        domainClassManager.createQueryMethods(domainClass)
        domainClassManager.createPersistenceMethods(domainClass)
        domainClassManager.addLazyLoadingSupport(domainClass)
        domainClassManager.addDynamicFinders(domainClass)
    }
}

database migration plugin will not be works, because it works only with hibernate.
You need to do some changes in plugin source. HBasePluginSupport.grovy

static doWithApplicationContext = {ApplicationContext applicationContext ->
    LOG.debug("Closure HBasePluginSupport.doWithApplicationContext{} invoked with arg $applicationContext")

    assert !PluginManagerHolder.getPluginManager().hasGrailsPlugin("hibernate"),"hibernate plug-in conflicts with gorm-hbase plug-in"

    // Read data source configuration, setting defaults as required
    def dataSource = application.config.dataSource
    // TODO write tests for this <--- Even maybe figure out if this is ever invoked
    if (!dataSource) dataSource = new HBaseDefaults()

    def dbCreate = dataSource?.dbCreate
    if (!dbCreate) dbCreate = "create-drop"
    LOG.debug("Data Source configured with dbCreate set to $dbCreate")

    // TODO Complete dbCreate related processing
    if (dbCreate?.toUpperCase()?.equals("CREATE-DROP")) {
        def createIndexedTables = dataSource?.indexed
        LOG.debug ("Flag createIndexedTables set to $createIndexedTables")
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")

        tableManager.createSequenceTable()
        tableManager.createReferenceTable()

        application.domainClasses.each {domainClass ->
            LOG.debug("Adding table for Domain Class $domainClass")
            tableManager.createDomainTable(domainClass, createIndexedTables)
        }

        LOG.debug("List of all store found :")
        tableManager.getTableNames().each {tn ->
            LOG.debug("- $tn")
        }
    } else if (dbCreate?.toUpperCase()?.equals("UPDATE")) {
        def createIndexedTables = dataSource?.indexed
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")
        def existingTables = tableManager.getTableNames();

        application.domainClasses.each {domainClass ->
            LOG.debug("Domain Class $domainClass")
            def tableDesc = new HTableDescriptor(HBaseNameUtils.getDomainTableName(domainClass))
            if (!existingTables.contains(tableDesc.getNameAsString())) {
                tableManager.createDomainTable(domainClass, createIndexedTables)
                LOG.debug("Adding table for Domain Class $domainClass")
            }
        }
    }

    application.domainClasses.each {domainClass ->
        LOG.debug("Adding dbms related methods to Domain Class $domainClass")
        def domainClassManager = new HBaseDomainClassManager()
        domainClassManager.createQueryMethods(domainClass)
        domainClassManager.createPersistenceMethods(domainClass)
        domainClassManager.addLazyLoadingSupport(domainClass)
        domainClassManager.addDynamicFinders(domainClass)
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文