@Override @Transactional(readOnly = true) public Customer findById(Long id) { if (id == null) { return null; } return findOne(qCustomer.id.eq(id)); }
@Override public long doInSqlDeleteClause(SQLDeleteClause delete) { return delete.where(qAddress.customerId.eq(customer.getId())).execute(); } });
@Override public long doInSqlDeleteClause(SQLDeleteClause delete) { return delete.where(qCustomer.id.eq(customer.getId())).execute(); } });
@Override public long doInSqlDeleteClause(SQLDeleteClause delete) { return delete.where(qAddress.customerId.eq(customer.getId()).and(qAddress.id.notIn(ids))).execute(); } });
@Override public long doInSqlUpdateClause(SQLUpdateClause update) { return update.where(qAddress.id.eq(a.getId())).set(qAddress.customerId, customer.getId()) .set(qAddress.street, a.getStreet()).set(qAddress.city, a.getCity()) .set(qAddress.country, a.getCountry()).execute(); } });
@Override public long doInSqlUpdateClause(SQLUpdateClause update) { return update .where(qCustomer.id.eq(customer.getId())) .set(qCustomer.firstName, customer.getFirstName()) .set(qCustomer.lastName, customer.getLastName()) .set(qCustomer.emailAddress, customer.getEmailAddress() == null ? null : customer.getEmailAddress().toString()).execute(); } });
@Override public boolean delete(final Long worklogId) { checkArgument(worklogId != null, "Cannot remove a worklog with id null."); return dbConnectionManager.executeQuery(dbConnection -> dbConnection .delete(WORKLOG) .where(WORKLOG.id.eq(worklogId)) .execute()) == 1; }
@Override public Boolean call(Connection connection, Configuration configuration) throws SQLException { QResource qResource = new QResource("qResource"); SQLDeleteClause deleteClause = new SQLDeleteClause(connection, configuration, qResource); long deletedRecordNum = deleteClause.where(qResource.resourceId.eq(resourceId)).execute(); return deletedRecordNum > 0; } });
@Test public void BasicOperations() { assertToString("cat.bodyWeight = kitten.bodyWeight", cat.bodyWeight.eq(kitten.bodyWeight)); }
@Override public Project updateProjectType(final ApplicationUser user, final Project project, final ProjectTypeKey newProjectType) { checkState(projectTypeValidator.isValid(user, newProjectType)); dbConnectionManager.execute(dbConnection -> { dbConnection.update(QProject.PROJECT) .set(QProject.PROJECT.projecttype, newProjectType != null ? newProjectType.getKey() : null) .where(QProject.PROJECT.id.eq(project.getId())) .execute(); }); return getProjectObj(project.getId()); }
private void updateIssueLinkType(final IssueLink issueLink, final IssueLinkType issueLinkType) { dbConnectionManager.execute(dbConnection -> dbConnection.update(QIssueLink.ISSUE_LINK) .set(QIssueLink.ISSUE_LINK.linktype, issueLinkType.getId()) .where(QIssueLink.ISSUE_LINK.id.eq(issueLink.getId())) .execute()); }
private List<Long> getMinusOneUserLocalePropertyIds(DbConnection dbConnection) { QOSPropertyEntry propertyEntry = QOSPropertyEntry.O_S_PROPERTY_ENTRY; QOSPropertyString propertyString = QOSPropertyString.O_S_PROPERTY_STRING; // MSSQL meet incompatible data type problem when we use equal operator (IN, EQUALS) so we have to use LIKE instead List<Long> propertyIds = dbConnection.newSqlQuery().from(propertyEntry).join(propertyString) .on(propertyEntry.id.eq(propertyString.id)) .where(propertyEntry.propertyKey.eq("jira.user.locale").and(propertyString.value.like("-1"))) .list(propertyString.id); return propertyIds; }
@Test public void DocoExamples97_6() throws Exception { query().from(cat).where(cat.mate.id.eq(69)).parse(); }
@Test public void Case() { QCat cat = QCat.cat; JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT); Expression<?> expr = Expressions.cases().when(cat.toes.eq(2)).then(2) .when(cat.toes.eq(3)).then(3) .otherwise(4); serializer.handle(expr); assertEquals("case when (cat.toes = ?1) then ?1 when (cat.toes = ?2) then ?2 else ?3 end", serializer.toString()); }
@Test public void Case_Hibernate() { QCat cat = QCat.cat; JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT); Expression<?> expr = Expressions.cases().when(cat.toes.eq(2)).then(2) .when(cat.toes.eq(3)).then(3) .otherwise(4); serializer.handle(expr); assertEquals("case when (cat.toes = ?1) then ?1 when (cat.toes = ?2) then ?2 else 4 end", serializer.toString()); }
@Test public void DocoExamples97_7() throws Exception { query().from(person).where( person.pid.country.eq("AU"), person.pid.medicareNumber.eq(123456)).parse(); }
@Test public void Case2() { QCat cat = QCat.cat; JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT); Expression<?> expr = Expressions.cases().when(cat.toes.eq(2)).then(cat.id.multiply(2)) .when(cat.toes.eq(3)).then(cat.id.multiply(3)) .otherwise(4); serializer.handle(expr); assertEquals("case when (cat.toes = ?1) then (cat.id * ?1) when (cat.toes = ?2) then (cat.id * ?2) else ?3 end", serializer.toString()); }
@Test public void And_Or() { //A.a.id.eq(theId).and(B.b.on.eq(false).or(B.b.id.eq(otherId))); QCat cat = QCat.cat; Predicate pred = cat.id.eq(1).and(cat.name.eq("Kitty").or(cat.name.eq("Boris"))); JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT); serializer.handle(pred); assertEquals("cat.id = ?1 and (cat.name = ?2 or cat.name = ?3)", serializer.toString()); assertEquals("cat.id = 1 && (cat.name = Kitty || cat.name = Boris)", pred.toString()); }
@Test @ExcludeIn({DERBY, HSQLDB, ORACLE}) public void DocoExamples98_10() throws Exception { query().from(item, ord).select(item).where( ord.items(ord.deliveredItemIndices(0)).eq(item), ord.id.eq(1l)).parse(); }
@Test @ExcludeIn(MYSQL) // doesn't work in Eclipselink public void Case4() { NumberExpression<Float> numExpression = cat.bodyWeight.floatValue().divide(otherCat.bodyWeight.floatValue()).multiply(100); NumberExpression<Float> numExpression2 = cat.id.when(0).then(0.0F).otherwise(numExpression); assertEquals(ImmutableList.of(200, 150, 133, 125, 120), query().from(cat, otherCat) .where(cat.id.eq(otherCat.id.add(1))) .orderBy(cat.id.asc(), otherCat.id.asc()) .list(numExpression2.intValue())); }