src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
RuntimeExceptionDao implements Dao<T, ID> { @Override public T mapSelectStarRow(DatabaseResults results) { try { return dao.mapSelectStarRow(results); } catch (SQLException e) { logMessage(e, "mapSelectStarRow threw exception on results"); throw new RuntimeException(e); } } RuntimeExceptionDao(Dao<T, ID> dao); static R...
@Test(expected = RuntimeException.class) public void testMapSelectStarRowThrow() throws Exception { @SuppressWarnings("unchecked") Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class); RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao); DatabaseResults results = createMock(Dat...
RuntimeExceptionDao implements Dao<T, ID> { @Override public GenericRowMapper<T> getSelectStarRowMapper() { try { return dao.getSelectStarRowMapper(); } catch (SQLException e) { logMessage(e, "getSelectStarRowMapper threw exception"); throw new RuntimeException(e); } } RuntimeExceptionDao(Dao<T, ID> dao); static Runtim...
@Test(expected = RuntimeException.class) public void testGetSelectStarRowMapperThrow() throws Exception { @SuppressWarnings("unchecked") Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class); RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao); expect(dao.getSelectStarRowMapper(...
RuntimeExceptionDao implements Dao<T, ID> { @Override public boolean idExists(ID id) { try { return dao.idExists(id); } catch (SQLException e) { logMessage(e, "idExists threw exception on " + id); throw new RuntimeException(e); } } RuntimeExceptionDao(Dao<T, ID> dao); static RuntimeExceptionDao<T, ID> createDao(Connect...
@Test(expected = RuntimeException.class) public void testIdExists() throws Exception { @SuppressWarnings("unchecked") Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class); RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao); String id = "eopwjfpwejf"; expect(dao.idExists(id)).a...
BaseConnectionSource implements ConnectionSource { @Override public DatabaseConnection getSpecialConnection(String tableName) { NestedConnection currentSaved = specialConnection.get(); if (currentSaved == null) { return null; } else { return currentSaved.connection; } } @Override DatabaseConnection getSpecialConnectio...
@Test public void testNestedSave() throws Exception { OurConnectionSource cs = new OurConnectionSource(); DatabaseConnection conn = cs.getReadOnlyConnection(null); cs.saveSpecialConnection(conn); cs.saveSpecialConnection(conn); cs.clearSpecialConnection(conn); assertEquals(conn, cs.getSpecialConnection(null)); cs.close...
DatabaseConnectionProxy implements DatabaseConnection { @Override public boolean isAutoCommitSupported() throws SQLException { if (proxy == null) { return false; } else { return proxy.isAutoCommitSupported(); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boo...
@Test public void testIsAutoCommitSupported() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); boolean supported = true; expect(conn.isAutoCommitSupported()).andReturn(supported); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); assertEqual...
DefaultParameterContext implements ParameterContext { @Override @Nullable public BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter) { if (!nameToTypeMap.containsKey(bindingParameter.getParameterName())) { BindingParameter newBindingParameter = bindingParameter.rightShift(); List<String> param...
@Test public void testTryExpandBindingParameter() throws Exception { List<Annotation> empty = Collections.emptyList(); ParameterDescriptor p0 = ParameterDescriptor.create(0, String.class, empty, "1"); ParameterDescriptor p1 = ParameterDescriptor.create(1, User.class, empty, "2"); List<ParameterDescriptor> pds = Arrays....
DatabaseConnectionProxy implements DatabaseConnection { @Override public boolean isAutoCommit() throws SQLException { if (proxy == null) { return false; } else { return proxy.isAutoCommit(); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boolean isAutoCommit(...
@Test public void testIsAutoCommit() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); boolean autoCommit = false; expect(conn.isAutoCommit()).andReturn(autoCommit); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); assertEquals(autoCommit, p...
DatabaseConnectionProxy implements DatabaseConnection { @Override public void setAutoCommit(boolean autoCommit) throws SQLException { if (proxy != null) { proxy.setAutoCommit(autoCommit); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boolean isAutoCommit(); ...
@Test public void testSetAutoCommit() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); boolean autoCommit = false; conn.setAutoCommit(autoCommit); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); proxy.setAutoCommit(autoCommit); proxy.close...
DatabaseConnectionProxy implements DatabaseConnection { @Override public Savepoint setSavePoint(String name) throws SQLException { if (proxy == null) { return null; } else { return proxy.setSavePoint(name); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boole...
@Test public void testSetSavePoint() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); String name = "savepoint"; expect(conn.setSavePoint(name)).andReturn(null); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); proxy.setSavePoint(name); pro...
DatabaseConnectionProxy implements DatabaseConnection { @Override public void commit(Savepoint savePoint) throws SQLException { if (proxy != null) { proxy.commit(savePoint); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boolean isAutoCommit(); @Override void...
@Test public void testCommit() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); conn.commit(null); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); proxy.commit(null); proxy.close(); verify(conn); }
DatabaseConnectionProxy implements DatabaseConnection { @Override public void rollback(Savepoint savePoint) throws SQLException { if (proxy != null) { proxy.rollback(savePoint); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boolean isAutoCommit(); @Override ...
@Test public void testRollback() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); conn.rollback(null); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); proxy.rollback(null); proxy.close(); verify(conn); }
DatabaseConnectionProxy implements DatabaseConnection { @Override public int insert(String statement, Object[] args, FieldType[] argfieldTypes, GeneratedKeyHolder keyHolder) throws SQLException { if (proxy == null) { return 0; } else { return proxy.insert(statement, args, argfieldTypes, keyHolder); } } DatabaseConnecti...
@Test public void testInsert() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); String statement = "insert bar"; int result = 13712321; expect(conn.insert(statement, null, null, null)).andReturn(result); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); r...
DatabaseConnectionProxy implements DatabaseConnection { @Override public int update(String statement, Object[] args, FieldType[] argfieldTypes) throws SQLException { if (proxy == null) { return 0; } else { return proxy.update(statement, args, argfieldTypes); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Overr...
@Test public void testUpdate() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); String statement = "insert bar"; int result = 13212321; expect(conn.update(statement, null, null)).andReturn(result); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(...
DatabaseConnectionProxy implements DatabaseConnection { @Override public int delete(String statement, Object[] args, FieldType[] argfieldTypes) throws SQLException { if (proxy == null) { return 0; } else { return proxy.delete(statement, args, argfieldTypes); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Overr...
@Test public void testDelete() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); String statement = "insert bar"; int result = 13872321; expect(conn.delete(statement, null, null)).andReturn(result); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(...
DatabaseConnectionProxy implements DatabaseConnection { @Override public <T> Object queryForOne(String statement, Object[] args, FieldType[] argfieldTypes, GenericRowMapper<T> rowMapper, ObjectCache objectCache) throws SQLException { if (proxy == null) { return null; } else { return proxy.queryForOne(statement, args, a...
@Test public void testQueryForOne() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); String statement = "insert bar"; Object result = new Object(); expect(conn.queryForOne(statement, null, null, null, null)).andReturn(result); conn.close(); DatabaseConnectionProxy proxy = new DatabaseC...
DatabaseConnectionProxy implements DatabaseConnection { @Override public void close() throws IOException { if (proxy != null) { proxy.close(); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boolean isAutoCommit(); @Override void setAutoCommit(boolean autoComm...
@Test public void testClose() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); proxy.close(); verify(conn); } @Test public void testCloseNull() throws Exception { new DatabaseConnectionProxy(...
InitStat { public void recordInit(long initTime) { if (initTime >= 0) { initCount.increment(); totalInitTime.add(initTime); } } private InitStat(); static InitStat create(); void recordInit(long initTime); long getInitCount(); long getTotalInitTime(); }
@Test public void testRecordInit() throws Exception { InitStat stat = InitStat.create(); long a = 1000; long b = 500; stat.recordInit(a); assertThat(stat.getInitCount(), equalTo(1L)); assertThat(stat.getTotalInitTime(), equalTo(a)); stat.recordInit(b); assertThat(stat.getInitCount(), equalTo(2L)); assertThat(stat.getTo...
DatabaseConnectionProxy implements DatabaseConnection { @Override public void closeQuietly() { if (proxy != null) { proxy.closeQuietly(); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boolean isAutoCommit(); @Override void setAutoCommit(boolean autoCommit); ...
@Test public void testCloseQuietly() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); conn.closeQuietly(); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); proxy.closeQuietly(); proxy.close(); verify(conn); }
DatabaseConnectionProxy implements DatabaseConnection { @Override public boolean isClosed() throws SQLException { if (proxy == null) { return true; } else { return proxy.isClosed(); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Override boolean isAutoCommit(); @Overr...
@Test public void testIsClosed() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); boolean closed = true; expect(conn.isClosed()).andReturn(closed); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(conn); replay(conn); assertEquals(closed, proxy.isClosed()); pro...
DatabaseConnectionProxy implements DatabaseConnection { @Override public boolean isTableExists(String tableName) throws SQLException { if (proxy == null) { return false; } else { return proxy.isTableExists(tableName); } } DatabaseConnectionProxy(DatabaseConnection proxy); @Override boolean isAutoCommitSupported(); @Ove...
@Test public void testIsTableExists() throws Exception { DatabaseConnection conn = createMock(DatabaseConnection.class); boolean tableExists = true; String tableName = "fjewfjwef"; expect(conn.isTableExists(tableName)).andReturn(tableExists); conn.close(); DatabaseConnectionProxy proxy = new DatabaseConnectionProxy(con...
SelectIterator implements CloseableIterator<T> { public boolean hasNextThrow() throws SQLException { if (closed) { return false; } if (alreadyMoved) { return true; } boolean result; if (first) { first = false; result = results.first(); } else { result = results.next(); } if (!result) { IOUtils.closeThrowSqlException(th...
@Test(expected = IllegalStateException.class) public void testHasNextThrow() throws Exception { ConnectionSource cs = createMock(ConnectionSource.class); cs.releaseConnection(null); CompiledStatement stmt = createMock(CompiledStatement.class); DatabaseResults results = createMock(DatabaseResults.class); expect(stmt.run...
SelectIterator implements CloseableIterator<T> { @Override public T nextThrow() throws SQLException { if (closed) { return null; } if (!alreadyMoved) { boolean hasResult; if (first) { first = false; hasResult = results.first(); } else { hasResult = results.next(); } if (!hasResult) { first = false; return null; } } fir...
@Test(expected = IllegalStateException.class) public void testNextThrow() throws Exception { ConnectionSource cs = createMock(ConnectionSource.class); cs.releaseConnection(null); CompiledStatement stmt = createMock(CompiledStatement.class); DatabaseResults results = createMock(DatabaseResults.class); expect(stmt.runQue...
SelectIterator implements CloseableIterator<T> { public void removeThrow() throws SQLException { if (last == null) { throw new IllegalStateException("No last " + dataClass + " object to remove. Must be called after a call to next."); } if (classDao == null) { throw new IllegalStateException("Cannot remove " + dataClass...
@Test(expected = IllegalStateException.class) public void testRemoveThrow() throws Exception { ConnectionSource cs = createMock(ConnectionSource.class); cs.releaseConnection(null); CompiledStatement stmt = createMock(CompiledStatement.class); DatabaseResults results = createMock(DatabaseResults.class); expect(results.f...
QueryBuilder extends StatementBuilder<T, ID> { @Override protected String getTableName() { return (alias == null ? tableName : alias); } QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); PreparedQuery<T> prepare(); QueryBuilder<T, ID> selectColumns(String... columns); QueryBuilder<T, ...
@Test public void testSelectAll() throws Exception { QueryBuilder<Foo, Integer> qb = new QueryBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); StringBuilder sb = new StringBuilder(); sb.append("SELECT * FROM "); databaseType.appendEscapedEntityName(sb, baseFooTableInfo.getTableName()); sb.append(' '); asser...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> selectColumns(String... columns) { for (String column : columns) { addSelectColumnToList(column); } return this; } QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); PreparedQuery<T> prepare(); QueryBuilder<T, ID...
@Test(expected = IllegalArgumentException.class) public void testAddBadColumn() { QueryBuilder<Foo, Integer> qb = new QueryBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); qb.selectColumns("unknown-column"); }
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> groupBy(String columnName) { FieldType fieldType = verifyColumnName(columnName); if (fieldType.isForeignCollection()) { throw new IllegalArgumentException("Can't groupBy foreign colletion field: " + columnName); } addGroupBy(ColumnNameOrRawSql.wi...
@Test public void testGroupBy() throws Exception { QueryBuilder<Foo, Integer> qb = new QueryBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); String field1 = Foo.VAL_COLUMN_NAME; qb.groupBy(field1); String field2 = Foo.ID_COLUMN_NAME; qb.groupBy(field2); StringBuilder sb = new StringBuilder(); sb.append("SEL...
Elements extends ArrayList<Element> { public boolean hasAttr(String attributeKey) { for (Element element : this) { if (element.hasAttr(attributeKey)) return true; } return false; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element.....
@Test public void hasAttr() { Document doc = Jsoup.parse("<p title=foo><p title=bar><p class=foo><p class=bar>"); Elements ps = doc.select("p"); assertTrue(ps.hasAttr("class")); assertFalse(ps.hasAttr("style")); }
MangoDaoScanner implements BeanFactoryPostProcessor { public void setPackages(List<String> packages) { for (String p : packages) { for (String daoEnd : DAO_ENDS) { String locationPattern = "classpath*:" + p.replaceAll("\\.", "/") + "*" + daoEnd + ".class"; logger.info("trnas package[" + p + "] to locationPattern[" + lo...
@Test public void testSetPackages() throws Exception { MangoDaoScanner mc = new MangoDaoScanner(); List<String> packages = Lists.newArrayList("org.jfaster.mango", "", "org.jfaster"); mc.setPackages(packages); assertThat(mc.locationPatterns.get(0), is("classpath*:org/jfaster/mango*Dao.class")); assertThat(mc.locationPat...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> orderBy(String columnName, boolean ascending) { FieldType fieldType = verifyColumnName(columnName); if (fieldType.isForeignCollection()) { throw new IllegalArgumentException("Can't orderBy foreign colletion field: " + columnName); } addOrderBy(ne...
@Test public void testOrderBy() throws Exception { QueryBuilder<Foo, Integer> qb = new QueryBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); String field1 = Foo.VAL_COLUMN_NAME; qb.orderBy(field1, true); String field2 = Foo.ID_COLUMN_NAME; qb.orderBy(field2, true); StringBuilder sb = new StringBuilder(); sb...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> distinct() { distinct = true; selectIdColumn = false; return this; } QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); PreparedQuery<T> prepare(); QueryBuilder<T, ID> selectColumns(String... columns); QueryBuild...
@Test public void testDistinct() throws Exception { QueryBuilder<Foo, Integer> qb = new QueryBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); qb.distinct(); StringBuilder sb = new StringBuilder(); sb.append("SELECT DISTINCT * FROM "); databaseType.appendEscapedEntityName(sb, baseFooTableInfo.getTableName())...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> limit(Long maxRows) { limit = maxRows; return this; } QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); PreparedQuery<T> prepare(); QueryBuilder<T, ID> selectColumns(String... columns); QueryBuilder<T, ID> selec...
@Test public void testLimit() throws Exception { QueryBuilder<Foo, Integer> qb = new QueryBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); long limit = 103; qb.limit(limit); StringBuilder sb = new StringBuilder(); sb.append("SELECT * FROM "); databaseType.appendEscapedEntityName(sb, baseFooTableInfo.getTabl...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> offset(Long startRow) throws SQLException { if (databaseType.isOffsetSqlSupported()) { offset = startRow; return this; } else { throw new SQLException("Offset is not supported by this database"); } } QueryBuilder(DatabaseType databaseType, TableI...
@Test public void testOffset() throws Exception { QueryBuilder<Foo, Integer> qb = new QueryBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); long offset = 1; long limit = 2; qb.offset(offset); qb.limit(limit); StringBuilder sb = new StringBuilder(); sb.append("SELECT * FROM "); databaseType.appendEscapedEnti...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> orderByRaw(String rawSql) { addOrderBy(new OrderBy(rawSql, (ArgumentHolder[]) null)); return this; } QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); PreparedQuery<T> prepare(); QueryBuilder<T, ID> selectColumn...
@Test public void testOrderByRaw() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); foo1.val = 1; foo1.equal = 10; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = 5; foo2.equal = 7; assertEquals(1, dao.create(foo2)); List<Foo> results = dao.queryBuilder() ...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao) { super(databaseType, tableInfo, dao, StatementType.SELECT); this.idField = tableInfo.getIdField(); this.selectIdColumn = (idField != null); } QueryBuilder(DatabaseType databaseType,...
@SuppressWarnings("unchecked") @Test public void testMixAndOrInline() throws Exception { Dao<Foo, String> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); foo1.val = 10; foo1.stringField = "zip"; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = foo1.val; foo2.stringField = foo1.stringField + "...
QueryBuilder extends StatementBuilder<T, ID> { public QueryBuilder<T, ID> leftJoin(QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException { addJoinInfo(JoinType.LEFT, null, null, joinedQueryBuilder, JoinWhereOperation.AND); return this; } QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID...
@Test public void testLeftJoin() throws Exception { Dao<Bar, Integer> barDao = createDao(Bar.class, true); Dao<Baz, Integer> bazDao = createDao(Baz.class, true); Bar bar1 = new Bar(); bar1.val = 2234; assertEquals(1, barDao.create(bar1)); Bar bar2 = new Bar(); bar2.val = 324322234; assertEquals(1, barDao.create(bar2));...
QueryBuilder extends StatementBuilder<T, ID> { public long countOf() throws SQLException { String countOfQuerySave = this.countOfQuery; try { setCountOf(true); return dao.countOf(prepare()); } finally { setCountOf(countOfQuerySave); } } QueryBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao)...
@Test public void testCountOf() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); QueryBuilder<Foo, Integer> qb = dao.queryBuilder(); assertEquals(0, qb.countOf()); Foo foo1 = new Foo(); int val = 123213; foo1.val = val; assertEquals(1, dao.create(foo1)); assertEquals(1, qb.countOf()); Foo foo2 = n...
Elements extends ArrayList<Element> { public String attr(String attributeKey) { for (Element element : this) { if (element.hasAttr(attributeKey)) return element.attr(attributeKey); } return ""; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Ele...
@Test public void attr() { Document doc = Jsoup.parse("<p title=foo><p title=bar><p class=foo><p class=bar>"); String classVal = doc.select("p").attr("class"); assertEquals("foo", classVal); }
In extends BaseComparison { @Override public void appendValue(DatabaseType databaseType, StringBuilder sb, List<ArgumentHolder> columnArgList) throws SQLException { sb.append('('); boolean first = true; for (Object value : objects) { if (value == null) { throw new IllegalArgumentException("one of the IN values for '" +...
@Test(expected = IllegalArgumentException.class) public void testAppendValueNull() throws Exception { List<Object> objList = new ArrayList<Object>(); objList.add(null); In in = new In("foo", numberFieldType, objList, true); in.appendValue(null, new StringBuilder(), null); } @Test public void testAppendValue() throws Ex...
Between extends BaseComparison { @Override public void appendOperation(StringBuilder sb) { sb.append("BETWEEN "); } Between(String columnName, FieldType fieldType, Object low, Object high); @Override void appendOperation(StringBuilder sb); @Override void appendValue(DatabaseType databaseType, StringBuilder sb, List<Arg...
@Test public void testAppendOperation() throws Exception { int low = 10; int high = 20; Between btw = new Between(COLUMN_NAME, numberFieldType, low, high); StringBuilder sb = new StringBuilder(); btw.appendOperation(sb); assertTrue(sb.toString().contains("BETWEEN")); sb.setLength(0); btw.appendValue(null, sb, new Array...
Between extends BaseComparison { @Override public void appendValue(DatabaseType databaseType, StringBuilder sb, List<ArgumentHolder> argList) throws SQLException { if (low == null) { throw new IllegalArgumentException("BETWEEN low value for '" + columnName + "' is null"); } if (high == null) { throw new IllegalArgument...
@Test(expected = IllegalArgumentException.class) public void testAppendValueLowNull() throws Exception { new Between(COLUMN_NAME, numberFieldType, null, 20L).appendValue(null, new StringBuilder(), new ArrayList<ArgumentHolder>()); } @Test(expected = IllegalArgumentException.class) public void testAppendValueHighNull() ...
BaseComparison implements Comparison { protected void appendArgOrValue(DatabaseType databaseType, FieldType fieldType, StringBuilder sb, List<ArgumentHolder> argList, Object argOrValue) throws SQLException { boolean appendSpace = true; if (argOrValue == null) { throw new SQLException("argument for '" + fieldType.getFie...
@Test(expected = SQLException.class) public void testAppendArgOrValueNull() throws Exception { cmpInt.appendArgOrValue(null, numberFieldType, new StringBuilder(), new ArrayList<ArgumentHolder>(), null); } @Test public void testAppendArgOrValueString() throws SQLException { String value = "23wbdqwbdq13"; StringBuilder s...
Not implements Clause, NeedsFutureClause { @Override public void setMissingClause(Clause clause) { if (this.comparison != null) { throw new IllegalArgumentException("NOT operation already has a comparison set"); } else if (clause instanceof Comparison) { this.comparison = (Comparison) clause; } else if (clause instance...
@Test(expected = IllegalArgumentException.class) public void test() { Not not = new Not(); Clause clause = new Comparison() { @Override public void appendOperation(StringBuilder sb) { } @Override public void appendValue(DatabaseType databaseType, StringBuilder sb, List<ArgumentHolder> argList) { } @Override public Stri...
Not implements Clause, NeedsFutureClause { @Override public void appendSql(DatabaseType databaseType, String tableName, StringBuilder sb, List<ArgumentHolder> selectArgList) throws SQLException { if (comparison == null && exists == null) { throw new IllegalStateException("Clause has not been set in NOT operation"); } i...
@Test(expected = IllegalStateException.class) public void testNoClause() throws Exception { Not not = new Not(); not.appendSql(databaseType, null, new StringBuilder(), new ArrayList<ArgumentHolder>()); }
Elements extends ArrayList<Element> { public String text() { StringBuilder sb = new StringBuilder(); for (Element element : this) { if (sb.length() != 0) sb.append(" "); sb.append(element.text()); } return sb.toString(); } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(Li...
@Test public void text() { String h = "<div><p>Hello<p>there<p>world</div>"; Document doc = Jsoup.parse(h); assertEquals("Hello there world", doc.select("div > *").text()); } @Test public void classWithHyphen() { Document doc = Jsoup.parse("<p class='tab-nav'>Check</p>"); Elements els = doc.getElementsByClass("tab-nav"...
Not implements Clause, NeedsFutureClause { @Override public String toString() { if (comparison == null) { return "NOT without comparison"; } else { return "NOT comparison " + comparison; } } Not(); Not(Clause clause); @Override void setMissingClause(Clause clause); @Override void appendSql(DatabaseType databaseType, S...
@Test public void testToString() throws Exception { String name = "foo"; String value = "bar"; SimpleComparison eq = new SimpleComparison(name, numberFieldType, value, SimpleComparison.EQUAL_TO_OPERATION); Not not = new Not(); assertTrue(not.toString().contains("NOT without comparison")); not.setMissingClause(eq); asse...
RawResultsImpl implements GenericRawResults<T> { @Override public List<T> getResults() throws SQLException { List<T> results = new ArrayList<T>(); try { while (iterator.hasNext()) { results.add(iterator.next()); } return results; } finally { IOUtils.closeThrowSqlException(this, "raw results iterator"); } } RawResultsIm...
@Test public void testQueryRawColumns() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); foo1.val = 1; foo1.equal = 10; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = 10; foo2.equal = 5; assertEquals(1, dao.create(foo2)); QueryBuilder<Foo, Integer> qb = d...
RawResultsImpl implements GenericRawResults<T> { @Override public T getFirstResult() throws SQLException { try { if (iterator.hasNextThrow()) { return iterator.nextThrow(); } else { return null; } } finally { IOUtils.closeThrowSqlException(this, "raw results iterator"); } } RawResultsImpl(ConnectionSource connectionSou...
@Test public void testGetFirstResult() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); foo1.val = 342; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = 9045342; assertEquals(1, dao.create(foo2)); QueryBuilder<Foo, Integer> qb = dao.queryBuilder(); qb.selec...
MappedDeleteCollection extends BaseMappedStatement<T, ID> { public static <T, ID> int deleteObjects(DatabaseType databaseType, TableInfo<T, ID> tableInfo, DatabaseConnection databaseConnection, Collection<T> datas, ObjectCache objectCache) throws SQLException { MappedDeleteCollection<T, ID> deleteCollection = MappedDel...
@Test(expected = SQLException.class) public void testNoIdBuildDelete() throws Exception { DatabaseConnection databaseConnection = createMock(DatabaseConnection.class); ConnectionSource connectionSource = createMock(ConnectionSource.class); expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes(); r...
BaseMappedQuery extends BaseMappedStatement<T, ID> implements GenericRowMapper<T> { @Override public T mapRow(DatabaseResults results) throws SQLException { Map<String, Integer> colPosMap; if (columnPositions == null) { colPosMap = new HashMap<String, Integer>(); } else { colPosMap = columnPositions; } ObjectCache obje...
@Test public void testMappedQuery() throws Exception { Field field = Foo.class.getDeclaredField(Foo.ID_COLUMN_NAME); String tableName = "basefoo"; FieldType[] resultFieldTypes = new FieldType[] { FieldType.createFieldType(connectionSource, tableName, field, Foo.class) }; BaseMappedQuery<Foo, Integer> baseMappedQuery = ...
MappedCreate extends BaseMappedStatement<T, ID> { public int insert(DatabaseType databaseType, DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { KeyHolder keyHolder = null; if (idField != null) { boolean assignId; if (idField.isAllowGeneratedIdInsert() && !idField.isObjectsFi...
@Test public void testGeneratedId() throws Exception { TableInfo<GeneratedId, Integer> tableInfo = new TableInfo<GeneratedId, Integer>(connectionSource, null, GeneratedId.class); StatementExecutor<GeneratedId, Integer> se = new StatementExecutor<GeneratedId, Integer>(databaseType, tableInfo, null); DatabaseConnection d...
Elements extends ArrayList<Element> { public boolean hasText() { for (Element element: this) { if (element.hasText()) return true; } return false; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements ...
@Test public void hasText() { Document doc = Jsoup.parse("<div><p>Hello</p></div><div><p></p></div>"); Elements divs = doc.select("div"); assertTrue(divs.hasText()); assertFalse(doc.select("div + div").hasText()); }
MappedCreate extends BaseMappedStatement<T, ID> { public static <T, ID> MappedCreate<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo) { StringBuilder sb = new StringBuilder(128); appendTableName(databaseType, sb, "INSERT INTO ", tableInfo.getTableName()); int argFieldC = 0; int versionFieldTypeIndex ...
@Test public void testNoCreateSequence() throws Exception { MappedCreate.build(databaseType, new TableInfo<GeneratedId, Integer>(connectionSource, null, GeneratedId.class)); }
MappedUpdateId extends BaseMappedStatement<T, ID> { public static <T, ID> MappedUpdateId<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException("Cannot update-id in " + tableInfo.getDataClass() +...
@Test(expected = SQLException.class) public void testUpdateIdNoId() throws Exception { MappedUpdateId.build(databaseType, new TableInfo<NoId, Void>(connectionSource, null, NoId.class)); }
MappedDelete extends BaseMappedStatement<T, ID> { public int delete(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { try { Object[] args = getFieldObjects(data); int rowC = databaseConnection.delete(statement, args, argFieldTypes); logger.debug("delete data with statement '{...
@Test(expected = SQLException.class) public void testDeleteNoId() throws Exception { StatementExecutor<NoId, Void> se = new StatementExecutor<NoId, Void>(databaseType, new TableInfo<NoId, Void>(connectionSource, null, NoId.class), null); NoId noId = new NoId(); noId.stuff = "1"; ConnectionSource connectionSource = crea...
MappedDelete extends BaseMappedStatement<T, ID> { public static <T, ID> MappedDelete<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException("Cannot delete from " + tableInfo.getDataClass() + " be...
@Test(expected = SQLException.class) public void testNoIdBuildDelete() throws Exception { MappedDelete.build(databaseType, new TableInfo<NoId, Void>(connectionSource, null, NoId.class)); }
MappedUpdate extends BaseMappedStatement<T, ID> { public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { try { if (argFieldTypes.length <= 1) { return 0; } Object[] args = getFieldObjects(data); Object newVersion = null; if (versionFieldType != null) { newVersion...
@Test(expected = SQLException.class) public void testUpdateNoId() throws Exception { StatementExecutor<NoId, String> se = new StatementExecutor<NoId, String>(databaseType, new TableInfo<NoId, String>(connectionSource, null, NoId.class), null); NoId noId = new NoId(); noId.id = "1"; se.update(null, noId, null); } @Test ...
MappedUpdate extends BaseMappedStatement<T, ID> { public static <T, ID> MappedUpdate<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo) throws SQLException { FieldType idField = tableInfo.getIdField(); if (idField == null) { throw new SQLException("Cannot update " + tableInfo.getDataClass() + " because...
@Test(expected = SQLException.class) public void testNoIdBuildUpdater() throws Exception { MappedUpdate.build(databaseType, new TableInfo<NoId, Void>(connectionSource, null, NoId.class)); } @Test(expected = SQLException.class) public void testJustIdBuildUpdater() throws Exception { MappedUpdate.build(databaseType, new ...
NullArgHolder implements ArgumentHolder { @Override public void setValue(Object value) { throw new UnsupportedOperationException("Cannot set null on " + getClass()); } NullArgHolder(); @Override String getColumnName(); @Override void setValue(Object value); @Override void setMetaInfo(String columnName); @Override void ...
@Test(expected = UnsupportedOperationException.class) public void testSetValueThrows() { new NullArgHolder().setValue(null); }
Elements extends ArrayList<Element> { public String html() { StringBuilder sb = new StringBuilder(); for (Element element : this) { if (sb.length() != 0) sb.append("\n"); sb.append(element.html()); } return sb.toString(); } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(L...
@Test public void html() { Document doc = Jsoup.parse("<div><p>Hello</p></div><div><p>There</p></div>"); Elements divs = doc.select("div"); assertEquals("<p>Hello</p>\n<p>There</p>", divs.html()); }
SelectArg extends BaseArgumentHolder { @Override public void setValue(Object value) { this.hasBeenSet = true; this.value = value; } SelectArg(); SelectArg(String columnName, Object value); SelectArg(SqlType sqlType, Object value); SelectArg(SqlType sqlType); SelectArg(Object value); @Override void setValue(Object v...
@Test public void testSetValue() throws Exception { SelectArg selectArg = new SelectArg(); Object foo = new Object(); selectArg.setValue(foo); assertSame(foo, selectArg.getSqlArgValue()); } @Test public void testSetNumber() throws Exception { SelectArg selectArg = new SelectArg(); int val = 10; selectArg.setMetaInfo("v...
StatementExecutor implements GenericRowMapper<String[]> { public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { if (mappedUpdate == null) { mappedUpdate = MappedUpdate.build(databaseType, tableInfo); } int result = mappedUpdate.update(databaseConnection, data, o...
@Test public void testUpdateThrow() throws Exception { TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class); DatabaseConnection connection = createMock(DatabaseConnection.class); @SuppressWarnings("unchecked") PreparedUpdate<Foo> update = createMock(PreparedUpdate.class); Com...
StatementExecutor implements GenericRowMapper<String[]> { public int delete(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { if (mappedDelete == null) { mappedDelete = MappedDelete.build(databaseType, tableInfo); } int result = mappedDelete.delete(databaseConnection, data, o...
@Test public void testDeleteThrow() throws Exception { TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class); DatabaseConnection connection = createMock(DatabaseConnection.class); @SuppressWarnings("unchecked") PreparedDelete<Foo> delete = createMock(PreparedDelete.class); Com...
StatementExecutor implements GenericRowMapper<String[]> { public <CT> CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable) throws SQLException { if (connectionSource.isSingleConnection(tableInfo.getTableName())) { synchronized (this) { return doCallBatchTasks(connectionSource, callable); } } else...
@Test public void testCallBatchTasksNoAutoCommit() throws Exception { TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class); ConnectionSource connectionSource = createMock(ConnectionSource.class); DatabaseConnection connection = createMock(DatabaseConnection.class); expect(con...
Elements extends ArrayList<Element> { public String outerHtml() { StringBuilder sb = new StringBuilder(); for (Element element : this) { if (sb.length() != 0) sb.append("\n"); sb.append(element.outerHtml()); } return sb.toString(); } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); ...
@Test public void outerHtml() { Document doc = Jsoup.parse("<div><p>Hello</p></div><div><p>There</p></div>"); Elements divs = doc.select("div"); assertEquals("<div><p>Hello</p></div><div><p>There</p></div>", TextUtil.stripNewlines(divs.outerHtml())); }
Where { @Override public String toString() { if (clauseStackLevel == 0) { return "empty where clause"; } else { Clause clause = peek(); return "where clause: " + clause; } } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T, ID> and(); Where<T, ID...
@Test public void testToString() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); assertTrue(where.toString().contains("empty where clause")); String value = "bar"; FieldType numberFieldType = FieldType.createFieldType(connectionSource, "foo", Foo.class.getDec...
Where { void appendSql(String tableName, StringBuilder sb, List<ArgumentHolder> columnArgList) throws SQLException { if (clauseStackLevel == 0) { throw new IllegalStateException("No where clauses defined. Did you miss a where operation?"); } if (clauseStackLevel != 1) { throw new IllegalStateException( "Both the \"left...
@Test(expected = IllegalStateException.class) public void testNoClauses() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); where.appendSql(null, new StringBuilder(), new ArrayList<ArgumentHolder>()); }
Where { public Where<T, ID> eq(String columnName, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, SimpleComparison.EQUAL_TO_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseTy...
@Test(expected = IllegalArgumentException.class) public void testComparisonUnknownField() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 1; where.eq("unknown-field", val); } @Test(expected = IllegalArgumentException.class) public void testCompariso...
Where { public Where<T, ID> between(String columnName, Object low, Object high) throws SQLException { addClause(new Between(columnName, findColumnFieldType(columnName), low, high)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T,...
@Test public void testBetween() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int low = 1; int high = 1; where.between(Foo.VAL_COLUMN_NAME, low, high); StringBuilder whereSb = new StringBuilder(); where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>...
Where { public Where<T, ID> ge(String columnName, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, SimpleComparison.GREATER_THAN_EQUAL_TO_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilde...
@Test public void testGe() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 112; where.ge(Foo.VAL_COLUMN_NAME, val); testOperation(where, Foo.VAL_COLUMN_NAME, ">=", val); }
Where { public Where<T, ID> gt(String columnName, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, SimpleComparison.GREATER_THAN_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, Databa...
@Test public void testGt() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 112; where.gt(Foo.VAL_COLUMN_NAME, val); testOperation(where, Foo.VAL_COLUMN_NAME, ">", val); }
Elements extends ArrayList<Element> { public String val() { if (size() > 0) return first().val(); else return ""; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attri...
@Test public void val() { Document doc = Jsoup.parse("<input value='one' /><textarea>two</textarea>"); Elements els = doc.select("input, textarea"); assertEquals(2, els.size()); assertEquals("one", els.val()); assertEquals("two", els.last().val()); els.val("three"); assertEquals("three", els.first().val()); assertEqual...
Where { public Where<T, ID> lt(String columnName, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, SimpleComparison.LESS_THAN_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseT...
@Test public void testLt() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 112; where.lt(Foo.VAL_COLUMN_NAME, val); testOperation(where, Foo.VAL_COLUMN_NAME, "<", val); }
Where { public Where<T, ID> le(String columnName, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, SimpleComparison.LESS_THAN_EQUAL_TO_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, ...
@Test public void testLe() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 112; where.le(Foo.VAL_COLUMN_NAME, val); testOperation(where, Foo.VAL_COLUMN_NAME, "<=", val); }
Where { public Where<T, ID> ne(String columnName, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, SimpleComparison.NOT_EQUAL_TO_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, Databa...
@Test public void testNe() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 112; where.ne(Foo.VAL_COLUMN_NAME, val); testOperation(where, Foo.VAL_COLUMN_NAME, "<>", val); }
Where { public Where<T, ID> in(String columnName, Iterable<?> objects) throws SQLException { addClause(new In(columnName, findColumnFieldType(columnName), objects, true)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T, ID> and()...
@Test public void testIn() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 112; where.in(Foo.VAL_COLUMN_NAME, val); StringBuilder whereSb = new StringBuilder(); where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>()); StringBuilder sb = new ...
Where { public Where<T, ID> notIn(String columnName, Iterable<?> objects) throws SQLException { addClause(new In(columnName, findColumnFieldType(columnName), objects, false)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T, ID> a...
@Test public void testNotIn() throws Exception { Dao<Foo, String> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); foo1.val = 63465365; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2 = new Foo(); foo2.val = 163123; assertEquals(1, dao.create(foo2)); List<Foo> results = dao.queryBuilder().where().i...
Where { public Where<T, ID> isNull(String columnName) throws SQLException { addClause(new IsNull(columnName, findColumnFieldType(columnName))); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T, ID> and(); Where<T, ID> and(Where<T, ...
@Test public void testIsNull() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); where.isNull(Foo.VAL_COLUMN_NAME); StringBuilder whereSb = new StringBuilder(); where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>()); StringBuilder sb = new StringBuilde...
Where { public Where<T, ID> isNotNull(String columnName) throws SQLException { addClause(new IsNotNull(columnName, findColumnFieldType(columnName))); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T, ID> and(); Where<T, ID> and(Whe...
@Test public void testIsNotNull() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); where.isNotNull(Foo.VAL_COLUMN_NAME); StringBuilder whereSb = new StringBuilder(); where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>()); StringBuilder sb = new String...
Where { public Where<T, ID> like(String columnName, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, SimpleComparison.LIKE_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType...
@Test public void testLike() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); int val = 112; where.like(Foo.VAL_COLUMN_NAME, val); StringBuilder whereSb = new StringBuilder(); where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>()); StringBuilder sb = ...
Where { public Where<T, ID> idEq(ID id) throws SQLException { if (idColumnName == null) { throw new SQLException("Object has no id column specified"); } addClause(new SimpleComparison(idColumnName, idFieldType, id, SimpleComparison.EQUAL_TO_OPERATION)); return this; } protected Where(TableInfo<T, ID> tableInfo, Statem...
@Test public void testIdEq() throws Exception { Where<FooId, Integer> where = new Where<FooId, Integer>(new TableInfo<FooId, Integer>(connectionSource, null, FooId.class), null, databaseType); int val = 112; where.idEq(val); StringBuilder whereSb = new StringBuilder(); where.appendSql(null, whereSb, new ArrayList<Argum...
Elements extends ArrayList<Element> { public Elements before(String html) { for (Element element : this) { element.before(html); } return this; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clo...
@Test public void before() { Document doc = Jsoup.parse("<p>This <a>is</a> <a>jsoup</a>.</p>"); doc.select("a").before("<span>foo</span>"); assertEquals("<p>This <span>foo</span><a>is</a> <span>foo</span><a>jsoup</a>.</p>", TextUtil.stripNewlines(doc.body().html())); }
Where { public Where<T, ID> raw(String rawStatement, ArgumentHolder... args) { for (ArgumentHolder arg : args) { String columnName = arg.getColumnName(); if (columnName == null) { if (arg.getSqlType() == null) { throw new IllegalArgumentException("Either the column name or SqlType must be set on each argument"); } } el...
@Test public void testRaw() throws Exception { TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(connectionSource, null, Foo.class); Where<Foo, Integer> where = new Where<Foo, Integer>(tableInfo, null, databaseType); String raw = "VAL = 1"; int val = 17; where.eq(Foo.VAL_COLUMN_NAME, val).and().raw(raw); ...
Where { public Where<T, ID> rawComparison(String columnName, String rawOperator, Object value) throws SQLException { addClause(new SimpleComparison(columnName, findColumnFieldType(columnName), value, rawOperator)); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, Dat...
@Test public void testRawComparison() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo = new Foo(); int val = 63465365; foo.val = val; assertEquals(1, dao.create(foo)); QueryBuilder<Foo, Integer> qb = dao.queryBuilder(); qb.where().rawComparison("id", "=", new SelectArg(foo.id)); List<Foo>...
Where { public Where<T, ID> or() { ManyClause clause = new ManyClause(pop("OR"), ManyClause.OR_OPERATION); push(clause); addNeedsFuture(clause); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T, ID> and(); Where<T, ID> and(Where<T,...
@Test(expected = IllegalArgumentException.class) public void testOrManyZero() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); where.or(0); }
Where { public Where<T, ID> and() { ManyClause clause = new ManyClause(pop("AND"), ManyClause.AND_OPERATION); push(clause); addNeedsFuture(clause); return this; } protected Where(TableInfo<T, ID> tableInfo, StatementBuilder<T, ID> statementBuilder, DatabaseType databaseType); Where<T, ID> and(); Where<T, ID> and(Where...
@Test(expected = IllegalArgumentException.class) public void testAndManyZero() throws Exception { Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType); where.and(0); }
UpdateBuilder extends StatementBuilder<T, ID> { public UpdateBuilder<T, ID> updateColumnValue(String columnName, Object value) throws SQLException { FieldType fieldType = verifyColumnName(columnName); if (fieldType.isForeignCollection()) { throw new SQLException("Can't update foreign colletion field: " + columnName); }...
@Test(expected = SQLException.class) public void testUpdateForeignCollection() throws Exception { UpdateBuilder<OurForeignCollection, Integer> stmtb = new UpdateBuilder<OurForeignCollection, Integer>( databaseType, new TableInfo<OurForeignCollection, Integer>(connectionSource, null, OurForeignCollection.class), null); ...
UpdateBuilder extends StatementBuilder<T, ID> { public UpdateBuilder<T, ID> updateColumnExpression(String columnName, String expression) throws SQLException { FieldType fieldType = verifyColumnName(columnName); if (fieldType.isForeignCollection()) { throw new SQLException("Can't update foreign colletion field: " + colu...
@Test(expected = SQLException.class) public void testUpdateForeignCollectionColumnExpression() throws Exception { UpdateBuilder<OurForeignCollection, Integer> stmtb = new UpdateBuilder<OurForeignCollection, Integer>( databaseType, new TableInfo<OurForeignCollection, Integer>(connectionSource, null, OurForeignCollection...
UpdateBuilder extends StatementBuilder<T, ID> { public PreparedUpdate<T> prepare() throws SQLException { return super.prepareStatement(null, false); } UpdateBuilder(DatabaseType databaseType, TableInfo<T, ID> tableInfo, Dao<T, ID> dao); PreparedUpdate<T> prepare(); UpdateBuilder<T, ID> updateColumnValue(String columnNa...
@Test(expected = IllegalArgumentException.class) public void testPrepareStatementUpdateNotSets() throws Exception { UpdateBuilder<Foo, Integer> stmtb = new UpdateBuilder<Foo, Integer>(databaseType, baseFooTableInfo, null); stmtb.prepare(); }
Elements extends ArrayList<Element> { public Elements after(String html) { for (Element element : this) { element.after(html); } return this; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone...
@Test public void after() { Document doc = Jsoup.parse("<p>This <a>is</a> <a>jsoup</a>.</p>"); doc.select("a").after("<span>foo</span>"); assertEquals("<p>This <a>is</a><span>foo</span> <a>jsoup</a><span>foo</span>.</p>", TextUtil.stripNewlines(doc.body().html())); }
Statements { public List<Statement> getStatements() { return statements; } List<Statement> getStatements(); void setStatements(List<Statement> statements); void accept(StatementVisitor statementVisitor); @Override String toString(); }
@Test public void testStatementsErrorRecovery() throws JSQLParserException, ParseException { String sqls = "select * from mytable; select * from;"; CCJSqlParser parser = new CCJSqlParser(new StringReader(sqls)); parser.setErrorRecovery(true); Statements parseStatements = parser.Statements(); assertEquals(2, parseStatem...
Execute implements Statement { @Override public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); } String getName(); void setName(String name); ExpressionList getExprList(); void setExprList(ExpressionList exprList); @Override void accept(StatementVisitor statementVisitor); @Override Stri...
@Test public void testAccept() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("EXECUTE myproc 'a', 2, 'b'"); }
TablesNamesFinder implements SelectVisitor, FromItemVisitor, ExpressionVisitor, ItemsListVisitor, SelectItemVisitor, StatementVisitor { public List<String> getTableList(Statement statement) { init(); statement.accept(this); return tables; } List<String> getTableList(Statement statement); @Override void visit(Select se...
@Test public void testGetTableList() throws Exception { String sql = "SELECT * FROM MY_TABLE1, MY_TABLE2, (SELECT * FROM MY_TABLE3) LEFT OUTER JOIN MY_TABLE4 " + " WHERE ID = (SELECT MAX(ID) FROM MY_TABLE5) AND ID2 IN (SELECT * FROM MY_TABLE6)"; net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReade...
Elements extends ArrayList<Element> { public Elements wrap(String html) { Validate.notEmpty(html); for (Element element : this) { element.wrap(html); } return this; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @...
@Test public void wrap() { String h = "<p><b>This</b> is <b>jsoup</b></p>"; Document doc = Jsoup.parse(h); doc.select("b").wrap("<i></i>"); assertEquals("<p><i><b>This</b></i> is <i><b>jsoup</b></i></p>", doc.body().html()); }
Elements extends ArrayList<Element> { public Elements unwrap() { for (Element element : this) { element.unwrap(); } return this; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String at...
@Test public void unwrap() { String h = "<div><font>One</font> <font><a href=\"/\">Two</a></font></div"; Document doc = Jsoup.parse(h); doc.select("font").unwrap(); assertEquals("<div>One <a href=\"/\">Two</a></div>", TextUtil.stripNewlines(doc.body().html())); }
TypeHandlerRegistry { public static <T> TypeHandler<T> getTypeHandler(Class<T> type) { return getTypeHandler(type, null); } static boolean hasTypeHandler(Class<?> javaType); @Nullable static TypeHandler<T> getNullableTypeHandler(Class<T> type); static TypeHandler<T> getTypeHandler(Class<T> type); @Nullable static Type...
@Test public void testException() throws Exception { thrown.expect(TypeException.class); thrown.expectMessage("Can't get type handle, java type is 'class java.lang.StringBuffer', jdbc type is 'null'"); TypeHandlerRegistry.getTypeHandler(StringBuffer.class); }
SelectUtils { public static void addExpression(Select select, final Expression expr) { select.getSelectBody().accept(new SelectVisitor() { @Override public void visit(PlainSelect plainSelect) { plainSelect.getSelectItems().add(new SelectExpressionItem(expr)); } @Override public void visit(SetOperationList setOpList) { ...
@Test public void testAddExpr() throws JSQLParserException { Select select = (Select) CCJSqlParserUtil.parse("select a from mytable"); SelectUtils.addExpression(select, new Column("b")); assertEquals("SELECT a, b FROM mytable", select.toString()); Addition add = new Addition(); add.setLeftExpression(new LongValue(5)); ...
SelectUtils { public static Join addJoin(Select select, final Table table, final Expression onExpression) { if (select.getSelectBody() instanceof PlainSelect) { PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); List<Join> joins = plainSelect.getJoins(); if (joins == null) { joins = new ArrayList<Join>(); ...
@Test public void testAddJoin() throws JSQLParserException { Select select = (Select)CCJSqlParserUtil.parse("select a from mytable"); final EqualsTo equalsTo = new EqualsTo(); equalsTo.setLeftExpression(new Column("a")); equalsTo.setRightExpression(new Column("b")); Join addJoin = SelectUtils.addJoin(select, new Table(...
SelectUtils { public static Select buildSelectFromTableAndExpressions(Table table, Expression ... expr) { SelectItem[] list = new SelectItem[expr.length]; for (int i=0;i<expr.length;i++) { list[i]=new SelectExpressionItem(expr[i]); } return buildSelectFromTableAndSelectItems(table, list); } private SelectUtils(); stat...
@Test public void testBuildSelectFromTableAndExpressions() { Select select = SelectUtils.buildSelectFromTableAndExpressions(new Table("mytable"), new Column("a"), new Column("b")); assertEquals("SELECT a, b FROM mytable", select.toString()); } @Test public void testBuildSelectFromTableAndParsedExpression() throws JSQLP...
SelectUtils { public static Select buildSelectFromTable(Table table) { return buildSelectFromTableAndSelectItems(table, new AllColumns()); } private SelectUtils(); static Select buildSelectFromTableAndExpressions(Table table, Expression ... expr); static Select buildSelectFromTableAndExpressions(Table table, String .....
@Test public void testBuildSelectFromTable() { Select select = SelectUtils.buildSelectFromTable(new Table("mytable")); assertEquals("SELECT * FROM mytable", select.toString()); }
Elements extends ArrayList<Element> { public Elements empty() { for (Element element : this) { element.empty(); } return this; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr...
@Test public void empty() { Document doc = Jsoup.parse("<div><p>Hello <b>there</b></p> <p>now!</p></div>"); doc.outputSettings().prettyPrint(false); doc.select("p").empty(); assertEquals("<div><p></p> <p></p></div>", doc.body().html()); }