@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(); } }
@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; }
@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(); } } }
/** * 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())); }
/** * 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 ); }
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 ) ); } }
@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; } }
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; }
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; }
/** * 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() ) ); }
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(); }
@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 ) ); } }
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 ); }
/** * 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); }
/** * {@inheritDoc} */ @Override public SQLFunction getFulltextSQLFunction() { if (useFulltextFeature) { return getSpecificFulltextSQLFunction(); } return super.getFulltextSQLFunction(); }
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()); return sf == null ? null : sf.getReturnType(null, null); }
protected void beginFunctionTemplate(AST m, AST i) { MethodNode methodNode = ( MethodNode ) m; SQLFunction template = methodNode.getSQLFunction(); if ( template == null ) { // if template is null we just write the function out as it appears in the hql statement super.beginFunctionTemplate( m, i ); } else { // this function has a template -> redirect output and catch the arguments outputStack.addFirst( writer ); writer = new FunctionArguments(); } }
protected void endFunctionTemplate(AST m) { MethodNode methodNode = ( MethodNode ) m; SQLFunction template = methodNode.getSQLFunction(); if ( template == null ) { super.endFunctionTemplate( m ); } else { // this function has a template -> restore output, apply the template and write the result out FunctionArguments functionArguments = ( FunctionArguments ) writer; // TODO: Downcast to avoid using an interface? Yuck. writer = ( SqlWriter ) outputStack.removeFirst(); out( template.render( functionArguments.getArgs(), sessionFactory ) ); } }
/** * Locate a registered sql function by name, requiring that such a registered function exist. * * @param functionName The name of the function to locate * @return The sql function. * @throws QueryException Indicates no matching sql functions could be found. */ private SQLFunction requireSQLFunction(String functionName) { SQLFunction f = findSQLFunction( functionName ); if ( f == null ) { throw new QueryException( "Unable to find SQL function: " + functionName ); } return f; }
private String locateAppropriateDialectFunctionNameForAliasTest() { for (Iterator itr = getDialect().getFunctions().entrySet().iterator(); itr.hasNext(); ) { final Map.Entry entry = (Map.Entry) itr.next(); final SQLFunction function = (SQLFunction) entry.getValue(); if ( !function.hasArguments() && !function.hasParenthesesIfNoArguments() ) { return (String) entry.getKey(); } } return null; }
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) { super.afterConfigurationBuilt( mappings, dialect ); Collection children = mappings.getCollection( Parent.class.getName() + ".children" ); Component childComponents = ( Component ) children.getElement(); Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next(); SQLFunction lengthFunction = ( SQLFunction ) dialect.getFunctions().get( "length" ); if ( lengthFunction != null ) { ArrayList args = new ArrayList(); args.add( "bio" ); f.setFormula( lengthFunction.render( args, null ) ); } }
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 = getSessionFactoryImplementor().getSqlFunctionRegistry().findSQLFunction( "concat"); List list = new ArrayList(); list.add("'fat'"); list.add("'skinny'"); assertTranslation( "from Animal an where an.description = " + concat.render(list, getSessionFactoryImplementor()) ); }
private static String getPartOfTest(Tests test, String part, Integer limit) { if (test == null || ("input".equals(part) == false && "output".equals(part) == false)) { return ""; } String substr = null; SessionFactory sf = HibernateUtil.getSessionFactory(); if (sf instanceof SessionFactoryImplementor) { SessionFactoryImplementor sfi = (SessionFactoryImplementor) HibernateUtil.getSessionFactory(); Dialect dialect = sfi.getDialect(); if (dialect != null) { SQLFunction function = dialect.getFunctions().get("substr"); if (function != null) { substr = function.render(StringType.INSTANCE, Arrays.asList("input", 0, limit), sfi); } } } if (substr == null) { substr = String.format("substr('%s',%d,%d)", "input", 1, limit); } return (String) sf.getCurrentSession() .createCriteria(Tests.class) .setProjection( Projections.sqlProjection( substr + " as short", new String[]{"short"}, new Type[]{StringType.INSTANCE})) .add(Restrictions.idEq(test.getId())) .uniqueResult(); }
public SQLiteDialect() { registerColumnType(Types.BIT, "boolean"); registerColumnType(Types.TINYINT, "tinyint"); registerColumnType(Types.SMALLINT, "smallint"); registerColumnType(Types.INTEGER, "integer"); registerColumnType(Types.BIGINT, "bigint"); registerColumnType(Types.FLOAT, "float"); registerColumnType(Types.REAL, "real"); registerColumnType(Types.DOUBLE, "double"); registerColumnType(Types.NUMERIC, "numeric($p, $s)"); registerColumnType(Types.DECIMAL, "decimal"); registerColumnType(Types.CHAR, "char"); registerColumnType(Types.VARCHAR, "varchar($l)"); registerColumnType(Types.LONGVARCHAR, "longvarchar"); registerColumnType(Types.DATE, "date"); registerColumnType(Types.TIME, "time"); registerColumnType(Types.TIMESTAMP, "datetime"); registerColumnType(Types.BINARY, "blob"); registerColumnType(Types.VARBINARY, "blob"); registerColumnType(Types.LONGVARBINARY, "blob"); registerColumnType(Types.BLOB, "blob"); registerColumnType(Types.CLOB, "clob"); registerColumnType(Types.BOOLEAN, "boolean"); registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", "")); registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2")); registerFunction("quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING)); registerFunction("random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER)); registerFunction("round", new StandardSQLFunction("round")); registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING)); registerFunction("trim", new AbstractAnsiTrimEmulationFunction() { protected SQLFunction resolveBothSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)"); } protected SQLFunction resolveBothSpaceTrimFromFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)"); } protected SQLFunction resolveLeadingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)"); } protected SQLFunction resolveTrailingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)"); } protected SQLFunction resolveBothTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)"); } protected SQLFunction resolveLeadingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)"); } protected SQLFunction resolveTrailingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)"); } }); }
protected void reset() { metadataSourceQueue = new MetadataSourceQueue(); createReflectionManager(); classes = new HashMap<String,PersistentClass>(); imports = new HashMap<String,String>(); collections = new HashMap<String,Collection>(); tables = new TreeMap<String,Table>(); namedQueries = new HashMap<String,NamedQueryDefinition>(); namedSqlQueries = new HashMap<String,NamedSQLQueryDefinition>(); sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>(); namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>(); namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>( ); typeDefs = new HashMap<String,TypeDef>(); filterDefinitions = new HashMap<String, FilterDefinition>(); fetchProfiles = new HashMap<String, FetchProfile>(); auxiliaryDatabaseObjects = new ArrayList<AuxiliaryDatabaseObject>(); tableNameBinding = new HashMap(); columnNameBindingPerTable = new HashMap(); secondPasses = new ArrayList<SecondPass>(); propertyReferences = new ArrayList<Mappings.PropertyReference>(); extendsQueue = new HashMap<ExtendsQueueEntry, String>(); xmlHelper = new XMLHelper(); interceptor = EmptyInterceptor.INSTANCE; properties = Environment.getProperties(); entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER; sqlFunctions = new HashMap<String, SQLFunction>(); entityTuplizerFactory = new EntityTuplizerFactory(); // componentTuplizerFactory = new ComponentTuplizerFactory(); identifierGeneratorFactory = new DefaultIdentifierGeneratorFactory(); mappedSuperClasses = new HashMap<Class<?>, MappedSuperclass>(); metadataSourcePrecedence = Collections.emptyList(); namedGenerators = new HashMap<String, IdGenerator>(); joins = new HashMap<String, Map<String, Join>>(); classTypes = new HashMap<String, AnnotatedClassType>(); generatorTables = new HashMap<String, Properties>(); defaultNamedQueryNames = new HashSet<String>(); defaultNamedNativeQueryNames = new HashSet<String>(); defaultSqlResultSetMappingNames = new HashSet<String>(); defaultNamedProcedure = new HashSet<String>( ); defaultNamedGenerators = new HashSet<String>(); uniqueConstraintHoldersByTable = new HashMap<Table, List<UniqueConstraintHolder>>(); jpaIndexHoldersByTable = new HashMap<Table,List<JPAIndexHolder>>( ); mappedByResolver = new HashMap<String, String>(); propertyRefResolver = new HashMap<String, String>(); caches = new ArrayList<CacheHolder>(); namingStrategyDelegator = LegacyNamingStrategyDelegator.DEFAULT_INSTANCE; setEntityResolver( new EJB3DTDEntityResolver() ); anyMetaDefs = new HashMap<String, AnyMetaDef>(); propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String, PropertyData>>(); propertiesAnnotatedWithIdAndToOne = new HashMap<XClass, Map<String, PropertyData>>(); specjProprietarySyntaxEnabled = System.getProperty( "hibernate.enable_specj_proprietary_syntax" ) != null; }
public void addSqlFunction(String functionName, SQLFunction function) { // HHH-7721: SQLFunctionRegistry expects all lowercase. Enforce, // just in case a user's customer dialect uses mixed cases. sqlFunctions.put( functionName.toLowerCase(), function ); }
protected SQLFunction getFunction(CriteriaQuery criteriaQuery) { return getFunction( getFunctionName(), criteriaQuery ); }
protected void registerFunction(String name, SQLFunction function) { // HHH-7721: SQLFunctionRegistry expects all lowercase. Enforce, // just in case a user's customer dialect uses mixed cases. sqlFunctions.put( name.toLowerCase(), function ); }
public SQLFunction getSQLFunction() { return sqlFunction; }
@Override public SQLFunction getSQLFunction() { return function; }
@Override public SQLFunction getSQLFunction() { return dialectCastFunction; }
private SQLFunction getFunction(String name, QueryTranslatorImpl q) { return q.getFactory().getSqlFunctionRegistry().findSQLFunction( name ); }
public SQLiteDialect() { registerColumnType(Types.BIT, "boolean"); registerColumnType(Types.TINYINT, "tinyint"); registerColumnType(Types.SMALLINT, "smallint"); registerColumnType(Types.INTEGER, "integer"); registerColumnType(Types.BIGINT, "bigint"); registerColumnType(Types.FLOAT, "float"); registerColumnType(Types.REAL, "real"); registerColumnType(Types.DOUBLE, "double"); registerColumnType(Types.NUMERIC, "numeric($p, $s)"); registerColumnType(Types.DECIMAL, "decimal"); registerColumnType(Types.CHAR, "char"); registerColumnType(Types.VARCHAR, "varchar($l)"); registerColumnType(Types.LONGVARCHAR, "longvarchar"); registerColumnType(Types.DATE, "date"); registerColumnType(Types.TIME, "time"); registerColumnType(Types.TIMESTAMP, "datetime"); registerColumnType(Types.BINARY, "blob"); registerColumnType(Types.VARBINARY, "blob"); registerColumnType(Types.LONGVARBINARY, "blob"); registerColumnType(Types.BLOB, "blob"); registerColumnType(Types.CLOB, "clob"); registerColumnType(Types.BOOLEAN, "boolean"); //registerFunction( "abs", new StandardSQLFunction("abs") ); registerFunction( "concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", "") ); //registerFunction( "length", new StandardSQLFunction("length", StandardBasicTypes.LONG) ); //registerFunction( "lower", new StandardSQLFunction("lower") ); registerFunction( "mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2" ) ); registerFunction( "quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING) ); registerFunction( "random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER) ); registerFunction( "round", new StandardSQLFunction("round") ); registerFunction( "substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING) ); registerFunction( "substring", new SQLFunctionTemplate( StandardBasicTypes.STRING, "substr(?1, ?2, ?3)" ) ); registerFunction( "trim", new AbstractAnsiTrimEmulationFunction() { protected SQLFunction resolveBothSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)"); } protected SQLFunction resolveBothSpaceTrimFromFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)"); } protected SQLFunction resolveLeadingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)"); } protected SQLFunction resolveTrailingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)"); } protected SQLFunction resolveBothTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)"); } protected SQLFunction resolveLeadingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)"); } protected SQLFunction resolveTrailingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)"); } } ); //registerFunction( "upper", new StandardSQLFunction("upper") ); }
public SQLiteDialect() { registerColumnType(Types.BIT, "boolean"); registerColumnType(Types.TINYINT, "tinyint"); registerColumnType(Types.SMALLINT, "smallint"); registerColumnType(Types.INTEGER, "integer"); registerColumnType(Types.BIGINT, "bigint"); registerColumnType(Types.FLOAT, "float"); registerColumnType(Types.REAL, "real"); registerColumnType(Types.DOUBLE, "double"); registerColumnType(Types.NUMERIC, "numeric($p, $s)"); registerColumnType(Types.DECIMAL, "decimal"); registerColumnType(Types.CHAR, "char"); registerColumnType(Types.VARCHAR, "varchar($l)"); registerColumnType(Types.LONGVARCHAR, "longvarchar"); registerColumnType(Types.DATE, "date"); registerColumnType(Types.TIME, "time"); registerColumnType(Types.TIMESTAMP, "datetime"); registerColumnType(Types.BINARY, "blob"); registerColumnType(Types.VARBINARY, "blob"); registerColumnType(Types.LONGVARBINARY, "blob"); registerColumnType(Types.BLOB, "blob"); registerColumnType(Types.CLOB, "clob"); registerColumnType(Types.BOOLEAN, "boolean"); registerFunction( "concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", "") ); registerFunction( "mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2" ) ); registerFunction( "quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING) ); registerFunction( "random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER) ); registerFunction( "round", new StandardSQLFunction("round") ); registerFunction( "substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING) ); registerFunction( "trim", new AbstractAnsiTrimEmulationFunction() { protected SQLFunction resolveBothSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)"); } protected SQLFunction resolveBothSpaceTrimFromFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)"); } protected SQLFunction resolveLeadingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)"); } protected SQLFunction resolveTrailingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)"); } protected SQLFunction resolveBothTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)"); } protected SQLFunction resolveLeadingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)"); } protected SQLFunction resolveTrailingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)"); } } ); uniqueDelegate = new SQLiteUniqueDelegate( this ); }
public SQLiteDialect() { registerColumnType(Types.BIT, "boolean"); // registerColumnType(Types.TINYINT, "tinyint"); // registerColumnType(Types.SMALLINT, "smallint"); // registerColumnType(Types.INTEGER, "integer"); // registerColumnType(Types.BIGINT, "bigint"); // registerColumnType(Types.FLOAT, "float"); // registerColumnType(Types.REAL, "real"); // registerColumnType(Types.DOUBLE, "double"); // registerColumnType(Types.NUMERIC, "numeric($p, $s)"); registerColumnType(Types.DECIMAL, "decimal"); registerColumnType(Types.CHAR, "char"); registerColumnType(Types.VARCHAR, "varchar($l)"); registerColumnType(Types.LONGVARCHAR, "longvarchar"); // registerColumnType(Types.DATE, "date"); // registerColumnType(Types.TIME, "time"); registerColumnType(Types.TIMESTAMP, "datetime"); registerColumnType(Types.BINARY, "blob"); registerColumnType(Types.VARBINARY, "blob"); registerColumnType(Types.LONGVARBINARY, "blob"); // registerColumnType(Types.BLOB, "blob"); // registerColumnType(Types.CLOB, "clob"); // registerColumnType(Types.BOOLEAN, "boolean"); registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", "")); registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2")); registerFunction("quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING)); registerFunction("random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER)); registerFunction("round", new StandardSQLFunction("round")); registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING)); registerFunction("trim", new AbstractAnsiTrimEmulationFunction() { @Override protected SQLFunction resolveBothSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)"); } @Override protected SQLFunction resolveBothSpaceTrimFromFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)"); } @Override protected SQLFunction resolveLeadingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)"); } @Override protected SQLFunction resolveTrailingSpaceTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)"); } @Override protected SQLFunction resolveBothTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)"); } @Override protected SQLFunction resolveLeadingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)"); } @Override protected SQLFunction resolveTrailingTrimFunction() { return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)"); } }); uniqueDelegate = new SQLiteUniqueDelegate(this); }
protected String render(BasicType basic, List<String> columns, SessionFactory sessionFactory, SQLFunction sqlFunction) { return sqlFunction.render(basic, columns, (SessionFactoryImplementor) sessionFactory); }
/** * {@inheritDoc} Will return s SQL Function rendering the "CONTAINS" of MSSQL */ @Override protected SQLFunction getSpecificFulltextSQLFunction() { return new MSSQLServerFulltextFunction(); }
/** * {@inheritDoc} Will return s SQL Function rendering the "CONTAINS" of Oracle */ @Override protected SQLFunction getSpecificFulltextSQLFunction() { return new OracleFulltextFunction(); }