QueryModel in WTableView: Please, an example of how to add a row and fill it with new record just created - c++

I've made a table:
class TableTag
{
public:
std::string name;
//Wt::Dbo::collection< Wt::Dbo::ptr<TablePost> > tablePosts;
TableTag();
~TableTag();
static void initTableRecords(Wt::Dbo::Session &_session);
template<class Action>
void persist(Action &_action)
{
Wt::Dbo::field(_action, name, "Name");
}
};
typedef Wt::Dbo::collection< Wt::Dbo::ptr<TableTag> > TableTags;
I create a Model and add it to a WTableView:
qModelTags_ = new Wt::Dbo::QueryModel< Wt::Dbo::ptr<TableTag> >();
qModelTags_->setQuery(ddbbSession_->find<TableTag>());
qModelTags_->addAllFieldsAsColumns();
//WtableView
ctrGridTags_ = new WTableView(this);
ctrGridTags_->setModel(qModelTags_); //qmTags1
ctrGridTags_->setSelectionMode(Wt::SelectionMode::SingleSelection);
root()->addWidget(ctrGridTags_);
This works OK. Now, I want to insert a record in the table:
{
Wt::Dbo::Transaction transaction(*ddbbSession_);
Wt::Dbo::ptr<TableTag> tag = ddbbSession_->add(new TableTag());
tag.modify()->name = "Example";
}
and refresh the view:
qModelTags_->reload();
This works, but I feel that if I have a table with 100.000 records and 100 fields, It's not acceptable to reload all records and fields in order to show a only one new record. I think I should use something like:
int rowNo = qModelTags_->rowCount();
qModelTags_->insertRow(rowNo);
qModelTags_->setItemData(...)
qModelTags_->setData(...)
But I can't figure how. I've googled, I've looked into examples, forums... but I found no example! Can anyone help me with a simple example?
Thanks in advance...

