List of usage examples for org.hibernate.internal.util SerializationHelper serialize
public static byte[] serialize(Serializable obj) throws SerializationException
Serializes an Object to a byte array for storage/serialization.
From source file:cpcc.vvrte.entities.Task.java
License:Open Source License
/** * @param sensorValues the sensor values to set. *//*w w w . j a v a 2 s. co m*/ public void setSensorValues(ScriptableObject sensorValues) { this.sensorValues = SerializationHelper.serialize(sensorValues); }
From source file:cpcc.vvrte.entities.VirtualVehicleStorage.java
License:Open Source License
/** * @param content the storage item's content to set. *//*from ww w . j a va 2s. co m*/ public void setContent(ScriptableObject content) { this.content = SerializationHelper.serialize(content); }
From source file:cpcc.vvrte.entities.VirtualVehicleStorageTest.java
License:Open Source License
@Test(dataProvider = "valuesDataProvider") public void shouldReturnContentAsByteArray(Integer id, VirtualVehicle virtualVehicle, String name, ScriptableObject content) {/*from w ww. j a v a2 s .c o m*/ byte[] required = SerializationHelper.serialize(content); storage.setContent(content); byte[] actual = storage.getContentAsByteArray(); assertThat(actual).isNotNull().isEqualTo(required); }
From source file:cpcc.vvrte.services.VirtualVehicleMigratorTest.java
License:Open Source License
public void setUpVv1() { Date startTime = new Date(); Date modificationTime1 = new Date(startTime.getTime() + 100); Date modificationTime2 = new Date(startTime.getTime() + 200); Date modificationTime3 = new Date(startTime.getTime() + 300); Date modificationTime4 = new Date(startTime.getTime() + 400); Date endTime = new Date(startTime.getTime() + 1000); vv1 = mock(VirtualVehicle.class); when(vv1.getId()).thenReturn(VV_ID1); when(vv1.getUuid()).thenReturn("efc6ef21-6d90-4f4b-95cf-baf5a9000467"); when(vv1.getName()).thenReturn("rv23"); when(vv1.getApiVersion()).thenReturn(1); when(vv1.getCode()).thenReturn("the code"); when(vv1.getState()).thenReturn(VirtualVehicleState.FINISHED); when(vv1.getContinuation()).thenReturn(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); when(vv1.getStartTime()).thenReturn(startTime); when(vv1.getEndTime()).thenReturn(endTime); ScriptableObject scriptableObject1 = new NativeObject(); scriptableObject1.put("a", scriptableObject1, "a"); scriptableObject1.put("b", scriptableObject1, null); scriptableObject1.put("c", scriptableObject1, Double.valueOf(3)); scriptableObject1.put("d", scriptableObject1, Boolean.TRUE); scriptableObject1.put("e", scriptableObject1, Integer.valueOf(13)); VirtualVehicleStorage storage1 = mock(VirtualVehicleStorage.class); when(storage1.getId()).thenReturn(1789); when(storage1.getVirtualVehicle()).thenReturn(vv1); when(storage1.getModificationTime()).thenReturn(modificationTime1); when(storage1.getName()).thenReturn("storage1"); when(storage1.getContent()).thenReturn(scriptableObject1); when(storage1.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject1)); ScriptableObject scriptableObject2 = new NativeObject(); scriptableObject2.put("A", scriptableObject2, "A"); scriptableObject2.put("B", scriptableObject2, scriptableObject1); scriptableObject2.put("C", scriptableObject2, scriptableObject1); scriptableObject2.put("D", scriptableObject2, scriptableObject1); scriptableObject2.put("E", scriptableObject2, scriptableObject1); scriptableObject2.put("F", scriptableObject2, scriptableObject1); scriptableObject2.put("G", scriptableObject2, scriptableObject1); VirtualVehicleStorage storage2 = mock(VirtualVehicleStorage.class); when(storage2.getId()).thenReturn(2789); when(storage2.getVirtualVehicle()).thenReturn(vv1); when(storage2.getModificationTime()).thenReturn(modificationTime2); when(storage2.getName()).thenReturn("storage2"); when(storage2.getContent()).thenReturn(scriptableObject2); when(storage2.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject2)); ScriptableObject scriptableObject3 = new NativeObject(); scriptableObject3.put("f", scriptableObject3, "FFF"); scriptableObject3.put("g", scriptableObject3, "GGGGG"); scriptableObject3.put("h", scriptableObject3, "HH"); scriptableObject3.put("i", scriptableObject3, ""); scriptableObject3.put("j", scriptableObject3, "J"); VirtualVehicleStorage storage3 = mock(VirtualVehicleStorage.class); when(storage3.getId()).thenReturn(3789); when(storage3.getVirtualVehicle()).thenReturn(vv1); when(storage3.getModificationTime()).thenReturn(modificationTime3); when(storage3.getName()).thenReturn("storage3"); when(storage3.getContent()).thenReturn(scriptableObject3); when(storage3.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject3)); ScriptableObject scriptableObject4 = null; VirtualVehicleStorage storage4 = mock(VirtualVehicleStorage.class); when(storage4.getId()).thenReturn(4789); when(storage4.getVirtualVehicle()).thenReturn(vv1); when(storage4.getModificationTime()).thenReturn(modificationTime4); when(storage4.getName()).thenReturn("storage4"); when(storage4.getContent()).thenReturn(scriptableObject4); when(storage4.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject4)); when(repo.findVirtualVehicleById(vv1.getId())).thenReturn(vv1); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq((String) null), eq(1))) .thenReturn(Arrays.asList(storage1)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq(""), eq(1))) .thenReturn(Arrays.asList(storage1)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq("storage1"), eq(1))) .thenReturn(Arrays.asList(storage2)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq("storage2"), eq(1))) .thenReturn(Arrays.asList(storage3)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq("storage3"), eq(1))) .thenReturn(Arrays.asList(storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq((String) null), eq(2))) .thenReturn(Arrays.asList(storage1, storage2)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq(""), eq(2))) .thenReturn(Arrays.asList(storage1, storage2)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq("storage2"), eq(2))) .thenReturn(Arrays.asList(storage3, storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq((String) null), eq(3))) .thenReturn(Arrays.asList(storage1, storage2, storage3)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq(""), eq(3))) .thenReturn(Arrays.asList(storage1, storage2, storage3)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq("storage3"), eq(3))) .thenReturn(Arrays.asList(storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq((String) null), eq(4))) .thenReturn(Arrays.asList(storage1, storage2, storage3, storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq(""), eq(4))) .thenReturn(Arrays.asList(storage1, storage2, storage3, storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv1.getId()), eq("storage4"), eq(4))) .thenReturn(new ArrayList<VirtualVehicleStorage>()); }
From source file:cpcc.vvrte.services.VirtualVehicleMigratorTest.java
License:Open Source License
public void setUpVv2() { Date startTime = new Date(); Date modificationTime1 = new Date(startTime.getTime() + 100); Date modificationTime2 = new Date(startTime.getTime() + 200); Date modificationTime3 = new Date(startTime.getTime() + 300); Date modificationTime4 = new Date(startTime.getTime() + 400); vv2 = mock(VirtualVehicle.class); when(vv2.getId()).thenReturn(VV_ID2); when(vv2.getUuid()).thenReturn("fec6ef21-6d90-4f4b-95cf-baf5a9000764"); when(vv2.getName()).thenReturn("rv32"); when(vv2.getApiVersion()).thenReturn(1); when(vv2.getCode()).thenReturn("the 2nd code"); when(vv2.getState()).thenReturn(VirtualVehicleState.FINISHED); when(vv2.getContinuation()).thenReturn(null); when(vv2.getStartTime()).thenReturn(null); when(vv2.getEndTime()).thenReturn(null); ScriptableObject scriptableObject1 = new NativeObject(); scriptableObject1.put("z", scriptableObject1, "a"); scriptableObject1.put("y", scriptableObject1, null); scriptableObject1.put("x", scriptableObject1, Double.valueOf(3)); scriptableObject1.put("w", scriptableObject1, Boolean.TRUE); scriptableObject1.put("v", scriptableObject1, Integer.valueOf(13)); VirtualVehicleStorage storage1 = mock(VirtualVehicleStorage.class); when(storage1.getId()).thenReturn(1789); when(storage1.getVirtualVehicle()).thenReturn(vv2); when(storage1.getModificationTime()).thenReturn(modificationTime1); when(storage1.getName()).thenReturn("storage1"); when(storage1.getContent()).thenReturn(scriptableObject1); when(storage1.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject1)); ScriptableObject scriptableObject2 = new NativeObject(); scriptableObject2.put("X", scriptableObject2, "Y"); scriptableObject2.put("Y", scriptableObject2, scriptableObject1); scriptableObject2.put("Z", scriptableObject2, scriptableObject1); scriptableObject2.put("U", scriptableObject2, scriptableObject1); scriptableObject2.put("T", scriptableObject2, scriptableObject1); VirtualVehicleStorage storage2 = mock(VirtualVehicleStorage.class); when(storage2.getId()).thenReturn(2789); when(storage2.getVirtualVehicle()).thenReturn(vv2); when(storage2.getModificationTime()).thenReturn(modificationTime2); when(storage2.getName()).thenReturn("storage2"); when(storage2.getContent()).thenReturn(scriptableObject2); when(storage2.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject2)); ScriptableObject scriptableObject3 = new NativeObject(); scriptableObject3.put("f", scriptableObject3, "FFF"); scriptableObject3.put("g", scriptableObject3, "GGGGG"); scriptableObject3.put("h", scriptableObject3, "h"); scriptableObject3.put("i", scriptableObject3, "iiiiiiiiiiiiii"); scriptableObject3.put("j", scriptableObject3, "jj"); scriptableObject3.put("k", scriptableObject3, "kk"); scriptableObject3.put("l", scriptableObject3, "lllll"); scriptableObject3.put("m", scriptableObject3, "mm"); VirtualVehicleStorage storage3 = mock(VirtualVehicleStorage.class); when(storage3.getId()).thenReturn(3789); when(storage3.getVirtualVehicle()).thenReturn(vv2); when(storage3.getModificationTime()).thenReturn(modificationTime3); when(storage3.getName()).thenReturn("storage3"); when(storage3.getContent()).thenReturn(scriptableObject3); when(storage3.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject3)); ScriptableObject scriptableObject4 = null; VirtualVehicleStorage storage4 = mock(VirtualVehicleStorage.class); when(storage4.getId()).thenReturn(4789); when(storage4.getVirtualVehicle()).thenReturn(vv2); when(storage4.getModificationTime()).thenReturn(modificationTime4); when(storage4.getName()).thenReturn("storage4"); when(storage4.getContent()).thenReturn(scriptableObject4); when(storage4.getContentAsByteArray()).thenReturn(SerializationHelper.serialize(scriptableObject4)); when(repo.findVirtualVehicleById(vv2.getId())).thenReturn(vv2); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq((String) null), eq(1))) .thenReturn(Arrays.asList(storage1)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq(""), eq(1))) .thenReturn(Arrays.asList(storage1)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq("storage1"), eq(1))) .thenReturn(Arrays.asList(storage2)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq("storage2"), eq(1))) .thenReturn(Arrays.asList(storage3)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq("storage3"), eq(1))) .thenReturn(Arrays.asList(storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq((String) null), eq(2))) .thenReturn(Arrays.asList(storage1, storage2)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq(""), eq(2))) .thenReturn(Arrays.asList(storage1, storage2)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq("storage2"), eq(2))) .thenReturn(Arrays.asList(storage3, storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq((String) null), eq(3))) .thenReturn(Arrays.asList(storage1, storage2, storage3)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq(""), eq(3))) .thenReturn(Arrays.asList(storage1, storage2, storage3)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq("storage3"), eq(3))) .thenReturn(Arrays.asList(storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq((String) null), eq(4))) .thenReturn(Arrays.asList(storage1, storage2, storage3, storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq(""), eq(4))) .thenReturn(Arrays.asList(storage1, storage2, storage3, storage4)); when(repo.findStorageItemsByVirtualVehicle(eq(vv2.getId()), eq("storage4"), eq(4))) .thenReturn(new ArrayList<VirtualVehicleStorage>()); }
From source file:org.fgsake.hibernate.cache.couchbase.internal.CouchbaseRegion.java
License:Apache License
protected String keyStrFor(Object key) { String keyStr;/*from ww w.j a va 2s . c o m*/ if (key instanceof QueryKey) { // Can't use toString, QueryKey.customTransformer shows up wrong in toString keyStr = DigestUtils.md5Hex(SerializationHelper.serialize((QueryKey) key)); } else { keyStr = key.toString(); if (name.length() + 1 + keyStr.length() > 250) { keyStr = DigestUtils.md5Hex(keyStr); } } return new StringBuilder(name.length() + 1 + keyStr.length()).append(name).append(":").append(keyStr) .toString(); }
From source file:org.hoteia.qalingo.core.service.GeolocService.java
License:Apache License
public GeolocCity geolocByCityAndCountry(final String city, final String country) { GeolocCity geolocCity = null;/*from w w w.j a v a2s .co m*/ String addressParam = encodeGoogleAddress(null, null, city, country); GoogleGeoCode geoCode = geolocGoogleWithAddress(addressParam); if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) { logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage()); engineSettingService.flagSettingGoogleGeolocationApiOverQuota(); return geolocCity; } if (geoCode != null) { geolocCity = new GeolocCity(); geolocCity.setCity(city); geolocCity.setCountry(country); geolocCity.setJson(SerializationHelper.serialize(geoCode)); geolocCity.setLatitude(geoCode.getLatitude()); geolocCity.setLongitude(geoCode.getLongitude()); if (city == null) { // SANITY CHECK : DON'T SAVE A CITY AS NULL TOO MANY TIME GeolocCity geolocCityCheck = geolocDao.getGeolocCityByCountryWithNullCity(country); if (geolocCityCheck == null) { try { geolocCity = geolocDao.saveOrUpdateGeolocCity(geolocCity); } catch (Exception e) { logger.error("Can't save GeolocCity: City: '" + geolocCity.getCity() + "', Country: '" + geolocCity.getCountry() + "'", e); } } } else { try { geolocCity = geolocDao.saveOrUpdateGeolocCity(geolocCity); } catch (Exception e) { logger.error("Can't save GeolocCity: City: '" + geolocCity.getCity() + "', Country: '" + geolocCity.getCountry() + "'", e); } } } return geolocCity; }
From source file:org.hoteia.qalingo.core.service.GeolocService.java
License:Apache License
public GeolocAddress geolocByAddress(final String address, final String postalCode, final String city, final String country) { GeolocAddress geolocAddress = null;//from www . ja v a 2s.c om String formatedAddress = encodeGoogleAddress(address, postalCode, city, country); GoogleGeoCode geoCode = geolocGoogleWithAddress(formatedAddress); if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) { logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage()); engineSettingService.flagSettingGoogleGeolocationApiOverQuota(); return geolocAddress; } if (geoCode != null) { geolocAddress = new GeolocAddress(); geolocAddress.setAddress(address); geolocAddress.setPostalCode(postalCode); geolocAddress.setCity(city); geolocAddress.setCountry(country); geolocAddress.setJson(SerializationHelper.serialize(geoCode)); geolocAddress.setFormatedAddress(formatedAddress); geolocAddress.setLatitude(geoCode.getLatitude()); geolocAddress.setLongitude(geoCode.getLongitude()); geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress); } return geolocAddress; }
From source file:org.hoteia.qalingo.core.service.GeolocService.java
License:Apache License
public GeolocAddress geolocByLatitudeLongitude(final String latitude, final String longitude) { GeolocAddress geolocAddress = null;/*from ww w . j a va 2s. c o m*/ GoogleGeoCode geoCode = geolocGoogleWithLatitudeLongitude(latitude, longitude); if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) { logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage()); engineSettingService.flagSettingGoogleGeolocationApiOverQuota(); return geolocAddress; } if (geoCode != null && geoCode.getResults().size() > 0) { GoogleGeoCodeResult googleGeoCodeResult = geoCode.getResults().get(0); String formatedAdress = googleGeoCodeResult.getFormattedAddress(); formatedAdress = formatedAdress.replace(" ", "+"); geolocAddress = new GeolocAddress(); geolocAddress.setAddress(googleGeoCodeResult.getAddress()); geolocAddress.setPostalCode(googleGeoCodeResult.getPostalCode()); geolocAddress.setCity(googleGeoCodeResult.getCity()); geolocAddress.setCountry(googleGeoCodeResult.getCountryCode()); geolocAddress.setJson(SerializationHelper.serialize(geoCode)); geolocAddress.setFormatedAddress(formatedAdress); geolocAddress.setLatitude(latitude); geolocAddress.setLongitude(longitude); // SANITY CHECK : DON'T SAVE AN ADDRESS WHICH ALREADY EXIST BUT WAS LOCATED WITH LAT/LONG DIFFERENT GeolocAddress geolocGeolocAddress = geolocDao.getGeolocAddressByFormatedAddress(formatedAdress); if (geolocGeolocAddress == null) { geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress); } } return geolocAddress; }