本文整理汇总了Java中org.hibernate.dialect.function.SQLFunction类的典型用法代码示例。如果您正苦于以下问题:Java SQLFunction类的具体用法?Java SQLFunction怎么用?Java SQLFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SQLFunction类属于org.hibernate.dialect.function包,在下文中一共展示了SQLFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isFunctionName
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
@Override
@SuppressWarnings("SimplifiableIfStatement")
protected boolean isFunctionName(AST ast) {
/*
* Semantic predicate used to determine whether a given AST node represents a function call
*/
AST child = ast.getFirstChild();
// assume it is a function if it has parameters
if ( child != null && "{param list}".equals( child.getText() ) ) {
return true;
}
// otherwise, in order for this to be a function logically it has to be a function that does not
// have arguments. So try to assert that using the registry of known functions
final SQLFunction function = context.getSqlFunctionRegistry().findSQLFunction( ast.getText() );
if ( function == null ) {
// no registered function, so we cannot know for certain
return false;
}
else {
// if function.hasParenthesesIfNoArguments() is true, then assume the node is not a function
return ! function.hasParenthesesIfNoArguments();
}
}
示例2: getDataType
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
@Override
public Type getDataType() {
Type type = super.getDataType();
if ( type != null ) {
return type;
}
FromElement fe = getFromElement();
if ( fe != null ) {
return fe.getDataType();
}
SQLFunction sf = getWalker().getSessionFactoryHelper().findSQLFunction( getText() );
if ( sf != null ) {
return sf.getReturnType( null, getWalker().getSessionFactoryHelper().getFactory() );
}
return null;
}
示例3: beginFunctionTemplate
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
@Override
protected void beginFunctionTemplate(AST node, AST nameNode) {
// NOTE for AGGREGATE both nodes are the same; for METHOD the first is the METHOD, the second is the
// METHOD_NAME
FunctionNode functionNode = (FunctionNode) node;
SQLFunction sqlFunction = functionNode.getSQLFunction();
if ( sqlFunction == null ) {
// if SQLFunction is null we just write the function out as it appears in the hql statement
super.beginFunctionTemplate( node, nameNode );
}
else {
// this function has a registered SQLFunction -> redirect output and catch the arguments
outputStack.addFirst( writer );
if ( node.getType() == CAST ) {
writer = new CastFunctionArguments();
}
else {
writer = new StandardFunctionArguments();
}
}
}
示例4: configFulltext
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
/**
* Sets the SQLFunction depending on dialect in the configuration
*
* @param config
* the configuration
* @param databaseConfiguration
* the database configuration that will be used
*/
private void configFulltext(Configuration config, DatabaseConfiguration databaseConfiguration) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Fulltext feature is {}",
databaseConfiguration.isUseFulltextFeature() ? "supported" : "not supported");
}
config.addSqlFunction("fulltext", databaseConfiguration.getFulltextSQLFunction());
SQLFunction datePartSQLFunction = databaseConfiguration.getDatepartSQLFunction();
if (datePartSQLFunction != null) {
config.addSqlFunction("date_part", datePartSQLFunction);
}
LOGGER.info("Using databaseConfiguration: "
+ databaseConfiguration.getClass().getName()
+ " fulltext function: "
+ databaseConfiguration.getFulltextSQLFunction().getClass().getName()
+ " date_part function: "
+ (datePartSQLFunction == null ? "not supported." : datePartSQLFunction.getClass()
.getName()));
}
示例5: findFunctionReturnType
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
/**
* Find the function return type given the function name and the first argument expression node.
*
* @param functionName The function name.
* @param first The first argument expression.
* @return the function return type given the function name and the first argument expression node.
*/
public Type findFunctionReturnType(String functionName, AST first) {
// locate the registered function by the given name
SQLFunction sqlFunction = requireSQLFunction( functionName );
// determine the type of the first argument...
Type argumentType = null;
if ( first != null ) {
if ( "cast".equals(functionName) ) {
argumentType = TypeFactory.heuristicType( first.getNextSibling().getText() );
}
else if ( first instanceof SqlNode ) {
argumentType = ( (SqlNode) first ).getDataType();
}
}
return sqlFunction.getReturnType( argumentType, sfi );
}
示例6: afterConfigurationBuilt
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
super.afterConfigurationBuilt( mappings, dialect );
// Oracle and Postgres do not have year() functions, so we need to
// redefine the 'User.person.yob' formula
//
// consider temporary until we add the capability to define
// mapping foprmulas which can use dialect-registered functions...
PersistentClass user = mappings.getClass( User.class.getName() );
org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
Component component = ( Component ) personProperty.getValue();
Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
if ( yearFunction == null ) {
// the dialect not know to support a year() function, so rely on the
// ANSI SQL extract function
f.setFormula( "extract( year from dob )");
}
else {
List args = new ArrayList();
args.add( "dob" );
f.setFormula( yearFunction.render( args, null ) );
}
}
示例7: testClob
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
@Test
public void testClob() {
SessionFactoryImplementor sf = (SessionFactoryImplementor) HibernateUtil.getSessionFactory();
Session session = sf.getCurrentSession();
Dialect dialect = sf.getDialect();
SQLFunction function = dialect.getFunctions().get("substr");
String substr = function.render(StringType.INSTANCE, Arrays.asList("input", 0, 5), sf);
Transaction t = session.beginTransaction();
TestsDAO dao = HibernateDAOFactory.DEFAULT.buildTestsDAO();
for (Tests test : dao.findAll()) {
try {
System.out.println("Test: " + test.getId());
System.out.println("\tinput length: " + test.getInput().length());
System.out.println("\tCriterion: " + session.createCriteria(Tests.class).setProjection(
Projections.sqlProjection(substr + " as short", new String[]{"short"}, new Type[]{StringType.INSTANCE})
).add(Restrictions.idEq(test.getId())).uniqueResult());
} catch (Throwable throwable) {
throwable.printStackTrace(System.err);
}
break;
}
}
示例8: getFunction
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
protected SQLFunction getFunction(CriteriaQuery criteriaQuery) {
final SQLFunctionRegistry sqlFunctionRegistry = criteriaQuery.getFactory().getSqlFunctionRegistry();
final SQLFunction function = sqlFunctionRegistry.findSQLFunction( "count" );
if ( function == null ) {
throw new HibernateException( "Unable to locate count function mapping" );
}
return function;
}
示例9: getFunction
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
protected SQLFunction getFunction(String functionName, CriteriaQuery criteriaQuery) {
final SQLFunction function = criteriaQuery.getFactory()
.getSqlFunctionRegistry()
.findSQLFunction( functionName );
if ( function == null ) {
throw new HibernateException( "Unable to locate mapping for function named [" + functionName + "]" );
}
return function;
}
示例10: renderWhereStringTemplate
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
/**
* Same functionality as {@link #renderWhereStringTemplate(String, String, Dialect, SQLFunctionRegistry)},
* except that a SQLFunctionRegistry is not provided (i.e., only the dialect-defined functions are
* considered). This is only intended for use by the annotations project until the
* many-to-many/map-key-from-target-table feature is pulled into core.
*
* @deprecated Only intended for annotations usage; use {@link #renderWhereStringTemplate(String, String, Dialect, SQLFunctionRegistry)} instead
*/
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect) {
return renderWhereStringTemplate(
sqlWhereString,
placeholder,
dialect,
new SQLFunctionRegistry( dialect, java.util.Collections.<String, SQLFunction>emptyMap() )
);
}
示例11: isFunction
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
private static boolean isFunction(String lcToken, String nextToken, SQLFunctionRegistry functionRegistry) {
// checking for "(" is currently redundant because it is checked before getting here;
// doing the check anyhow, in case that earlier check goes away;
if ( "(".equals( nextToken ) ) {
return true;
}
SQLFunction function = functionRegistry.findSQLFunction(lcToken);
if ( function == null ) {
// lcToken does not refer to a function
return false;
}
// if function.hasParenthesesIfNoArguments() is true, then assume
// lcToken is not a function (since it is not followed by '(')
return ! function.hasParenthesesIfNoArguments();
}
示例12: endFunctionTemplate
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
@Override
protected void endFunctionTemplate(AST node) {
FunctionNode functionNode = (FunctionNode) node;
SQLFunction sqlFunction = functionNode.getSQLFunction();
if ( sqlFunction == null ) {
super.endFunctionTemplate( node );
}
else {
final Type functionType = functionNode.getFirstArgumentType();
// this function has a registered SQLFunction -> redirect output and catch the arguments
FunctionArgumentsCollectingWriter functionArguments = (FunctionArgumentsCollectingWriter) writer;
writer = outputStack.removeFirst();
out( sqlFunction.render( functionType, functionArguments.getArgs(), sessionFactory ) );
}
}
示例13: findFunctionReturnType
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
public Type findFunctionReturnType(String functionName, SQLFunction sqlFunction, AST firstArgument) {
// determine the type of the first argument...
Type argumentType = null;
if ( firstArgument != null ) {
if ( "cast".equals( functionName ) ) {
argumentType = sfi.getTypeResolver().heuristicType( firstArgument.getNextSibling().getText() );
}
else if ( SqlNode.class.isInstance( firstArgument ) ) {
argumentType = ( (SqlNode) firstArgument ).getDataType();
}
}
return sqlFunction.getReturnType( argumentType, sfi );
}
示例14: registerSQLFunction
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
/**
* Register a sql function in the session factory, after this call it can be used by queries.
*/
public void registerSQLFunction(String name, SQLFunction function) {
final DalSessionFactory dalSessionFactory = (DalSessionFactory) SessionFactoryController
.getInstance().getSessionFactory();
final Dialect dialect = ((SessionFactoryImpl) dalSessionFactory.getDelegateSessionFactory())
.getDialect();
dialect.getFunctions().put(name, function);
}
示例15: getFulltextSQLFunction
import org.hibernate.dialect.function.SQLFunction; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public SQLFunction getFulltextSQLFunction() {
if (useFulltextFeature) {
return getSpecificFulltextSQLFunction();
}
return super.getFulltextSQLFunction();
}