@Override public SQLQuery newSqlQuery() { return new SQLQuery(con, dialect); }
@Override public SQLQuery query() { return new SQLQuery(connection.get(), configuration); }
@Override public SQLQuery query() { return new SQLQuery(connection.get(), configuration); }
private boolean hasRow() { SQLQuery query = new SQLQuery(connection, configuration).from(entity); addKeyConditions(query); return query.exists(); }
@Override public String getProperty(final String key) { String cacheValue = cache.get(key); if (cacheValue != null) { return cacheValue; } else { try (Connection connection = dataSource.getConnection()) { SQLQuery sqlQuery = new SQLQuery(connection, sqlTemplates); QProperties prop = QProperties.propProperties; List<String> values = sqlQuery.from(prop).where(prop.key.eq(key)).list(prop.value); if (values.isEmpty()) { return null; } else { return values.get(0); } } catch (SQLException e) { throw new PropertyServiceDataSourceConnectionException("Cannot connect to DataSource.", e); } } }
@Override public Optional<Long> getResourceId(final String principal) { return querydslSupport.execute((connection, configuration) -> { QSimpleSubject qSimpleSubject = QSimpleSubject.simpleSubject; Long resourceId = new SQLQuery(connection, configuration) .from(qSimpleSubject) .where(qSimpleSubject.principal.eq(principal)) .singleResult(qSimpleSubject.resourceId); return Optional.ofNullable(resourceId); }); }
private boolean lockOnResource(final Connection connection, final Configuration configuration, final long resourceId) { SQLQuery query = new SQLQuery(connection, configuration); QResource resource = QResource.resource; List<Long> results = query.from(resource).where(resource.resourceId.eq(resourceId)).forUpdate() .list(resource.resourceId); return !(results.size() == 0); }
@Override public SQLQuery clone(Connection conn) { SQLQuery q = new SQLQuery(conn, getConfiguration(), getMetadata().clone()); q.clone(this); return q; }
/** * Note: transaction must be provided to this method. */ private void lockAuditApplicationTypeTargetResourceId() { querydslSupport.execute((connection, configuration) -> { QResource qResource = QResource.resource; return new SQLQuery(connection, configuration) .from(qResource) .where(qResource.resourceId.eq(auditApplicationTypeTargetResourceId)) .forUpdate(); }); }
/** * Note: transaction must be provided to this method. */ private void lockAuditApplication(final long applicationId) { querydslSupport.execute((connection, configuration) -> { QApplication qApplication = QApplication.application; return new SQLQuery(connection, configuration) .from(qApplication) .where(qApplication.applicationId.eq(applicationId)) .forUpdate(); }); }
@Override public String readEncryptedCredential(final String principal) { return querydslSupport.execute((connection, configuration) -> { QSimpleSubject qSimpleSubject = QSimpleSubject.simpleSubject; return new SQLQuery(connection, configuration) .from(qSimpleSubject) .where(qSimpleSubject.principal.eq(principal)) .singleResult(qSimpleSubject.encryptedCredential); }); }
private long[] readParentResourceIdsFromDatabase(final long resourceId) { return querydslSupport.execute((connection, configuration) -> { SQLQuery query = new SQLQuery(connection, configuration); QPermissionInheritance permissioninheritance = QPermissionInheritance.permissionInheritance; List<Long> result = query.from(permissioninheritance) .where(permissioninheritance.childResourceId.eq(resourceId)) .list(permissioninheritance.parentResourceId); return AuthorizationImpl.convertCollectionToLongArray(result); }); }
private List<AuditEventType> selectAuditEventTypes(final String applicationName, final List<String> eventTypeNames) { return querydslSupport.execute((connection, configuration) -> { QEventType qEventType = QEventType.eventType; QApplication qApplication = QApplication.application; List<AuditEventType> rval = new ArrayList<>(); int numberOfEventTypeNames = eventTypeNames.size(); for (int fromIndex = 0; fromIndex < numberOfEventTypeNames; fromIndex = fromIndex + SELECT_AUDIT_EVENT_TYPES_PAGE_SIZE) { int toIndex = fromIndex + SELECT_AUDIT_EVENT_TYPES_PAGE_SIZE; if (toIndex > numberOfEventTypeNames) { toIndex = numberOfEventTypeNames; } List<String> actualEventTypeNames = new ArrayList<>(eventTypeNames.subList(fromIndex, toIndex)); List<AuditEventType> auditEventTypes = new SQLQuery(connection, configuration) .from(qEventType) .innerJoin(qApplication).on(qEventType.applicationId.eq(qApplication.applicationId)) .where(qApplication.applicationName.eq(applicationName) .and(qEventType.eventTypeName.in(actualEventTypeNames))) .list(Projections.fields(AuditEventType.class, qEventType.eventTypeId, qEventType.eventTypeName, qEventType.resourceId)); rval.addAll(auditEventTypes); } return rval; }); }
@Override public SimpleSubject readSimpleSubjectByPrincipal(final String principal) { return querydslSupport.execute((connection, configuration) -> { QSimpleSubject qSimpleSubject = QSimpleSubject.simpleSubject; return new SQLQuery(connection, configuration) .from(qSimpleSubject) .where(qSimpleSubject.principal.eq(principal)) .singleResult(ConstructorExpression.create(SimpleSubject.class, qSimpleSubject.simpleSubjectId, qSimpleSubject.principal, qSimpleSubject.resourceId)); }); }
private AuditApplication selectAuditApplication(final String applicationName) { return querydslSupport.execute((connection, configuration) -> { QApplication qApplication = QApplication.application; return new SQLQuery(connection, configuration) .from(qApplication) .where(qApplication.applicationName.eq(applicationName)) .uniqueResult(Projections.fields(AuditApplication.class, qApplication.applicationId, qApplication.applicationName, qApplication.resourceId)); }); }
private boolean readPermissionFromDatabase(final long authorizedResourceId, final long targetResourceId, final String action) { return querydslSupport.execute((connection, configuration) -> { SQLQuery query = new SQLQuery(connection, configuration); QPermission permission = QPermission.permission; return query.from(permission) .where(permission.authorizedResourceId.eq(authorizedResourceId) .and(permission.targetResourceId.eq(targetResourceId)) .and(permission.action.eq(action))) .exists(); }); }
private List<QueuedEmailDTO> selectQueuedEmailForUpdate(final int limit) { return querydslSupport.execute((connection, configuration) -> { QEmailQueue qEmailQueue = QEmailQueue.emailQueue; return new SQLQuery(connection, configuration) .from(qEmailQueue) .orderBy(qEmailQueue.timestamp_.asc(), qEmailQueue.queuedEmailId.asc()) .limit(limit) .forUpdate() .list(Projections.fields(QueuedEmailDTO.class, qEmailQueue.queuedEmailId, qEmailQueue.storedEmailId)); }); }
@Test public void Insert_Query_Update() { QPerson person = QPerson.person; // insert SQLInsertClause insert = new SQLInsertClause(connection, configuration, person); insert.set(person.id, 10); insert.set(person.firstname, "Bob"); insert.set(person.gender, Gender.MALE); assertEquals(1l, insert.execute()); // query SQLQuery query = new SQLQuery(connection, configuration); assertEquals(Gender.MALE, query.from(person).where(person.id.eq(10)).uniqueResult(person.gender)); // update SQLUpdateClause update = new SQLUpdateClause(connection, configuration, person); update.set(person.gender, Gender.FEMALE); update.set(person.firstname, "Jane"); update.where(person.id.eq(10)); update.execute(); // query query = new SQLQuery(connection, configuration); assertEquals(Gender.FEMALE, query.from(person).where(person.id.eq(10)).uniqueResult(person.gender)); }