public SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { //SqlString result = new SqlString(criteriaQuery.GetSQLAlias(criteria)); //result.Replace(sql, "{alias}"); //return result; return(new SqlString(StringHelper.Replace(sql, "{alias}", criteriaQuery.GetSQLAlias(criteria)))); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { string entityName = criteriaQuery.GetEntityName(criteria, propertyName); string actualPropertyName = criteriaQuery.GetPropertyName(propertyName); string sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName); ISessionFactoryImplementor factory = criteriaQuery.Factory; IQueryableCollection collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory); string[] collectionKeys = collectionPersister.KeyColumnNames; string[] ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames; StringBuilder innerSelect = new StringBuilder(); innerSelect.Append("(select 1 from ") .Append(collectionPersister.TableName) .Append(" where ") .Append( new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment()); if (collectionPersister.HasWhere) { innerSelect.Append(" and (") .Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName)) .Append(") "); } innerSelect.Append(")"); return new SqlString(new string[] {ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString()}); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { var entityName = criteriaQuery.GetEntityName(criteria, propertyName); var actualPropertyName = criteriaQuery.GetPropertyName(propertyName); var sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName); var factory = criteriaQuery.Factory; var collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory); var collectionKeys = collectionPersister.KeyColumnNames; var ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames; var innerSelect = new StringBuilder(); innerSelect.Append("(select 1 from ") .Append(collectionPersister.TableName) .Append(" where ") .Append( new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment()); if (collectionPersister.HasWhere) { innerSelect.Append(" and (") .Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName)) .Append(") "); } innerSelect.Append(")"); return(new SqlString(new object[] { ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString() })); }
public SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { string entityName = criteriaQuery.GetEntityName(criteria, propertyName); string actualPropertyName = criteriaQuery.GetPropertyName(propertyName); string sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName); ISessionFactoryImplementor factory = criteriaQuery.Factory; IQueryableCollection collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory); string[] collectionKeys = collectionPersister.KeyColumnNames; string[] ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames; StringBuilder innerSelect = new StringBuilder(); innerSelect.Append("(select 1 from ") .Append(collectionPersister.TableName) .Append(" where ") .Append( new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment()); if (collectionPersister.HasWhere) { innerSelect.Append(" and (") .Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName)) .Append(") "); } innerSelect.Append(")"); return(new SqlString(new string[] { ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString() })); }
public SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery) { //SqlString result = new SqlString(criteriaQuery.GetSQLAlias(criteria)); //result.Replace(sql, "{alias}"); //return result; return(new SqlString(StringHelper.Replace(sql, "{alias}", criteriaQuery.GetSQLAlias(criteria)))); }
public SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { //SqlString result = new SqlString(criteriaQuery.GetSQLAlias(criteria)); //result.Replace(sql, "{alias}"); //return result; return new SqlString(StringHelper.Replace(sql, "{alias}", criteriaQuery.GetSQLAlias(criteria))); }
public SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery) { //SqlString result = new SqlString(criteriaQuery.GetSQLAlias(criteria)); //result.Replace(sql, "{alias}"); //return result; return new SqlString(StringHelper.Replace(sql, "{alias}", criteriaQuery.GetSQLAlias(criteria))); }
///<summary> /// HQL 문을 생성한다. ///</summary> ///<exception cref="QueryException"></exception> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { string alias; Type targetType; ICriteria aliasedCriteria; if (_propertyNameOrAlias.IsWhiteSpace()) { alias = criteriaQuery.GetSQLAlias(criteria); string entityName = criteriaQuery.GetEntityName(criteria); targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco); } else if ((aliasedCriteria = criteria.GetCriteriaByAlias(_propertyNameOrAlias)) != null) { alias = criteriaQuery.GetSQLAlias(aliasedCriteria); string entityName = criteriaQuery.GetEntityName(aliasedCriteria); targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco); } else { alias = criteriaQuery.GetSQLAlias(criteria, _propertyNameOrAlias); var type = criteriaQuery.GetTypeUsingProjection(criteria, _propertyNameOrAlias); if (!type.IsEntityType) { throw new QueryException("Only entities can be used with an IsAExpression"); } targetType = type.ReturnedClass; } if (!targetType.IsAssignableFrom(_entityClass)) { return(new SqlString("1=0")); } var queryable = ObtainQueryable(criteriaQuery); var condition = queryable.WhereJoinFragment(alias, true, true); if (condition.IndexOfCaseInsensitive(" and ") == 0) { condition = condition.Substring(5); } return((condition.Length > 0) ? condition : new SqlString("1=1")); }
private void SetFields(ICriteriaQuery criteriaQuery) { //Persister is required, so let's use it as "initialized marker" if (Persister != null) { return; } if (!(criteriaQuery is ISupportEntityProjectionCriteriaQuery entityProjectionQuery)) { throw new ArgumentException( $"Projecting to entities requires a '{criteriaQuery.GetType().FullName}' type to implement " + $"{nameof(ISupportEntityProjectionCriteriaQuery)} interface.", nameof(criteriaQuery)); } var criteria = entityProjectionQuery.RootCriteria; if (!Lazy) { entityProjectionQuery.RegisterEntityProjection(this); } if (_entityType == null) { _entityType = criteria.GetRootEntityTypeIfAvailable(); } if (_entityAlias == null) { _entityAlias = criteria.Alias; } Persister = criteriaQuery.Factory.GetEntityPersister(_entityType.FullName) as IQueryable; if (Persister == null) { throw new HibernateException($"Projecting to entities requires a '{typeof(IQueryable).FullName}' persister, '{_entityType.FullName}' does not have one."); } ICriteria subcriteria = criteria.GetCriteriaByAlias(_entityAlias); if (subcriteria == null) { throw new HibernateException($"Criteria\\QueryOver alias '{_entityAlias}' for entity projection is not found."); } TableAlias = criteriaQuery.GetSQLAlias( subcriteria, Persister.IdentifierPropertyName ?? string.Empty); ColumnAliasSuffix = BasicLoader.GenerateSuffix(criteriaQuery.GetIndexForAlias()); _identifierColumnAliases = Persister.GetIdentifierAliases(ColumnAliasSuffix); _types = new IType[] { TypeFactory.ManyToOne(Persister.EntityName, true) }; }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { string alias = null; Type targetType = null; ICriteria aliasedCriteria; if (string.IsNullOrEmpty(_alias)) { alias = criteriaQuery.GetSQLAlias(criteria); string entityName = criteriaQuery.GetEntityName(criteria); targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco); } else if ((aliasedCriteria = criteria.GetCriteriaByAlias(_alias)) != null) { alias = criteriaQuery.GetSQLAlias(aliasedCriteria); string entityName = criteriaQuery.GetEntityName(aliasedCriteria); targetType = criteriaQuery.Factory.GetEntityPersister(entityName).GetMappedClass(EntityMode.Poco); } if (targetType == null || !targetType.IsAssignableFrom(_entityClass)) { return(new SqlString("1=0")); } IQueryable queryable = ObtainQueryable(criteriaQuery); string condition = queryable.FilterFragment(alias, enabledFilters); if (condition.IndexOf(" and ", StringComparison.InvariantCultureIgnoreCase) == 0) { condition = condition.Substring(5); } if (condition == string.Empty) { condition = "1=1"; } return(new SqlString(condition)); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { var parameters = _sql.GetParameters().ToList(); var paramPos = 0; for (int i = 0; i < _typedValues.Length; i++) { var controlledParameters = criteriaQuery.NewQueryParameter(_typedValues[i]); foreach (Parameter parameter in controlledParameters) { parameters[paramPos++].BackTrack = parameter.BackTrack; } } return _sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria)); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { var parameters = _sql.GetParameters().ToList(); var paramPos = 0; for (int i = 0; i < _typedValues.Length; i++) { var controlledParameters = criteriaQuery.NewQueryParameter(_typedValues[i]); foreach (Parameter parameter in controlledParameters) { parameters[paramPos++].BackTrack = parameter.BackTrack; } } return(criteriaQuery.RenderSQLAliases(_sql).Replace("{alias}", criteriaQuery.GetSQLAlias(criteria))); }
/// <summary> /// Render a SqlString for the expression. /// </summary> /// <param name="criteria"></param> /// <param name="criteriaQuery"></param> /// <param name="enabledFilters"></param> /// <returns> /// A SqlString that contains a valid Sql fragment. /// </returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { IEnumerable <Parameter> parameters = criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)); Parameter p = null; foreach (Parameter p_ in parameters) { p = p_; } //Parameter[] p = criteriaQuery.NewQueryParameter(GetTypedValues(criteria, criteriaQuery)[0]).ToArray(); ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect; string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName); IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName); if (typeUsingProjection.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), this.propertyName)); } string[] keyColumns = criteriaQuery.GetIdentifierColumns(criteria); string entityType = criteriaQuery.GetEntityName(criteria, this.propertyName); AbstractEntityPersister entityPersister = (AbstractEntityPersister)criteriaQuery.Factory.GetEntityPersister(entityType); // Only one key column is assumed string keyColumn = keyColumns[0]; string alias = criteriaQuery.GetSQLAlias(criteria, this.propertyName); string tableName = entityPersister.TableName; int aliasLength = alias.Length + 1; SqlStringBuilder builder = new SqlStringBuilder(10 * columnsUsingProjection.Length); for (int i = 0; i < columnsUsingProjection.Length; i++) { if (i > 0) { builder.Add(" AND "); } string geometryColumn = columnsUsingProjection[i].Remove(0, aliasLength); builder.Add(spatialDialect.GetSpatialFilterString(alias, geometryColumn, keyColumn, tableName, p)); } return(builder.ToSqlString()); }
/// <summary> /// Render a SqlString for the expression. /// </summary> /// <param name="criteria"></param> /// <param name="criteriaQuery"></param> /// <param name="enabledFilters"></param> /// <returns> /// A SqlString that contains a valid Sql fragment. /// </returns> public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { //criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery)); ISpatialDialect spatialDialect = (ISpatialDialect)criteriaQuery.Factory.Dialect; string[] columnsUsingProjection = criteriaQuery.GetColumnsUsingProjection(criteria, this.propertyName); IType typeUsingProjection = criteriaQuery.GetTypeUsingProjection(criteria, this.propertyName); if (typeUsingProjection.IsCollectionType) { throw new QueryException(string.Format("cannot use collection property ({0}.{1}) directly in a criterion, use ICriteria.CreateCriteria instead", criteriaQuery.GetEntityName(criteria), this.propertyName)); } string[] keyColumns = criteriaQuery.GetIdentifierColumns(criteria); string entityType = criteriaQuery.GetEntityName(criteria, this.propertyName); AbstractEntityPersister entityPersister = (AbstractEntityPersister)criteriaQuery.Factory.GetEntityPersister(entityType); // Only one key column is assumed string keyColumn = keyColumns[0]; string alias = criteriaQuery.GetSQLAlias(criteria, this.propertyName); string tableName = entityPersister.TableName; int aliasLength = alias.Length + 1; SqlStringBuilder builder = new SqlStringBuilder(10 * columnsUsingProjection.Length); for (int i = 0; i < columnsUsingProjection.Length; i++) { if (i > 0) { builder.Add(" AND "); } string geometryColumn = columnsUsingProjection[i].Remove(0, aliasLength); builder.Add(spatialDialect.GetSpatialFilterString(alias, geometryColumn, keyColumn, tableName)); } return builder.ToSqlString(); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { return _sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria)); }
public SqlString ToSqlString(ICriteria criteria, int loc, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { return new SqlString(StringHelper.Replace(this.sql, "{alias}", criteriaQuery.GetSQLAlias(criteria))); }
private SqlString GetSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, string sqlTemplate) { return(criteriaQuery.RenderSQLAliases(new SqlString(sqlTemplate)).Replace("{alias}", criteriaQuery.GetSQLAlias(criteria))); }
public SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { return(new SqlString(StringHelper.Replace(groupBy, "{alias}", criteriaQuery.GetSQLAlias(criteria)))); }
public SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters) { return new SqlString(StringHelper.Replace(groupBy, "{alias}", criteriaQuery.GetSQLAlias(criteria))); }
public SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { return(new SqlString(StringHelper.Replace(groupBy, "{alias}", criteriaQuery.GetSQLAlias(criteria)))); }
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters) { return(_sql.Replace("{alias}", criteriaQuery.GetSQLAlias(criteria))); }
public SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery) { return new SqlString(StringHelper.Replace(groupBy, "{alias}", criteriaQuery.GetSQLAlias(criteria))); }