Search in sources :

Example 61 with Serializable

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());
}
Also used : Serializable(java.io.Serializable) Session(org.hibernate.Session) Test(org.junit.Test)

Example 62 with Serializable

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();
    }
}
Also used : Serializable(java.io.Serializable)

Example 63 with Serializable

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();
    }
}
Also used : Serializable(java.io.Serializable)

Example 64 with Serializable

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();
    }
}
Also used : Serializable(java.io.Serializable) HashSet(java.util.HashSet) Set(java.util.Set)

Example 65 with Serializable

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());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) Serializable(java.io.Serializable) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) JavaSerializer(com.hazelcast.internal.serialization.impl.JavaDefaultSerializers.JavaSerializer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Serializable (java.io.Serializable)1280 Test (org.junit.Test)334 HashMap (java.util.HashMap)265 ArrayList (java.util.ArrayList)215 Map (java.util.Map)127 List (java.util.List)94 Metacard (ddf.catalog.data.Metacard)89 IOException (java.io.IOException)89 HashSet (java.util.HashSet)70 Session (org.hibernate.Session)63 Task (org.apache.hadoop.hive.ql.exec.Task)57 ByteArrayInputStream (java.io.ByteArrayInputStream)50 Set (java.util.Set)50 ObjectInputStream (java.io.ObjectInputStream)43 Date (java.util.Date)41 LinkedHashMap (java.util.LinkedHashMap)40 EntityPersister (org.hibernate.persister.entity.EntityPersister)34 File (java.io.File)33 Iterator (java.util.Iterator)33 URI (java.net.URI)32