List of usage examples for org.apache.commons.lang SerializationUtils clone
public static Object clone(Serializable object)
Deep clone an Object
using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:com.floreantpos.ui.views.payment.GroupSettleTicketDialog.java
private void settleTicket(CardProcessor cardProcessor, PosTransaction transaction) { try {//from w w w . ja v a 2 s.c om List<PosTransaction> transactionList = new ArrayList<PosTransaction>(); totalTenderAmount = paymentView.getTenderedAmount(); for (Ticket ticket : tickets) { PosTransaction cardTransaction = new PosTransaction(); if (totalTenderAmount <= 0) { break; } cardTransaction = (PosTransaction) SerializationUtils.clone(transaction); cardTransaction.setId(null); cardTransaction.setGlobalId(GlobalIdGenerator.generate()); cardTransaction.setTicket(ticket); setTransactionAmounts(cardTransaction); if (ticket.getOrderType().isPreAuthCreditCard()) {// authorize onlly do not capture cardProcessor.preAuth(transaction); } else { cardProcessor.chargeAmount(transaction); } confirmLoyaltyDiscount(ticket); PosTransactionService transactionService = PosTransactionService.getInstance(); transactionService.settleTicket(ticket, cardTransaction); transactionList.add(cardTransaction); printTicket(ticket, cardTransaction); } //FIXME showTransactionCompleteMsg(totalDueAmount, totalTenderAmount, tickets, transactionList); setCanceled(false); dispose(); } catch (UnknownHostException e) { POSMessageDialog.showError(Application.getPosWindow(), Messages.getString("SettleTicketDialog.12")); //$NON-NLS-1$ } catch (Exception e) { POSMessageDialog.showError(this, POSConstants.ERROR_MESSAGE, e); } }
From source file:net.lmxm.ute.gui.MainFrame.java
/** * Clone identifiable bean.//from w ww . j av a 2s. com * * @param bean the bean * @return the identifiable bean */ private IdentifiableBean cloneIdentifiableBean(final IdentifiableBean bean) { final IdentifiableBean newBean = (IdentifiableBean) SerializationUtils.clone(bean); newBean.setId("Copy of " + newBean.getId()); return newBean; }
From source file:com.flexive.ejb.beans.configuration.GenericConfigurationImpl.java
/** * Returns the cached value of the given parameter * * @param path the parameter path/*from w w w . ja v a 2 s .co m*/ * @param key the parameter key * @return the cached value of the given parameter * @throws FxCacheException if a cache exception occurred */ protected Serializable getCache(String path, String key) throws FxCacheException { final Serializable value = (Serializable) CacheAdmin.getInstance().get(path, key); if (value == null || value instanceof String || Primitives.isWrapperType(value.getClass())) { // immutable value type return value; } if (value instanceof Cloneable) { // use clone if possible try { final Object clone = ObjectUtils.clone(value); if (clone != null && clone instanceof Serializable) { return (Serializable) clone; } } catch (CloneFailedException e) { LOG.warn("Failed to clone cached configuration value " + path + "/" + key, e); } } // use generic clone via serialization return (Serializable) SerializationUtils.clone(value); }
From source file:ec.gob.ceaaces.controller.MallasController.java
public void nuevaMalla(ActionEvent evt) { this.mallaCrearEditar = (MallaCurricularDTO) SerializationUtils.clone(new MallaCurricularDTO()); cargarOrganizacionesVacias(mallaCrearEditar); organizacionMallaSelect = "0"; numeroNivelesSelect = "0"; }
From source file:ec.gob.ceaaces.controller.MallasController.java
public void editarMalla(MallaCurricularDTO malla, Boolean idEditMalla) { System.out.println("esCopiaMalla.." + idEditMalla); // if (idEditMalla) { // if (alertaFaseRectificacion && alertaUsuarioIes) { // if (malla.getId() != null // && !malla.getFaseIesDTO().getTipo().name() // .startsWith("RECTIFICACION")) { // JsfUtil.msgError("No se puede editar esta malla en fase de Rectificacin."); // return;/*from www .ja va 2s. c o m*/ // } // } // } mallaCrearEditar = (MallaCurricularDTO) SerializationUtils.clone(malla); List<OrganizacionCurricularDTO> organizacionCurricularList = null; try { organizacionCurricularList = registroServicio.obtenerOrganizacionCurricular(mallaCrearEditar.getId()); } catch (ServicioException e) { e.printStackTrace(); return; } if (organizacionCurricularList == null || organizacionCurricularList.isEmpty()) { cargarOrganizacionesVacias(mallaCrearEditar); } else { mallaCrearEditar.setOrganizacionesCurricularDTO(organizacionCurricularList); } if (mallaCrearEditar.getOrganizacionMallaEnum() != null) { organizacionMallaSelect = mallaCrearEditar.getOrganizacionMallaEnum().getValue(); } if (mallaCrearEditar.getNumeroNiveles() != null) { cargarNiveles(); numeroNivelesSelect = mallaCrearEditar.getNumeroNiveles().toString(); } RequestContext context = RequestContext.getCurrentInstance(); context.execute("dlgCrearEditarMallaId.show();"); }
From source file:ec.gob.ceaaces.controller.MallasController.java
public void guardarMalla(boolean esImportacion) { RequestContext context = RequestContext.getCurrentInstance(); context.addCallbackParam("cerrarVentana", false); if (esCopiaMalla) { try {/*from w w w .j a v a2 s .co m*/ AuditoriaDTO auditoria = new AuditoriaDTO(); auditoria.setFechaModificacion(new Date()); auditoria.setUsuarioModificacion(usuarioSistema); MallaCurricularDTO copiaMalla = (MallaCurricularDTO) SerializationUtils.clone(mallaCrearEditar); Long idMalla = copiaMalla.getId(); copiaMalla.setId(null); copiaMalla.setCodigoUnico(null); if (esImportacion) { copiaMalla.setReforma(null); } else { copiaMalla.setReforma(idMalla); } copiaMalla.setAuditoria(auditoria); Map<AreaFormacionOrganizacionEnum, Long> organizacionesAnterioresIds = new HashMap<>(); Map<Long, Long> organizacionesNuevasIds = new HashMap<>(); for (OrganizacionCurricularDTO organizacion : copiaMalla.getOrganizacionesCurricularDTO()) { organizacionesAnterioresIds.put(organizacion.getAreaFormacion(), organizacion.getId()); organizacion.setId(null); organizacion.setAuditoria(auditoria); organizacion.setMallaDTO(copiaMalla); } copiaMalla = insertarActualizarMalla(copiaMalla); // si no pas las validaciones retorna null if (copiaMalla == null) { return; } List<OrganizacionCurricularDTO> organizaciones = registroServicio .obtenerOrganizacionCurricular(copiaMalla.getId()); for (OrganizacionCurricularDTO org : organizaciones) { organizacionesNuevasIds.put(organizacionesAnterioresIds.get(org.getAreaFormacion()), org.getId()); } List<AsignaturaDTO> asignaturas = registroServicio.obtenerAsignaturasPorMalla(idMalla); int contador = 1; Map<Long, Long> idsAsignatura = new HashMap<>(); List<AsignaturaDTO> asignaturasHijas = new ArrayList<>(); for (AsignaturaDTO asignatura : asignaturas) { Long id = asignatura.getId(); asignatura.setOrganizacionCurricular( organizacionesNuevasIds.get(asignatura.getOrganizacionCurricular())); asignatura.setMallaCurricularDTO(copiaMalla); asignatura.setId(null); asignatura.setAuditoria(auditoria); asignatura.setCodigoUnico( ies.getSiglas() + "_" + copiaMalla.getCodigoUnico() + "_" + asignatura.getCodigo() + "_" + asignatura.getNombre().substring(0, 3).toUpperCase() + "_" + contador); contador++; asignatura.setFaseIesDTO(faseIesDTO); AsignaturaDTO asignaturaCreada = registroServicio.crearActualizar(asignatura); idsAsignatura.put(id, asignaturaCreada.getId()); if (asignaturaCreada.getIdAsignaturaPadre() != null) { asignaturasHijas.add(asignaturaCreada); } for (RequisitoAsignaturaDTO requisito : asignatura.getCorRequisitoMalla()) { if (requisito.getActivo()) { requisito.setId(null); requisito.setAuditoria(auditoria); requisito.setAsignaturaDTO(asignaturaCreada); requisito.setFaseIesDTO(faseIesDTO); registroServicio.crearActualizar(requisito); } } for (RequisitoAsignaturaDTO requisito : asignatura.getPreRequisitoMalla()) { if (requisito.getActivo()) { requisito.setId(null); requisito.setAuditoria(auditoria); requisito.setAsignaturaDTO(asignaturaCreada); requisito.setFaseIesDTO(faseIesDTO); registroServicio.crearActualizar(requisito); } } } for (AsignaturaDTO asignaturaHija : asignaturasHijas) { asignaturaHija.setIdAsignaturaPadre(idsAsignatura.get(asignaturaHija.getIdAsignaturaPadre())); asignaturaHija.setFaseIesDTO(faseIesDTO); registroServicio.crearActualizar(asignaturaHija); } cargarMallas(); JsfUtil.msgInfo("La copia de la malla se realiz correctamente"); context.addCallbackParam("cerrarVentana", true); } catch (Exception e) { JsfUtil.msgError("Error al copiar la malla, comunquese con el administrador del sistema"); e.printStackTrace(); } } else { try { mallaCrearEditar.setVerificarEvidencia(false); if (insertarActualizarMalla(mallaCrearEditar) != null) { JsfUtil.msgInfo("Se guard la nueva malla correctamente"); context.addCallbackParam("cerrarVentana", true); } else { return; } } catch (Exception e) { e.printStackTrace(); JsfUtil.msgError("Error al guardar la malla, comunquese con el administrador del sistema."); return; } } }
From source file:jp.co.opentone.bsol.linkbinder.service.correspon.impl.CorresponSaveServiceImplTest.java
/** * PIC?????? ?.// ww w. ja v a 2 s . c o m */ @Test public void testSave09() throws Exception { createMasterForUpdateData(); MockAbstractService.IS_SYSTEM_ADMIN = true; MockAbstractService.IS_PROJECT_ADMIN = false; MockAbstractService.IS_ANY_GROUP_ADMIN = false; User loginUser = new User(); loginUser.setEmpNo("80002"); loginUser.setNameE("Approver User"); MockAbstractService.CURRENT_USER = loginUser; ProjectUser pUser = new ProjectUser(); pUser.setUser(loginUser); MockAbstractService.CURRENT_PROJECT_USER = pUser; CorresponGroup cg1 = new CorresponGroup(); cg1.setId(2L); cg1.setName("GRP:A01"); CorresponGroup cg = cg1; Correspon correspon = new Correspon(); correspon.setId(100L); // ????id? correspon.setCreatedBy(loginUser); correspon.setWorkflowStatus(WorkflowStatus.ISSUED); correspon.setCorresponStatus(CorresponStatus.OPEN); correspon.setFromCorresponGroup(cg); correspon.setSubject("PIC?????"); correspon.setBody("********"); correspon.setReplyRequired(ReplyRequired.NO); correspon.setUpdatedBy(loginUser); correspon.setVersionNo(1L); correspon.setProjectId("PJ1"); User picUser = new User(); picUser.setEmpNo("TEST_01"); User createdBy = new User(); createdBy.setEmpNo("CREATE_01"); createdBy.setNameE("Creater_01"); User updatedBy = new User(); updatedBy.setEmpNo("UPDATE_01"); updatedBy.setNameE("Updater_01"); User attention1 = new User(); attention1.setEmpNo("ATTENTION_01"); attention1.setNameE("Attention_01"); CorresponType ct = new CorresponType(); ct.setId(1L); ct.setCorresponType("P1"); correspon.setCorresponType(ct); List<AddressCorresponGroup> acgs = new ArrayList<AddressCorresponGroup>(); AddressCorresponGroup acg = new AddressCorresponGroup(); acg.setId(10L); acg.setAddressType(AddressType.TO); acg.setMode(UpdateMode.UPDATE); acgs.add(acg); correspon.setAddressCorresponGroups(acgs); List<AddressUser> aus = new ArrayList<AddressUser>(); AddressUser au1 = new AddressUser(); au1.setId(1000L); au1.setAddressUserType(AddressUserType.ATTENTION); au1.setAddressCorresponGroupId(10L); au1.setUser(attention1); aus.add(au1); acg.setUsers(aus); CorresponCustomField ccf = new CorresponCustomField(); ccf.setCorresponId(100L); ccf.setUpdatedBy(loginUser); MockCorresponCustomFieldDao.RET_UPDATE_CORRESPONCUSTOMFIELD = ccf; AddressUser expectAu = new AddressUser(); expectAu.setAddressCorresponGroupId(10L); expectAu.setUpdatedBy(loginUser); MockAddressUserDao.RET_UPDATE_ADDRESSUSER = expectAu; List<AddressUser> exp_au = new ArrayList<AddressUser>(); expectAu = new AddressUser(); expectAu.setAddressCorresponGroupId(acg.getId()); expectAu.setAddressUserType(AddressUserType.ATTENTION); expectAu.setUser(attention1); expectAu.setCreatedBy(correspon.getCreatedBy()); expectAu.setUpdatedBy(loginUser); exp_au.add(expectAu); MockAbstractDao.RET_CREATE_ADDRESSUSER = exp_au; List<PersonInCharge> pics1 = new ArrayList<PersonInCharge>(); PersonInCharge pic1 = new PersonInCharge(); pic1.setId(100L); pic1.setAddressUserId(1000L); pic1.setUser(picUser); pic1.setCreatedBy(createdBy); pic1.setUpdatedBy(loginUser); pics1.add(pic1); MockPersonInChargeDao.RET_FIND_BY_ADDRESS_USER_ID = pics1; PersonInCharge pic2 = (PersonInCharge) SerializationUtils.clone(pic1); pic2.setUpdatedBy(loginUser); MockPersonInChargeDao.RET_UPDATE_PERSONINCHARGE = pic2; List<PersonInCharge> exp_pic = new ArrayList<PersonInCharge>(); PersonInCharge expect = new PersonInCharge(); expect.setAddressUserId(99L); expect.setUser(picUser); expect.setCreatedBy(createdBy); expect.setUpdatedBy(loginUser); exp_pic.add(expect); MockAbstractDao.RET_CREATE_PERSONINCHARGE = exp_pic; Correspon expectCorrespon = new Correspon(); expectCorrespon.setId(100L); // ????id? expectCorrespon.setCreatedBy(null); expectCorrespon.setWorkflowStatus(null); expectCorrespon.setCorresponStatus(CorresponStatus.OPEN); expectCorrespon.setFromCorresponGroup(cg); expectCorrespon.setSubject("PIC?????"); expectCorrespon.setBody("********"); expectCorrespon.setReplyRequired(ReplyRequired.NO); expectCorrespon.setUpdatedBy(loginUser); expectCorrespon.setVersionNo(1L); expectCorrespon.setCorresponType(ct); expectCorrespon.setAddressCorresponGroups(acgs); MockAbstractDao.RET_UPDATE_CORRESPON = expectCorrespon; MockAddressCorresponGroupDao.RET_FIND_BY_CORRESPON_ID = acgs; assertEquals(correspon.getId(), service.save(correspon)); }
From source file:org.apache.crunch.MaterializeToMapIT.java
@Test public void testMRMaterializeToMap() throws IOException { Pipeline p = new MRPipeline(MaterializeToMapIT.class, tmpDir.getDefaultConfiguration()); String inputFile = tmpDir.copyResourceFileName("set1.txt"); PCollection<String> c = p.readTextFile(inputFile); PTypeFamily tf = c.getTypeFamily();/*from ww w. j a v a 2s .co m*/ PTable<Integer, String> t = c.parallelDo(new Set1Mapper(), tf.tableOf(tf.ints(), tf.strings())); Map<Integer, String> m = t.materializeToMap(); assertMatches(m); Map<Integer, String> mclone = (Map<Integer, String>) SerializationUtils.clone((Serializable) m); assertMatches(mclone); }
From source file:org.apache.flink.streaming.api.datastream.AllWindowedStream.java
/** * Applies a reduce function to the window. The window function is called for each evaluation * of the window for each key individually. The output of the reduce function is interpreted * as a regular non-windowed stream./*from w ww. j a v a2 s . co m*/ * <p> * This window will try and pre-aggregate data as much as the window policies permit. For example, * tumbling time windows can perfectly pre-aggregate the data, meaning that only one element per * key is stored. Sliding time windows will pre-aggregate on the granularity of the slide interval, * so a few elements are stored per key (one per slide interval). * Custom windows may not be able to pre-aggregate, or may need to store extra values in an * aggregation tree. * * @param function The reduce function. * @return The data stream that is the result of applying the reduce function to the window. */ public SingleOutputStreamOperator<T, ?> reduce(ReduceFunction<T> function) { //clean the closure function = input.getExecutionEnvironment().clean(function); String callLocation = Utils.getCallLocationName(); String udfName = "Reduce at " + callLocation; SingleOutputStreamOperator<T, ?> result = createFastTimeOperatorIfValid(function, input.getType(), udfName); if (result != null) { return result; } String opName = "NonParallelTriggerWindow(" + windowAssigner + ", " + trigger + ", " + udfName + ")"; OneInputStreamOperator<T, T> operator; boolean setProcessingTime = input.getExecutionEnvironment() .getStreamTimeCharacteristic() == TimeCharacteristic.ProcessingTime; if (evictor != null) { operator = new EvictingNonKeyedWindowOperator<>(windowAssigner, windowAssigner.getWindowSerializer(getExecutionEnvironment().getConfig()), new HeapWindowBuffer.Factory<T>(), new ReduceAllWindowFunction<W, T>(function), trigger, evictor).enableSetProcessingTime(setProcessingTime); } else { // we need to copy because we need our own instance of the pre aggregator @SuppressWarnings("unchecked") ReduceFunction<T> functionCopy = (ReduceFunction<T>) SerializationUtils.clone(function); operator = new NonKeyedWindowOperator<>(windowAssigner, windowAssigner.getWindowSerializer(getExecutionEnvironment().getConfig()), new PreAggregatingHeapWindowBuffer.Factory<>(functionCopy), new ReduceAllWindowFunction<W, T>(function), trigger) .enableSetProcessingTime(setProcessingTime); } return input.transform(opName, input.getType(), operator).setParallelism(1); }
From source file:org.apache.flink.streaming.api.datastream.WindowedStream.java
/** * Applies a reduce function to the window. The window function is called for each evaluation * of the window for each key individually. The output of the reduce function is interpreted * as a regular non-windowed stream./*w w w.j av a 2 s. c om*/ * <p> * This window will try and pre-aggregate data as much as the window policies permit. For example, * tumbling time windows can perfectly pre-aggregate the data, meaning that only one element per * key is stored. Sliding time windows will pre-aggregate on the granularity of the slide interval, * so a few elements are stored per key (one per slide interval). * Custom windows may not be able to pre-aggregate, or may need to store extra values in an * aggregation tree. * * @param function The reduce function. * @return The data stream that is the result of applying the reduce function to the window. */ public SingleOutputStreamOperator<T, ?> reduce(ReduceFunction<T> function) { //clean the closure function = input.getExecutionEnvironment().clean(function); String callLocation = Utils.getCallLocationName(); String udfName = "Reduce at " + callLocation; SingleOutputStreamOperator<T, ?> result = createFastTimeOperatorIfValid(function, input.getType(), udfName); if (result != null) { return result; } String opName = "TriggerWindow(" + windowAssigner + ", " + trigger + ", " + udfName + ")"; KeySelector<T, K> keySel = input.getKeySelector(); OneInputStreamOperator<T, T> operator; boolean setProcessingTime = input.getExecutionEnvironment() .getStreamTimeCharacteristic() == TimeCharacteristic.ProcessingTime; if (evictor != null) { operator = new EvictingWindowOperator<>(windowAssigner, windowAssigner.getWindowSerializer(getExecutionEnvironment().getConfig()), keySel, input.getKeyType().createSerializer(getExecutionEnvironment().getConfig()), new HeapWindowBuffer.Factory<T>(), new ReduceWindowFunction<K, W, T>(function), trigger, evictor).enableSetProcessingTime(setProcessingTime); } else { // we need to copy because we need our own instance of the pre aggregator @SuppressWarnings("unchecked") ReduceFunction<T> functionCopy = (ReduceFunction<T>) SerializationUtils.clone(function); operator = new WindowOperator<>(windowAssigner, windowAssigner.getWindowSerializer(getExecutionEnvironment().getConfig()), keySel, input.getKeyType().createSerializer(getExecutionEnvironment().getConfig()), new PreAggregatingHeapWindowBuffer.Factory<>(functionCopy), new ReduceWindowFunction<K, W, T>(function), trigger) .enableSetProcessingTime(setProcessingTime); } return input.transform(opName, input.getType(), operator); }