Xpages and OrientDB - how to handle connection object properly? - xpages

We would like to involve OrientDB (http://www.orientechnologies.com/) into the one of our Xpages projects. It suites well for our purposes using DocumentDatabase part of OrientDB.
Here we found a problem of how to deal with connection object. Instead of connecting and disconnecting manualy on every request we would like to use some shared connection for entire application. Documentation talks about it here https://github.com/orientechnologies/orientdb/wiki/Java-Web-Apps but its servlet filter, which is not suitable for Domino. Is there anyone having solution working properly with Domino and Xpages?

You need to write a custom datasource and within this datasource handle to connection pooling
look at this presentation
http://www.slideshare.net/NotesSensei/show107-the-datasource-session-take-xpages-data-boldly-where-no-xpages-data-has-been-taken-before
or check how it's done within the extension library sources. http://extlib.openntf.org/
a post about the connecting to jdbc using java
http://lazynotesguy.net/blog/2013/08/09/subclassing-an-extlib-component/

One thing you should be able to do is use an ApplicationListener in your App that will allow you to create the object on startup of the app and shut it down when the application is pulled out of memory.

Related

Identifying connect to Postgres using node pg-postgres

I have an application using a PostgreSQL database with multiple backend-API's. Because we some times run out of connections, I would like to be able to identify which backend API has active connections in view pg_stat_activity. Is it possible to identify the connection from node pg-postgres?
What you see (in pg_stat_activity) is what you get. If none of those fields are helpful, then I guess the answer is no.
Aren't all the APIs pooled together through the same shared connections?
Application_name could help if you can convince node.js to set them per API. query text could help if you recognize what query text is from which API.

Connection Pooling in typeorm with postgressql

I've gone through enough articles and typeorm official documentation on setting up connection pooling with typeorm and postgressql but couldn't find a solution.
All the articles, I've seen so far explains about adding the max/Poolsize attribute in orm configuration or connection pooling but this is not setting up a pool of idle connections in the database.
When I verify pg_stat_activity table after the application bootstraps, I could not see any idle connections in the DB but when a request is sent to the application I could see an active connection to the DB
The max/poolSize attribute defined under the extras in the orm configuration merely acts as the max number of connections that can be opened from the application to the db concurrently.
What I'm expecting is that during the bootstrap, the application opens a predefined number of connections with the database and keep it in idle state. When a request comes into the application one of the idle connection is picked up and the request is served.
Can anyone provide your insights on how to have this configuration defined with typeorm and postgresql?
TypeORM uses node-postgres which has built in pg-pool and doesn't have that kind of option, as far as I can tell. It supports a max, and as your app needs more connections it will create them, so if you want to pre-warm it, or maybe load/stress test it, and see those additional connections you'll need to write some code that kicks off a bunch of async queries/inserts.
I think I understand what you're looking for as I used to do enterprise Java, and connection pools in things like glassfish and jboss have more options where you can keep hot unused connections in the pool. There are no such options in TypeORM/node-postgres though.

Proper way of using db connections? (Python + pyodbc)

I am currently building a REST API using Python and Flask. Most endpoints require some type of interaction with a SQL database (SQL Server, using pyodbc). What is the best way of going around this.
Should I open a single connection (e.g. in a singleton class) and try and reuse it as much as possible?
Should I use different connections? If so, at what granularity? One connection per endpoint? One connection per query?
What role does connection pooling play in all of this and how do I make use of it?
Do I have to worry about concurrent requests?

Mongoose Schema.post across network

I have two Node.js applications each running Mongoose on a different machine. There is a single MongoDB database running on the first, and the second connects to it and adds documents periodically. I'm trying to add a hook to the creation of these documents so the server running the database is aware that other server has added data. I tried using the Schema.post() method, but it doesn't seem to work since there are two separate instances of Mongoose. Is this true or am I just implementing it incorrectly? I can get the hook to fire if the document is created on the same server, but not the other.
So my thought is to add the hook to MongoDB directly, instead of Mongoose, but I'm not sure how to go about doing that. Am I on the right track?
That is true, Schema.post() only work in the same process. You either need to use a library that tails MongoDB's oplog (like mongo-oplog), implement it yourself using a message queue (or pub/sub) that all instances are connected to (like Redis, RabbitMQ, etc) or use a database that supports this natively. PostgreSQL supports this with its NOTIFY feature for example.

For each model a new connection? Is that right?

I am creating a Node.js application through Express.js foundation and my knowledge lead me to create a models folder and a file for each model. Ok, so far, so good — but the point is: each model of mine has the following fragment of code on its top:
var mongoose = require ('mongoose')
, database = mongoose.createConnection('mongodb://localhost:27017/test');
Am I repeating myself doing this? I'm not searching for "the best approach ever", but doing this is not a bad design thing?
If this is something normal, could someone explain me why this behavior happens? Couldn't I create an organic mechanism to establish a connection and just distribute its properties for the entire application?
I already worked on Rails, C# and PHP and I've never see something like this before. Probably because database connections were for me something very abstract — I touched just a few times on the connection bridge.
DISCLAIMER: My question is really very specific. I just want to know if there's a way to announce the database connection from one file to the rest of the application.
What you're doing is not typical.
Unless you have a specific need to do something else, call mongoose.connect once during app startup and register all models using mongoose.model.
This lets your app share a common connection pool. You can tweak the size of the connection pool via the options provided in the mongoose.connect call.

Resources