Koen Deforche (the Wt framework's creator) replied me in the Wt forum, and pointed me to the right path (thanks, Koen!!). I think I should share the answer for all you, so here I go:
I infer that, given a QueryModel associated to a WTableView, there are two ways to insert records and refresh the table and underlying query:
1.- Insert records directly in database and reload the entire QueryModel:
{
//Insert one or more records...
Wt::Dbo::Transaction transaction(*ddbbSession_);
Wt::Dbo::ptr<TableTag> tag = ddbbSession_->add(new TableTag());
tag.modify()->name = "Example";
}
qModelTags_->reload();
2.- Insert records indirectly one by one via the QueryModel, wich will autorefresh the WTableView:
int rowNo = qModelTags_->rowCount();
qModelTags_->insertRow(rowNo);
qModelTags_->setData(rowNo, 1, newTagName.narrow());
ctrGridTags_->select(qModelTags_->index(rowNo, 0));

Related

emr-dynamodb-connector don't save if primary key is present in dynamodb

We are using Spark job with emr-dynamodb-connector to load the data from S3 files into Dyanamodb.
https://github.com/awslabs/emr-dynamodb-connector
But if document is already present in dynamodb, my code is replacing it.
Is there a way to avoid updating existing records (based on id) if they are present in Dynamodb. If id is present in dynamodb, i simply don't want to update it, just skip that id and write rest of records. Code i am using is
JobConf ddbConf = new JobConf(spark.sparkContext().hadoopConfiguration());
ddbConf.set("dynamodb.output.tableName", tableName);
ddbConf.set("dynamodb.throughput.write.percent", "50");
ddbConf.set("mapred.input.format.class", "org.apache.hadoop.dynamodb.read.DynamoDBInputFormat");
ddbConf.set("mapred.output.format.class", "org.apache.hadoop.dynamodb.write.DynamoDBOutputFormat");
JavaPairRDD<Text, DynamoDBItemWritable> ddbInsertFormattedRDD = finalDatasetToBeSaved.toJavaRDD().mapToPair(new PairFunction<Row, Text, DynamoDBItemWritable>() {
#Override
public Tuple2<Text, DynamoDBItemWritable> call(Row row) throws Exception {
Map<String, AttributeValue> ddbMap = new HashMap<String, AttributeValue>();
for (int i = 0 ; i <= schemaDdb.length - 1; i++) {
Object value = row.get(i);
if (value != null) {
AttributeValue att = new AttributeValue();
if(schemaDdb[i]._2.toString().equalsIgnoreCase("IntegerType")){
att.setN(value.toString());
}else{
att.setS(value.toString());
}
ddbMap.put((String)schemaDdb[i]._1, att);
}
}
DynamoDBItemWritable item = new DynamoDBItemWritable();
item.setItem(ddbMap);
return new Tuple2<Text, DynamoDBItemWritable>(new Text(""), item);
}
});
ddbInsertFormattedRDD.saveAsHadoopDataset(ddbConf);
By saying Is there a way to avoid updating existing records (based on id) if they are already present, Do you want to add another document instead of replacing/updating it?
If yes, I am afraid it wont be possible with primary key, since that should be unique and distinguishes it from other. You need to make a key non-primary in order to do this.
If you want to ignore the insertion (if item exists), you can use condition-expression attribute_not_exists(your-key) as defined in the documentation

Acumatica GI - Inventory Transaction History Screen

I want to create a GI for Inventory Transaction History Screen (IN405000).
Since the table InventoryTranHistEnqResult isn't present in the database...few of the columns of this screen are taken from INTran Table.
I am not able to find following columns: BegQty, QtyIn, QtyOut, EndQty...
I also tried the following query on database to find these columns
SELECT c.name AS ColName, t.name AS TableName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%EndQty%'
The DAC for these fields is:
enter image description here
Looking at the information behind the page in the page Graph will give you the answers to your question. Inventory Transaction History Screen (IN405000) uses graph InventoryTranHistEnq. The grid in this page uses DAC InventoryTranHistEnqResult in the following view:
PXSelectJoin<InventoryTranHistEnqResult,
CrossJoin<INTran>,
Where<True, Equal<True>>,
OrderBy<Asc<InventoryTranHistEnqResult.gridLineNbr>>> ResultRecords
The ResultsRecords are built dynamically in the inquiry using the following:
protected virtual IEnumerable resultRecords()
{
int startRow = PXView.StartRow;
int totalRows = 0;
decimal? beginQty = null;
List<object> list = InternalResultRecords.View.Select(PXView.Currents, PXView.Parameters, new object[PXView.SortColumns.Length], PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);
PXView.StartRow = 0;
foreach (PXResult<InventoryTranHistEnqResult> item in list)
{
InventoryTranHistEnqResult it = (InventoryTranHistEnqResult)item;
it.BegQty = beginQty = (beginQty ?? it.BegQty);
decimal? QtyIn = it.QtyIn;
decimal? QtyOut = it.QtyOut;
beginQty += (QtyIn ?? 0m) - (QtyOut ?? 0m);
it.EndQty = beginQty;
}
return list;
}
So i guess the short answer is you cannot use the results of this page for a GI as it is built in the page only. You might want to look into adding what you need to this history page via a customization or make your own version of this page/graph/dac if the information you need is that important.

Sitecore 8 search against index for pages giving a specific tag

I'm working on upgrading from 8.1 to 8.2 update 3. I understand that the search/indexing was changed and some code is obsolete or no longer works.
Unfortunately in one of our class projects there were some methods our sitecore partners had built for us that are no longer working due to obsolete code and now I need help updating that code. I've been able to narrow it down to just 2 files, with some simple code.
Here is the first set of code:
public partial class TagResults
{
/// <summary>
/// Searches against the Lucene index for pages given a specific tag
/// </summary>
/// <returns></returns>
public List<BasePage> GetPagesForTag(string Tag, int page, int pageSize, out int totalCount)
{
var tags = new List<BasePage>();
Index searchIndex = SearchManager.GetIndex(Constants.LuceneIndexes.Tags);
using (IndexSearchContext context = searchIndex.CreateSearchContext())
{
//The wildcard search allows us to pull back all items with the given tag
var query = new WildcardQuery(new Term(Constants.LuceneFields.Tags, Tag));
SearchHits hits = context.Search(query);
totalCount = hits.Length;
//Go through the results
SearchResultCollection results = hits.FetchResults(page * pageSize, pageSize);
foreach (SearchResult result in results)
{
var searchItem = result.GetObject<Item>();
Item currentDbItem = ItemUtility.GetItem(searchItem.ID);
//Store the item if it exists and is a descendant of the news listing
if (currentDbItem != null)
{
tags.Add(new BasePage(currentDbItem));
}
}
}
return tags.ToList();
}
public static bool IsItemCastable(Item sitecoreItem)
{
return sitecoreItem != null && !string.IsNullOrEmpty(sitecoreItem[FieldIds.IsTagResultsComponent]);
}
}
I think I have some of this changed correctly:
ISearchIndex searchIndex = ContentSearchManager.GetIndex(Constants.LuceneIndexes.tags);
using (IProviderSearchContext context = searchIndex.CreateSearchContent())
But then I get stuck on
SearchHits hits = context.Search(query);
totalCount = hits.Length;
//Go through the results
SearchResultCollection results = hits.FetchResults(page * pageSize, pageSize);
foreach (SearchResult result in results)
Now I'm asking a lot but I am learning. If someone could help me correct this, I would be really appreciative. I've been doing a lot of searching to try to figure out how to correct this but I feel like I'm missing something and I just need some help.
Thank you in advance.

Can't edit data in TADOTable

I made ​​the connection between C++Builder with access
like this: ADOConnection> ADOTable> DataSource> DBGrid
I want to change the value of the current difficulties in this way ADOTable
void __fastcall TForm1::DBGrid1CellClick(TColumn *Column) {
int a, b;
a = ADOTable1->FieldByName("Value1")->AsInteger;
b = ADOTable1->FieldByName("Value2")->AsInteger;
ADOTable1->FieldByName("Total")->AsInteger = a + b;
}
When I run the above command directly in case of error.
I hope you understand what I say. because I do not speak English
Before setting field value you need to go into Insert, Append or Edit state:
ADOTable1->Edit(); // edit the current record
ADOTable1->FieldByName("Total")->AsInteger = a + b;
ADOTable1->Post(); // save changes

DBGrid order by calculated field

My question is: How can I order a DBGrid by a calculated field. I am using the C++Builder Starter Editon and do not have a ClientDataSet available in this version to create an Index on the field and order by the index of a column.So this is not an option. (Read this in many threads) I am using an TIBDataSet (ibds below) and I am filtering the data. Works fine....for the DB-columns, not for the calculated ones... Any ideas of how I might get around this problem?
void __fastcall TForm1::DBGrid3TitleClick(TColumn *Column)
{
static cIdx = 0;
static String oby = "ASC";
TBookmark CurrentPosition;
TIBDataSet *ibds = IBDS_accountsDist;
CurrentPosition = ibds->GetBookmark();
if (cIdx != Column->Index) {
oby = "ASC"; // ANOTHER column choosen
} else if (oby == "ASC") {
oby = "DESC";
} else oby = "ASC";
cIdx = Column->Index;
ibds->Filtered = false;
switch (Column->Index){
case 0: ibds->Filter = "ORDER BY SumAj "+oby; break; // SumAj is a calculated field => Does not work
case 1: ibds->Filter = "ORDER BY CSAL_ACCOUNTNAME "+ oby; break; // DB-field WORKS FINE
}
ibds->Filtered = true;
ibds->GotoBookmark(CurrentPosition);
}
You cannot do it. TIBDataSet is a representation of the underlying database. Basically it fetches the records in the order defined in the SQL.
The easiest way is to use TDBClientDataset but it is not included in Starter version of c++ Builder. You can explore other ways, for example pre-loading all records in a std::list and then use the order function to order the records. Finally you can show them using a simple TGrid o TStringGrid.
In any case, I recommend to upgrade C++Builder since TClientDataSet is one of the main pieces in most of data projects, specially when you need to create medium-large projects.
Mixing database specific components like TIBDataSet with the user interface penalizes the scalability and maintenance of the project.