Get modified Notes document in java from particular time - java

i saved all my indexed notes documents to Solr server,
so my problem is if any of my notes document is change in my .nsf database. i have to update my notes documents on Solr server.
for that i have to get last modified documents from particular time means i will provide a time as parameter then from that time i should get modified documents.
i searched about it but not getting clear idea about it to initiate my work .
it would be nice if anyone guide me .

If your plan is to get every documents modified since a certain date/time, the best way would be to use the search function on the Database class.
Specify Select #All to get every documents of the database and set the last time you indexed as the second parameter. This way, Domino will get you every documents created or modified since this time.
DateTime dt
A start date. The method searches only documents created or modified since the start date. Can be null to indicate no start date.
Here a small example :
Session session = getSession();
Database db = session.getCurrentDatabase();
Document profile = db.getProfileDocument("solrIndexer","nameOfTheDatabase");
Item lastTimeIndexedItem = profile.getFirstItem("lastTimeYouIndexed");
DateTime lastTimeIndexed = lastTimeIndexedItem.getDateTimeValue();
DocumentCollection col = db.search("Select #All", lastTimeIndexed);
// (Your code goes here)

Related

Android Studio project not reading correctly from SQLite database?

I've been struggling with this for days now and can't work out what's wrong. The thing is, I am not getting errors at the moment. Im just not producing the result I hoped for. I am trying to read from a specific record in my sqlite database where the data is a week ago today - I am trying to get the weather on this day, which is in my database. Here is my DB code for the method I am using:
public long homepageTB(){
LocalDate now = LocalDate.now();
LocalDate lastWeek = now.minusDays(7+now.getDayOfWeek().getValue()-1);
LocalDate currentDate = now.minusDays(now.getDayOfWeek().getValue());
String[] lweek = new String[1];
lweek[0] = String.valueOf(lastWeek);
String lastwk = String.valueOf(lastWeek);
long rv = -1; //<<<< default return to indicate no such row
SQLiteDatabase DB=this.getReadableDatabase();
Cursor cursor=DB.rawQuery("select weather from dailyQuiz1 where date =?",lweek);
if (cursor.moveToFirst()) {
rv = cursor.getLong(cursor.getColumnIndex("weather"));
}
System.out.println(lweek[0]);
System.out.println(rv);
return rv;
}
At the moment, this correctly returns the data week ago in format: 2022-01-31
and returns rv: -1 (which means it can't find the record). However, the record is there in my database:
So realistically I don't want -1 to be returned as I would want the variable in another class I am calling it from to now hold the value of the weather, which you can see in my database is 'Rainy'. Any ideas what I've done wrong or what is a better approach? I feel it will be something so obvious but I've been trying so many things for the past few days :( Thanks for the help
With the exception that you will have an issue with the returned value being 0 if the data is found
i.e. you are getting a long from a text value when using rv = cursor.getLong(cursor.getColumnIndex("weather")) so instead of crashing when trying to convert Rainy to a long 0 is given.
What you have shown works as expected. That leaves the issue to probably be that the database does not in fact contain a row where the date column does equal the String 2022-01-31.
You need to ensure that what is in the actual database being used is as expected (your image appears to be from a tool rather than the actual database and often issues are due to differences).
So in Android Studio run the App and get to a point where it is awaiting for user interaction. The click on App Inspection do you see the same data? e.g. it should look like (not all columns have been included in the example):-
If not then your issue is that the data is not being added as expected and that needs to be corrected.
Otherwise click on the Query Icon
Enter and run SELECT length(date), * FROM dailyquiz1 WHERE date like '2022-01%' e.g. :-
if the first column returned is > 10 then there is an issue with the data that is being stored, as it contains additional data.
if the first column returned is < 10 then you are storing data that is shorter than it should be.
if no data is returned then the data stored is even further away from what it should be.

Spring and MongoDB - How to query documents depend on the filters?

I have a project that uploads/download documents, and in the metadata of this documents are in MongoDB. I'm using java spring to store the data into MongoDb. And all is fine to save, get, delete and updates.
The problem is when i try to search the documents depend on a filter.
For example, the filter can be:
Region = Europe, Country = Spain, Category = cat1
or can be just:
Region = Europe, Country = Spain
So the filters are variable, depend on the client selection. They can filter by several fields or just by one or none..
So I don't know how to do that. Because I'm using the repository and if the filter is null, they search by this null value...
For example: If category is null, because the client is not filtering by this field, mongo search the documents by category=null...
Any one can help me?
Thanks,

What is the best way to import an XML string into a SQL Server table

I am working with a 3rd product called JPOS and it has an XMLPackager whereby I get a string from this packager that contains a record in an XML format such as:
<MACHINE><B000>STRING_VALUE</B000><B002>STRING_VALUE</B002><B003>STRING_VALUE</B003><B004>STRING_VALUE</B004><B007>STRING_VALUE</B007><B011>STRING_VALUE</B011><B012>STRING_VALUE</B012><B013>STRING_VALUE</B013><B015>STRING_VALUE</B015><B018>STRING_VALUE</B018><B028>STRING_VALUE</B028><B032>STRING_VALUE</B032><B035>STRING_VALUE</B035><B037>STRING_VALUE</B037><B039>STRING_VALUE</B039><B041>STRING_VALUE</B041><B043>STRING_VALUE</B043><B048>STRING_VALUE</B048><B049>STRING_VALUE</B049><B058>STRING_VALUE</B058><B061>STRING_VALUE</B061><B063>STRING_VALUE</B063><B127>STRING_VALUE</B127></MACHINE>
I have a SQL server table that contains a column for each of the listed. Not that it matters but I could potentially have thru defined with specific STRING_VALUEs. I'm not sure what is the best way to go about this in Java. My understanding is that SQL Server can take an XML string (not document) and do an insert. Is it best to parse each value and then put into a list that populate each value into? This is the first time I've used an XML file and therefore trying to get some help/direction.
Thanks.
Sorry, one of my colleagues was able to help and provide a quick answer. I'll try it from my Java code and it looks like it should work great. Thanks anyway.
Here is the SP that she created whereby I can pass in my XML string and bit value:
CREATE PROCEDURE [dbo].[sbssp_InsertArchivedMessages]
(
#doc varchar(max),
#fromTo bit
)
AS
BEGIN
DECLARE #idoc int, #lastId int
EXEC sp_xml_preparedocument #idoc OUTPUT, #doc
INSERT INTO [dbo].[tblArchivedMessages]
SELECT * FROM OPENXML(#idoc, '/MACHINE', 2) WITH [dbo].[tblArchivedMessages]
SET #lastId = (SELECT IDENT_CURRENT('tblArchivedMessages'))
UPDATE [dbo].[tblArchivedMessages]
SET FromToMach = #fromTo
WHERE ID = #lastId
END
GO
Regards.

lotus notes search by date with Java api

I'm trying to select records by date from a Lotus Notes database and have run into trouble with correctly formatting the date.
Here's the relevant code:
public void runNotes() {
Session s;
try {
s = NotesFactory.createSession((String)null, (String)null, "mypassword");
Database hkDB =
s.getDatabase("NBHDH001/YNM", "H\\DHH00001.nsf", false);
DocumentCollection docs = hkDB.search("[Date]>[2012/03/20]");
Date is a field in the record, and when I looked up records (with FTSearch), the date came back in the format above: [yyyy/mm/dd].
The parameter of the search is what I need here.
i.e. what should I put instead of "[Date]>[2012/03/20]"
I tried various constructions with Calendar and DateFormat, but it's not coming together...
Any suggestions?
You should get rid of the square brackets on the field name. The search method expects a Notes Formula, like what you'd put into a view selection formula:
"Date > [03/20/2012]"
It might also be required that dates are in mm/dd/yyyy format, though if you are in a non-US locale I'm not 100% sure.
You mentioned that you have been doing full text searches in the database, so it is definitely worth mentioning this... If the database actually has a full text index, then you may want to consider using the NotesDatabase.FTSearch() method instead of NotesDatabase.Search(). The FTSearch method will be considerably faster for a large database.
The syntax for FTSearch is different from the syntax for Search. You could use either "FIELD Date > 03/20/2012" or "[Date] > 03/20/2012".

Retrieving the UUID from Apache Solr after a commit

I am using Solrj to add new documents to a Solr instance. In my document schema the id is a UUID (solr.UUIDField). Each time a document is created the id is filled with the unique id, which is exactly what I want. Sometimes it's necessary in my application that I can retrieve this unique id to add it as a field value when inserting another document. So my question is, how can I retrieve this generated uuid from solr after adding a document?
Solrj returns me this UpdateResponse object after commiting, but I don't know how to get the new uuid out of it.
I am adding a document like this
CommonsHttpSolrServer server = new CommonsHttpSolrServer(MY_SERVER_URL);
SolrInputDocument doc = new SolrInputDocument();
// [...] multiple addField calls
server.add(doc);
UpdateResponse ur = server.commit();
AFAIK you aren't going to ever get a UUID from an add or a commit. When you do an add or commit, the update request handler gives you back query time and status, but not much else (assuming it is successful). You can actually see what is in the HTTP response by running a manual add/commit like so:
http://localhost:8983/solr/update?stream.body=<add><doc><field name="id">test</field><field name="title">test title</field></doc></add>
http://localhost:8983/solr/update?stream.body=<commit/>
If you run those queries in a web browser, they will submit a test document and commit it, respectively. You will then be able to see what information is available to SolrJ (not much).
You could write your own (modified) update handler in Java, but that seems like a ton of work. You could also enable the "timestamp" field in your Solr schema so you can query solr by last modified date and find the items you just committed.
Both of those methods would be major hacks, though. Your best bet is to figure out a unique ID for your documents before you submit them to Solr, then use that unique ID to retrieve them. Using a generated UUID is more of a "fire and forget about this" method. Since you don't want to forget, you will need to generate your own UUID.
Since you're using Java, it should be dead simple to do with UUID, using some code like this:
CommonsHttpSolrServer server = new CommonsHttpSolrServer(MY_SERVER_URL);
SolrInputDocument doc = new SolrInputDocument();
UUID uuid = UUID.randomUUID();
doc.addField("id", uuid.toString());
// [...] multiple addField calls
server.add(doc);
UpdateResponse ur = server.commit();

Categories