List of usage examples for org.hibernate Query getQueryString
String getQueryString();
From source file:com.lp.server.bestellung.fastlanereader.BestellvorschlagAlleTermineHandler.java
License:Open Source License
/** * gets the data page for the specified row using the current query. The row * at rowIndex will be located in the middle of the page. * // w ww.j av a 2 s. co m * @see UseCaseHandler#getPageAt(java.lang.Integer) * @param rowIndex * Integer * @throws EJBExceptionLP * @return QueryResult */ public QueryResult getPageAt(Integer rowIndex) throws EJBExceptionLP { QueryResult result = null; SessionFactory factory = FLRSessionFactory.getFactory(); Session session = null; try { int colCount = getTableInfo().getColumnClasses().length; int pageSize = BestellvorschlagAlleTermineHandler.PAGE_SIZE; int startIndex = Math.max(rowIndex.intValue() - (pageSize / 2), 0); int endIndex = startIndex + pageSize - 1; session = factory.openSession(); String queryString = this.getFromClause() + this.buildWhereClause() + this.buildOrderByClause(); Query query = session.createQuery(queryString); String qs = query.getQueryString(); query = session.createQuery("select distinct bestellvorschlagalletermine.t_liefertermin from " + "FLRBestellvorschlagAlleTermine bestellvorschlagalletermine " + "WHERE bestellvorschlagalletermine.t_liefertermin IS NOT NULL " + "AND bestellvorschlagalletermine.mandant_c_nr = " + "'" + theClientDto.getMandant() + "' " + "ORDER BY bestellvorschlagalletermine.t_liefertermin"); query.setFirstResult(startIndex); query.setMaxResults(pageSize); List<?> resultList = query.list(); Iterator<?> resultListIterator = resultList.iterator(); Object[][] rows = new Object[resultList.size()][colCount]; int row = 0; int col = 0; while (resultListIterator.hasNext()) { Date t_liefertermin = (Date) resultListIterator.next(); rows[row][col++] = t_liefertermin; rows[row][col++] = t_liefertermin == null ? null : t_liefertermin; row++; col = 0; } result = new QueryResult(rows, this.getRowCount(), startIndex, endIndex, 0); } catch (Exception e) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, e); } finally { closeSession(session); } return result; }
From source file:com.medigy.service.impl.person.PatientWorklistServiceImpl.java
License:Open Source License
public PatientWorklistReturnValues getWorkList(final PatientWorklistParameters parameters) { final List<PatientWorkListItem> itemList = new ArrayList<PatientWorkListItem>(); Query patientWorkListQuery = null; // if for some reason no date is supplied, use todays date final Date selectedDate = parameters.getSelectedDate() != null ? parameters.getSelectedDate() : new Date(); final Date startingTime = parameters.getStartingTime(); final Date endingTime = parameters.getEndingTime(); Calendar cal = new GregorianCalendar(); final Date currentDate = new Date(); cal.setTime(currentDate);/*from w w w.j a v a 2s. c o m*/ // get current hour and minute final int currentHour = cal.get(Calendar.HOUR_OF_DAY); final int currentMinute = cal.get(Calendar.MINUTE); final String queryString = "SELECT \n" + "patient.id, \n" + "patient.lastName, \n" + "patient.firstName, \n" + "roles.person.id, \n" + "roles.person.lastName, \n " + "roles.person.firstName, \n" + "appt.scheduledTime, \n" + "appt.startTime, \n" + "appt.checkoutTime, \n" + "appt.id, \n" + "appt.patientType.label \n" + "FROM HealthCareEncounter appt \n" + " join appt.patient as patient \n" + " left join appt.roles as roles \n" + " with roles.type.id = " + HealthCareVisitRoleType.Cache.REQ_PHYSICIAN.getEntity().getSystemId() + " \n" + "WHERE \n" + " appt.scheduledTime >= :beforeTime and \n" + " appt.scheduledTime < :afterTime " + "ORDER BY \n" + " appt.scheduledTime, patient.lastName, patient.firstName"; // now set the calendar to the selected date and the current hour/minute cal.setTime(selectedDate); if (startingTime == null) { cal.set(Calendar.HOUR_OF_DAY, currentHour); cal.set(Calendar.MINUTE, currentMinute); // save this date! final Date baseComparisonTime = cal.getTime(); final int beforeMinutes = parameters.getBeforeMinutes(); final int afterMinutes = parameters.getAfterMinutes(); cal.add(Calendar.MINUTE, 0 - beforeMinutes); final Date beforeTime = cal.getTime(); cal.setTime(baseComparisonTime); cal.add(Calendar.MINUTE, afterMinutes); final Date afterTime = cal.getTime(); patientWorkListQuery = getSession().createQuery(queryString); patientWorkListQuery.setTimestamp("beforeTime", beforeTime); patientWorkListQuery.setTimestamp("afterTime", afterTime); } else { final Calendar startCal = new GregorianCalendar(); startCal.setTime(startingTime); final Calendar endCal = new GregorianCalendar(); endCal.setTime(endingTime); cal.set(Calendar.HOUR_OF_DAY, startCal.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, startCal.get(Calendar.MINUTE)); final Date beforeTime = cal.getTime(); cal.set(Calendar.HOUR_OF_DAY, endCal.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, endCal.get(Calendar.MINUTE)); final Date afterTime = cal.getTime(); patientWorkListQuery = getSession().createQuery(queryString); patientWorkListQuery.setTimestamp("beforeTime", beforeTime); patientWorkListQuery.setTimestamp("afterTime", afterTime); } final List list = patientWorkListQuery.list(); if (log.isInfoEnabled()) log.info(patientWorkListQuery.getQueryString() + " \n" + list.size()); final Map<Long, Float> accountBalance = getAccountBalance(parameters); //final Map<Long, Float> patientBalance = getPatientBalance(parameters); for (int i = 0; i < list.size(); i++) { final Object rowObject = list.get(i); if (rowObject instanceof Object[]) { final PatientWorkListItemImpl item = new PatientWorkListItemImpl(); final Object[] columnValues = (Object[]) rowObject; item.setPatientId((Long) columnValues[0]); item.setAccountBalance(accountBalance.get(item.getPatientId())); //item.setPatientBalance(patientBalance.get(item.getPatientId())); item.setPatientLastName((String) columnValues[1]); item.setPatientFirstName((String) columnValues[2]); item.setPhysicianId((Long) columnValues[3]); item.setPhysicianLastName((String) columnValues[4]); item.setPhysicianFirstName((String) columnValues[5]); item.setAppointmentTimestamp((Date) columnValues[6]); item.setCheckinTimestamp((Date) columnValues[7]); item.setCheckoutTimestamp((Date) columnValues[8]); item.setEncounterId((Long) columnValues[9]); item.setPatientType((String) columnValues[10]); itemList.add(item); } } return new PatientWorklistReturnValues() { public List<PatientWorkListItem> getItems() { return itemList; } public ServiceParameters getParameters() { return parameters; } public String getErrorMessage() { return null; } }; }
From source file:com.mg.jet.birt.report.data.oda.ejbql.Statement.java
License:Open Source License
public void prepare(String query) throws OdaException { Query qry = null; // Test the connection testConnection();/*from w w w .j a va 2 s . c o m*/ // holds the column types List<String> arColsType = new ArrayList<String>(); List<String> arCols = new ArrayList<String>(); List<String> arColClass = new ArrayList<String>(); // holds the column names, also used for labels String[] props = null; try { Session hibsession = HibernateUtil.currentSession(); // Create a Hibernate Query query = query.replaceAll("[\\n\\r]+", " "); query = query.trim(); qry = hibsession.createQuery(query); // Get the list of return types from the query Type[] qryReturnTypes = qry.getReturnTypes(); paramNames = Arrays.asList(qry.getNamedParameters()); paramValues = new Object[paramNames.size()]; // When specifing the HQL "from object" the returned type is a // Hibernate EntityType // When the columns are specified the returned values are normal // data types // The first half of this if statment handles the EntityType, the // else handles the // other case. // We are not handling multipe result sets. if (qryReturnTypes.length > 0 && qryReturnTypes[0].isEntityType()) { for (int j = 0; j < qryReturnTypes.length; j++) { // Get the classname and use utility function to retrieve // data types String clsName = qryReturnTypes[j].getName(); // props holds the column names props = HibernateUtil.getHibernateProp(clsName); for (int x = 0; x < props.length; x++) { String propType = HibernateUtil.getHibernatePropTypes(clsName, props[x]); // Verify that the data type is valid if (DataTypes.isValidType(propType)) { arColsType.add(propType); // Only do this on Entity Types so we dont have a // name collision arCols.add(props[x]); arColClass.add(clsName); } else { throw new OdaException( Messages.getString("Statement.SOURCE_DATA_ERROR") + " " + propType); } } } } else { // Extract the column names from the query props = extractColumns(qry.getQueryString()); // Get the return types from the Type[] for (int t = 0; t < qryReturnTypes.length; t++) { // Verify that the data type is valid String propType = qryReturnTypes[t].getName(); if (DataTypes.isValidType(propType)) { arColsType.add(qryReturnTypes[t].getName()); arCols.add(props[t]); } else { throw new OdaException(Messages.getString("Statement.SOURCE_DATA_ERROR") + " " + propType); } } } } catch (OdaException e) { throw e; } catch (Exception e) { throw new OdaException(e); } // this example does not enforce unique column names // Create a new ResultSetMetaData object passing in the column names and // data types // Have to remove . which BIRT does not allow String[] arLabels = (String[]) arCols.toArray(new String[arCols.size()]); for (int j = 0; j < arLabels.length; j++) { arLabels[j] = arLabels[j].replace('.', ':'); } this.resultSetMetaData = new ResultSetMetaData(arLabels, (String[]) arColsType.toArray(new String[arColsType.size()]), arLabels, (String[]) arColClass.toArray(new String[arColClass.size()])); // query is saved for execution this.query = query; }
From source file:com.vertec.daoimpl.IssuesDAO.java
public String setComplete(int id) { Session session = NewHibernateUtil.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); if (session != null) { try {//from w ww . j a va 2s . c o m Query query = session.createQuery("Update Issues i set i.isFixed=:isFixed where i.id=:id"); System.out.println("GOT QUERY...."); query.setParameter("isFixed", true); query.setParameter("id", id); System.out.println(query.getQueryString()); query.executeUpdate(); transaction.commit(); return VertecConstants.SUCCESS; } catch (Exception e) { e.printStackTrace(); return VertecConstants.ERROR; } finally { if (session != null && session.isOpen()) { session.close(); } } } return VertecConstants.ERROR; }
From source file:com.vertec.daoimpl.IssuesDAO.java
public boolean updateIssue(Issues issue) { Session session = NewHibernateUtil.getSessionFactory().openSession(); Transaction transaction = session.beginTransaction(); if (session != null) { try {// w w w . j av a2 s . c o m Query query = session.createQuery("Update Issues i set i.issue=:issue where i.id=:id"); System.out.println("GOT QUERY...."); query.setParameter("issue", issue.getIssue()); query.setParameter("id", issue.getId()); System.out.println(query.getQueryString()); query.executeUpdate(); transaction.commit(); return true; } catch (Exception e) { e.printStackTrace(); return false; } finally { if (session != null && session.isOpen()) { session.close(); } } } return false; }
From source file:com.wavemaker.runtime.data.task.NamedQueryTask.java
License:Open Source License
/** * First element in input array is the query name *//*from w w w. j ava 2 s . com*/ @Override public Object run(Session session, String dbName, Object... input) { PagingOptions pagingOptions = null; if (input.length > 0) { Object o = input[input.length - 1]; if (o instanceof PagingOptions) { pagingOptions = (PagingOptions) o; Object[] ar = new Object[input.length - 1]; System.arraycopy(input, 0, ar, 0, ar.length); input = ar; } } DataServiceMetaData meta = getMetaData(dbName); String queryName = (String) input[0]; Object bindParamValues[] = new Object[input.length - 1]; System.arraycopy(input, 1, bindParamValues, 0, bindParamValues.length); Query query = session.getNamedQuery(queryName); String queryString = query.getQueryString(); handleBindParams(query, queryName, bindParamValues, meta); Object rtn = null; if (DataServiceUtils.isDML(queryString)) { ArrayList<Object> l = new ArrayList<Object>(1); l.add(query.executeUpdate()); rtn = l; } else { AbstractReadTask.applyPaging(pagingOptions, query); rtn = query.list(); NamedQueryDefinition def = meta.getQueryDefinition(queryName); boolean supportsReturnType = !(def instanceof NamedSQLQueryDefinition); if (supportsReturnType && DataServiceUtils.requiresResultWrapper(queryString) && !DataServiceUtils.isDynamicInstantiationQuery(queryString)) { rtn = marshalIntoCustomType(queryName, meta, query, rtn); } } if (this.logger.isDebugEnabled()) { this.logger.debug("rtn for query \"" + queryName + "\": " + rtn); } return rtn; }
From source file:com.wavemaker.runtime.data.task.QueryTask.java
License:Open Source License
protected Object runQuery(Query query) { if (DataServiceUtils.isDML(query.getQueryString())) { return query.executeUpdate(); }//from ww w. ja v a 2 s . c om return query.list(); }
From source file:com.xpn.xwiki.store.XWikiHibernateStore.java
License:Open Source License
public List search(Query query, int nb, int start, XWikiContext context) throws XWikiException { boolean bTransaction = true; if (query == null) { return null; }/*from ww w. jav a 2 s. c o m*/ MonitorPlugin monitor = Util.getMonitorPlugin(context); try { // Start monitoring timer if (monitor != null) { monitor.startTimer("hibernate", query.getQueryString()); } checkHibernate(context); bTransaction = beginTransaction(false, context); if (start != 0) { query.setFirstResult(start); } if (nb != 0) { query.setMaxResults(nb); } Iterator it = query.list().iterator(); List list = new ArrayList(); while (it.hasNext()) { list.add(it.next()); } if (bTransaction) { // The session is closed here, too. endTransaction(context, false, false); bTransaction = false; } return list; } catch (Exception e) { Object[] args = { query.toString() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, "Exception while searching documents with sql {0}", e, args); } finally { try { if (bTransaction) { endTransaction(context, false, false); } } catch (Exception e) { } // End monitoring timer if (monitor != null) { monitor.endTimer("hibernate"); } } }
From source file:daos.impl.OperacionDaoImpl.java
@Override public List<ClsEntidadOperacionHib> listByFilters(Date inicio, Date fin, ClsEntidadCuenta cuenta) { Session session = HibernateUtil.getInstance().getSession(); session.beginTransaction();// ww w.j a v a 2s. c om String query = "FROM ClsEntidadOperacionHib c WHERE c.hora >= :fechaInicial AND c.hora <= :fechaFinal"; if (cuenta != null) { query += " AND cuenta=" + cuenta.getIdCuenta().toString(); } Query query_e = session.createQuery(query); query_e.setParameter("fechaInicial", inicio); query_e.setParameter("fechaFinal", fin); System.out.println("Query: " + query_e.getQueryString()); List<ClsEntidadOperacionHib> cuentas = query_e.list(); //session.getTransaction().commit(); session.close(); return cuentas; }
From source file:de.fhdo.terminologie.ws.conceptAssociation.ListConceptAssociations.java
License:Apache License
/** * Verbindungen zwischen Begriffen auflisten * * @param parameter//w ww . ja va 2 s .co m * @return Liste von Entity-Assoziationen */ public ListConceptAssociationsResponseType ListConceptAssociations(ListConceptAssociationsRequestType parameter, org.hibernate.Session session, String ipAddress) { if (logger.isInfoEnabled()) logger.info("====== ListConceptAssociations gestartet ======"); boolean createHibernateSession = (session == null); logger.debug("createHibernateSession: " + createHibernateSession); // Return-Informationen anlegen ListConceptAssociationsResponseType response = new ListConceptAssociationsResponseType(); response.setReturnInfos(new ReturnType()); // Parameter prfen if (validateParameter(parameter, response) == false) { return response; // Fehler bei den Parametern } // Login-Informationen auswerten (gilt fr jeden Webservice) boolean loggedIn = false; AuthenticateInfos loginInfoType = null; if (parameter != null && parameter.getLoginToken() != null) { loginInfoType = Authorization.authenticate(ipAddress, parameter.getLoginToken()); loggedIn = loginInfoType != null; } if (logger.isDebugEnabled()) { logger.debug("Benutzer ist eingeloggt: " + loggedIn); } try { java.util.List<CodeSystemConcept> list = null; // Hibernate-Block, Session ffnen org.hibernate.Session hb_session = session; if (createHibernateSession || hb_session == null) { hb_session = HibernateUtil.getSessionFactory().openSession(); //hb_session.getTransaction().begin(); } try //Try-Catch-Block um Hibernate-Fehler abzufangen { CodeSystemEntityVersion csev_parameter = (CodeSystemEntityVersion) parameter.getCodeSystemEntity() .getCodeSystemEntityVersions().toArray()[0]; long cse_versionId = csev_parameter.getVersionId(); // TODO leftID korrekt implementieren // directionBoth implementieren (reverse funktioniert) if (parameter.getDirectionBoth() == null) { parameter.setDirectionBoth(false); } if (parameter.getReverse() == null || parameter.getDirectionBoth()) { parameter.setReverse(false); } //Hibernate Query Language erstellen String hql = "select distinct term from CodeSystemConcept term"; //String hql = "select term from CodeSystemConcept term"; hql += " join fetch term.codeSystemEntityVersion csev"; hql += " join fetch csev.codeSystemEntity cse"; // je nach Richtung wird die 1 oder 2 angehangen hql += " join fetch csev.codeSystemEntityVersionAssociationsForCodeSystemEntityVersionId"; if (parameter.getReverse()) { hql += "1"; } else { hql += "2"; } hql += " cseva"; hql += " join fetch cseva.associationType at"; hql += " join cseva.codeSystemEntityVersionByCodeSystemEntityVersionId"; if (parameter.getReverse()) { hql += "2"; } else { hql += "1"; } hql += " csev_source"; HQLParameterHelper parameterHelper = new HQLParameterHelper(); parameterHelper.addParameter("csev_source.", "versionId", cse_versionId); if (parameter.getCodeSystemEntityVersionAssociation() != null) { parameterHelper.addParameter("cseva.", "associationKind", parameter.getCodeSystemEntityVersionAssociation().getAssociationKind()); } if (loggedIn == false) { parameterHelper.addParameter("csev.", "statusVisibility", Definitions.STATUS_CODES.ACTIVE.getCode()); } // Parameter hinzufgen (immer mit AND verbunden) hql += parameterHelper.getWhere(""); if (logger.isDebugEnabled()) logger.debug("HQL: " + hql); // Query erstellen org.hibernate.Query q = hb_session.createQuery(hql); // Die Parameter knnen erst hier gesetzt werden (bernimmt Helper) parameterHelper.applyParameter(q); // Datenbank-Aufruf durchfhren list = (java.util.List<CodeSystemConcept>) q.list(); if (logger.isDebugEnabled()) logger.debug("size: " + list.size()); List<CodeSystemEntityVersionAssociation> returnList = new LinkedList<CodeSystemEntityVersionAssociation>(); //if (createHibernateSession) // tx.commit(); // Ergebnisliste befllen //Iterator<CodeSystemConcept> it = list.iterator(); //while (it.hasNext()) for (CodeSystemConcept term : list) { // CodeSystemEntityVersion lesen CodeSystemEntityVersion csev = term.getCodeSystemEntityVersion(); logger.debug("term found: " + term.getCode()); if (csev != null) { csev.setAssociationTypes(null); //csev.setCodeSystemEntity(null); csev.setConceptValueSetMemberships(null); csev.setCodeSystemMetadataValues(null); csev.setValueSetMetadataValues(null); if (parameter != null && parameter.getReverse()) { if (parameter != null && parameter.getLookForward() != null && parameter.getLookForward()) { // Gibt immer die nchste Verbindung mit zurck Iterator<CodeSystemEntityVersionAssociation> itTemp = csev .getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2() .iterator(); while (itTemp.hasNext()) { CodeSystemEntityVersionAssociation csevaTemp = itTemp.next(); if (csevaTemp.getAssociationKind() == Definitions.ASSOCIATION_KIND.TAXONOMY .getCode()) { csevaTemp.setAssociationType(null); csevaTemp.setCodeSystemEntityVersionByCodeSystemEntityVersionId1(null); csevaTemp.setCodeSystemEntityVersionByCodeSystemEntityVersionId2(null); } else { itTemp.remove(); } } if (csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2() != null && csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2() .size() == 0) csev.setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2(null); } else { csev.setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2(null); } } else { if (parameter != null && parameter.getLookForward() != null && parameter.getLookForward()) { logger.debug("lookForward"); // Gibt immer die nchste Verbindung mit zurck Iterator<CodeSystemEntityVersionAssociation> itTemp = csev .getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() .iterator(); while (itTemp.hasNext()) { logger.debug("Verbindung prfen, iterator.next()"); CodeSystemEntityVersionAssociation csevaTemp = itTemp.next(); if (csevaTemp.getAssociationKind() == Definitions.ASSOCIATION_KIND.TAXONOMY .getCode()) { csevaTemp.setAssociationType(null); csevaTemp.setCodeSystemEntityVersionByCodeSystemEntityVersionId1(null); csevaTemp.setCodeSystemEntityVersionByCodeSystemEntityVersionId2(null); logger.debug("Verbindung taxonomisch, drin lassen"); } else { logger.debug("Verbindung lschen, iterator.remove()"); itTemp.remove(); } } logger.debug("Anzahl: " + csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() .size()); if (csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() != null && csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() .size() == 0) csev.setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1(null); } else { csev.setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1(null); } //csev.setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1(null); } if (csev.getCodeSystemEntity() != null) { csev.getCodeSystemEntity().setCodeSystemVersionEntityMemberships(null); csev.getCodeSystemEntity().setCodeSystemEntityVersions(null); } // der Version wieder das Concept hinzufgen und die Verbindungen null setzen csev.setCodeSystemConcepts(new HashSet<CodeSystemConcept>()); term.setCodeSystemEntityVersion(null); term.setCodeSystemConceptTranslations(null); csev.getCodeSystemConcepts().add(term); // Assoziation lesen und Verbindungen auf null setzen if (parameter.getReverse()) { if (csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() != null && csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() .size() > 0) { CodeSystemEntityVersionAssociation association = (CodeSystemEntityVersionAssociation) csev .getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() .toArray()[0]; //association.setCodeSystemEntityVersionByCodeSystemEntityVersionId2(null); //association.getCodeSystemEntityVersionByCodeSystemEntityVersionId1().setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1(null); if (association.getCodeSystemEntityVersionByCodeSystemEntityVersionId1() != null) { association.setCodeSystemEntityVersionByCodeSystemEntityVersionId2(null); association.getCodeSystemEntityVersionByCodeSystemEntityVersionId1() .setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1( null); } else if (association .getCodeSystemEntityVersionByCodeSystemEntityVersionId2() != null) { association.setCodeSystemEntityVersionByCodeSystemEntityVersionId1(null); association.getCodeSystemEntityVersionByCodeSystemEntityVersionId2() .setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1( null); } else { association.setCodeSystemEntityVersionByCodeSystemEntityVersionId1(null); association.setCodeSystemEntityVersionByCodeSystemEntityVersionId2(null); } // Verbindungen von AssociationType auf null setzen AssociationType at = association.getAssociationType(); at.setCodeSystemEntityVersion(null); at.setCodeSystemEntityVersionAssociations(null); returnList.add(association); } } else { //logger.debug("ass size: " + csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2().size()); if (csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2() != null && csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2() .size() > 0) { CodeSystemEntityVersionAssociation association = (CodeSystemEntityVersionAssociation) csev .getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2() .toArray()[0]; association.setCodeSystemEntityVersionByCodeSystemEntityVersionId1(null); association.getCodeSystemEntityVersionByCodeSystemEntityVersionId2() .setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2(null); // Verbindungen von AssociationType auf null setzen AssociationType at = association.getAssociationType(); at.setCodeSystemEntityVersion(null); at.setCodeSystemEntityVersionAssociations(null); returnList.add(association); } } } } // DirectionBoth if (parameter.getDirectionBoth()) { // Hibernate Query Language erstellen hql = "select distinct term from CodeSystemConcept term"; //hql = "select term from CodeSystemConcept term"; hql += " join fetch term.codeSystemEntityVersion csev"; hql += " join fetch csev.codeSystemEntity cse"; hql += " join fetch csev.codeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1 cseva"; hql += " join fetch cseva.associationType at"; hql += " join cseva.codeSystemEntityVersionByCodeSystemEntityVersionId2 csev_source"; parameterHelper = new HQLParameterHelper(); parameterHelper.addParameter("csev_source.", "versionId", cse_versionId); if (parameter.getCodeSystemEntityVersionAssociation() != null) { parameterHelper.addParameter("cseva.", "associationKind", parameter.getCodeSystemEntityVersionAssociation().getAssociationKind()); } if (loggedIn == false) { parameterHelper.addParameter("csev.", "statusVisibility", Definitions.STATUS_CODES.ACTIVE.getCode()); } // Parameter hinzufgen (immer mit AND verbunden) hql += parameterHelper.getWhere(""); if (logger.isDebugEnabled()) { logger.debug("HQL#2 (DirectionBoth): " + hql); logger.debug("CSEV-VersionId: " + cse_versionId); } // Query erstellen Query q2 = hb_session.createQuery(hql); // Die Parameter knnen erst hier gesetzt werden (bernimmt Helper) parameterHelper.applyParameter(q2); logger.debug("SQL: " + q2.getQueryString()); // Datenbank-Aufruf durchfhren java.util.List<CodeSystemConcept> list2 = (java.util.List<CodeSystemConcept>) q2.list(); // Ergebnisliste befllen for (CodeSystemConcept term : list2) { // CodeSystemConcept holen // CodeSystemEntityVersion lesen //logger.error("Term: " + term.getCodeSystemEntityVersionId() + ", " + term.getCode()); CodeSystemEntityVersion csev = term.getCodeSystemEntityVersion(); if (csev != null) { csev.setAssociationTypes(null); csev.setConceptValueSetMemberships(null); csev.setCodeSystemMetadataValues(null); csev.setValueSetMetadataValues(null); csev.setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId2(null); if (csev.getCodeSystemEntity() != null) { csev.getCodeSystemEntity().setCodeSystemVersionEntityMemberships(null); csev.getCodeSystemEntity().setCodeSystemEntityVersions(null); } // der Version wieder das Concept hinzufgen und die Verbindungen null setzen csev.setCodeSystemConcepts(new HashSet<CodeSystemConcept>()); term.setCodeSystemEntityVersion(null); term.setCodeSystemConceptTranslations(null); csev.getCodeSystemConcepts().add(term); // Assoziation lesen und Verbindungen auf null setzen if (csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() != null && csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() .size() > 0) { //CodeSystemEntityVersionAssociation association = //(CodeSystemEntityVersionAssociation) csev.getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1().toArray()[0]; CodeSystemEntityVersionAssociation association = csev .getCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1() .iterator().next(); if (association.getCodeSystemEntityVersionByCodeSystemEntityVersionId1() != null) { association.setCodeSystemEntityVersionByCodeSystemEntityVersionId2(null); association.getCodeSystemEntityVersionByCodeSystemEntityVersionId1() .setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1( null); } else if (association .getCodeSystemEntityVersionByCodeSystemEntityVersionId2() != null) { association.setCodeSystemEntityVersionByCodeSystemEntityVersionId1(null); association.getCodeSystemEntityVersionByCodeSystemEntityVersionId2() .setCodeSystemEntityVersionAssociationsForCodeSystemEntityVersionId1( null); } else { association.setCodeSystemEntityVersionByCodeSystemEntityVersionId1(null); association.setCodeSystemEntityVersionByCodeSystemEntityVersionId2(null); } // Verbindungen von AssociationType auf null setzen AssociationType at = association.getAssociationType(); at.setCodeSystemEntityVersion(null); at.setCodeSystemEntityVersionAssociations(null); returnList.add(association); } } else { logger.warn("ListConceptAssociations.java: CodeSystemEntityVersion ist null"); } } } // Direction Both Ende response.setCodeSystemEntityVersionAssociation(returnList); if (returnList.isEmpty()) { response.getReturnInfos().setMessage("Keine passenden Assoziationen vorhanden!"); } else { response.getReturnInfos() .setMessage("Assoziationen erfolgreich gelesen, Anzahl: " + returnList.size()); response.getReturnInfos().setCount(returnList.size()); } response.getReturnInfos().setOverallErrorCategory(ReturnType.OverallErrorCategory.INFO); response.getReturnInfos().setStatus(ReturnType.Status.OK); //hb_session.getTransaction().commit(); } catch (Exception e) { //hb_session.getTransaction().rollback(); // Fehlermeldung (Hibernate) an den Aufrufer weiterleiten response.getReturnInfos().setOverallErrorCategory(ReturnType.OverallErrorCategory.ERROR); response.getReturnInfos().setStatus(ReturnType.Status.FAILURE); response.getReturnInfos() .setMessage("Fehler bei 'ListConceptAssociation', Hibernate: " + e.getLocalizedMessage()); logger.error("Fehler bei 'ListConceptAssociation', Hibernate: " + e.getLocalizedMessage()); e.printStackTrace(); } finally { // Transaktion abschlieen if (createHibernateSession) { logger.debug("Schliee Hibernate-Session (ListConceptAssociations.java)"); hb_session.close(); } } } catch (Exception e) { // Fehlermeldung an den Aufrufer weiterleiten response.getReturnInfos().setOverallErrorCategory(ReturnType.OverallErrorCategory.ERROR); response.getReturnInfos().setStatus(ReturnType.Status.FAILURE); response.getReturnInfos().setMessage("Fehler bei 'ListConceptAssociation': " + e.getLocalizedMessage()); logger.error("Fehler bei 'ListConceptAssociation': " + e.getLocalizedMessage()); } return response; }