Tuesday, April 07, 2009

Once we put all that together, what we get is a set of very clean way of storing and querying data in Oracle Coherence.

A Coherence Linq provider now supports passing a CoherenceQueryTranslator as a parameter. I am providing a MetadataCoherenceQueryTranslator that uses getProperty method to access property originally serialized by the Generic Serializer. Here’s almost all relative .Net Code:

Person Class

[POFSerializableObject(StoreMetadata=true)]

publicclass Person// : IPortableObject

{

[POFSerializableMember(Order=0,WriteAsType=POFWriteAsTypeEnum.Int16)]

publicint ID { get; set; }

[POFSerializableMember(Order=1)]

publicstring FirstName { get; set; }

[POFSerializableMember(Order = 2)]

publicstring LastName { get; set; }

[POFSerializableMember(Order = 3)]

publicstring Address { get; set; }

[POFSerializableMember(Order = 4)]

publicstring Title { get; set; }

public Person()

{

}

}

Add object function

INamedCache cache = CacheFactory.GetCache("dist-Person");

for (int i = 0; i < 1000; i++)

{

cache.Add(i, new Person()

{

ID = i,

FirstName = string.Format("First Name {0}", i),

LastName = string.Format("LastName {0}", i),

Address = string.Format("Address {0}" , Guid.NewGuid()) ,

Title = i % 2 == 1 ? "Mr" : "Mrs"

});

}

Query using Linq Query:

CoherenceQuery<Person> coherenceData =

new CoherenceQuery<Person>(

new CoherenceQueryProvider(CacheFactory.GetCache("dist-Person"),

new MetadataCoherenceQueryTranslator()));

string likeClause = "%8";

var people = from person in coherenceData

where

(person.FirstName.Like("Test")

|| person.LastName.Like(likeClause))

&& person.Title == "Mrs"

select new { person.Title, person.ID, person.LastName };

IFilter filter = ((ICoherenceQueryable)people).Filter;

dataGridView1.DataSource = people.ToArray();

Internally, MetadataCoherenceQueryTranslator, will convert the linq query into a filter and execute the query against the Java POFGenericObject