use of siena.QueryFilterSearch in project siena by mandubian.
the class H2PersistenceManager method doSearchCount.
protected <T> int doSearchCount(Query<T> query) {
// TODO this is a very raw impl: need some work certainly
try {
Connection conn = this.getConnection();
ClassInfo ci = ClassInfo.getClassInfo(query.getQueriedClass());
// doesn't index a table that has already been indexed
if (!tableIndexMap.containsKey(ci.tableName)) {
List<String> colList = ci.getUpdateFieldsColumnNames();
String cols = null;
if (!colList.isEmpty()) {
cols = "";
// removes auto generated IDs from index
int sz = colList.size();
for (int i = 0; i < sz; i++) {
if ("h2".equals(dbMode))
cols += colList.get(i).toUpperCase();
else // !!! mysql mode means case INsensitive to lowercase !!!!
if ("mysql".equals(dbMode))
cols += colList.get(i).toLowerCase();
else
cols += colList.get(i).toUpperCase();
if (i < sz - 1)
cols += ",";
}
}
// creates the index
FullText.createIndex(conn, "PUBLIC", ci.tableName.toUpperCase(), cols);
tableIndexMap.put(ci.tableName, true);
}
String searchString = "";
Iterator<QueryFilterSearch> it = query.getSearches().iterator();
boolean first = true;
while (it.hasNext()) {
if (!first) {
searchString += " ";
} else {
first = false;
}
searchString += it.next().match;
}
ResultSet rs = FullText.searchData(conn, searchString, 0, 0);
int count = 0;
while (rs.next()) {
//String queryStr = rs.getString("QUERY");
//String score = rs.getString("SCORE");
//Array columns = rs.getArray("COLUMNS");
Object[] keys = (Object[]) rs.getArray("KEYS").getArray();
count += keys.length;
}
return count;
} catch (SQLException e) {
throw new SienaException(e);
}
}
use of siena.QueryFilterSearch in project siena by mandubian.
the class H2PersistenceManager method doSearchKeys.
protected <T> List<T> doSearchKeys(Query<T> query, int limit, int offset) {
// TODO this is a very raw impl: need some work certainly
try {
Connection conn = this.getConnection();
ClassInfo ci = ClassInfo.getClassInfo(query.getQueriedClass());
// doesn't index a table that has already been indexed
if (!tableIndexMap.containsKey(ci.tableName)) {
List<String> colList = ci.getUpdateFieldsColumnNames();
String cols = null;
if (!colList.isEmpty()) {
cols = "";
// removes auto generated IDs from index
int sz = colList.size();
for (int i = 0; i < sz; i++) {
if ("h2".equals(dbMode))
cols += colList.get(i).toUpperCase();
else // !!! mysql mode means case INsensitive to lowercase !!!!
if ("mysql".equals(dbMode))
cols += colList.get(i).toLowerCase();
else
cols += colList.get(i).toUpperCase();
if (i < sz - 1)
cols += ",";
}
}
// creates the index
FullText.createIndex(conn, "PUBLIC", ci.tableName.toUpperCase(), cols);
tableIndexMap.put(ci.tableName, true);
}
String searchString = "";
Iterator<QueryFilterSearch> it = query.getSearches().iterator();
boolean first = true;
while (it.hasNext()) {
if (!first) {
searchString += " ";
} else {
first = false;
}
searchString += it.next().match;
}
ResultSet rs = FullText.searchData(conn, searchString, limit, offset);
List<T> res = new ArrayList<T>();
Class<T> clazz = query.getQueriedClass();
while (rs.next()) {
//String queryStr = rs.getString("QUERY");
//String score = rs.getString("SCORE");
//Array columns = rs.getArray("COLUMNS");
Object[] keys = (Object[]) rs.getArray("KEYS").getArray();
for (Object key : keys) {
T obj = Util.createObjectInstance(clazz);
for (Field field : JdbcClassInfo.getClassInfo(clazz).keys) {
JdbcMappingUtils.setFromObject(obj, field, key);
}
res.add(obj);
}
}
return res;
} catch (SQLException e) {
throw new SienaException(e);
} catch (Exception e) {
throw new SienaException(e);
}
}
Aggregations