{"id":5486,"date":"2014-03-30T22:47:34","date_gmt":"2014-03-30T22:47:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/add-multiple-databases-instead-of-one-to-an-existing-application-collection-of-common-programming-errors\/"},"modified":"2014-03-30T22:47:34","modified_gmt":"2014-03-30T22:47:34","slug":"add-multiple-databases-instead-of-one-to-an-existing-application-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/add-multiple-databases-instead-of-one-to-an-existing-application-collection-of-common-programming-errors\/","title":{"rendered":"Add multiple databases (instead of one) to an existing application-Collection of common programming errors"},"content":{"rendered":"<p>We are using Mongo Db as a database.<\/p>\n<p>If we got the following JAX-RS service (or some other Stateless\/Statefull EJB).<\/p>\n<pre><code>@Path(\"my_service_path\")\n@Stateless\npublic class GetSomeObject{\n\n  @Inject\n  public DB database;\n\n  @GET\n  @Consumes(\"application\/json\")\n  @Produces(\"application\/json\")\n  public SomeDomainObject get(@QueryParam(\"some_param\") String param){\n  ...\n  database.find(...);\n  ...\n  return something;\n  }\n}\n<\/code><\/pre>\n<p>The PROBLEM: We need to use two or more databases, but in our current source it seems impossible. We are currently using injected DBs, but if we were using <code>EntityManager<\/code> implementation or something other we would meet the same problem. Are there some integrated solutions for injecting different instances of a class, depending of user\/application. We can try<\/p>\n<pre><code>  @Inject\n  public Map databases;\n<\/code><\/pre>\n<p>but we must add too many conditional logic to handle these maps of databases.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are using Mongo Db as a database. If we got the following JAX-RS service (or some other Stateless\/Statefull EJB). @Path(&#8220;my_service_path&#8221;) @Stateless public class GetSomeObject{ @Inject public DB database; @GET @Consumes(&#8220;application\/json&#8221;) @Produces(&#8220;application\/json&#8221;) public SomeDomainObject get(@QueryParam(&#8220;some_param&#8221;) String param){ &#8230; database.find(&#8230;); &#8230; return something; } } The PROBLEM: We need to use two or more databases, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5486","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5486"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5486\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}