Lotus Notes Java program to access $Revisions columns - java

I am very new to lotus notes and java.
I am trying to get all documents which are modified by specific time.
I can not use getallmodifieddocuments because , notes version R5.
I am trying to get it as follows:
String query = Select Form = Protocol & ( last value from $revision ) > input datetime stamp
DocumentCollection dc = db.search ( query );
Then get all documents and process them.
Is it possible.
I can not get to $revision value to get print by getitemvaluestring ( $revision )
Is query even possible to implement?
I will appreciate if any other way !

The Notes formula language has a built in formula for accessing the last modified date of a document: #Modified
Or if you have a reference to the document from Java, the getLastModified() method should get you that information.
Your query could be:
String query = "Form = ""Protocol"" & #Modified > #TextToTime(""1/1/1970"") "

Related

How to scroll to first record again using OracleDataReader class or another class?

I'm migrating a Java application to VB.Net and I try to translate following Java code
Statement stmt
= conx.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE
,ResultSet.CONCUR_READ_ONLY
);
ResultSet rsSheet = stmt.executeQuery(sSql);
bStatus = rsSheet.next();
...
bStatus = rsSheet.first();
In this code, a scrollable ResultSet is used. I can read the records returned by executeQuery() function and when I have terminated to read them, I can read it again without interrogating the Database a second time.
You can find some information on ResultSet here https://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html
My translated code is following
Dim cmd = conx.CreateCommand()
cmd.CommandText = sSql
Dim rsSheet as OracleDataReader = cmd.ExecuteReader()
bStatus = rsSheet.Read()
...
bStatus = rsSheet.? 'how to read first record again ?
But I don't find how to do so that OracleDataReader is scrollable ?
I can read the ResultSet from first to last record but I cannot read it again.
The only simple solution that I found to read all these records again is to call ExecuteReader() function a second time.
QUESTIONS
Is OracleDataReader Class scrollable ? How ?
Does another Class exist to do the job ? Which ?
PS: using Linq is not solution because SQL statements are executed in an environnement where Database structure is unknown. It is impossible to create entities.
A DataReader is one way only. Use a DataTable. This is an in memory representation of the result set. You can also use a DataTable to as a DataSource for various controls. You can use Linq on a DataTable.AsEnumerable()
Private Sub OPCode()
Dim sSql = "Your command text"
Dim dt As New DataTable
Using cn As New OracleConnection(ConStr),
cmd As New OracleCommand(sSql, cn)
cn.Open()
dt.Load(cmd.ExecuteReader)
End Using
'Code to read data.
End Sub
EDIT
The simplest way to see what is in the DataTable is to display it in a DataGridView if this is WinForms.
DataGridView1.DataSource = dt.
To access a specific row and column.
Dim s = dt.Rows(1)("ColName").ToString
The Rows collection starts with index 0 and the column name is from you Select statement. You then need to convert to the datatype with .ToString or Cint(), CDbl() etc. as this returns an object.

Get documents between a range of dates in IBM Notes

I'm going crazy with all possible query syntaxes used on IBM Notes (old Lotus) databases for searching documents.
I just need all documents (i.e. emails) created (or delivered, which seems to be the same) between a given range of dates, using lotus.domino.Database.search(query) method in Java package for IBM Notes. Consider that I already know the dates format in my system ("dd/MM/yyyy").
Which should be the query?
First of all: To find out about the syntax just create a view in Domino Designer or check the views that are there (e.g. in your own mail database) and check the "Selection"- formula. Then remove the "SELECT" statement in front of it and use that as query.
Your query would be quite simple:
Form = "Memo" : "Reply" & #Date(#Created) >= [2018/01/01] & #Date(#Created) <= [2018/05/04]
if you are not sure, which date format your server uses, then just use this query instead:
Form = "Memo" : "Reply" &
#Date(#Created) >= #Date( 2018 ; 1 ; 1 ) &
#Date(#Created) <= #Date( 2018 ; 5 ; 4 )
This is the right formula for all mail- types. If you need alle calendar- type- documents, then use Form = "Appointment" : "Notice".
As a rule of thumb: Just go to the items- tab in the properties of any document you want to return and examine all items in the left hand site. Then simply use the item name in your formula as variable (except Body: That one would need special treatment).

Java Couchbase Querying to find a document's ID?

