/** * Creates an SQL String suitable for initialising a PreparedStatement * * @param table the table to insert in * @param row an example row * @return the SQL String * @throws NullPointerException if any arguments are null */ protected String createSQLStatement(String table, String row) { if ((table == null) || (row == null)) { throw new NullPointerException("Arguments to createSQLStatement must not be null"); } fields = StringUtil.countOccurances("\t", row) + 1; StringBuffer sql = new StringBuffer(); sql.append("INSERT INTO ") .append(table) .append(" VALUES("); for (int i = 0; i < fields; i++) { sql.append("?"); if (i != (fields - 1)) { sql.append(", "); } } sql.append(")"); return sql.toString(); }
/** * Creates an SQL String suitable for initialising a PreparedStatement * * @param table the table to insert in * @param row an example row * @return the SQL String * @throws NullPointerException if any arguments are null */ protected String createSQLStatement(String table, String row) { if ((table == null) || (row == null)) { throw new NullPointerException("Arguments to createSQLStatement must not be null"); } fields = StringUtil.countOccurances("\t", row) + 1; StringBuffer sql = new StringBuffer(); sql.append("INSERT INTO ") .append(table) .append(" VALUES("); for (int i = 0; i < fields; i++) { sql.append("?"); if (i != (fields - 1)) { sql.append(", "); } } sql.append(")"); return sql.toString(); }
public void testCountOccurancesNullTarget() throws Exception { try { StringUtil.countOccurances("e", null); fail("Expected: NullPointerException"); } catch (NullPointerException e) { } }
public void testCountOccurancesNullStr() throws Exception { try { StringUtil.countOccurances(null, "A test string"); fail("Expected: NullPointerException"); } catch (NullPointerException e) { } }
public void testCountOccurances() throws Exception { assertEquals(0,StringUtil.countOccurances("z", "A sentence without the required letter in it")); assertEquals(8,StringUtil.countOccurances("e", "A sentence with the required letter in it")); assertEquals(1,StringUtil.countOccurances("e", "effffffff")); assertEquals(1,StringUtil.countOccurances("e", "ffffffffffffff fffe")); }
/** * Return the Query that was passed to the constructor. * @param bag the collection to use to constrain the query * @param extraFieldValue the value used if any extra constraint is configured * @return the Query * @throws ClassNotFoundException if class given by type not found */ public Query getQuery(Collection<String> bag, String extraFieldValue) throws ClassNotFoundException { List<String> lowerCaseBag = new ArrayList<String>(); for (String o : bag) { o = o.toLowerCase(); lowerCaseBag.add(o); } // if this should be the default query using class key fields, create it now if (isDefaultQuery) { Query q = BagQueryHelper.createDefaultBagQuery(type, bagQueryConfig, model, classKeys, lowerCaseBag); return addExtraConstraint(q, extraFieldValue); } List<Object> bags = new ArrayList<Object>(); int bagCount = StringUtil.countOccurances("?", queryString); for (int i = 0; i < bagCount; i++) { bags.add(lowerCaseBag); } IqlQuery q = new IqlQuery(queryString, packageName, bags); return addExtraConstraint(q.toQuery(), extraFieldValue); }
/** * Return the Query that was passed to the constructor. * @param bag the collection to use to constrain the query * @param extraFieldValue the value used if any extra constraint is configured * @return the Query * @throws ClassNotFoundException if class given by type not found */ public Query getQuery(Collection<String> bag, String extraFieldValue) throws ClassNotFoundException { List<String> lowerCaseBag = new ArrayList<String>(); for (String o : bag) { o = o.toLowerCase(); lowerCaseBag.add(o); } // if this should be the default query using class key fields, create it now if (isDefaultQuery) { Query q = BagQueryHelper.createDefaultBagQuery(type, bagQueryConfig, model, classKeys, lowerCaseBag); return addExtraConstraint(q, extraFieldValue); } List<Object> bags = new ArrayList<Object>(); int bagCount = StringUtil.countOccurances("?", queryString); for (int i = 0; i < bagCount; i++) { bags.add(lowerCaseBag); } IqlQuery q = new IqlQuery(queryString, packageName, bags); return addExtraConstraint(q.toQuery(), extraFieldValue); }