Search in sources :

Example 1 with DateTime

use of lotus.domino.DateTime in project org.openntf.domino by OpenNTF.

the class NotesRunner method run1.

public void run1(final Session session) throws NotesException {
    Long sessId = getLotusId(session);
    sessionid.set(sessId);
    Database db = session.getDatabase("", "names.nsf");
    System.out.println("Db id:" + getLotusId(db));
    Name name = null;
    int i = 0;
    try {
        for (i = 0; i <= 100000; i++) {
            name = session.createName(UUID.randomUUID().toString());
            getLotusId(name);
            DateTime dt = session.createDateTime(new Date());
            getLotusId(dt);
            DateTime end = session.createDateTime(new Date());
            getLotusId(end);
            DateRange dr = session.createDateRange(dt, end);
            getLotusId(dr);
            Document doc = db.createDocument();
            getLotusId(doc);
            Item i1 = doc.replaceItemValue("Foo", dr);
            getLotusId(i1);
            Item i2 = doc.replaceItemValue("Bar", dr.getText());
            getLotusId(i2);
            Item i3 = doc.replaceItemValue("Blah", dr.getStartDateTime().getLocalTime());
            getLotusId(i3);
            lotus.domino.ColorObject color = session.createColorObject();
            getLotusId(color);
            color.setRGB(128, 128, 128);
            Item i4 = doc.replaceItemValue("color", color.getNotesColor());
            getLotusId(i4);
            i1.recycle();
            i2.recycle();
            i3.recycle();
            i4.recycle();
            DateTime create = doc.getCreated();
            getLotusId(create);
            @SuppressWarnings("unused") String lc = create.getLocalTime();
            // if (i % 10000 == 0) {
            // System.out.println(Thread.currentThread().getName() + " Name " + i + " is " + name.getCommon() + " "
            // + "Local time is " + lc + "  " + dr.getText());
            // }
            dr.recycle();
            doc.recycle();
            dt.recycle();
            end.recycle();
            create.recycle();
            color.recycle();
            name.recycle();
        }
    } catch (Throwable t) {
        t.printStackTrace();
        System.out.println("Exception at loop point " + i);
    }
}
Also used : Document(lotus.domino.Document) DateTime(lotus.domino.DateTime) Date(java.util.Date) Name(lotus.domino.Name) Item(lotus.domino.Item) DateRange(lotus.domino.DateRange) Database(lotus.domino.Database)

Example 2 with DateTime

use of lotus.domino.DateTime in project org.openntf.xsp.jakartaee by OpenNTF.

the class DefaultDominoDocumentCollectionManager method select.

@Override
public Stream<DocumentEntity> select(DocumentQuery query) {
    try {
        QueryConverterResult queryResult = QueryConverter.select(query);
        long skip = queryResult.getSkip();
        long limit = queryResult.getLimit();
        List<Sort> sorts = query.getSorts();
        Stream<DocumentEntity> result;
        if (sorts != null && !sorts.isEmpty()) {
            Database database = supplier.get();
            Session sessionAsSigner = sessionSupplier.get();
            Database qrpDatabase = getQrpDatabase(sessionAsSigner, database);
            String userName = database.getParent().getEffectiveUserName();
            // $NON-NLS-1$
            String viewName = getClass().getName() + "-" + (String.valueOf(sorts) + skip + limit + userName).hashCode();
            View view = qrpDatabase.getView(viewName);
            try {
                if (view != null) {
                    // Check to see if we need to "expire" it based on the data mod time of the DB
                    DateTime created = view.getCreated();
                    try {
                        long dataMod = NotesSession.getLastDataModificationDateByName(database.getServer(), database.getFilePath());
                        if (dataMod > (created.toJavaDate().getTime() / 1000)) {
                            view.remove();
                            view.recycle();
                            view = null;
                        }
                    } catch (NotesAPIException e) {
                        throw new RuntimeException(e);
                    } finally {
                        recycle(created);
                    }
                }
                if (view != null) {
                    result = EntityConverter.convert(database, view);
                } else {
                    DominoQuery dominoQuery = database.createDominoQuery();
                    QueryResultsProcessor qrp = qrpDatabase.createQueryResultsProcessor();
                    try {
                        qrp.addDominoQuery(dominoQuery, queryResult.getStatement().toString(), null);
                        for (Sort sort : sorts) {
                            int dir = sort.getType() == SortType.DESC ? QueryResultsProcessor.SORT_DESCENDING : QueryResultsProcessor.SORT_ASCENDING;
                            qrp.addColumn(sort.getName(), null, null, dir, false, false);
                        }
                        if (skip == 0 && limit > 0 && limit <= Integer.MAX_VALUE) {
                            qrp.setMaxEntries((int) limit);
                        }
                        view = qrp.executeToView(viewName, 24);
                        try {
                            result = EntityConverter.convert(database, view);
                        } finally {
                            recycle(view);
                        }
                    } finally {
                        recycle(qrp, dominoQuery, qrpDatabase);
                    }
                }
            } finally {
                recycle(view);
            }
        } else {
            Database database = supplier.get();
            DominoQuery dominoQuery = database.createDominoQuery();
            DocumentCollection docs = dominoQuery.execute(queryResult.getStatement().toString());
            try {
                result = EntityConverter.convert(docs);
            } finally {
                recycle(docs, dominoQuery);
            }
        }
        if (skip > 0) {
            result = result.skip(skip);
        }
        if (limit > 0) {
            result = result.limit(limit);
        }
        return result;
    } catch (NotesException e) {
        throw new RuntimeException(e);
    }
}
Also used : QueryResultsProcessor(lotus.domino.QueryResultsProcessor) QueryConverterResult(org.openntf.xsp.nosql.communication.driver.QueryConverter.QueryConverterResult) DocumentCollection(lotus.domino.DocumentCollection) View(lotus.domino.View) DateTime(lotus.domino.DateTime) NotesException(lotus.domino.NotesException) DocumentEntity(jakarta.nosql.document.DocumentEntity) Database(lotus.domino.Database) Sort(jakarta.nosql.Sort) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) DominoQuery(lotus.domino.DominoQuery) NotesSession(com.ibm.designer.domino.napi.NotesSession) Session(lotus.domino.Session)

