Search in sources :

Example 1 with Filter

use of com.tangosol.util.Filter in project teiid by teiid.

the class TestCoherenceConnection method xtestEqualOnContainerObject.

/**
 * this test will not work out-of-the-box.  Coherence, from what I've found, doen'st support this, but can be developed.
 * @throws Exception
 */
@Test
public void xtestEqualOnContainerObject() throws Exception {
    CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
    f.setCacheName(CACHE_NAME);
    f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
    CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
    long l = 1;
    // NOTE:  Coherence, because the datatype of ID is long, wants the "l" appended to the value
    // Filter criteria = CoherenceFilterUtil.createFilter("Id = 1l");
    Filter criteria = CoherenceFilterUtil.createCompareFilter("getLegs.getLegId", l, Comparison.Operator.EQ, Long.class);
    List<?> trades = conn.get(criteria);
    assertNotNull(trades);
    assertEquals("Did not get expected number of trades", 1, trades.size());
}
Also used : Filter(com.tangosol.util.Filter) CoherenceManagedConnectionFactory(org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory) CoherenceConnection(org.teiid.resource.adapter.coherence.CoherenceConnection) Test(org.junit.Test)

Example 2 with Filter

use of com.tangosol.util.Filter in project teiid by teiid.

the class TestCoherenceConnection method testLike.

@Test
public void testLike() throws Exception {
    CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
    f.setCacheName(CACHE_NAME);
    f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
    CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
    Filter criteria = CoherenceFilterUtil.createFilter("Name like 'Name%'");
    List<?> trades = conn.get(criteria);
    assertNotNull(trades);
    assertEquals("Did not get expected number of trades", 3, trades.size());
}
Also used : Filter(com.tangosol.util.Filter) CoherenceManagedConnectionFactory(org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory) CoherenceConnection(org.teiid.resource.adapter.coherence.CoherenceConnection) Test(org.junit.Test)

Example 3 with Filter

use of com.tangosol.util.Filter in project teiid by teiid.

the class TestCoherenceConnection method testAddAndRemoveTrade.

@Test
public void testAddAndRemoveTrade() throws Exception {
    CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
    f.setCacheName(CACHE_NAME);
    f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
    CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
    Trade trade = new Trade();
    trade.setId(999);
    trade.setName("NameIs " + 999);
    trade.setLegs(null);
    conn.add(999l, trade);
    // NOTE:  Coherence, because the datatype of ID is long, wants the "l" appended to the value
    Filter criteria = CoherenceFilterUtil.createFilter("Id = 999l");
    List<?> trades = conn.get(criteria);
    assertNotNull(trades);
    assertEquals("Did not get expected 999 trade", 1, trades.size());
    long l = 999l;
    criteria = CoherenceFilterUtil.createCompareFilter("Id", l, Comparison.Operator.EQ, Long.class);
    trades = conn.get(CoherenceFilterUtil.createFilter("Id = 999l"));
    assertNotNull(trades);
    assertEquals("Did not get expected 999 trade", 1, trades.size());
    conn.remove(l);
    trades = conn.get(CoherenceFilterUtil.createFilter("Id = 999l"));
    assertNotNull(trades);
    assertEquals("Expected no trade", 0, trades.size());
}
Also used : Filter(com.tangosol.util.Filter) CoherenceManagedConnectionFactory(org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory) CoherenceConnection(org.teiid.resource.adapter.coherence.CoherenceConnection) Test(org.junit.Test)

Example 4 with Filter

use of com.tangosol.util.Filter in project teiid by teiid.

the class TestCoherenceConnection method testGet1Trade.

/**
 * This will instantiate the {@link CoherenceManagedConnectionFactory} and
 * obtain a connection to
 *
 * @throws Exception
 */
@Test
public void testGet1Trade() throws Exception {
    CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
    f.setCacheName(CACHE_NAME);
    f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
    CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
    List<Object> ids = new ArrayList<Object>();
    ids.add(new Long(1));
    Filter criteria = CoherenceFilterUtil.createInFilter("id", ids, Long.class);
    List<?> trades = conn.get(criteria);
    assertNotNull(trades);
    assertEquals("Did not get expected number of trades", 1, trades.size());
    // grab the first trade to confirm trade 1 was found in the cache.
    Trade t = (Trade) trades.get(0);
    Map legs = t.getLegs();
    assertEquals("Did not get expected number of legs", NUMLEGS, legs.size());
}
Also used : Filter(com.tangosol.util.Filter) ArrayList(java.util.ArrayList) CoherenceManagedConnectionFactory(org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory) Map(java.util.Map) HashMap(java.util.HashMap) CoherenceConnection(org.teiid.resource.adapter.coherence.CoherenceConnection) Test(org.junit.Test)

Example 5 with Filter

use of com.tangosol.util.Filter in project teiid by teiid.

the class TestCoherenceConnection method testEqualOnTrade.

@Test
public void testEqualOnTrade() throws Exception {
    CoherenceManagedConnectionFactory f = new CoherenceManagedConnectionFactory();
    f.setCacheName(CACHE_NAME);
    f.setCacheTranslatorClassName(OBJECT_TRANSLATOR);
    CoherenceConnection conn = (CoherenceConnection) f.createConnectionFactory().getConnection();
    // NOTE:  Coherence, because the datatype of ID is long, wants the "l" appended to the value
    Filter criteria = CoherenceFilterUtil.createFilter("Id = 1l");
    List<?> trades = conn.get(criteria);
    assertNotNull(trades);
    assertEquals("Did not get expected number of trades", 1, trades.size());
    long l = 1;
    criteria = CoherenceFilterUtil.createCompareFilter("Id", l, Comparison.Operator.EQ, Long.class);
    trades = conn.get(criteria);
    assertNotNull(trades);
    assertEquals("Did not get expected number of trades", 1, trades.size());
}
Also used : Filter(com.tangosol.util.Filter) CoherenceManagedConnectionFactory(org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory) CoherenceConnection(org.teiid.resource.adapter.coherence.CoherenceConnection) Test(org.junit.Test)

Aggregations

Filter (com.tangosol.util.Filter)6 Test (org.junit.Test)6 CoherenceConnection (org.teiid.resource.adapter.coherence.CoherenceConnection)6 CoherenceManagedConnectionFactory (org.teiid.resource.adapter.coherence.CoherenceManagedConnectionFactory)6 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1