List of usage examples for org.hibernate LockMode NONE
LockMode NONE
To view the source code for org.hibernate LockMode NONE.
Click Source Link
From source file:alma.acs.tmcdb.TestSnmpTables.java
License:Open Source License
@SuppressWarnings("unchecked") public void testFillSnmpTmcdb() throws Exception { createDB();/*from w ww . j a v a 2 s . co m*/ try { Configuration config = new Configuration(); config.setActive(true); config.setConfigurationName("pg_Config"); config.setCreationTime(new Date()); config.setFullName("Testing configuration"); config.setDescription("Configuration used for testing SNMP"); Computer comp1 = new Computer(); comp1.setName("osf.comp-1"); comp1.setNetworkName("pc014692.hq.eso.org"); comp1.setPhysicalLocation("Alma building"); comp1.setRealTime(false); comp1.setDiskless(false); comp1.setProcessorType(ComputerProcessorType.SMP); comp1.setConfiguration(config); Computer comp2 = new Computer(); comp2.setName("osf.comp-2"); comp2.setNetworkName("pc008506.hq.eso.org"); comp2.setPhysicalLocation("Alma building"); comp2.setRealTime(false); comp2.setDiskless(false); comp2.setProcessorType(ComputerProcessorType.UNI); comp2.setConfiguration(config); /* setup a SNMP trap sink */ SnmpTrapSink sink = new SnmpTrapSink(); sink.setComputer(comp1); sink.setTrapPort(new Integer(10162)); sink.setTrapSourcesNetworkMask("0.0.0.0"); sink.setSnmpTrapCommunity("public"); sink.setConfiguration(config); /* setup a powerstrip with 3 sockets */ NetworkPowerstrip strip1 = new NetworkPowerstrip(); strip1.setName("osf.pdu1"); strip1.setNetworkName("pdu1.hq.eso.org"); strip1.setPhysicalLocation("Alma building"); strip1.setConfiguration(config); PowerstripSocket socket1 = new PowerstripSocket(); socket1.setNetworkPowerstrip(strip1); socket1.setNetworkDevice(comp1); socket1.setSocketNumber(new Integer(1)); socket1.setSocketName("comp-1"); PowerstripSocket socket2 = new PowerstripSocket(); socket2.setNetworkPowerstrip(strip1); socket2.setNetworkDevice(comp1); socket2.setSocketNumber(new Integer(2)); socket2.setSocketName("comp-1"); PowerstripSocket socket3 = new PowerstripSocket(); socket3.setNetworkPowerstrip(strip1); socket3.setNetworkDevice(comp2); socket3.setSocketNumber(new Integer(3)); socket3.setSocketName("comp-2"); HashSet<PowerstripSocket> pss = new HashSet<PowerstripSocket>(); pss.add(socket1); pss.add(socket2); pss.add(socket3); //strip1.setPowerstripSockets(pss); HashSet<NetworkDevice> nds = new HashSet<NetworkDevice>(); nds.add(comp1); nds.add(comp2); nds.add(strip1); //config.setNetworkDevices(nds); /* setup a SNMP configuration for computers */ NetworkDeviceSnmpConfig snmp1 = new NetworkDeviceSnmpConfig(); snmp1.setPropagateNA(false); snmp1.setSnmpCommunity("public"); snmp1.setAcsAlarm(NetDevSnmpConfigAcsAlarm.NEVER); snmp1.setNetworkDevice(comp1); String xml1 = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + "<netnode name=\"ps014692\" xmlns=\"Alma/Exec/SnmpConfig\">\n" + "<uptime />\n" + "<cpuload type=\"2\" max=\"10\" />\n" + "<memory min=\"10\" />\n" + "<diskspace>\n" + " <disk name=\"/home\" max=\"90\" />\n" + " <disk name=\"/\" max=\"90\" />\n" + " <file name=\"/var/log/messages\" max=\"100000000\" />\n" + " </diskspace>\n" + " <services>\n" + " <proc name=\"maciContainer\" min=\"0\" max=\"1\" />\n" + " </services>\n" + " <scripts>\n" + " <exec name=\"/usr/bin/uptime\" />\n" + " <exec name=\"/sbin/reboot\" />\n" + " <exec name=\"/home/pgrosbol/bin/snmpexec.sh\" />\n" + " </scripts>\n" + " <netports>\n" + "<port name=\"udp/0.0.0.0:161\" />\n" + " <port name=\"udp/0.0.0.0:10162\" />\n" + " </netports>\n" + " <interfaces>\n" + " <interface name=\"eth0\" />\n" + " </interfaces>\n" + " </netnode>\n"; snmp1.setSnmpXmlClob(xml1); NetworkDeviceSnmpConfig snmp2 = new NetworkDeviceSnmpConfig(); snmp2.setPropagateNA(true); snmp2.setSnmpCommunity("public"); snmp2.setAcsAlarm(NetDevSnmpConfigAcsAlarm.ALWAYS); snmp2.setNetworkDevice(comp2); String xml2 = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + "<netnode name=\"pc008506\" xmlns=\"Alma/Exec/SnmpConfig\">\n" + "<uptime />\n" + "<cpuload type=\"2\" max=\"10\" />\n" + "<memory min=\"10\" />\n" + "<diskspace>\n" + " <disk name=\"/home\" max=\"90\" />\n" + " <disk name=\"/\" max=\"90\" />\n" + " <file name=\"/var/log/messages\" max=\"100000000\" />\n" + " </diskspace>\n" + " <services>\n" + " <proc name=\"maciContainer\" min=\"0\" max=\"1\" />\n" + " </services>\n" + " <scripts>\n" + " <exec name=\"/usr/bin/uptime\" />\n" + " <exec name=\"/sbin/reboot\" />\n" + " <exec name=\"/home/pgrosbol/bin/snmpexec.sh\" />\n" + " </scripts>\n" + " <netports>\n" + "<port name=\"udp/0.0.0.0:161\" />\n" + " <port name=\"udp/0.0.0.0:10162\" />\n" + " </netports>\n" + " <interfaces>\n" + " <interface name=\"eth0\" />\n" + " </interfaces>\n" + " </netnode>\n"; snmp2.setSnmpXmlClob(xml2); /* store data in TMCDB */ hibernateUtil.beginTransaction(); hibernateUtil.getSession().save(config); hibernateUtil.getSession().save(comp1); hibernateUtil.getSession().save(comp2); hibernateUtil.getSession().save(snmp1); hibernateUtil.getSession().save(snmp2); hibernateUtil.getSession().save(sink); hibernateUtil.getSession().save(strip1); hibernateUtil.getSession().save(socket1); hibernateUtil.getSession().save(socket2); hibernateUtil.getSession().save(socket3); hibernateUtil.commitTransaction(); assertEquals(1, hibernateUtil.getList(Configuration.class).size()); assertEquals(1, hibernateUtil.getList(NetworkPowerstrip.class).size()); assertEquals(1, hibernateUtil.getList(SnmpTrapSink.class).size()); assertEquals(3, hibernateUtil.getList(PowerstripSocket.class).size()); assertEquals(2, hibernateUtil.getList(Computer.class).size()); assertEquals(2, hibernateUtil.getList(NetworkDeviceSnmpConfig.class).size()); hibernateUtil.closeSession(); hibernateUtil.beginTransaction(); List<PowerstripSocket> sockets = hibernateUtil.getList(PowerstripSocket.class); hibernateUtil.getSession().lock(strip1, LockMode.NONE); for (PowerstripSocket powerstripSocket : sockets) { hibernateUtil.getSession().lock(powerstripSocket, LockMode.NONE); assertEquals(powerstripSocket.getSocketName().equals("comp-1") ? comp1.getName() : comp2.getName(), powerstripSocket.getNetworkDevice().getName()); assertEquals(strip1.getName(), powerstripSocket.getNetworkPowerstrip().getName()); } hibernateUtil.closeSession(); } finally { dropDB(); } }
From source file:br.com.arsmachina.dao.hibernate.ReadableDAOImpl.java
License:Apache License
/** * Reattaches the object to the current {@link org.hibernate.Session} using * <code>Session.lock(object, LockMode.NONE)</code> and then returns the object. * //from w ww .j a v a2s . c o m * @param a <code>T</code>. * @return <code>object</code>. * @see br.com.arsmachina.dao.ReadableDAO#reattach(java.lang.Object) */ public T reattach(T object) { getSession().lock(object, LockMode.NONE); return object; }
From source file:br.com.bluesoft.pronto.dao.TicketDao.java
License:Open Source License
private void defineValores(final Ticket... tickets) { log.info("Entrou TicketDao.defineValores"); for (final Ticket ticket : tickets) { getSession().lock(ticket, LockMode.NONE); if (ticket.getReporter() == null) { ticket.setReporter(Seguranca.getUsuario()); }/* w w w . j a va 2 s . co m*/ // Se um ticket tiver filhos, atualizar os dados dos filhos que devem ser sempre iguais aos do pai. if (ticket.temFilhos()) { log.info("Ticket tem filhos, atualizando dados"); ticket.setEsforco(ticket.getSomaDoEsforcoDosFilhos()); for (final Ticket filho : ticket.getFilhos()) { if (!filho.isImpedido() && !filho.isLixo()) { filho.setBacklog(ticket.getBacklog()); } filho.setCliente(ticket.getCliente()); filho.setSolicitador(ticket.getSolicitador()); // filho.setSprint(ticket.getSprint()); filho.setTipoDeTicket((TipoDeTicket) getSession().get(TipoDeTicket.class, TipoDeTicket.TAREFA)); } if (ticket.isTodosOsFilhosProntos()) { if (ticket.getDataDePronto() == null) { ticket.setDataDePronto(new Date()); } } else { ticket.setDataDePronto(null); } } // Se o ticket pai estiver impedido ou na lixeira, o ticket filho deve permancer da mesma forma. if (ticket.temPai()) { log.info("Ticket tem pai, sincronizando em TicketDao.defineValores()"); final Ticket pai = ticket.getPai(); if (pai.isLixo() || pai.isImpedido()) { ticket.setBacklog(pai.getBacklog()); } else { if (!ticket.isLixo() && !ticket.isImpedido()) { ticket.setBacklog(pai.getBacklog()); } } // ticket.setSprint(pai.getSprint()); ticket.setTipoDeTicket((TipoDeTicket) getSession().get(TipoDeTicket.class, TipoDeTicket.TAREFA)); if (ticket.isDone() && pai.isTodosOsFilhosProntos()) { if (pai.getDataDePronto() == null) { pai.setDataDePronto(new Date()); pai.setKanbanStatus((KanbanStatus) getSession().get(KanbanStatus.class, KanbanStatus.DONE)); super.getSession().update(pai); } } else { if (pai.isEmAndamento()) { pai.setKanbanStatus( (KanbanStatus) getSession().get(KanbanStatus.class, KanbanStatus.DOING)); } else { pai.setKanbanStatus( (KanbanStatus) getSession().get(KanbanStatus.class, KanbanStatus.TO_DO)); } pai.setDataDePronto(null); } } // Tarefa nao tem valor de Negocio if (ticket.isTarefa()) { ticket.setValorDeNegocio(0); } // Grava sysdate na criacao if (ticket.getDataDeCriacao() == null) { ticket.setDataDeCriacao(new Date()); } // Se o status for pronto tem que ter data de pronto. if (ticket.getKanbanStatus().getKanbanStatusKey() == KanbanStatus.DONE && ticket.getDataDePronto() == null) { ticket.setDataDePronto(new Date()); } getSession().saveOrUpdate(ticket); log.info("Executou TicketDao.defineValores"); } }
From source file:br.gov.jfrj.siga.ex.bl.ExCompetenciaBL.java
License:Open Source License
/** * Retorna um configurao existente para a combinao dos dados passados * como parmetros, caso exista.//from ww w .jav a 2 s . c om * * @param titularIniciador * @param lotaTitularIniciador * @param tipoConfig * @param procedimento * @param raia * @param tarefa * @return * @throws Exception */ private ExConfiguracao preencherFiltroEBuscarConfiguracao(DpPessoa titularIniciador, DpLotacao lotaTitularIniciador, long tipoConfig, long tipoMov, ExTipoDocumento exTipoDocumento, ExTipoFormaDoc exTipoFormaDoc, ExFormaDocumento exFormaDocumento, ExModelo exModelo, ExClassificacao exClassificacao, ExVia exVia, ExNivelAcesso exNivelAcesso, ExPapel exPapel, CpOrgaoUsuario orgaoObjeto) { ExConfiguracao cfgFiltro = new ExConfiguracao(); cfgFiltro.setCargo(titularIniciador.getCargo()); cfgFiltro.setOrgaoUsuario(lotaTitularIniciador.getOrgaoUsuario()); cfgFiltro.setFuncaoConfianca(titularIniciador.getFuncaoConfianca()); cfgFiltro.setLotacao(lotaTitularIniciador); cfgFiltro.setDpPessoa(titularIniciador); cfgFiltro.setCpTipoConfiguracao(CpDao.getInstance().consultar(tipoConfig, CpTipoConfiguracao.class, false)); if (cfgFiltro.getCpTipoConfiguracao() == null) throw new RuntimeException("No permitido buscar uma configurao sem definir seu tipo."); if (tipoMov != 0) cfgFiltro .setExTipoMovimentacao(CpDao.getInstance().consultar(tipoMov, ExTipoMovimentacao.class, false)); cfgFiltro.setExTipoDocumento(exTipoDocumento); cfgFiltro.setExTipoFormaDoc(exTipoFormaDoc); cfgFiltro.setExFormaDocumento(exFormaDocumento); cfgFiltro.setExModelo(exModelo); cfgFiltro.setExClassificacao(exClassificacao); cfgFiltro.setExVia(exVia); cfgFiltro.setExNivelAcesso(exNivelAcesso); cfgFiltro.setExPapel(exPapel); cfgFiltro.setOrgaoObjeto(orgaoObjeto); ExConfiguracao cfg = (ExConfiguracao) getConfiguracaoBL().buscaConfiguracao(cfgFiltro, new int[] { 0 }, null); // Essa linha necessria porque quando recuperamos um objeto da classe // WfConfiguracao do TreeMap esttico que os armazena, este objeto est // detached, ou seja, no est conectado com a seo atual do hibernate. // Portanto, quando vamos acessar alguma propriedade dele que seja do // tipo LazyRead, obtemos um erro. O mtodo lock, attacha ele novamente // na seo atual. if (cfg != null) ExDao.getInstance().getSessao().lock(cfg, LockMode.NONE); return cfg; }
From source file:br.gov.jfrj.siga.wf.bl.WfCompetenciaBL.java
License:Open Source License
/** * Retorna um configurao existente para a combinao dos dados passados * como parmetros, caso exista./*w w w .ja va2s . c o m*/ * * @param titularIniciador * @param lotaTitularIniciador * @param tipoConfig * @param procedimento * @param raia * @param tarefa * @return * @throws Exception */ private WfConfiguracao preencherFiltroEBuscarConfiguracao(DpPessoa titularIniciador, DpLotacao lotaTitularIniciador, long tipoConfig, final String procedimento, final String raia, final String tarefa) throws Exception { WfConfiguracao cfgFiltro = new WfConfiguracao(); cfgFiltro.setCargo(titularIniciador != null ? titularIniciador.getCargo() : null); cfgFiltro.setOrgaoUsuario(lotaTitularIniciador.getOrgaoUsuario()); cfgFiltro.setFuncaoConfianca(titularIniciador != null ? titularIniciador.getFuncaoConfianca() : null); cfgFiltro.setLotacao(lotaTitularIniciador); cfgFiltro.setDpPessoa(titularIniciador != null ? titularIniciador : null); cfgFiltro.setCpTipoConfiguracao(CpDao.getInstance().consultar(tipoConfig, CpTipoConfiguracao.class, false)); cfgFiltro.setProcedimento(procedimento); cfgFiltro.setRaia(raia); cfgFiltro.setTarefa(tarefa); WfConfiguracao cfg = (WfConfiguracao) getConfiguracaoBL().buscaConfiguracao(cfgFiltro, new int[] { 0 }, null); // Essa linha necessria porque quando recuperamos um objeto da classe // WfConfiguracao do TreeMap esttico que os armazena, este objeto est // detached, ou seja, no est conectado com a seo atual do hibernate. // Portanto, quando vamos acessar alguma propriedade dele que seja do // tipo LazyRead, obtemos um erro. O mtodo lock, attacha ele novamente // na seo atual. if (cfg != null) WfDao.getInstance().getSessao().lock(cfg, LockMode.NONE); return cfg; }
From source file:com.actelion.research.spiritcore.services.dao.DAORevision.java
License:Open Source License
/** * Returns all revisions of the given entity until the given maxRevId * @param obj/*from ww w. j a v a 2s . c o m*/ * @param maxRevId (-1, to ignore) * @return */ @SuppressWarnings("unchecked") public static List<Revision> getLastRevisions(Class<?> claz, Serializable entityId, int maxRevId, int n) { long s = System.currentTimeMillis(); EntityManager session = JPAUtil.getManager(); AuditReader reader = AuditReaderFactory.get(session); AuditQuery query = reader.createQuery().forRevisionsOfEntity(claz, false, true).setCacheable(false) .setLockMode(LockMode.NONE); query.add(AuditEntity.id().eq(entityId)); if (maxRevId > 0) { query.add(AuditEntity.revisionNumber().le(maxRevId)); } if (n > 0) { query.setMaxResults(n); query.addOrder(AuditEntity.revisionNumber().desc()); } List<Revision> revisions = getRevisions(null, query.getResultList()); LoggerFactory.getLogger(DAORevision.class).debug("Loaded revisions for " + claz.getSimpleName() + "(" + entityId + ") maxRevId=" + maxRevId + "-" + n + " in " + (System.currentTimeMillis() - s) + "ms"); return revisions; }
From source file:com.actelion.research.spiritcore.services.dao.DAORevision.java
License:Open Source License
/** * Get the different version of an element, the first element of the list shows the most recent version * @param obj//ww w. ja v a 2 s. c o m * @return */ public static <T extends IObject> List<T> getHistory(Class claz, Serializable objectId, int maxRevs) { long s = System.currentTimeMillis(); EntityManager session = JPAUtil.getManager(); AuditReader reader = AuditReaderFactory.get(session); AuditQuery query = reader.createQuery().forRevisionsOfEntity(claz, true, false) .add(AuditEntity.id().eq(objectId)).addOrder(AuditEntity.revisionNumber().desc()) .setCacheable(false).setLockMode(LockMode.NONE); if (maxRevs > 0) { query.setMaxResults(maxRevs); } List<T> res = query.getResultList(); for (T t : res) { session.detach(t); } LoggerFactory.getLogger(DAORevision.class).debug("Loaded history for " + claz.getSimpleName() + ": (" + objectId + ") in " + (System.currentTimeMillis() - s) + "ms"); return res; }
From source file:com.actelion.research.spiritcore.services.dao.DAORevision.java
License:Open Source License
/** * Gets the last version and the change for the given entity, in the given context. * This method should return the last change, even if the changes of the given entity have not been committed. * * This method should be used exclusively from the SpritRevisionEntityListener to record the differences between the object to be saved and the last revision. * (when the record to be saved in already in the audit table) * * @param entityClass// ww w . j a v a2 s. c o m * @param entityId * @return */ @SuppressWarnings("unchecked") public static <T extends IAuditable> Pair<IAuditable, DifferenceList> getLastChange(RevisionType revisionType, Class<T> entityClass, Serializable entityId) { //Query the 2 last revisions of entityClass:entityId EntityManager session = JPAUtil.getManager(); AuditReader reader = AuditReaderFactory.get(session); AuditQuery query = reader.createQuery().forRevisionsOfEntity(entityClass, false, true) .add(AuditEntity.id().eq(entityId)).addOrder(AuditEntity.revisionNumber().desc()).setMaxResults(2) .setCacheable(false).setLockMode(LockMode.NONE); List<Object[]> histories = query.getResultList(); //Compute the difference between those 2 last versions assert histories.size() > 0; DifferenceList diff = null; if (revisionType == RevisionType.DEL) { diff = ((T) histories.get(0)[0]).getDifferenceList(null); diff.add("", ChangeType.DEL); assert diff.size() == 1; } else if (revisionType == RevisionType.ADD) { diff = ((T) histories.get(0)[0]).getDifferenceList(null); diff.add("", ChangeType.ADD); assert diff.size() == 1; } else if (histories.size() >= 2) { diff = ((T) histories.get(0)[0]).getDifferenceList((T) histories.get(1)[0]); } else { return null; } return new Pair<IAuditable, DifferenceList>((T) histories.get(0)[0], diff); }
From source file:com.actelion.research.spiritcore.services.dao.DAORevision.java
License:Open Source License
/** * Returns the lastChange from the given entity. * This method should be called outside the SpritRevisionEntityListener (when the record is not yet in the audit table) * * @param auditable// w w w. j ava 2 s . c o m * @return */ @SuppressWarnings("unchecked") public static <T extends IAuditable> Pair<T, DifferenceList> getLastChange(IAuditable auditable) { //Query the 2 last revisions of entityClass:entityId EntityManager session = JPAUtil.getManager(); AuditReader reader = AuditReaderFactory.get(session); AuditQuery query = reader.createQuery().forRevisionsOfEntity(auditable.getClass(), true, true) .add(AuditEntity.id().eq(auditable.getSerializableId())) .addOrder(AuditEntity.revisionNumber().desc()).setMaxResults(1).setCacheable(false) .setLockMode(LockMode.NONE); List<IAuditable> histories = query.getResultList(); //Compute the difference between those 2 last versions if (histories.size() == 0) { return new Pair<T, DifferenceList>(null, new DifferenceList()); } else { return new Pair<T, DifferenceList>((T) histories.get(0), auditable.getDifferenceList(histories.get(0))); } }
From source file:com.bitranger.parknshop.admin.data.PsAdminAccDAO.java
License:Open Source License
public void attachClean(PsAdminAcc instance) { log.debug("attaching clean PsAdminAcc instance"); try {/*from w w w. j a v a 2s. c om*/ getHibernateTemplate().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } }