-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...b/src/main/java/org/hswebframework/ezorm/rdb/supports/mssql/SqlServerQuerySqlBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.hswebframework.ezorm.rdb.supports.mssql; | ||
|
||
import org.hswebframework.ezorm.rdb.executor.SqlRequest; | ||
import org.hswebframework.ezorm.rdb.metadata.RDBFeatureType; | ||
import org.hswebframework.ezorm.rdb.metadata.RDBSchemaMetadata; | ||
import org.hswebframework.ezorm.rdb.metadata.TableOrViewMetadata; | ||
import org.hswebframework.ezorm.rdb.operator.builder.DefaultQuerySqlBuilder; | ||
import org.hswebframework.ezorm.rdb.operator.builder.FragmentBlock; | ||
import org.hswebframework.ezorm.rdb.operator.builder.Paginator; | ||
import org.hswebframework.ezorm.rdb.operator.builder.fragments.BlockSqlFragments; | ||
import org.hswebframework.ezorm.rdb.operator.builder.fragments.PrepareSqlFragments; | ||
import org.hswebframework.ezorm.rdb.operator.builder.fragments.SqlFragments; | ||
import org.hswebframework.ezorm.rdb.operator.dml.query.QueryOperatorParameter; | ||
|
||
class SqlServerQuerySqlBuilder extends DefaultQuerySqlBuilder { | ||
public SqlServerQuerySqlBuilder(RDBSchemaMetadata schema) { | ||
super(schema); | ||
} | ||
|
||
protected SqlRequest build(TableOrViewMetadata metadata, QueryOperatorParameter parameter) { | ||
BlockSqlFragments fragments = BlockSqlFragments.of(); | ||
|
||
fragments.addBlock(FragmentBlock.before, "select"); | ||
|
||
fragments.addBlock(FragmentBlock.selectColumn, select(parameter, metadata) | ||
.orElseGet(() -> PrepareSqlFragments.of().addSql("*"))); | ||
|
||
fragments.addBlock(FragmentBlock.selectFrom, from(metadata, parameter)); | ||
|
||
|
||
if (Boolean.TRUE.equals(parameter.getForUpdate())) { | ||
fragments.addBlock(FragmentBlock.selectFrom, PrepareSqlFragments.of().addSql("with(updlock)")); | ||
} | ||
|
||
join(parameter, metadata) | ||
.ifPresent(join -> fragments.addBlock(FragmentBlock.join, join)); | ||
//where | ||
|
||
where(parameter, metadata) | ||
.ifPresent(where -> | ||
fragments.addBlock(FragmentBlock.where, "where") | ||
.addBlock(FragmentBlock.where, where)); | ||
|
||
//group by | ||
|
||
//having | ||
|
||
//order by | ||
orderBy(parameter, metadata) | ||
.ifPresent(order -> fragments.addBlock(FragmentBlock.orderBy, "order by") | ||
.addBlock(FragmentBlock.orderBy, order)); | ||
|
||
//分页 | ||
if (!Boolean.TRUE.equals(parameter.getForUpdate()) && parameter.getPageIndex() != null && parameter.getPageSize() != null) { | ||
return metadata.<Paginator>findFeature(RDBFeatureType.paginator.getId()) | ||
.map(paginator -> paginator.doPaging(fragments, parameter.getPageIndex(), parameter.getPageSize())) | ||
.map(SqlFragments::toRequest) | ||
.orElseGet(fragments::toRequest); | ||
|
||
} | ||
return fragments.toRequest(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters