4
4
*/
5
5
package org .hibernate .sql ;
6
6
7
- import java .util .ArrayList ;
8
- import java .util .HashMap ;
9
- import java .util .HashSet ;
10
- import java .util .List ;
11
- import java .util .Map ;
12
- import java .util .Set ;
13
-
14
7
import org .hibernate .Internal ;
15
8
import org .hibernate .LockMode ;
16
9
import org .hibernate .LockOptions ;
17
10
import org .hibernate .dialect .Dialect ;
18
11
import org .hibernate .engine .jdbc .spi .JdbcServices ;
19
12
import org .hibernate .engine .spi .SessionFactoryImplementor ;
13
+ import org .hibernate .internal .util .StringHelper ;
14
+ import org .hibernate .sql .ast .internal .ParameterMarkerStrategyStandard ;
20
15
import org .hibernate .sql .ast .spi .ParameterMarkerStrategy ;
21
16
17
+ import java .util .ArrayList ;
18
+ import java .util .HashMap ;
19
+ import java .util .HashSet ;
20
+ import java .util .List ;
21
+ import java .util .Map ;
22
+ import java .util .Set ;
23
+
22
24
/**
23
25
* A SQL {@code SELECT} statement with no table joins.
24
26
*
27
29
@ Internal
28
30
public class SimpleSelect implements RestrictionRenderingContext {
29
31
protected String tableName ;
32
+ protected String tableAlias ;
30
33
protected String orderBy ;
31
34
protected String comment ;
32
35
@@ -46,6 +49,15 @@ public SimpleSelect(final SessionFactoryImplementor factory) {
46
49
this .parameterMarkerStrategy = jdbcServices .getParameterMarkerStrategy ();
47
50
}
48
51
52
+ public SimpleSelect (Dialect dialect ) {
53
+ this ( dialect , dialect .getNativeParameterMarkerStrategy () );
54
+ }
55
+
56
+ public SimpleSelect (Dialect dialect , ParameterMarkerStrategy parameterMarkerStrategy ) {
57
+ this .dialect = dialect ;
58
+ this .parameterMarkerStrategy = parameterMarkerStrategy ;
59
+ }
60
+
67E6
code>
49
61
@ Override
50
62
public String makeParameterMarker () {
51
63
return parameterMarkerStrategy .createMarker ( ++parameterCount , null );
@@ -55,7 +67,15 @@ public String makeParameterMarker() {
55
67
* Sets the name of the table we are selecting from
56
68
*/
57
69
public SimpleSelect setTableName (String tableName ) {
70
+ return setTableName ( tableName , null );
71
+ }
72
+
73
+ /**
74
+ * Sets the name of the table we are selecting from
75
+ */
76
+ public SimpleSelect setTableName (String tableName , String tableAlias ) {
58
77
this .tableName = tableName ;
78
+ this .tableAlias = tableAlias ;
59
79
return this ;
60
80
}
61
81
@@ -205,6 +225,9 @@ private void applySelectClause(StringBuilder buf) {
205
225
206
226
private void applyFromClause (StringBuilder buf ) {
207
227
buf .append ( " from " ).append ( dialect .appendLockHint ( lockOptions , tableName ) );
228
+ if ( StringHelper .isNotEmpty ( tableAlias ) ) {
229
+ buf .append ( " as " ).append ( tableAlias );
230
+ }
208
231
}
209
232
210
233
private void applyWhereClause (StringBuilder buf ) {
0 commit comments