Search in sources :

Example 1 with Gender

use of org.apache.ignite.cache.store.jdbc.model.Gender in project ignite by apache.

the class CacheJdbcPojoStoreAbstractSelfTest method checkPutRemove.

/**
     * Check put in cache and store it in db.
     *
     * @throws Exception If failed.
     */
private void checkPutRemove() throws Exception {
    boolean binaryMarshaller = marshaller() instanceof BinaryMarshaller || marshaller() == null;
    IgniteCache<Object, Person> c1 = grid().cache(CACHE_NAME);
    Connection conn = getConnection();
    try {
        PreparedStatement stmt = conn.prepareStatement("SELECT ID, ORG_ID, BIRTHDAY, NAME, GENDER FROM PERSON WHERE ID = ?");
        stmt.setInt(1, -1);
        ResultSet rs = stmt.executeQuery();
        assertFalse("Unexpected non empty result set", rs.next());
        U.closeQuiet(rs);
        Date testDate = Date.valueOf("2001-05-05");
        Gender testGender = Gender.random();
        Person val = new Person(-1, -2, testDate, "Person-to-test-put-insert", 999, testGender);
        Object key = builtinKeys ? Integer.valueOf(-1) : new PersonKey(-1);
        // Test put-insert.
        c1.put(key, val);
        rs = stmt.executeQuery();
        assertTrue("Unexpected empty result set", rs.next());
        assertEquals(-1, rs.getInt(1));
        assertEquals(-2, rs.getInt(2));
        assertEquals(testDate, rs.getDate(3));
        assertEquals("Person-to-test-put-insert", rs.getString(4));
        assertEquals(testGender.toString(), binaryMarshaller ? Gender.values()[rs.getInt(5)].toString() : rs.getString(5));
        assertFalse("Unexpected more data in result set", rs.next());
        U.closeQuiet(rs);
        // Test put-update.
        testDate = Date.valueOf("2016-04-04");
        c1.put(key, new Person(-1, -3, testDate, "Person-to-test-put-update", 999, testGender));
        rs = stmt.executeQuery();
        assertTrue("Unexpected empty result set", rs.next());
        assertEquals(-1, rs.getInt(1));
        assertEquals(-3, rs.getInt(2));
        assertEquals(testDate, rs.getDate(3));
        assertEquals("Person-to-test-put-update", rs.getString(4));
        assertEquals(testGender.toString(), binaryMarshaller ? Gender.values()[rs.getInt(5)].toString() : rs.getString(5));
        assertFalse("Unexpected more data in result set", rs.next());
        // Test remove.
        c1.remove(key);
        rs = stmt.executeQuery();
        assertFalse("Unexpected non-empty result set", rs.next());
        U.closeQuiet(rs);
    } finally {
        U.closeQuiet(conn);
    }
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) PersonKey(org.apache.ignite.cache.store.jdbc.model.PersonKey) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Gender(org.apache.ignite.cache.store.jdbc.model.Gender) Person(org.apache.ignite.cache.store.jdbc.model.Person) Date(java.sql.Date)

Aggregations

Connection (java.sql.Connection)1 Date (java.sql.Date)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Gender (org.apache.ignite.cache.store.jdbc.model.Gender)1 Person (org.apache.ignite.cache.store.jdbc.model.Person)1 PersonKey (org.apache.ignite.cache.store.jdbc.model.PersonKey)1 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)1