Search in sources :

Example 1 with ExtendedColumnDefinition

use of org.entando.entando.aps.system.init.model.ExtendedColumnDefinition in project entando-core by entando.

the class TableFactory method createTable.

private void createTable(Class tableClass, ConnectionSource connectionSource) throws Throwable {
    int result = 0;
    String logTableName = this.getDatabaseName() + "/" + getTableName(tableClass);
    try {
        result = ApsTableUtils.createTable(connectionSource, tableClass);
        if (result > 0) {
            _logger.info("Created table - {}", logTableName);
            Object tableModel = tableClass.newInstance();
            if (tableModel instanceof ExtendedColumnDefinition) {
                String[] extensions = ((ExtendedColumnDefinition) tableModel).extensions(this.getType());
                if (null != extensions && extensions.length > 0) {
                    Dao dao = DaoManager.createDao(connectionSource, tableClass);
                    for (int i = 0; i < extensions.length; i++) {
                        String query = extensions[i];
                        dao.executeRaw(query);
                    }
                }
            }
        } else {
            throw new RuntimeException("Error creating table from class " + logTableName);
        }
    } catch (Throwable t) {
        _logger.error("Error creating table {}", logTableName, t);
        if (result > 0) {
            TableUtils.dropTable(connectionSource, tableClass, true);
        }
        throw new ApsSystemException("Error creating table " + logTableName, t);
    }
}
Also used : Dao(com.j256.ormlite.dao.Dao) ExtendedColumnDefinition(org.entando.entando.aps.system.init.model.ExtendedColumnDefinition) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 Dao (com.j256.ormlite.dao.Dao)1 ExtendedColumnDefinition (org.entando.entando.aps.system.init.model.ExtendedColumnDefinition)1