Linq to Coherence + Attributes + MetaData = Cool
First, we got the Linq Provider for Oracle Coherence
Second, we got attribute based serialization
Third, Metadata in the serialization stream
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
Add object function[POFSerializableObject(StoreMetadata=true)]
public class Person// : IPortableObject{[POFSerializableMember(Order=0,WriteAsType=POFWriteAsTypeEnum.Int16)]public int ID { get; set; }[POFSerializableMember(Order=1)]public string FirstName { get; set; }[POFSerializableMember(Order = 2)]public string LastName { get; set; }[POFSerializableMember(Order = 3)]public string Address { get; set; }[POFSerializableMember(Order = 4)]public string Title { get; set; }public Person()
{}}
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
No comments:
Post a Comment