01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.rdbms.evaluation;
07:
08: /**
09: * Facilitates the building of a regular expression in SQL.
10: *
11: * @author James Leigh
12: *
13: */
14: public class SqlRegexBuilder {
15: private SqlExprBuilder where;
16: private SqlExprBuilder value;
17: private SqlExprBuilder pattern;
18: private SqlExprBuilder flags;
19:
20: public SqlRegexBuilder(SqlExprBuilder where,
21: QueryBuilderFactory factory) {
22: super ();
23: this .where = where;
24: value = factory.createSqlExprBuilder();
25: pattern = factory.createSqlExprBuilder();
26: flags = factory.createSqlExprBuilder();
27: }
28:
29: public SqlExprBuilder value() {
30: return value;
31: }
32:
33: public SqlExprBuilder pattern() {
34: return pattern;
35: }
36:
37: public SqlExprBuilder flags() {
38: return flags;
39: }
40:
41: public SqlExprBuilder close() {
42: appendRegExp(where);
43: return where;
44: }
45:
46: protected void appendRegExp(SqlExprBuilder where) {
47: where.append("REGEXP(");
48: appendValue(where);
49: where.append(", ");
50: appendPattern(where);
51: where.append(", ");
52: appendFlags(where);
53: where.append(")");
54: }
55:
56: protected SqlExprBuilder appendValue(SqlExprBuilder where) {
57: where.append(value.toSql());
58: where.addParameters(value.getParameters());
59: return where;
60: }
61:
62: protected SqlExprBuilder appendPattern(SqlExprBuilder where) {
63: where.append(pattern.toSql());
64: where.addParameters(pattern.getParameters());
65: return where;
66: }
67:
68: protected SqlExprBuilder appendFlags(SqlExprBuilder where) {
69: where.append(flags.toSql());
70: where.addParameters(flags.getParameters());
71: return where;
72: }
73: }
|