use of java.io.Serializable in project hibernate-orm by hibernate.
the class CachedMutableNaturalIdTest method testNaturalIdRecachingWhenNeeded.
@Test
public void testNaturalIdRecachingWhenNeeded() {
Session session = openSession();
session.getSessionFactory().getStatistics().clear();
session.beginTransaction();
Another it = new Another("it");
session.save(it);
Serializable id = it.getId();
session.getTransaction().commit();
session.close();
session = openSession();
for (int i = 0; i < 10; i++) {
session.beginTransaction();
it = session.byId(Another.class).load(id);
if (i == 9) {
it.setName("name" + i);
}
// changing something but not the natural-id's
it.setSurname("surname" + i);
session.getTransaction().commit();
}
session = openSession();
session.beginTransaction();
it = session.bySimpleNaturalId(Another.class).load("it");
assertNull(it);
assertEquals(0, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount());
it = session.byId(Another.class).load(id);
session.delete(it);
session.getTransaction().commit();
session.close();
// finally there should be only 2 NaturalIdCache puts : 1. insertion, 2. when updating natural-id from 'it' to 'name9'
assertEquals(2, session.getSessionFactory().getStatistics().getNaturalIdCachePutCount());
}
use of java.io.Serializable in project translationstudio8 by heartsome.
the class VerticalRowSelectionModel method getFullySelectedRows.
/**
* 得到被整行选中的所有行
* @see net.sourceforge.nattable.selection.ISelectionModel#getFullySelectedRows(int)
*/
public int[] getFullySelectedRows(int rowWidth) {
selectionsLock.readLock().lock();
try {
int[] selectedRowPositions = new int[selectedRows.size()];
int i = 0;
for (Serializable selectedRow : selectedRows) {
int rowPosition = rowIdAccessor.getRowIds().indexOf(selectedRow);
if (rowPosition > -1) {
selectedRowPositions[i++] = rowPosition;
}
}
return selectedRowPositions;
} finally {
selectionsLock.readLock().unlock();
}
}
use of java.io.Serializable in project translationstudio8 by heartsome.
the class VerticalRowSelectionModel method removeSelection.
public void removeSelection(int columnPosition, int rowPosition) {
selectionsLock.writeLock().lock();
try {
Serializable rowId = getRowIdByPosition(rowPosition);
selectedRows.remove(rowId);
} finally {
selectionsLock.writeLock().unlock();
}
}
use of java.io.Serializable in project translationstudio8 by heartsome.
the class VerticalRowSelectionModel method addSelection.
@SuppressWarnings("unchecked")
public void addSelection(Rectangle range) {
selectionsLock.writeLock().lock();
try {
if (range == lastSelectedRange) {
// Unselect all previously selected rowIds
if (lastSelectedRowIds != null) {
for (Serializable rowId : lastSelectedRowIds) {
selectedRows.remove(rowId);
}
}
}
int rowPosition = range.y / VerticalNatTableConfig.ROW_SPAN;
int end = (int) Math.ceil((range.y + range.height) * 1.0 / VerticalNatTableConfig.ROW_SPAN);
int length = end - range.y / VerticalNatTableConfig.ROW_SPAN;
Set<Serializable> rowsToSelect = (Set<Serializable>) rowIdAccessor.getRowIdsByPositionRange(rowPosition, length);
selectedRows.addAll(rowsToSelect);
if (range == lastSelectedRange) {
lastSelectedRowIds = rowsToSelect;
} else {
lastSelectedRowIds = null;
}
lastSelectedRange = range;
} finally {
selectionsLock.writeLock().unlock();
}
}
use of java.io.Serializable in project hazelcast by hazelcast.
the class SerializationTest method testGlobalSerializer_withOverrideJavaSerializable.
@Test
public void testGlobalSerializer_withOverrideJavaSerializable() {
GlobalSerializerConfig globalSerializerConfig = new GlobalSerializerConfig();
globalSerializerConfig.setOverrideJavaSerialization(true);
final AtomicInteger writeCounter = new AtomicInteger();
final AtomicInteger readCounter = new AtomicInteger();
final JavaSerializer javaSerializer = new JavaSerializer(true, false);
SerializationConfig serializationConfig = new SerializationConfig().setGlobalSerializerConfig(globalSerializerConfig.setImplementation(new StreamSerializer<Object>() {
@Override
public void write(ObjectDataOutput out, Object v) throws IOException {
writeCounter.incrementAndGet();
if (v instanceof Serializable) {
out.writeBoolean(true);
javaSerializer.write(out, v);
} else if (v instanceof DummyValue) {
out.writeBoolean(false);
out.writeUTF(((DummyValue) v).s);
out.writeInt(((DummyValue) v).k);
}
}
@Override
public Object read(ObjectDataInput in) throws IOException {
readCounter.incrementAndGet();
boolean java = in.readBoolean();
if (java) {
return javaSerializer.read(in);
}
return new DummyValue(in.readUTF(), in.readInt());
}
public int getTypeId() {
return 123;
}
public void destroy() {
}
}));
SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
DummyValue value = new DummyValue("test", 111);
Data data1 = ss1.toData(value);
Data data2 = ss1.toData(new Foo());
Assert.assertNotNull(data1);
Assert.assertNotNull(data2);
assertEquals(2, writeCounter.get());
SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
Object o1 = ss2.toObject(data1);
Object o2 = ss2.toObject(data2);
Assert.assertEquals(value, o1);
Assert.assertNotNull(o2);
assertEquals(2, readCounter.get());
}
Aggregations