Example 3 with DateTime

use of lotus.domino.DateTime in project org.openntf.xsp.jakartaee by OpenNTF.

the class AbstractOpenAPIResource method getVersionNumber.

private static String getVersionNumber(Database database) throws NotesException {
    NoteCollection noteCollection = database.createNoteCollection(true);
    noteCollection.setSelectSharedFields(true);
    noteCollection.setSelectionFormula("$TITLE=\"$TemplateBuild\"");
    noteCollection.buildCollection();
    String noteID = noteCollection.getFirstNoteID();
    Document designDoc = database.getDocumentByID(noteID);
    if (null != designDoc) {
        String buildVersion = designDoc.getItemValueString("$TemplateBuild");
        Date buildDate = ((DateTime) designDoc.getItemValueDateTimeArray("$TemplateBuildDate").get(0)).toJavaDate();
        String buildDateFormatted = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT).format(buildDate);
        return buildVersion + " (" + buildDateFormatted + ")";
    }
    return "";
}
Also used : NoteCollection(lotus.domino.NoteCollection) Document(lotus.domino.Document) Date(java.util.Date) DateTime(lotus.domino.DateTime)

Example 4 with DateTime

use of lotus.domino.DateTime in project org.openntf.domino by OpenNTF.

the class DominoRunner method run.

@Override
public void run() {
    try {
        System.out.println("Starting NotesRunner");
        Session session = NotesFactory.createSession();
        sessionid.set(getLotusId(session));
        Database db = session.getDatabase("", "log.nsf");
        getLotusId(db);
        Name name = null;
        int i = 0;
        try {
            for (i = 0; i <= 100000; i++) {
                name = session.createName(UUID.randomUUID().toString());
                getLotusId(name);
                DateTime dt = session.createDateTime(new Date());
                getLotusId(dt);
                DateTime end = session.createDateTime(new Date());
                getLotusId(end);
                DateRange dr = session.createDateRange(dt, end);
                getLotusId(dr);
                Document doc = db.createDocument();
                getLotusId(doc);
                Item i1 = doc.replaceItemValue("Foo", dr);
                getLotusId(i1);
                Item i2 = doc.replaceItemValue("Bar", dr.getText());
                getLotusId(i2);
                Item i3 = doc.replaceItemValue("Blah", dr.getStartDateTime().getLocalTime());
                getLotusId(i3);
                lotus.domino.ColorObject color = session.createColorObject();
                getLotusId(color);
                color.setRGB(128, 128, 128);
                Item i4 = doc.replaceItemValue("color", color.getNotesColor());
                getLotusId(i4);
                i1.recycle();
                i2.recycle();
                i3.recycle();
                i4.recycle();
                DateTime create = doc.getCreated();
                getLotusId(create);
                String lc = create.getLocalTime();
                if (i % 10000 == 0) {
                    System.out.println(Thread.currentThread().getName() + " Name " + i + " is " + name.getCommon() + " " + "Local time is " + lc + "  " + dr.getText());
                }
                dr.recycle();
                doc.recycle();
                dt.recycle();
                end.recycle();
                create.recycle();
                color.recycle();
                if (name != null)
                    name.recycle();
            }
        } catch (Throwable t) {
            t.printStackTrace();
            System.out.println("Exception at loop point " + i);
        }
        session.recycle();
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.out.println("FINI!");
}
Also used : Document(lotus.domino.Document) DateTime(lotus.domino.DateTime) Date(java.util.Date) Name(lotus.domino.Name) Item(lotus.domino.Item) DateRange(lotus.domino.DateRange) Database(lotus.domino.Database) Session(lotus.domino.Session)

Aggregations

DateTime (lotus.domino.DateTime)4 Date (java.util.Date)3 Database (lotus.domino.Database)3 Document (lotus.domino.Document)3 DateRange (lotus.domino.DateRange)2 Item (lotus.domino.Item)2 Name (lotus.domino.Name)2 Session (lotus.domino.Session)2 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 NotesSession (com.ibm.designer.domino.napi.NotesSession)1 Sort (jakarta.nosql.Sort)1 DocumentEntity (jakarta.nosql.document.DocumentEntity)1 DocumentCollection (lotus.domino.DocumentCollection)1 DominoQuery (lotus.domino.DominoQuery)1 NoteCollection (lotus.domino.NoteCollection)1 NotesException (lotus.domino.NotesException)1 QueryResultsProcessor (lotus.domino.QueryResultsProcessor)1 View (lotus.domino.View)1 QueryConverterResult (org.openntf.xsp.nosql.communication.driver.QueryConverter.QueryConverterResult)1