Is it possible to reload the view listing programmatically?
I am creating a view and then running some code to work with said view. The program sees that the view exists, but can’t pull any information from it until I physically go into the view listing in designer and hit F9.
Is there any way to get around that, or even do it programmatically? Obviously this is not something a user could do.
Subject: anyone?
Anyone have any tips at all on this?
Subject: Need more information
For instance, if you could show your code. If you’re not sure what other information to supply, the C R I S P Y document might help you.
Are you sure you really need to create a view here, by the way? There are easier and faster ways to retrieve a sorted selection of documents, if that’s what you’re after.
- Andre Guirard, IBM/Lotus Development
Useful blog: Best Practice Makes Perfect
Subject: more info
The code isn’t really the problem. The issue is that I’m facing is that I’m creating a view via Java code and then referencing the view. It can grab the column, but the column data is null until I manually go into designer and refresh the views.
What I’m attempting to do is create my own dynamic reporting. The user selects a field from the database they’re working on, enters criteria for the field and some other options, and it exports it to excel.
The code 99% works except for the view part. Again, if I go into designer and select views and click f9, and then run the export agent, it works perfectly. If I run the agent without doing refreshing, it returns null.
The reason I chose a view is because it is the quickest way to select only a few of the thousands of records in the database and the only other way I knew of creating a proper document list was iterating through every document in the database searching for the proper criteria. That would take ages and would only get longer as the years go on.
If there is another way to build the collection quickly, I am all for it, but I was unable to find something that could match the speed of a view selection formula.
Hopefully this is enough information for someone to give at least some insight into my problem.
Subject: There are several ways to search for documents…
…described here: Performance basics for developers (whitepaper)
I’m not sure exactly what you’re comparing creating a view to in terms of performance. Certainly it’s faster than iterating through all the documents in a loop in your code, if that’s what you mean. But there’s a Database.search method, where the iteration occurs in the fast C code. By the way, how do you think the view indexer figures out which documents belong in the view? It has to iterate, too. Plus, it has to execute column formulas and sort and write all that view index data to disk. Then when you want to retrieve the data you have to read the index from disk and transmit it over the network. I really think it’s more efficient to work with collections in memory. Server’s disks tend to be very busy, so if you can work with data in memory instead, you’ll get better performance overall – not just for whatever search you’re doing.
Please note also that if you have a full-text index in your application, you can do searches without iterating through all the documents. As mentioned in the performance whitepaper, which is better performing depends in part on how many documents you expect to retrieve.
Or you can take advantage of an existing view index to retrieve documents by key.
Also, of course, creating a view at runtime requires Designer access to the application, which is more access than it’s safe to give end-users as a general rule.
If you insist on creating a view on the fly, perhaps what you need is the refresh method. But without seeing your code it’s hard to say what else you might be doing wrong. As a rule, if you ask questions here, if your code doesn’t do what you want or expect, your code is relevant to getting the question answered. We can’t take your word for it that “the code is not really the problem,” especially when we who answer questions here have found through experience that in the vast majority of cases, the code is precisely the problem. Everybody assumes their code is perfect and it’s the product that’s at fault, and really, that is the wrong assumption to start with.
Subject: method
I don’t see how the code could be the problem since it works as intended when I refresh the view, but here is a test script I’ve been using to attempt to get the values in a particular column.
boolean createView(Vector columnFormula){
try{
View view = db.createView(this.getReportName().replace(" ",""), this.getSelectionCriteria());
//remove the first column in the view
view.removeColumn(1);
//add the appropriate columns to the view
for(int i = 0; i < columnFormula.size();i++){
view.createColumn((i + 1),"",columnFormula.elementAt(i));
}//end for
//Agent refreshViews = db.getAgent("(refreshViews)");
//refreshViews.run();
System.out.println("No idea: " + view.getColumnValues(1).toString());
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}//end try/catch
}//end createView
I will definitely look through the whitepaper though. The view was simply to get the data, all of the manipulation I do will be done in member, I had simply assumed that creating the view to get the initial data was the fastest approach.
Also note that the agent I attempted to call was calling ws.viewrebuild and ws.ViewRefresh.
As for the access being given – the agents are ran signed by the server, and are being called by an agent ran as the users, so their access is only editor and not designer.
Also, I never once believed the product was at fault, I simply asked for a method which would accomplish what I need, as I could not find one.