use of org.hibernate.dialect.function.SQLFunction 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.dialect.function.SQLFunction 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.dialect.function.SQLFunction in project hibernate-orm by hibernate.
the class CompositeElementTest method afterMetadataBuilt.
@Override
protected void afterMetadataBuilt(Metadata metadata) {
Collection children = metadata.getCollectionBinding(Parent.class.getName() + ".children");
Component childComponents = (Component) children.getElement();
Formula f = (Formula) childComponents.getProperty("bioLength").getValue().getColumnIterator().next();
SQLFunction lengthFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get("length");
if (lengthFunction != null) {
ArrayList args = new ArrayList();
args.add("bio");
f.setFormula(lengthFunction.render(StandardBasicTypes.INTEGER, args, null));
}
}
use of org.hibernate.dialect.function.SQLFunction in project hibernate-orm by hibernate.
the class FunctionNameAsColumnTest method testGetMultiColumnSameNameAsNoArgFunctionCriteria.
@Test
public void testGetMultiColumnSameNameAsNoArgFunctionCriteria() {
SQLFunction function = sessionFactory().getSqlFunctionRegistry().findSQLFunction("current_date");
if (function == null || function.hasParenthesesIfNoArguments()) {
SkipLog.reportSkip("current_date reuires ()", "tests noarg function that does not require ()");
return;
}
Session s = openSession();
Transaction t = s.beginTransaction();
EntityWithNoArgFunctionAsColumn e1 = new EntityWithNoArgFunctionAsColumn();
e1.setCurrentDate("blah blah blah");
EntityWithNoArgFunctionAsColumn e2 = new EntityWithNoArgFunctionAsColumn();
e2.setCurrentDate("yadda yadda yadda");
EntityWithFunctionAsColumnHolder holder1 = new EntityWithFunctionAsColumnHolder();
holder1.getEntityWithNoArgFunctionAsColumns().add(e1);
EntityWithFunctionAsColumnHolder holder2 = new EntityWithFunctionAsColumnHolder();
holder2.getEntityWithNoArgFunctionAsColumns().add(e2);
holder1.setNextHolder(holder2);
s.save(holder1);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
holder1 = (EntityWithFunctionAsColumnHolder) s.createCriteria(EntityWithFunctionAsColumnHolder.class).add(Restrictions.isNotNull("nextHolder")).setFetchMode("entityWithNoArgFunctionAsColumns", FetchMode.JOIN).setFetchMode("nextHolder", FetchMode.JOIN).setFetchMode("nextHolder.entityWithNoArgFunctionAsColumns", FetchMode.JOIN).uniqueResult();
assertTrue(Hibernate.isInitialized(holder1.getEntityWithNoArgFunctionAsColumns()));
assertTrue(Hibernate.isInitialized(holder1.getNextHolder()));
assertTrue(Hibernate.isInitialized(holder1.getNextHolder().getEntityWithNoArgFunctionAsColumns()));
assertEquals(1, holder1.getEntityWithNoArgFunctionAsColumns().size());
e1 = (EntityWithNoArgFunctionAsColumn) holder1.getEntityWithNoArgFunctionAsColumns().iterator().next();
assertEquals("blah blah blah", e1.getCurrentDate());
assertEquals(1, holder1.getNextHolder().getEntityWithNoArgFunctionAsColumns().size());
e2 = (EntityWithNoArgFunctionAsColumn) (holder1.getNextHolder()).getEntityWithNoArgFunctionAsColumns().iterator().next();
assertEquals("yadda yadda yadda", e2.getCurrentDate());
t.commit();
s.close();
cleanup();
}
use of org.hibernate.dialect.function.SQLFunction in project hibernate-orm by hibernate.
the class HQLTest method testExpressionInFunction.
@SuppressWarnings({ "unchecked" })
@Test
public void testExpressionInFunction() throws Exception {
assertTranslation("from Animal an where an.bodyWeight > abs(3-5)");
assertTranslation("from Animal an where an.bodyWeight > abs(3/5)");
assertTranslation("from Animal an where an.bodyWeight > abs(3+5)");
assertTranslation("from Animal an where an.bodyWeight > abs(3*5)");
SQLFunction concat = sessionFactory().getSqlFunctionRegistry().findSQLFunction("concat");
List list = new ArrayList();
list.add("'fat'");
list.add("'skinny'");
assertTranslation("from Animal an where an.description = " + concat.render(StringType.INSTANCE, list, sessionFactory()));
}
Aggregations