Get back total number of rows from Silverlight RIA DomainService, not any other data - wcf-ria-services

I would like to make continuous calls to the DATABASE to get current row count of a TABLE in every 5 mins. Users using my application are expected to be huge and they will be making calls to DB and I need row count to be able to do some custom stuff.
public IQueryable<CPOQC_Errorlog> GetCPOQC_Errorlog()
{
return this.ObjectContext.CPOQC_Errorlog;
}
I do not wish to load all the data from the server as it will put pressure on the server and may result in slow performance. Could there be something like:
public int GetCPOQC_Errorlog()
{
return this.ObjectContext.CPOQC_Errorlog.Count();
}

you can write a stored procedure which returns only the number of rows from the table and call this stored procedure from service.

I have written a below function in my Domain Service class
public int GetCPOQC_ErrorlogCount()
{
return this.ObjectContext.CPOQC_Errorlog.Count();
}
which I invoke from my Silverlight project to get the current row count
dataContext.Load(GetCPOQC_ErrorlogCount()).Completed += new EventHandler(errorLogCount_Completed);
void errorLogCount_Completed(object sender, EventArgs e)
{
int errorLogRowCount = ((InvokeOperation<int>)sender).Value;
}

Related

How to set values in ItemPreparedStatementSetter for one to many mapping

I am trying to use JdbcBatchItemWriter for a domain object RemittanceClaimVO . RemittanceClaimVO has a List of another domain object , ClaimVO .
public class RemittanceClaimVO {
private long remitId;
private List<ClaimVO> claims = new ArrayList<ClaimVO>();
//setter and getters
}
So for each remit id, there would be multiple claims and I wish to use single batch statement to insert all rows.
With plain jdbc, I used to write this object by putting values in batches like below ,
ist<ClaimVO> claims = remittanceClaimVO.getClaims();
if(claims != null && !claims.isEmpty()){
for(ClaimVO claim:claims){
int counter = 1 ;
stmt.setLong(counter++, remittanceClaimVO.getRemitId());
stmt.setLong(counter++, claim.getClaimId());
stmt.addBatch();
}
}
stmt.executeBatch();
I am not sure how to achieve same in Spring Batch by using ItemPreparedStatementSetter.
I have tried similar loop as above in setValues method but values not getting set.
#Override
public void setValues(RemittanceClaimVO remittanceClaimVO, PreparedStatement ps) throws SQLException {
List<ClaimVO> claims = remittanceClaimVO.getClaims();
for(ClaimVO claim:claims){
int counter = 1 ;
ps.setLong(counter++, remittanceClaimVO.getRemitId());
ps.setLong(counter++, claim.getClaimId());
}
}
This seems another related question.
Please suggest.

cassandra trigger create vs update

I need to implement a cassandra trigger in java that will take a different action for INSERT vs UPDATE operations.
I've seen how it is possible to identify a DELETE operation in the question Cassandra sample trigger to get the deleted row and column values but I can't see any methods in the ColumnFamily object that would allow allow the code to differentiate between INSERT vs UPDATE, is there a way to achieve this?
There isn't conceptually any difference between INSERT and UPDATE. Indeed an INSERT and an UPDATE are just mutation. Cassandra gives them different name so that people coming from the relational DB have familiar concepts
As #doanduyhai mentioned and according to Casssandra sources only INSERT operation updates row timestamp (LivenessInfo).
For other operations this timestamp is not updated and equals Long.MIN_VALUE.
Custom Trigger which checks for INSERT operation
public class CustomTrigger implements ITrigger {
#Override
public Collection<Mutation> augment(Partition partition) {
checkQueryType(partition));
return Collections.emptyList();
}
private void checkQueryType(Partition partition) {
UnfilteredRowIterator it = partition.unfilteredIterator();
while (it.hasNext()) {
Unfiltered unfiltered = it.next();
Row row = (Row) unfiltered;
if (isInsert(row)) {
// Implement insert related logic
}
}
}
private boolean isInsert(Row row) {
return row.primaryKeyLivenessInfo().timestamp() != Long.MIN_VALUE;
}
}

How to get outArgument WorkflowApplication when wf wait for response(bookmark OR idle) and not complete

Accessing Out Arguments with WorkflowApplication when wf wait for response(bookmark OR idle) and not complete
I also used Tracking to retrieve the values, but instead of saving it to a database I come up with the following solution.
Make a Trackingparticipant and collect the data from an activity.
You can fine tune the tracking participant profile with a spefic tracking query.
I have added a public property Output to set the value of the data from the record.
public class CustomTrackingParticipant : TrackingParticipant
{
//TODO: Fine tune the profile with the correct query.
public IDictionary<String, object> Outputs { get; set; }
protected override void Track(TrackingRecord record, TimeSpan timeout)
{
if (record != null)
{
if (record is CustomTrackingRecord)
{
var customTrackingRecord = record as CustomTrackingRecord;
Outputs = customTrackingRecord.Data;
}
}
}
}
In your custom activity you can set the values you want to expose for tracking with a CustomTrackingRecord.
Here is a sample to give you an idea.
protected override void Execute(NativeActivityContext context)
{
var customRecord = new CustomTrackingRecord("QuestionActivityRecord");
customRecord.Data.Add("Question", Question.Get(context));
customRecord.Data.Add("Answers", Answers.Get(context).ToList());
context.Track(customRecord);
//This will create a bookmark with the display name and the workflow will go idle.
context.CreateBookmark(DisplayName, Callback, BookmarkOptions.None);
}
On the WorklfowApplication instance you can add the Tracking participant to the extensions.
workflowApplication.Extensions.Add(new CustomTrackingParticipant());
On the persistable idle event from the workflowApplication instance I subscribed with the following method.
In the method I get the tracking participant from the extensions.
Because we have set the outputs in the public property we can access them and set them in a member outside the workflow. See the following example.
private PersistableIdleAction PersistableIdle(WorkflowApplicationIdleEventArgs
workflowApplicationIdleEventArgs)
{
var ex = workflowApplicationIdleEventArgs.GetInstanceExtensions<CustomTrackingParticipant>();
Outputs = ex.First().Outputs;
return PersistableIdleAction.Unload;
}
I hope this example helped.
Even simpler: Use another workflow activity to store the value you are looking for somewhere (database, file, ...) before starting to wait for a response!
You could use Tracking.
required steps would be:
define a tracking profile which queries ActivityStates with the state closed
Implement an TrackingParticipant to save the OutArgument in process memory, a database or a file on disk
hook everything together
The link cotains all the information you will need to do this.

