Search in sources :

Example 1 with Mapping

use of org.hibernate.engine.spi.Mapping in project hibernate-orm by hibernate.

the class InformixDialectTestCase method testCurrentTimestampFunction.

@Test
@TestForIssue(jiraKey = "HHH-10800")
public void testCurrentTimestampFunction() {
    Map<String, SQLFunction> functions = dialect.getFunctions();
    SQLFunction sqlFunction = functions.get("current_timestamp");
    Type firstArgumentType = null;
    Mapping mapping = null;
    assertEquals(StandardBasicTypes.TIMESTAMP, sqlFunction.getReturnType(firstArgumentType, mapping));
    firstArgumentType = null;
    List arguments = Collections.emptyList();
    SessionFactoryImplementor factory = null;
    assertEquals("current", sqlFunction.render(firstArgumentType, arguments, factory));
}
Also used : Type(org.hibernate.type.Type) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Mapping(org.hibernate.engine.spi.Mapping) List(java.util.List) SQLFunction(org.hibernate.dialect.function.SQLFunction) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with Mapping

use of org.hibernate.engine.spi.Mapping in project hibernate-orm by hibernate.

the class InformixDialectTestCase method testCurrentDateFunction.

@Test
@TestForIssue(jiraKey = "HHH-10800")
public void testCurrentDateFunction() {
    Map<String, SQLFunction> functions = dialect.getFunctions();
    SQLFunction sqlFunction = functions.get("current_date");
    Type firstArgumentType = null;
    Mapping mapping = null;
    assertEquals(StandardBasicTypes.DATE, sqlFunction.getReturnType(firstArgumentType, mapping));
    firstArgumentType = null;
    List arguments = Collections.emptyList();
    SessionFactoryImplementor factory = null;
    assertEquals("today", sqlFunction.render(firstArgumentType, arguments, factory));
}
Also used : Type(org.hibernate.type.Type) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Mapping(org.hibernate.engine.spi.Mapping) List(java.util.List) SQLFunction(org.hibernate.dialect.function.SQLFunction) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with Mapping

use of org.hibernate.engine.spi.Mapping in project uPortal by Jasig.

the class HibernateDbLoader method process.

@Override
public void process(DbLoaderConfig configuration) throws ParserConfigurationException, SAXException, IOException {
    final String scriptFile = configuration.getScriptFile();
    final List<String> script;
    if (scriptFile == null) {
        script = null;
    } else {
        script = new LinkedList<String>();
    }
    final ITableDataProvider tableData = this.loadTables(configuration, dialect);
    //Handle table drop/create
    if (configuration.isDropTables() || configuration.isCreateTables()) {
        //Load Table object model
        final Map<String, Table> tables = tableData.getTables();
        final Mapping mapping = this.configuration.buildMapping();
        final String defaultCatalog = this.configuration.getProperty(Environment.DEFAULT_CATALOG);
        final String defaultSchema = this.configuration.getProperty(Environment.DEFAULT_SCHEMA);
        final Map<String, DataAccessException> failedSql = new LinkedHashMap<String, DataAccessException>();
        //Generate and execute drop table scripts
        if (configuration.isDropTables()) {
            final List<String> dropScript = this.dropScript(tables.values(), dialect, defaultCatalog, defaultSchema);
            if (script == null) {
                this.logger.info("Dropping existing tables");
                for (final String sql : dropScript) {
                    this.logger.info(sql);
                    try {
                        jdbcOperations.update(sql);
                    } catch (NonTransientDataAccessResourceException dae) {
                        throw dae;
                    } catch (DataAccessException dae) {
                        failedSql.put(sql, dae);
                    }
                }
            } else {
                script.addAll(dropScript);
            }
        }
        //Log any drop/create statements that failed
        for (final Map.Entry<String, DataAccessException> failedSqlEntry : failedSql.entrySet()) {
            this.logger.warn("'" + failedSqlEntry.getKey() + "' failed to execute due to " + failedSqlEntry.getValue());
        }
        //Generate and execute create table scripts
        if (configuration.isCreateTables()) {
            final List<String> createScript = this.createScript(tables.values(), dialect, mapping, defaultCatalog, defaultSchema);
            if (script == null) {
                this.logger.info("Creating tables");
                for (final String sql : createScript) {
                    this.logger.info(sql);
                    jdbcOperations.update(sql);
                }
            } else {
                script.addAll(createScript);
            }
        }
    }
    //Perform database population
    if (script == null && configuration.isPopulateTables()) {
        this.logger.info("Populating database");
        final Map<String, Map<String, Integer>> tableColumnTypes = tableData.getTableColumnTypes();
        this.populateTables(configuration, tableColumnTypes);
    }
    //Write out the script file
    if (script != null) {
        for (final ListIterator<String> iterator = script.listIterator(); iterator.hasNext(); ) {
            final String sql = iterator.next();
            iterator.set(sql + ";");
        }
        final File outputFile = new File(scriptFile);
        FileUtils.writeLines(outputFile, script);
        this.logger.info("Saved DDL to: " + outputFile.getAbsolutePath());
    }
}
Also used : Table(org.hibernate.mapping.Table) Mapping(org.hibernate.engine.spi.Mapping) LinkedHashMap(java.util.LinkedHashMap) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) DataAccessException(org.springframework.dao.DataAccessException)

Aggregations

Mapping (org.hibernate.engine.spi.Mapping)3 List (java.util.List)2 SQLFunction (org.hibernate.dialect.function.SQLFunction)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 TestForIssue (org.hibernate.testing.TestForIssue)2 Type (org.hibernate.type.Type)2 Test (org.junit.Test)2 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Table (org.hibernate.mapping.Table)1 DataAccessException (org.springframework.dao.DataAccessException)1 NonTransientDataAccessResourceException (org.springframework.dao.NonTransientDataAccessResourceException)1