|
1
|
|
|
/* |
|
2
|
|
|
* Copyright 2014, Armenak Grigoryan, and individual contributors as indicated |
|
3
|
|
|
* by the @authors tag. See the copyright.txt in the distribution for a |
|
4
|
|
|
* full listing of individual contributors. |
|
5
|
|
|
* |
|
6
|
|
|
* This is free software; you can redistribute it and/or modify it |
|
7
|
|
|
* under the terms of the GNU Lesser General Public License as |
|
8
|
|
|
* published by the Free Software Foundation; either version 2.1 of |
|
9
|
|
|
* the License, or (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This software is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14
|
|
|
* Lesser General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
package com.strider.datadefender.database.sqlbuilder; |
|
18
|
|
|
|
|
19
|
|
|
import com.strider.datadefender.DbConfig; |
|
20
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
21
|
|
|
|
|
22
|
|
|
import lombok.extern.log4j.Log4j2; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Oracle implementation of the ISqlBuilder |
|
26
|
|
|
* |
|
27
|
|
|
* @author Armenak Grigoryan |
|
28
|
|
|
*/ |
|
29
|
|
|
@Log4j2 |
|
30
|
|
|
public class OracleSqlBuilder extends SqlBuilder { |
|
31
|
|
|
|
|
32
|
|
|
public OracleSqlBuilder(DbConfig config) { |
|
33
|
|
|
super(config); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Uses ROWNUM to limit the passed query. |
|
38
|
|
|
* |
|
39
|
|
|
* @param sqlString |
|
40
|
|
|
* @param limit |
|
41
|
|
|
* @return |
|
42
|
|
|
*/ |
|
43
|
|
|
@Override |
|
44
|
|
|
public String buildSelectWithLimit(final String sqlString, final int limit) { |
|
45
|
|
|
String sql = "SELECT q.* FROM (" + StringUtils.stripEnd(sqlString.trim(), ";") + ") q WHERE ROWNUM <= " + limit; |
|
46
|
|
|
log.debug("Query after adding limit: [{}]", sql); |
|
47
|
|
|
return sql; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|