Here are the examples of the java api org.hibernate.query.Query.setParameter() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
260 Examples
19
Source : HibernatePersistenceProvider.java
with MIT License
from VoxelGamesLib
with MIT License
from VoxelGamesLib
@Override
public List<Pair<UUID, Double>> getTopWithUUID(Trackable type, int amount) {
return session(session -> {
Query query = session.createQuery("select stat.uuid, stat.val from StatInstance stat\n" + "where stat.statType = :type\n" + "order by stat.val desc");
query.setParameter("type", type);
query.setMaxResults(amount);
List<Pair<UUID, Double>> result = new ArrayList<>();
// noinspection unchecked
for (Object[] row : (List<Object[]>) query.getResultList()) {
result.add(new Pair<>((UUID) row[0], (Double) row[1]));
}
return result;
});
}
19
Source : HibernatePersistenceProvider.java
with MIT License
from VoxelGamesLib
with MIT License
from VoxelGamesLib
@Override
public List<Pair<Component, Double>> getTopWithName(Trackable type, int amount) {
return session(session -> {
Query query = session.createQuery("select user.displayName, stat.val from StatInstance stat, UserData user\n" + "where user.uuid = stat.uuid\n" + "and stat.statType = :type\n" + "order by stat.val desc");
query.setParameter("type", type);
query.setMaxResults(amount);
List<Pair<Component, Double>> result = new ArrayList<>();
// noinspection unchecked
for (Object[] row : (List<Object[]>) query.getResultList()) {
result.add(new Pair<>((Component) row[0], (Double) row[1]));
}
return result;
});
}
19
Source : VersioningUtils.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
/**
* Checks the database and returns if a commitHash belongs to a repository
*
* @param session
* @param commitHash : hash of commit
* @param repositoryId : id of the repository
* @return
*/
static boolean commitRepositoryMappingExists(Session session, String commitHash, Long repositoryId) {
Query query = session.createQuery(COMMIT_BELONGS_TO_REPO_QUERY);
query.setParameter("commitHash", commitHash);
query.setParameter("repositoryId", repositoryId);
Long count = (Long) query.getSingleResult();
return count > 0;
}
19
Source : MetadataDAORdbImpl.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
private void deleteLabels(Session session, IdentificationType id, List<String> labels, boolean deleteAll) {
if (deleteAll) {
StringBuilder stringQueryBuilder = new StringBuilder("delete from ").append(LabelsMappingEnreplacedy.clreplaced.getSimpleName()).append(" lm WHERE ");
stringQueryBuilder.append(" lm.").append(ModelDBConstants.ID).append(".").append(ModelDBConstants.ENreplacedY_HASH).append(" = :").append(ModelDBConstants.ENreplacedY_HASH).append(" AND lm.id.").append(ModelDBConstants.ENreplacedY_TYPE).append(" = :").append(ModelDBConstants.ENreplacedY_TYPE);
Query<LabelsMappingEnreplacedy> query = session.createQuery(stringQueryBuilder.toString()).setLockOptions(new LockOptions().setLockMode(LockMode.PESSIMISTIC_WRITE));
query.setParameter(ModelDBConstants.ENreplacedY_HASH, getEnreplacedyHash(id));
query.setParameter(ModelDBConstants.ENreplacedY_TYPE, id.getIdTypeValue());
query.executeUpdate();
} else {
for (String label : labels) {
LabelsMappingEnreplacedy.LabelMappingId id0 = LabelsMappingEnreplacedy.createId(id, label);
LabelsMappingEnreplacedy existingLabelsMappingEnreplacedy = session.get(LabelsMappingEnreplacedy.clreplaced, id0, LockMode.PESSIMISTIC_WRITE);
if (existingLabelsMappingEnreplacedy != null) {
session.delete(existingLabelsMappingEnreplacedy);
}
}
}
}
19
Source : MetadataDAORdbImpl.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
@Override
public void deleteKeyValueProperties(DeleteKeyValuePropertiesRequest request) {
try (Session session = modelDBHibernateUtil.getSessionFactory().openSession()) {
session.beginTransaction();
if (request.getDeleteAll()) {
StringBuilder stringQueryBuilder = new StringBuilder("delete from ").append(KeyValuePropertyMappingEnreplacedy.clreplaced.getSimpleName()).append(" kv WHERE ");
stringQueryBuilder.append(" kv.").append(ModelDBConstants.ID).append(".").append(ModelDBConstants.ENreplacedY_HASH).append(" = :").append(ModelDBConstants.ENreplacedY_HASH).append(" AND kv.id.").append(ModelDBConstants.PROPERTY_NAME).append(" = :").append(ModelDBConstants.PROPERTY_NAME);
Query<LabelsMappingEnreplacedy> query = session.createQuery(stringQueryBuilder.toString()).setLockOptions(new LockOptions().setLockMode(LockMode.PESSIMISTIC_WRITE));
query.setParameter(ModelDBConstants.ENreplacedY_HASH, getEnreplacedyHash(request.getId()));
query.setParameter(ModelDBConstants.PROPERTY_NAME, request.getPropertyName());
query.executeUpdate();
} else {
for (String key : request.getKeysList()) {
KeyValuePropertyMappingEnreplacedy.KeyValuePropertyMappingId id0 = KeyValuePropertyMappingEnreplacedy.createId(request.getId(), key, request.getPropertyName());
KeyValuePropertyMappingEnreplacedy kvEnreplacedy = session.get(KeyValuePropertyMappingEnreplacedy.clreplaced, id0, LockMode.PESSIMISTIC_WRITE);
if (kvEnreplacedy != null) {
session.delete(kvEnreplacedy);
}
}
}
session.getTransaction().commit();
}
}
19
Source : DefaultIssueManager.java
with MIT License
from theonedev
with MIT License
from theonedev
@SuppressWarnings({ "unchecked", "rawtypes" })
@Transactional
@Override
public void fixFieldValueOrders() {
Query query = getSession().createQuery("select distinct name, value, ordinal from IssueField where type=:choice");
query.setParameter("choice", FieldSpec.ENUMERATION);
for (Object[] row : (List<Object[]>) query.getResultList()) {
String name = (String) row[0];
String value = (String) row[1];
long ordinal = (long) row[2];
SpecifiedChoices specifiedChoices = SpecifiedChoices.of(getIssueSetting().getFieldSpec(name));
if (specifiedChoices != null) {
long newOrdinal = specifiedChoices.getChoiceValues().indexOf(value);
if (ordinal != newOrdinal) {
query = getSession().createQuery("update IssueField set ordinal=:newOrdinal where name=:fieldName and value=:fieldValue");
query.setParameter("fieldName", name);
query.setParameter("fieldValue", value);
query.setParameter("newOrdinal", newOrdinal);
query.executeUpdate();
}
}
}
}
19
Source : DefaultBuildParamManager.java
with MIT License
from theonedev
with MIT License
from theonedev
@Transactional
@Override
public void deleteParams(Build build) {
Query<?> query = getSession().createQuery("delete from BuildParam where build = :build");
query.setParameter("build", build);
query.executeUpdate();
build.getParams().clear();
}
19
Source : UserSongRecordDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds a song record by its endtime and the user.
* @param endtime The endtime of the record
* @param user The user of the record
* @return A matching record, or null
*/
public UserSongRecord findByEndtimeAndUser(final LocalDateTime endtime, final UserProfile user) {
final Query<UserSongRecord> query = this.getCurrentSession().createQuery("from UserSongRecord where user = :user and endtime = :endtime");
query.setParameter("user", user);
query.setParameter("endtime", endtime);
query.setTimeout(20);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
19
Source : ShopDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds a shop by its PCBID.
* @param pcbId The PCBID to query for.
* @return The matching Shop, or null if none are found.
*/
public Shop findByPcbId(final String pcbId) {
final Query<Shop> query = this.getCurrentSession().createQuery("from Shop where pcb_id = :pcbid");
query.setParameter("pcbid", pcbId);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
19
Source : ProfileDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds a DDR profile by the dancer code.
* @param dancerCode The dancer code for the profile
* @return The profile for the given dancer code
*/
public UserProfile findByDancerCode(final int dancerCode) {
final Query<UserProfile> query = this.getCurrentSession().createQuery("from UserProfile where dancer_code = :dancerCode");
query.setParameter("dancerCode", dancerCode);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
19
Source : ProfileDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Find a DDR profile by the owner.
* @param user The owning account
* @return The profile for the given user
*/
public UserProfile findByUser(final ButterflyUser user) {
final Query<UserProfile> query = this.getCurrentSession().createQuery("from UserProfile where user = :user");
query.setParameter("user", user);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
19
Source : EventSaveDataDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds an entry for an event for a user based on its event id.
* @param user The user for the events
* @param eventId The id of the event
* @return The matching records
*/
public EventSaveData findByUserAndEventId(final UserProfile user, final int eventId) {
final Query<EventSaveData> query = this.getCurrentSession().createQuery("from EventSaveData where user = :user and eventId = :eventId").setMaxResults(1);
query.setParameter("user", user);
query.setParameter("eventId", eventId);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
19
Source : HibernateStatisticsCounterDao.java
with Mozilla Public License 2.0
from secdec
with Mozilla Public License 2.0
from secdec
private void addParameterLists(List<Integer> filteredSeverities, List<Integer> filteredVulnerabilities, Scan scan, Query query) {
if (!filteredSeverities.isEmpty()) {
query.setParameterList("filteredSeverities", filteredSeverities);
}
if (!filteredVulnerabilities.isEmpty()) {
query.setParameterList("filteredVulnerabilities", filteredVulnerabilities);
}
if (scan != null) {
query.setParameter("scanId", scan.getId());
}
}
19
Source : HibernateUserStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public String getDisplayName(String userUid) {
String sql = "select concat(firstname, ' ', surname) from userinfo where uid =:uid";
Query<String> query = getSession().createNativeQuery(sql);
query.setParameter("uid", userUid);
return query.getSingleResult();
}
19
Source : HibernateTrackedEntityAttributeValueStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public int getCountOfreplacedignedTEAValues(TrackedEnreplacedyAttribute attribute) {
Query query = getQuery("select count(distinct c) from TrackedEnreplacedyAttributeValue c where c.attribute = :attribute");
query.setParameter("attribute", attribute);
return ((Long) query.getSingleResult()).intValue();
}
19
Source : HibernateTrackedEntityAttributeValueStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public List<TrackedEnreplacedyAttributeValue> get(TrackedEnreplacedyInstance enreplacedyInstance, Program program) {
String query = " from TrackedEnreplacedyAttributeValue v where v.enreplacedyInstance =:enreplacedyInstance and v.attribute.program =:program";
Query<TrackedEnreplacedyAttributeValue> typedQuery = getQuery(query);
typedQuery.setParameter("enreplacedyInstance", enreplacedyInstance);
typedQuery.setParameter("program", program);
return getList(typedQuery);
}
19
Source : HibernateProgramStageInstanceStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public boolean exists(String uid) {
if (uid == null) {
return false;
}
Query query = getSession().createNativeQuery("select exists(select 1 from programstageinstance where uid=:uid and deleted is false)");
query.setParameter("uid", uid);
return ((Boolean) query.getSingleResult()).booleanValue();
}
19
Source : HibernateProgramStageInstanceStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public boolean existsIncludingDeleted(String uid) {
if (uid == null) {
return false;
}
Query query = getSession().createNativeQuery("select exists(select 1 from programstageinstance where uid=:uid)");
query.setParameter("uid", uid);
return ((Boolean) query.getSingleResult()).booleanValue();
}
19
Source : HibernateOrganisationUnitStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public Long getOrganisationUnitHierarchyMemberCount(OrganisationUnit parent, Object member, String collectionName) {
final String hql = "select count(*) from OrganisationUnit o " + "where o.path like :path " + "and :object in elements(o." + collectionName + ")";
Query<Long> query = getTypedQuery(hql);
query.setParameter("path", parent.getPath() + "%").setParameter("object", member);
return query.getSingleResult();
}
19
Source : HibernateMessageConversationStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public long getUnreadUserMessageConversationCount(User user) {
replacedert.notNull(user, "User must be specified");
String hql = "select count(*) from MessageConversation m join m.userMessages u where u.user = :user and u.read = false";
Query<Long> query = getTypedQuery(hql);
query.setParameter("user", user);
return query.uniqueResult();
}
19
Source : HibernateMapStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public int countMapViewMaps(MapView mapView) {
Query<Long> query = getTypedQuery("select count(distinct c) from Map c where :mapView in elements(c.mapViews)");
query.setParameter("mapView", mapView);
return query.getSingleResult().intValue();
}
19
Source : HibernateKeyJsonValueStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public List<String> getKeysInNamespace(String namespace) {
String hql = "select key from KeyJsonValue where namespace = :namespace";
Query<String> query = getTypedQuery(hql);
return query.setParameter("namespace", namespace).list();
}
19
Source : HibernateDataValueStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public List<DataValue> getDataValues(OrganisationUnit source, Period period, Collection<DataElement> dataElements, CategoryOptionCombo attributeOptionCombo) {
Period storedPeriod = periodStore.reloadPeriod(period);
if (storedPeriod == null || dataElements == null || dataElements.isEmpty()) {
return new ArrayList<>();
}
String hql = "select dv from DataValue dv where dv.dataElement in (:dataElements) and dv.period =:period and dv.deleted = false ";
if (source != null) {
hql += " and dv.source =:source ";
}
if (attributeOptionCombo != null) {
hql += " and dv.attributeOptionCombo =:attributeOptionCombo ";
}
Query<DataValue> query = getQuery(hql).setParameter("dataElements", dataElements).setParameter("period", storedPeriod);
if (source != null) {
query.setParameter("source", source);
}
if (attributeOptionCombo != null) {
query.setParameter("attributeOptionCombo", attributeOptionCombo);
}
return getList(query);
}
19
Source : HibernateDashboardItemStore.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public Dashboard getDashboardFromDashboardItem(DashboardItem dashboardItem) {
Query<Dashboard> query = getTypedQuery("from Dashboard d where :item in elements(d.items)");
query.setParameter("item", dashboardItem);
return query.getSingleResult();
}
19
Source : SubjectUtils.java
with MIT License
from ConnectedPlacesCatapult
with MIT License
from ConnectedPlacesCatapult
public static List<Subject> subjectsWithinSubject(SubjectType subjectType, Subject subject) {
return HibernateUtil.withSession(session -> {
Query query = session.createQuery("from Subject where subjectType = :subjectType and within(shape, :geom) = true", Subject.clreplaced);
query.setParameter("subjectType", subjectType);
query.setParameter("geom", subject.getShape());
query.setCacheable(true);
return (List<Subject>) query.getResultList();
});
}
19
Source : SubjectUtils.java
with MIT License
from ConnectedPlacesCatapult
with MIT License
from ConnectedPlacesCatapult
public static List<Subject> subjectsContainingSubject(SubjectType subjectType, Subject subject) {
return HibernateUtil.withSession(session -> {
Query query = session.createQuery("from Subject where subjectType = :subjectType and contains(shape, :geom) = true", Subject.clreplaced);
query.setParameter("subjectType", subjectType);
query.setParameter("geom", subject.getShape());
query.setCacheable(true);
return (List<Subject>) query.getResultList();
});
}
19
Source : SubjectUtils.java
with MIT License
from ConnectedPlacesCatapult
with MIT License
from ConnectedPlacesCatapult
public static Subject subjectNearestSubject(SubjectType subjectType, Subject subject, Double radius) {
return HibernateUtil.withSession(session -> {
Query query = session.createQuery("from Subject where subjectType = :subjectType and st_dwithin(shape, :geom, :radius) = true order by st_distance(shape, :geom)", Subject.clreplaced);
query.setParameter("subjectType", subjectType);
query.setParameter("geom", subject.getShape());
query.setParameter("radius", radius);
query.setCacheable(true);
query.setMaxResults(1);
return (Subject) query.uniqueResult();
});
}
19
Source : SubjectUtils.java
with MIT License
from ConnectedPlacesCatapult
with MIT License
from ConnectedPlacesCatapult
public static List<Subject> getSubjectByTypeAndNameIsNull(SubjectType subjectType, boolean includeNull) {
return HibernateUtil.withSession(session -> {
Query query;
if (includeNull)
query = session.createQuery("from Subject where subjectType = :subjectType and name is null", Subject.clreplaced);
else
query = session.createQuery("from Subject where subjectType = :subjectType and name is not null", Subject.clreplaced);
return query.setParameter("subjectType", subjectType).list();
});
}
19
Source : AttributeUtils.java
with MIT License
from ConnectedPlacesCatapult
with MIT License
from ConnectedPlacesCatapult
public static Attribute getByProviderAndLabel(String providerLabel, String attributeLabel) {
return HibernateUtil.withSession(session -> {
Query query = session.createQuery("from Attribute where provider.label = :providerLabel and label = :attributeLabel", Attribute.clreplaced);
query.setCacheable(true);
query.setParameter("providerLabel", providerLabel);
query.setParameter("attributeLabel", attributeLabel);
return (Attribute) query.uniqueResult();
});
}
19
Source : AbsSupportDao.java
with MIT License
from aiyoyoyo
with MIT License
from aiyoyoyo
private void _set_parameter(Query _query, String[] _param, Object[] _value) {
if (_param != null && _value != null) {
for (int i = 0; i < _param.length; i++) {
if (_value[i] instanceof Collection)
_query.setParameterList(_param[i], (Collection<?>) _value[i]);
else
_query.setParameter(_param[i], _value[i]);
}
}
}
18
Source : VersioningUtils.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
public static Set<ArtifactPartEnreplacedy> getArtifactPartEnreplacedies(Session session, String artifactId, int artifactType) {
String queryString = "From " + ArtifactPartEnreplacedy.clreplaced.getSimpleName() + " arp WHERE arp.artifact_type = :artifactType AND arp.artifact_id = :artifactId";
Query query = session.createQuery(queryString);
query.setParameter("artifactType", artifactType);
query.setParameter("artifactId", artifactId);
List<ArtifactPartEnreplacedy> artifactPartEnreplacedies = query.list();
return new HashSet<>(artifactPartEnreplacedies);
}
18
Source : DatasetBlobFactory.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
static PathDatasetBlob getPathBlob(Session session, String blobHash) {
String pathComponentQueryHQL = "From " + PathDatasetComponentBlobEnreplacedy.clreplaced.getSimpleName() + " p WHERE p.id.path_dataset_blob_id = :blobShas";
Query<PathDatasetComponentBlobEnreplacedy> pathComponentQuery = session.createQuery(pathComponentQueryHQL);
pathComponentQuery.setParameter("blobShas", blobHash);
List<PathDatasetComponentBlobEnreplacedy> pathDatasetComponentBlobEnreplacedies = pathComponentQuery.list();
if (pathDatasetComponentBlobEnreplacedies != null && pathDatasetComponentBlobEnreplacedies.size() > 0) {
List<PathDatasetComponentBlob> componentBlobs = pathDatasetComponentBlobEnreplacedies.stream().map(PathDatasetComponentBlobEnreplacedy::toProto).collect(Collectors.toList());
return PathDatasetBlob.newBuilder().addAllComponents(componentBlobs).build();
} else {
return null;
}
}
18
Source : SoftDeleteProjects.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
@Override
protected ReconcileResult reconcile(Set<String> ids) {
LOGGER.debug("Reconciling projects " + ids.toString());
roleService.deleteEnreplacedyResourcesWithServiceUser(new ArrayList<>(ids), ModelDBResourceEnum.ModelDBServiceResourceTypes.PROJECT);
try (Session session = modelDBHibernateUtil.getSessionFactory().openSession()) {
String projectsQueryString = String.format("from %s where id in (:ids)", ProjectEnreplacedy.clreplaced.getSimpleName());
Query projectDeleteQuery = session.createQuery(projectsQueryString);
projectDeleteQuery.setParameter("ids", ids);
List<ProjectEnreplacedy> projectEnreplacedies = projectDeleteQuery.list();
Transaction transaction = session.beginTransaction();
String updateDeletedChildren = String.format("UPDATE %s SET deleted=:deleted WHERE project_id IN (:ids)", ExperimentEnreplacedy.clreplaced.getSimpleName());
Query updateDeletedChildrenQuery = session.createQuery(updateDeletedChildren);
updateDeletedChildrenQuery.setParameter("deleted", true);
updateDeletedChildrenQuery.setParameter("ids", ids);
updateDeletedChildrenQuery.executeUpdate();
transaction.commit();
// TODO: figure out if doing a single query to delete all projects
for (ProjectEnreplacedy projectEnreplacedy : projectEnreplacedies) {
transaction = session.beginTransaction();
session.delete(projectEnreplacedy);
transaction.commit();
}
}
return new ReconcileResult();
}
18
Source : SoftDeleteExperiments.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
@Override
protected ReconcileResult reconcile(Set<String> ids) {
LOGGER.debug("Reconciling experiments " + ids.toString());
deleteRoleBindings(ids);
try (Session session = modelDBHibernateUtil.getSessionFactory().openSession()) {
String experimentQueryString = String.format("from %s where id in (:ids)", ExperimentEnreplacedy.clreplaced.getSimpleName());
Query<ExperimentEnreplacedy> experimentDeleteQuery = session.createQuery(experimentQueryString, ExperimentEnreplacedy.clreplaced);
experimentDeleteQuery.setParameter("ids", ids);
List<ExperimentEnreplacedy> experimentEnreplacedies = experimentDeleteQuery.list();
Transaction transaction = session.beginTransaction();
String updateDeletedChildren = String.format("UPDATE %s SET deleted=:deleted WHERE experiment_id IN (:ids)", ExperimentRunEnreplacedy.clreplaced.getSimpleName());
Query updateDeletedChildrenQuery = session.createQuery(updateDeletedChildren);
updateDeletedChildrenQuery.setParameter("deleted", true);
updateDeletedChildrenQuery.setParameter("ids", ids);
updateDeletedChildrenQuery.executeUpdate();
transaction.commit();
for (ExperimentEnreplacedy experimentEnreplacedy : experimentEnreplacedies) {
transaction = session.beginTransaction();
session.delete(experimentEnreplacedy);
transaction.commit();
}
}
return new ReconcileResult();
}
18
Source : SoftDeleteExperimentRuns.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
@Override
protected ReconcileResult reconcile(Set<String> ids) {
LOGGER.debug("Reconciling experiment runs " + ids.toString());
deleteRoleBindings(ids);
try (Session session = modelDBHibernateUtil.getSessionFactory().openSession()) {
String experimentRunQueryString = String.format("from %s where id in (:ids)", ExperimentRunEnreplacedy.clreplaced.getSimpleName());
Query<ExperimentRunEnreplacedy> experimentRunDeleteQuery = session.createQuery(experimentRunQueryString, ExperimentRunEnreplacedy.clreplaced);
experimentRunDeleteQuery.setParameter("ids", ids);
List<ExperimentRunEnreplacedy> experimentRunEnreplacedies = experimentRunDeleteQuery.list();
Transaction transaction = session.beginTransaction();
String delete = String.format("DELETE FROM %s WHERE enreplacedy_id IN (:ids)", CommentEnreplacedy.clreplaced.getSimpleName());
Query deleteQuery = session.createQuery(delete);
deleteQuery.setParameter("ids", ids);
deleteQuery.executeUpdate();
transaction.commit();
for (ExperimentRunEnreplacedy experimentRunEnreplacedy : experimentRunEnreplacedies) {
transaction = session.beginTransaction();
session.delete(experimentRunEnreplacedy);
transaction.commit();
}
}
return new ReconcileResult();
}
18
Source : MetadataDAORdbImpl.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
private List<LabelsMappingEnreplacedy> getLabelsMappingEnreplacedies(Session session, IdentificationType id) {
Query<LabelsMappingEnreplacedy> query = session.createQuery(GET_LABELS_HQL + " ORDER BY lm.id.label", LabelsMappingEnreplacedy.clreplaced);
query.setParameter("enreplacedyHash", getEnreplacedyHash(id));
query.setParameter("enreplacedyType", id.getIdTypeValue());
return query.list();
}
18
Source : MetadataDAORdbImpl.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
@Override
public List<KeyValueStringProperty> getKeyValueProperties(GetKeyValuePropertiesRequest request) {
try (Session session = modelDBHibernateUtil.getSessionFactory().openSession()) {
List<KeyValueStringProperty> keyValues = new ArrayList<>();
if (request.getGetAll()) {
Query<KeyValuePropertyMappingEnreplacedy> query = session.createQuery(GET_KEY_VALUE_PROPERTY_HQL, KeyValuePropertyMappingEnreplacedy.clreplaced);
query.setParameter(ModelDBConstants.ENreplacedY_HASH, getEnreplacedyHash(request.getId()));
query.setParameter(ModelDBConstants.PROPERTY_NAME, request.getPropertyName());
List<KeyValuePropertyMappingEnreplacedy> kvMappings = query.list();
if (!kvMappings.isEmpty()) {
kvMappings.forEach(mappingEnreplacedy -> {
keyValues.add(KeyValueStringProperty.newBuilder().setKey(mappingEnreplacedy.getId().getKey()).setValue(mappingEnreplacedy.getValue()).build());
});
}
} else {
for (String key : request.getKeysList()) {
KeyValuePropertyMappingEnreplacedy.KeyValuePropertyMappingId id0 = KeyValuePropertyMappingEnreplacedy.createId(request.getId(), key, request.getPropertyName());
KeyValuePropertyMappingEnreplacedy kvEnreplacedy = session.get(KeyValuePropertyMappingEnreplacedy.clreplaced, id0);
if (kvEnreplacedy != null) {
keyValues.add(KeyValueStringProperty.newBuilder().setKey(key).setValue(kvEnreplacedy.getValue()).build());
}
}
}
return keyValues;
}
}
18
Source : CleanUpEntitiesCron.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
private void cleanProjects(Session session) {
LOGGER.trace("Project cleaning");
String alias = "pr";
String deleteProjectsQueryString = new StringBuilder("FROM ").append(ProjectEnreplacedy.clreplaced.getSimpleName()).append(" ").append(alias).append(" WHERE ").append(alias).append(".").append(ModelDBConstants.CREATED).append(" = :created ").append(" AND ").append(alias).append(".").append(ModelDBConstants.DATE_CREATED).append(" < :created_date ").toString();
// Time less then a minute because possible to have create project request running when cron job
// running
// 5 minute lesser time
long time = Calendar.getInstance().getTimeInMillis() - 300000;
Query projectDeleteQuery = session.createQuery(deleteProjectsQueryString);
projectDeleteQuery.setParameter("created", false);
projectDeleteQuery.setParameter("created_date", time);
projectDeleteQuery.setMaxResults(this.recordUpdateLimit);
List<ProjectEnreplacedy> projectEnreplacedies = projectDeleteQuery.list();
List<String> projectIds = new ArrayList<>();
if (!projectEnreplacedies.isEmpty()) {
for (ProjectEnreplacedy projectEnreplacedy : projectEnreplacedies) {
projectIds.add(projectEnreplacedy.getId());
}
try {
roleService.deleteEnreplacedyResourcesWithServiceUser(projectIds, ModelDBResourceEnum.ModelDBServiceResourceTypes.PROJECT);
for (ProjectEnreplacedy projectEnreplacedy : projectEnreplacedies) {
try {
Transaction transaction = session.beginTransaction();
session.delete(projectEnreplacedy);
transaction.commit();
} catch (OptimisticLockException ex) {
LOGGER.info("CleanUpEnreplacediesCron : cleanProjects : Exception: {}", ex.getMessage());
}
}
} catch (OptimisticLockException ex) {
LOGGER.info("CleanUpEnreplacediesCron : cleanProjects : Exception: {}", ex.getMessage());
} catch (Exception ex) {
LOGGER.warn("CleanUpEnreplacediesCron : cleanProjects : Exception: ", ex);
}
}
LOGGER.debug("Project cleaned successfully : Cleaned projects count {}", projectIds.size());
}
18
Source : CommentDAORdbImpl.java
with Apache License 2.0
from VertaAI
with Apache License 2.0
from VertaAI
@Override
public Boolean deleteComment(String enreplacedyType, String enreplacedyId, String commentId, UserInfo userInfo) {
try (Session session = modelDBHibernateUtil.getSessionFactory().openSession()) {
String finalQuery = DELETE_USER_COMMENTS_QUERY;
if (userInfo != null) {
finalQuery = finalQuery + " AND uc." + ModelDBConstants.OWNER + " = :vertaId";
}
Query query = session.createQuery(finalQuery);
query.setParameter("id", commentId);
if (userInfo != null) {
query.setParameter("vertaId", authService.getVertaIdFromUserInfo(userInfo));
}
Transaction transaction = session.beginTransaction();
query.executeUpdate();
transaction.commit();
LOGGER.debug("Comments deleted successfully");
return true;
} catch (Exception ex) {
if (ModelDBUtils.needToRetry(ex)) {
return deleteComment(enreplacedyType, enreplacedyId, commentId, userInfo);
} else {
throw ex;
}
}
}
18
Source : DefaultPullRequestManager.java
with MIT License
from theonedev
with MIT License
from theonedev
@Transactional
@Listen
public void on(EnreplacedyRemoved event) {
if (event.getEnreplacedy() instanceof Project) {
Project project = (Project) event.getEnreplacedy();
for (PullRequest request : project.getOutgoingRequests()) {
if (!request.getTargetProject().equals(project) && request.isOpen())
discard(request, "Source project is deleted.");
}
Query<?> query = getSession().createQuery("update PullRequest set sourceProject=null where " + "sourceProject=:project");
query.setParameter("project", project);
query.executeUpdate();
}
}
18
Source : DefaultPullRequestManager.java
with MIT License
from theonedev
with MIT License
from theonedev
@Transactional
@Override
public void delete(PullRequest request) {
request.deleteRefs();
for (PullRequestUpdate update : request.getUpdates()) update.deleteRefs();
Query<?> query = getSession().createQuery("update CodeComment set request=null where request=:request");
query.setParameter("request", request);
query.executeUpdate();
dao.remove(request);
}
18
Source : DefaultMilestoneManager.java
with MIT License
from theonedev
with MIT License
from theonedev
@Transactional
@Override
public void delete(Milestone milestone) {
Query<?> query = getSession().createQuery("update Issue set milestone=null where milestone=:milestone");
query.setParameter("milestone", milestone);
query.executeUpdate();
super.delete(milestone);
}
18
Source : DefaultBuildParamManager.java
with MIT License
from theonedev
with MIT License
from theonedev
@SuppressWarnings("unchecked")
@Sessional
@Listen
public void on(SystemStarted event) {
logger.info("Caching build param info...");
Map<Long, Long> projectIds = new HashMap<>();
Query<?> query = dao.getSession().createQuery("select id, project.id from Build");
for (Object[] fields : (List<Object[]>) query.list()) projectIds.put((Long) fields[0], (Long) fields[1]);
query = dao.getSession().createQuery("select build.id, name from BuildParam where type != :secret");
query.setParameter("secret", ParamSpec.SECRET);
for (Object[] fields : (List<Object[]>) query.list()) {
Long projectId = projectIds.get(fields[0]);
if (projectId != null)
addBuildParam(projectId, (String) fields[1]);
}
}
18
Source : UserPhasesDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Get the phases for a particular user.
* @param user
* @return
*/
public UserPhases getPhasesForUser(final ButterflyUser user) {
final Query<UserPhases> query = this.getCurrentSession().createQuery("from UserPhases p where p.user = :user");
query.setParameter("user", user);
return query.uniqueResult();
}
18
Source : MachineDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds a machine by its PCBID.
* @param pcbId The PCBID to query for.
* @return The matching Machine, or null if none are found.
*/
public Machine findByPcbId(final String pcbId) {
final Query<Machine> query = this.getCurrentSession().createQuery("from Machine where pcbid = :pcbid");
query.setParameter("pcbid", pcbId);
return query.uniqueResult();
}
18
Source : GoldenLeagueStatusDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds a Golden League status by its user and period.
* @param user The user of the record
* @param period The Golden League period of the record
* @return A matching record, or null
*/
public GoldenLeagueStatus findByUserAndPeriod(final UserProfile user, final GoldenLeaguePeriod period) {
final Query<GoldenLeagueStatus> query = this.getCurrentSession().createQuery("from GoldenLeagueStatus where user = :user and leaguePeriod = :leaguePeriod").setMaxResults(1);
query.setParameter("user", user);
query.setParameter("leaguePeriod", period);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
18
Source : EventSaveDataDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds all event progress for a user.
* @param user The user for the events
* @return A list of matching records
*/
public List<EventSaveData> findByUser(final UserProfile user) {
final Query<EventSaveData> query = this.getCurrentSession().createQuery("from EventSaveData where user = :user");
query.setParameter("user", user);
return query.getResultList();
}
18
Source : CardDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds a card by its ref ID.
* @param refId The ref ID to query for.
* @return The matching Card, or null if none are found.
*/
public Card findByRefId(final String refId) {
final Query<Card> query = this.getCurrentSession().createQuery("from Card where ref_id = :refId");
query.setParameter("refId", refId);
return query.uniqueResult();
}
18
Source : CardDao.java
with Apache License 2.0
from skogaby
with Apache License 2.0
from skogaby
/**
* Finds a card by its NFC ID.
* @param nfcId The NFC ID to query for.
* @return The matching Card, or null if none are found.
*/
public Card findByNfcId(final String nfcId) {
final Query<Card> query = this.getCurrentSession().createQuery("from Card where nfc_id = :nfcId");
query.setParameter("nfcId", nfcId);
return query.uniqueResult();
}
18
Source : UserDao.java
with Apache License 2.0
from quick-perf
with Apache License 2.0
from quick-perf
public User findByEmail(String email) {
Session session = sessionFactory.getCurrentSession();
String emailParam = "email";
String hqlQuery = " FROM " + User.clreplaced.getCanonicalName() + " user" + " WHERE user.email =" + ":" + emailParam;
Query<User> query = session.createQuery(hqlQuery, User.clreplaced);
query.setParameter(emailParam, email);
return query.getSingleResult();
}
See More Examples