List of usage examples for javax.persistence EntityManager find
public <T> T find(Class<T> entityClass, Object primaryKey);
From source file:org.apache.juddi.api.impl.UDDISubscriptionImpl.java
public void deleteSubscription(DeleteSubscription body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {// ww w. j av a2 s.co m tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidateSubscription(publisher).validateDeleteSubscription(em, body); List<String> subscriptionKeyList = body.getSubscriptionKey(); for (String subscriptionKey : subscriptionKeyList) { Object obj = em.find(org.apache.juddi.model.Subscription.class, subscriptionKey); em.remove(obj); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.DELETE_SUBSCRIPTION, QueryStatus.SUCCESS, procTime); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(SubscriptionQuery.DELETE_SUBSCRIPTION, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:op.care.values.PnlValues.java
private JPanel createContentPanel4Year(final ResValueTypes vtype, final int year) { final String keyYears = vtype.getID() + ".xtypes." + Integer.toString(year) + ".year"; java.util.List<ResValue> myValues; synchronized (mapType2Values) { if (!mapType2Values.containsKey(keyYears)) { mapType2Values.put(keyYears, ResValueTools.getResValues(resident, vtype, year)); }// w w w . j ava 2 s. c om if (mapType2Values.get(keyYears).isEmpty()) { JLabel lbl = new JLabel(SYSTools.xx("misc.msg.novalue")); JPanel pnl = new JPanel(); pnl.add(lbl); return pnl; } myValues = mapType2Values.get(keyYears); } JPanel pnlYear = new JPanel(new VerticalLayout()); pnlYear.setOpaque(false); for (final ResValue resValue : myValues) { String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"200\" align=\"left\">" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT).format(resValue.getPit()) + " [" + resValue.getID() + "]</td>" + "<td width=\"340\" align=\"left\">" + ResValueTools.getValueAsHTML(resValue) + "</td>" + "<td width=\"200\" align=\"left\">" + resValue.getUser().getFullname() + "</td>" + "</tr>" + "</table>" + "</html>"; final DefaultCPTitle pnlTitle = new DefaultCPTitle(title, null); pnlTitle.getMain().setBackground(GUITools.blend(vtype.getColor(), Color.WHITE, 0.1f)); pnlTitle.getMain().setOpaque(true); if (resValue.isObsolete()) { pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22eraser)); } if (resValue.isReplacement()) { pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22edited)); } if (!resValue.getText().trim().isEmpty()) { pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22info)); } if (pnlTitle.getAdditionalIconPanel().getComponentCount() > 0) { pnlTitle.getButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { GUITools.showPopup( GUITools.getHTMLPopup(pnlTitle.getButton(), ResValueTools.getInfoAsHTML(resValue)), SwingConstants.NORTH); } }); } if (!resValue.getAttachedFilesConnections().isEmpty()) { /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = new JButton( Integer.toString(resValue.getAttachedFilesConnections().size()), SYSConst.icon22greenStar); btnFiles.setToolTipText(SYSTools.xx("misc.btnfiles.tooltip")); btnFiles.setForeground(Color.BLUE); btnFiles.setHorizontalTextPosition(SwingUtilities.CENTER); btnFiles.setFont(SYSConst.ARIAL18BOLD); btnFiles.setPressedIcon(SYSConst.icon22Pressed); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.setAlignmentY(Component.TOP_ALIGNMENT); btnFiles.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnFiles.setContentAreaFilled(false); btnFiles.setBorder(null); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgFiles(resValue, new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); final ResValue myValue = em.find(ResValue.class, resValue.getID()); em.close(); synchronized (mapType2Values) { mapType2Values.get(keyYears).remove(resValue); mapType2Values.get(keyYears).add(myValue); Collections.sort(mapType2Values.get(keyYears)); } createCP4Year(vtype, year); buildPanel(); } }); } }); btnFiles.setEnabled(OPDE.isFTPworking()); pnlTitle.getRight().add(btnFiles); } if (!resValue.getAttachedProcessConnections().isEmpty()) { /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = new JButton( Integer.toString(resValue.getAttachedProcessConnections().size()), SYSConst.icon22redStar); btnProcess.setToolTipText(SYSTools.xx("misc.btnprocess.tooltip")); btnProcess.setForeground(Color.YELLOW); btnProcess.setHorizontalTextPosition(SwingUtilities.CENTER); btnProcess.setFont(SYSConst.ARIAL18BOLD); btnProcess.setPressedIcon(SYSConst.icon22Pressed); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); btnProcess.setAlignmentY(Component.TOP_ALIGNMENT); btnProcess.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnProcess.setContentAreaFilled(false); btnProcess.setBorder(null); btnProcess.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgProcessAssign(resValue, new Closure() { @Override public void execute(Object o) { if (o == null) { return; } Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o; ArrayList<QProcess> assigned = result.getFirst(); ArrayList<QProcess> unassigned = result.getSecond(); EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); ResValue myValue = em.merge(resValue); em.lock(myValue, LockModeType.OPTIMISTIC_FORCE_INCREMENT); ArrayList<SYSVAL2PROCESS> attached = new ArrayList<SYSVAL2PROCESS>( resValue.getAttachedProcessConnections()); for (SYSVAL2PROCESS linkObject : attached) { if (unassigned.contains(linkObject.getQProcess())) { linkObject.getQProcess().getAttachedNReportConnections() .remove(linkObject); linkObject.getResValue().getAttachedProcessConnections() .remove(linkObject); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": " + myValue.getTitle() + " ID: " + myValue.getID(), PReportTools.PREPORT_TYPE_REMOVE_ELEMENT, linkObject.getQProcess())); em.remove(linkObject); } } attached.clear(); for (QProcess qProcess : assigned) { java.util.List<QProcessElement> listElements = qProcess.getElements(); if (!listElements.contains(myValue)) { QProcess myQProcess = em.merge(qProcess); SYSVAL2PROCESS myLinkObject = em .merge(new SYSVAL2PROCESS(myQProcess, myValue)); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": " + myValue.getTitle() + " ID: " + myValue.getID(), PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess)); qProcess.getAttachedResValueConnections().add(myLinkObject); myValue.getAttachedProcessConnections().add(myLinkObject); } } em.getTransaction().commit(); synchronized (mapType2Values) { mapType2Values.get(keyYears).remove(resValue); mapType2Values.get(keyYears).add(myValue); Collections.sort(mapType2Values.get(keyYears)); } createCP4Year(vtype, year); buildPanel(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (RollbackException ole) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); } }); btnProcess.setEnabled(OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)); pnlTitle.getRight().add(btnProcess); } /*** * __ __ * | \/ | ___ _ __ _ _ * | |\/| |/ _ \ '_ \| | | | * | | | | __/ | | | |_| | * |_| |_|\___|_| |_|\__,_| * */ final JButton btnMenu = new JButton(SYSConst.icon22menu); btnMenu.setPressedIcon(SYSConst.icon22Pressed); btnMenu.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMenu.setAlignmentY(Component.TOP_ALIGNMENT); btnMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnMenu.setContentAreaFilled(false); btnMenu.setBorder(null); btnMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnMenu); popup.removeExcludedComponent(btnMenu); JPanel pnl = getMenu(resValue); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnMenu.setEnabled(!resValue.isObsolete()); pnlTitle.getRight().add(btnMenu); pnlYear.add(pnlTitle.getMain()); synchronized (linemap) { linemap.put(resValue, pnlTitle.getMain()); } } return pnlYear; }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves all the annotated Resources of an Annotation * @param _annotation/* w ww. java2s .com*/ * @return */ public Collection<Resource> retrieveAnnotatedForAnnotation(Annotation _annotation) { if (_annotation.getId() == null) { System.out.println("[RetrieveAnnotation.retrieveAnnotatedForAnnotation] unable to retrieve annotated" + " label : " + _annotation.getLabel() + " cause : _annotation doesn't exist"); return new ArrayList<Resource>(); } else { //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); //EntityTransaction tx = em.getTransaction(); _annotation = (Annotation) em.find(_annotation.getClass(), _annotation.getId()); Collection<Resource> _annotated = _annotation.getAnnotated(); return _annotated; } }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves all the added Resources of an Annotation * @param _annotation//w ww . j a v a 2s. c om * @return */ public Collection<Resource> retrieveAddedForAnnotation(Annotation _annotation) { if (_annotation.getId() == null) { System.out.println("[RetrieveAnnotation.retrieveddedForAnnotation] unable to retrieve added" + " label : " + _annotation.getLabel() + " cause : _annotation doesn't exist"); return new ArrayList<Resource>(); } else { //EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); //EntityTransaction tx = em.getTransaction(); _annotation = (Annotation) em.find(_annotation.getClass(), _annotation.getId()); Collection<Resource> _added = _annotation.getAdded(); return _added; } }
From source file:org.apache.juddi.api.impl.UDDIInquiryImpl.java
public ServiceList findService(FindService body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); try {/* w w w. j a va 2 s. c o m*/ new ValidateInquiry(null).validateFindService(body); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_SERVICE, QueryStatus.FAILED, procTime); throw drfm; } EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); if (isAuthenticated()) this.getEntityPublisher(em, body.getAuthInfo()); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(body.getFindQualifiers()); List<?> keysFound = InquiryHelper.findService(body, findQualifiers, em); if (keysFound.size() == 0) { if (body.getBusinessKey() != null) { // Check that we were passed a valid businessKey per // 5.1.12.4 of the UDDI v3 spec String businessKey = body.getBusinessKey(); org.apache.juddi.model.BusinessEntity modelBusinessEntity = null; try { modelBusinessEntity = em.find(org.apache.juddi.model.BusinessEntity.class, businessKey); } catch (ClassCastException e) { } if (modelBusinessEntity == null) { throw new InvalidKeyPassedException( new ErrorMessage("errors.invalidkey.BusinessNotFound", businessKey)); } } } ServiceList result = InquiryHelper.getServiceListFromKeys(body, findQualifiers, em, keysFound); tx.rollback(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_SERVICE, QueryStatus.SUCCESS, procTime); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.api.impl.UDDIInquiryImpl.java
public BindingDetail findBinding(FindBinding body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); try {//from w ww . ja va 2s. com new ValidateInquiry(null).validateFindBinding(body); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_BINDING, QueryStatus.FAILED, procTime); throw drfm; } EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); if (isAuthenticated()) this.getEntityPublisher(em, body.getAuthInfo()); org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers(); findQualifiers.mapApiFindQualifiers(body.getFindQualifiers()); List<?> keysFound = InquiryHelper.findBinding(body, findQualifiers, em); if (keysFound != null && keysFound.size() == 0) { if (body.getServiceKey() != null) { // Check that we were passed a valid serviceKey per // 5.1.12.4 of the UDDI v3 spec String serviceKey = body.getServiceKey(); org.apache.juddi.model.BusinessService modelBusinessService = null; try { modelBusinessService = em.find(org.apache.juddi.model.BusinessService.class, serviceKey); } catch (ClassCastException e) { logger.info("uh oh!", e); } if (modelBusinessService == null) throw new InvalidKeyPassedException( new ErrorMessage("errors.invalidkey.ServiceNotFound", serviceKey)); } } BindingDetail result = InquiryHelper.getBindingDetailFromKeys(body, findQualifiers, em, keysFound); tx.rollback(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(InquiryQuery.FIND_BINDING, QueryStatus.SUCCESS, procTime); return result; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.validation.ValidateSubscription.java
private void validateSubscription(EntityManager em, org.uddi.sub_v3.Subscription subscription) throws DispositionReportFaultMessage { // A supplied subscription can't be null if (subscription == null) { throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.NullInput")); }/*from w w w. jav a2s. c om*/ if (df == null) { try { df = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException ex) { throw new FatalErrorException(new ErrorMessage("errors.DatatypeFactor")); } } boolean entityExists = false; String entityKey = subscription.getSubscriptionKey(); //no key specified, make a new one if (entityKey == null || entityKey.length() == 0) { KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator(); entityKey = keyGen.generate(); subscription.setSubscriptionKey(entityKey); } else { //key specified, validate it // Per section 4.4: keys must be case-folded entityKey = entityKey.toLowerCase(); subscription.setSubscriptionKey(entityKey); Object obj = em.find(org.apache.juddi.model.Subscription.class, entityKey); if (obj != null) { entityExists = true; //revising a new item // Make sure publisher owns this entity. if (!publisher.getAuthorizedName() .equals(((org.apache.juddi.model.Subscription) obj).getAuthorizedName())) { throw new UserMismatchException( new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey)); } } else { //new item // Inside this block, we have a key proposed by the publisher on a new entity // Validate key and then check to see that the proposed key is valid for this publisher ValidateUDDIKey.validateUDDIv3Key(entityKey); if (!publisher.isValidPublisherKey(em, entityKey)) { throw new KeyUnavailableException( new ErrorMessage("errors.keyunavailable.BadPartition", entityKey)); } } } if (!entityExists) { // Check to make sure key isn't used by another entity. if (!isUniqueKey(em, entityKey)) { throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.KeyExists", entityKey)); } } //AO, if it's already expired, why even allow it? if (subscription.getExpiresAfter() != null) { long expiresat = subscription.getExpiresAfter().toGregorianCalendar().getTimeInMillis(); if (System.currentTimeMillis() > expiresat) { throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.expired")); } } if (subscription.getMaxEntities() != null) { if (subscription.getMaxEntities().intValue() <= 0) { throw new ValueNotAllowedException(new ErrorMessage("errors.subscription.maxrecordstoosmall")); } } //maxEntities: This optional integer specifies the maximum number of entities in a notification returned to a subscription listener. //If not specified, the number of entities sent is not limited, unless by node policy. try { if (subscription.getMaxEntities() == null || subscription.getMaxEntities().intValue() > AppConfig .getConfiguration().getInt(Property.JUDDI_SUBSCRIPTION_MAXENTITIES, 1000)) { subscription.setMaxEntities( AppConfig.getConfiguration().getInt(Property.JUDDI_SUBSCRIPTION_MAXENTITIES, 1000)); } } catch (ConfigurationException x) { subscription.setMaxEntities(1000); } /* * notificationInterval: This optional argument is only required when asynchronous notifications are used. * It is of type xsd:duration and specifies how often change notifications are to be provided to a subscriber. * If the notificationInterval specified is not acceptable due to node policy, then the node adjusts the value to * match the next longer time period that is supported. The adjusted value is provided with the returns from this * API. Also see Section 5.5.1.1 Specifying Durations. */ if (subscription.getNotificationInterval() == null && subscription.getBindingKey() != null) { throw new ValueNotAllowedException( new ErrorMessage("errors.subscription.notificationintervalnotdefined")); } //validate that the binding key exists validateSubscriptionBindingkeyExists(em, subscription.getBindingKey()); validateSubscriptionFilter(subscription.getSubscriptionFilter(), entityExists); }
From source file:fr.natoine.dao.annotation.DAOAnnotation.java
/** * Retrieves an annotationStatus//from w w w . j a v a2 s . co m * @param id * @return */ public AnnotationStatus retrieveAnnotationStatus(long id) { // EntityManagerFactory emf = this.setEMF(); EntityManager em = emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); AnnotationStatus _synchro = em.find(AnnotationStatus.class, id); tx.commit(); if (_synchro != null) return _synchro; System.out.println( "[RetrieveAnnotationStatus.retrieveAnnotationStatus] unable to retrieve AnnotationStatus" + " id : " + id); return new AnnotationStatus(); } catch (Exception e) { tx.rollback(); //em.close(); System.out.println( "[RetrieveAnnotationStatus.retrieveAnnotationStatus] unable to retrieve AnnotationStatus" + " id : " + id + " cause : " + e.getMessage()); return new AnnotationStatus(); } }
From source file:com.gnadenheimer.mg.frames.admin.FrameConfigAdmin.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {//from w w w . ja va 2 s . c om CurrentUser currentUser = CurrentUser.getInstance(); Map<String, String> persistenceMap = Utils.getInstance().getPersistenceMap(); EntityManager entityManager = Persistence.createEntityManagerFactory("mg_PU", persistenceMap) .createEntityManager(); entityManager.getTransaction().begin(); Query queryEventoDetalle = entityManager.createQuery("SELECT t FROM TblEventoDetalle t ORDER BY t.id"); List<TblEventoDetalle> listEventoDetalle = org.jdesktop.observablecollections.ObservableCollections .observableList(queryEventoDetalle.getResultList()); TblCuentasContablesPorDefecto cuentasContablesPorDefecto = entityManager .find(TblCuentasContablesPorDefecto.class, 1); for (TblEventoDetalle evd : listEventoDetalle) { if (evd.getTblAsientosList().size() == 2) { Integer indexAsientoAporte = -1; Integer indexAsientoDonacion = -1; if (((List<TblAsientos>) evd.getTblAsientosList()).get(0).getIdCuentaContableHaber() .equals(cuentasContablesPorDefecto.getIdCuentaAportes())) { indexAsientoAporte = 0; indexAsientoDonacion = 1; } else if (((List<TblAsientos>) evd.getTblAsientosList()).get(1).getIdCuentaContableHaber() .equals(cuentasContablesPorDefecto.getIdCuentaAportes())) { indexAsientoAporte = 1; indexAsientoDonacion = 0; } ((List<TblAsientos>) evd .getTblAsientosList()) .get(indexAsientoAporte) .setMonto(((Long) (evd.getMonto().longValue() * evd.getIdEvento().getPorcentajeAporte().longValue() / 100)) .intValue()); ((List<TblAsientos>) evd.getTblAsientosList()).get(indexAsientoDonacion).setMonto(evd.getMonto() - ((List<TblAsientos>) evd.getTblAsientosList()).get(indexAsientoAporte).getMonto()); entityManager.merge(evd); } else if (evd.getTblAsientosList().isEmpty()) { List<TblAsientos> ts = evd.getTblAsientosList(); if (ts == null) { ts = new LinkedList<>(); evd.setTblAsientosList((List) ts); } TblAsientos asientoAporte = new TblAsientos(); asientoAporte.setFechahora(evd.getIdEvento().getFecha().atStartOfDay()); asientoAporte.setIdCentroDeCostoDebe(evd.getIdEvento().getIdCentroDeCosto()); asientoAporte.setIdCentroDeCostoHaber(evd.getIdEvento().getIdCentroDeCosto()); asientoAporte.setIdCuentaContableDebe(cuentasContablesPorDefecto.getIdCuentaACobrar()); asientoAporte.setIdCuentaContableHaber(cuentasContablesPorDefecto.getIdCuentaAportes()); asientoAporte.setMonto(((Long) (evd.getMonto().longValue() * evd.getIdEvento().getPorcentajeAporte().longValue() / 100)).intValue()); asientoAporte.setIdUser(currentUser.getUser()); ts.add(asientoAporte); TblAsientos asientoDonacion = new TblAsientos(); asientoDonacion.setFechahora(evd.getIdEvento().getFecha().atStartOfDay()); asientoDonacion.setIdCentroDeCostoDebe(evd.getIdEvento().getIdCentroDeCosto()); asientoDonacion.setIdCentroDeCostoHaber(evd.getIdEvento().getIdCentroDeCosto()); asientoDonacion.setIdCuentaContableDebe(cuentasContablesPorDefecto.getIdCuentaACobrar()); asientoDonacion.setIdCuentaContableHaber(cuentasContablesPorDefecto.getIdCuentaDonaciones()); asientoDonacion.setMonto(evd.getMonto() - asientoAporte.getMonto()); asientoDonacion.setIdUser(currentUser.getUser()); ts.add(asientoDonacion); entityManager.merge(evd); } } /* List<TblTransferencias> listT = (List<TblTransferencias>) entityManager.createQuery("select t from TblTransferencias t").getResultList(); for (TblTransferencias t : listT) { Query queryEvd = entityManager.createQuery("select e from TblEventoDetalle e where e.idEvento.idEventoTipo = :eventoTipo and EXTRACT(MONTH FROM e.idEvento.fecha) = :mes and EXTRACT(YEAR FROM e.idEvento.fecha) = :ano and e.idEntidad = :entidad"); Calendar c = Calendar.getInstance(); c.setTime(t.getFechahora()); queryEvd.setParameter("mes", c.get(Calendar.MONTH) + 1); queryEvd.setParameter("ano", c.get(Calendar.YEAR)); queryEvd.setParameter("entidad", t.getIdEntidad()); queryEvd.setParameter("eventoTipo", t.getIdEventoTipo()); List<TblEventoDetalle> listEvd = queryEvd.getResultList(); List<TblAsientos> listAsientos = new ArrayList<>(); for (TblEventoDetalle evd : listEvd) { listAsientos.addAll(evd.getTblAsientosList()); } List<TblAsientosTemporales> listAsientosTemporales = t.getTblAsientosTemporalesList(); if (listAsientosTemporales == null) { listAsientosTemporales = new LinkedList<>(); t.setTblAsientosTemporalesList(listAsientosTemporales); } if (t.getTblAsientosTemporalesList().isEmpty()) { for (TblAsientos asiento : listAsientos) { TblAsientosTemporales aT = new TblAsientosTemporales(); entityManager.persist(aT); aT.setFacturado(false); aT.setFechahora(t.getFechahora()); aT.setIdCentroDeCosto(asiento.getIdCentroDeCosto()); aT.setIdCuentaContableDebe(asiento.getIdCentroDeCosto().getIdCuentaContableCtaCtePorDefecto()); aT.setIdCuentaContableHaber(asiento.getIdCuentaContableDebe()); if (asiento.getIdCuentaContableHaber().equals(cuentasContablesPorDefecto.getIdCuentaAportes())) { aT.setEsAporte(true); } else { aT.setEsAporte(false); } aT.setMonto(asiento.getMonto()); listAsientosTemporales.add(aT); } entityManager.merge(t); } }*/ entityManager.getTransaction().commit(); entityManager.getTransaction().begin(); JOptionPane.showMessageDialog(null, "Actualizacion satisfactoria!"); } catch (Exception ex) { JOptionPane.showMessageDialog(null, Thread.currentThread().getStackTrace()[1].getMethodName() + " - " + ex.getMessage()); LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); } }
From source file:org.apache.juddi.api.impl.UDDIPublicationImpl.java
public void deletePublisherAssertions(DeletePublisherAssertions body) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {//from www.j a v a 2 s. c om tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo()); new ValidatePublish(publisher).validateDeletePublisherAssertions(em, body); List<org.uddi.api_v3.PublisherAssertion> entityList = body.getPublisherAssertion(); for (org.uddi.api_v3.PublisherAssertion entity : entityList) { org.apache.juddi.model.PublisherAssertionId pubAssertionId = new org.apache.juddi.model.PublisherAssertionId( entity.getFromKey(), entity.getToKey()); Object obj = em.find(org.apache.juddi.model.PublisherAssertion.class, pubAssertionId); em.remove(obj); } tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.DELETE_PUBLISHERASSERTIONS, QueryStatus.SUCCESS, procTime); } catch (DispositionReportFaultMessage drfm) { long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(PublicationQuery.DELETE_PUBLISHERASSERTIONS, QueryStatus.FAILED, procTime); throw drfm; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }