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));
}
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));
}
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());
}
}
Aggregations