use of siena.core.options.QueryOption in project siena by mandubian.
the class JdbcPersistenceManager method appendSqlSearch.
public <T> void appendSqlSearch(QueryFilterSearch qf, Class<?> clazz, JdbcClassInfo info, StringBuilder sql, List<Object> parameters) {
List<String> cols = new ArrayList<String>();
try {
for (String field : qf.fields) {
Field f = Util.getField(clazz, field);
String[] columns = ClassInfo.getColumnNames(f, info.tableName);
for (String col : columns) {
cols.add(col);
}
}
QueryOption opt = qf.option;
if (opt != null) {
// only manages QueryOptionJdbcSearch
if (QueryOptionJdbcSearch.class.isAssignableFrom(opt.getClass())) {
if (((QueryOptionJdbcSearch) opt).booleanMode) {
sql.append("MATCH(" + Util.join(cols, ",") + ") AGAINST(? IN BOOLEAN MODE)");
} else {
}
} else {
sql.append("MATCH(" + Util.join(cols, ",") + ") AGAINST(?)");
}
} else {
// as mysql default search is fulltext and as it requires a FULLTEXT index,
// by default, we use boolean mode which works without fulltext index
sql.append("MATCH(" + Util.join(cols, ",") + ") AGAINST(? IN BOOLEAN MODE)");
}
parameters.add(qf.match);
} catch (Exception e) {
throw new SienaException(e);
}
}
use of siena.core.options.QueryOption in project siena by mandubian.
the class PostgresqlPersistenceManager method appendSqlSearch.
@Override
public <T> void appendSqlSearch(QueryFilterSearch qf, Class<?> clazz, JdbcClassInfo info, StringBuilder sql, List<Object> parameters) {
List<String> cols = new ArrayList<String>();
try {
for (String field : qf.fields) {
Field f = Util.getField(clazz, field);
Class<?> cl = f.getType();
// if a number or date, doesn't try to coalesce
if (Number.class.isAssignableFrom(cl) || Date.class.isAssignableFrom(cl)) {
String[] columns = ClassInfo.getColumnNames(f, info.tableName);
for (String col : columns) {
cols.add(col);
}
} else // if is model, gets the key type and does the same as herebefore
if (ClassInfo.isModel(cl)) {
ClassInfo ci = ClassInfo.getClassInfo(cl);
if (ci.keys.size() == 1) {
Field key = ci.keys.get(0);
if (Number.class.isAssignableFrom(key.getType()) || Date.class.isAssignableFrom(key.getType())) {
cols.add(f.getName());
} else {
cols.add("coalesce(" + f.getName() + ", '')");
}
} else {
for (Field key : ci.keys) {
String[] columns = ClassInfo.getColumnNamesWithPrefix(key, f.getName() + "_");
if (Number.class.isAssignableFrom(key.getType()) || Date.class.isAssignableFrom(key.getType())) {
for (String col : columns) {
cols.add(col);
}
} else {
for (String col : columns) {
cols.add("coalesce(" + col + ", '')");
}
}
}
}
} else {
String[] columns = ClassInfo.getColumnNames(f, info.tableName);
for (String col : columns) {
cols.add("coalesce(" + col + ", '')");
}
}
}
QueryOption opt = qf.option;
if (opt != null) {
// only manages QueryOptionJdbcSearch
if (QueryOptionPostgresqlSearch.class.isAssignableFrom(opt.getClass())) {
String lang = ((QueryOptionPostgresqlSearch) opt).language;
if (lang != null && !"".equals(lang)) {
sql.append("to_tsvector('" + lang + "', " + Util.join(cols, " || ' ' || ") + ") @@ to_tsquery(?)");
} else {
sql.append("to_tsvector('english', " + Util.join(cols, " || ' ' || ") + ") @@ to_tsquery(?)");
}
} else {
}
} else {
sql.append("to_tsvector('english', " + Util.join(cols, " || ' ' || ") + ") @@ to_tsquery(?)");
}
parameters.add(qf.match);
} catch (Exception e) {
throw new SienaException(e);
}
}
use of siena.core.options.QueryOption in project siena by mandubian.
the class AbstractPersistenceManager method release.
public <T> void release(Query<T> query) {
QueryOptionOffset offset = (QueryOptionOffset) query.option(QueryOptionOffset.ID);
QueryOption state = query.option(QueryOptionState.ID);
// resets offset
if (offset.isActive())
offset.offset = 0;
// disables reusable and cludge
if (state.isActive()) {
state.passivate();
}
}
use of siena.core.options.QueryOption in project siena by mandubian.
the class AbstractPersistenceManagerAsync method release.
public <T> void release(QueryAsync<T> query) {
QueryOptionOffset offset = (QueryOptionOffset) query.option(QueryOptionOffset.ID);
QueryOption reuse = query.option(QueryOptionState.ID);
// resets offset
if (offset.isActive())
offset.offset = 0;
// disables reusable and cludge
if (reuse.isActive()) {
reuse.passivate();
}
}
use of siena.core.options.QueryOption in project siena by mandubian.
the class BaseTest method testRestoreQueryOption.
public void testRestoreQueryOption() {
QueryOption optRestored = (QueryOption) JsonSerializer.deserialize(QueryOption.class, Json.loads("{\"type\":\"" + QueryOptionPage.class.getName() + "\", \"value\": {\"pageType\": \"TEMPORARY\", \"state\": \"PASSIVE\", \"pageSize\": 0, \"type\": 1} }"));
Query<PersonLongAutoID> query = pm.createQuery(PersonLongAutoID.class);
QueryOption opt = query.option(QueryOptionPage.ID);
assertEquals(opt, optRestored);
}
Aggregations