Invoke operation in wcf ria services not able to include foriegn key tables

Hi.
I m using a Invoke Operation which return a class "Product"
public Product GetProductById(int Id)
{
Product Record = this.ObjectContext.Product.Include("Order_Detail").Where(d=>d.ProductID=Id).FirstOrDefault()
return Record;
}
But i m not able to get Order_Detail in the the completed event of the class
InvokeOperation<Product> Invk = ObjProduct.GetProductById();
Invk.Completed += (sender, e) =>
{
if (!Invk.HasError)
{
Product ObjProduct = Invk.Value;
Order objorder=ObjProduct.Order_Detail;
}
};
i m getting ObjProduct.Order_Detail as Null i not known why i m not able to include Order_Detail in this Product entity
I have written [Include] in metadata as well
[Include]
public Order Order { get; set; }
But Still i m not able to get Order_Detail In the collection.
Waiting for a positive response.
This is the expected behavior. Invokes are meant to execute an operation on the server or retrieve a simple object. As you can see, the InvokeOperation callback don't contains the usual Entities/AllEntities properties that make room for Included Entities. I suggest you to use a standard load operation with a parameter to get your data.
public IQueryable<Product> GetProductById(int Id)
{
return this.ObjectContext.Product.Include("Order_Detail").Where(d=>d.ProductID=Id);
}
If what you're trying to achieve is "Non Accumulating Execution" (i.e. don't load your domainContext's entityContainer with the result of the query) than have a look at this post from Mathew Charles

Use external datasource with NUnit's TestCaseAttribute

Is it possible to get the values for a TestCaseAttribute from an external data source such as an Excel Spreadsheet, CSV file or Database? i.e. Have a .csv file with 1 row of data per test case and pass that data to NUnit one at a time.
Here's the specific situation that I'd like to use this for. I'm currently merging some features from one system into another. This is pretty much just a copy and paste process from the old system into the new one. Unfortunately, the code being moved not only does not have any tests, but is not written in a testable manner (i.e. tightly coupled with the database and other code.) Taking the time to make the code testable isn't really possible since its a big mess, i'm on a tight schedule and the entire feature is scheduled to be re-written from the ground up in the next 6-9 months. However, since I don't like the idea of not having any tests around the code, I'm going to create some simple Selenium tests using WebDriver to test the page through the UI. While this is not ideal, it's better than nothing.
The page in question has about 10 input values and about 20 values that I need to assert against after the calculations are completed, with about 30 valid combinations of values that I'd like to test. I already have the data in a spreadsheet so it'd be nice to simply be able to pull that out rather than having to re-type it all in Visual Studio.
I was finally able to accomplish what I wanted using NUnit's TestCaseSource attribute. The code looks a little ugly but it works.
Here is an example of pullind the data from a .csv file and passing it to the test method. The test is for the Add method of a simple calculator that takes two ints, adds them together and returns the sum.
Class to load the test data from the file.
public class TestData
{
public int number1 { get; set; }
public int number2 { get; set; }
public int sum { get; set; }
public static IEnumerable TestCases
{
get
{
string inputLine;
using(FileStream inputStream =
new FileStream("C:\\Code\\TestData\\TestData.csv",
FileMode.Open,
FileAccess.Read))
{
StreamReader streamReader = new StreamReader(inputStream);
while((inputLine = streamReader.ReadLine()) != null)
{
var data = inputLine.Split(',');
yield return new TestData {
number1 = Convert.ToInt32(data[0])
,number2 = Convert.ToInt32(data[1])
,sum = Convert.ToInt32(data[2])
};
}
streamReader.Close();
inputStream.Close();
}
}
}
}
Class with the actual tests:
[TestFixture]
public class CalculatorTests
{
[Test]
[TestCaseSource(typeof(TestData), "TestCases")]
public void AddTwoNumbers(TestData data)
{
int sum = Calculator.Add(data.number1, data.number2);
sum.ShouldEqual(data.sum);
}
}
Contents of TestData.csv
4,4,8
15,20,35
8,8,16
5,5,10
42,13,55
It should be fairly simple to modify the get property in the TestData class to pull data from any datasource you want (i.e. Database, Web Service, Excel...)
You could always open your csv file in excel or any spreadsheet tool and then add a new column that concatenates the input/output values into the test case syntax.
Something like: =CONCATENATE("[TestCase(", A1, ",", B1, ",", C1, ",", D1, ",", E1, ")]")
Then copy/paste the column into the code.