I'm new to couchbase. I'm using Java for this. I'm trying to remove a document from a bucket by looking up its ID with query parameters(assuming the ID is unknown).
Lets say I have a bucket called test-data. In that bucked I have a document with ID of 555 and Content of {"name":"bob","num":"10"}
I want to be able to remove that document by querying using 'name' and 'num'.
So far I have this (hardcoded):
String statement = "SELECT META(`test-data`).id from `test-data` WHERE name = \"bob\" and num = \"10\"";
N1qlQuery query = N1qlQuery.simple(statement);
N1qlQueryResult result = bucket.query(query);
List<N1qlQueryRow> row = result.allRows();
N1qlQueryRow res1 = row.get(0);
System.out.println(res1);
//output: {"id":"555"}
So I'm getting a json that has the document's ID in it. What would be the best way to extract that ID so that I can then remove the queryed document from the bucket using its ID? Am I doing to many steps? Is there a better way to extract the document's ID?
bucket.remove(docID)
Ideally I'd like to use something like a N1q1QueryResult to get this going but I'm not sure how to set that up.
N1qlQueryResult result = bucket.query(select("META.id").fromCurrentBucket().where((x("num").eq("\""+num+"\"")).and(x("name").eq("\""+name+"\""))));
But that isn't working at the moment.
Any help or direction would be appreciated. Thanks.
There might be a better way which is running this kind of query:
delete from `test-data` use keys '00000874a09e749ab6f199c0622c5cb0' returning raw META(`test-data`).id
or if your fields has index:
delete from `test-data` where name='bob' and num='10' returning raw META(`test-data`).id
This query deletes the specified document with given document key (which is meta.id) and returns document id of deleted document if it deletes any document. Returns empty if no documents deleted.
You can implement this query with couchbase sdk as follows:
Statement statement = deleteFrom("test-data")
.where(x("name").eq(s("bob")).and(x("num").eq(s("10"))))
.returningRaw(meta(i("test-data")).get("id"));
You can make this statement parameterized or just execute like that.

How to do MongoDB query with JavaScript expression in Java code , like in Mongo shell

1.
I know how to query with JavaScript expression in Mongo shell
( collection name is resource_phys. field name is val which defined as String type and contains only numeric value ) :
//in Mongo shell:
var query1 = ("Number(this.val)>-1 && Number(this.val)<3")
db.resource_phys.find(query1)
//result found
2.
Now, I want to do the same thing in Java code but cannot find any API to support JavaScript. I solicit your help to give some hints.
3.P.s.
If the field val is numeric type, I am aware of using operator $gt and $lt :
//in Java codes:
DBCollection coll = db.getCollection("resource_phys");
DBObject query2 = new BasicDBObject("val",new BasicDBObject("$gt",-1).append("lt",3));
DBCursor cursor = coll.find(query2);
//result got in cursor
The form of query you are doing in the shell is actually just a shortcut form of the $where operator. So you would translate like this:
DBObject query = new BasicDBObject(
"$where",
"Number(this.val)>-1 && Number(this.val)<3"
);
Please note the documentation though, as running JavaScript is not a good idea for performance. You really should convert your strings to be actual numeric values.

Finding document by numeric fields in Lucene

For example, I have some documents described by fields: id, date and price.
First document: id=1, date='from 10.01.2014 to 20.01.2014', price='120'
Second document: id=2, date='19.01.2014' and price='from 100 to 140'
My program receives key/value parameters and should find the most suitable documents. So, for example, with this parameters date=19.01.2014 and price='120' program should find both documents. With date=20.01.2014, price=120' only the first document. With date='19.01.2014, price=140' only the second one.
How can I do it with Lucene in Java? I saw examples where I'm typing query like 'give me docs where date is from .. to ..', and Lucene gives me docs in this range. Instead of this I want to specify range for my document and not for query.
You could index both opening and closing ranges for dates and prices, e.g.
Your document #1 would be indexed as:
id = 1
dateFrom = 10.01.2014
dateTo = 20.01.2014
priceFrom = 120
priceTo = 9999999999
And document #2 as
id=2
dateFrom = 19.01.2014
dateTo = 01.01.2099
priceFrom = 100
priceTo = 140
The query would look like this:
+dateFrom:[19.01.2014 TO *] +priceFrom:[120 TO *] +priceTo:[* TO 140]
This is not very effective but it should work.

Categories

Resources