I have two datasource in my app-ds.xml file. I want only one to load at a time. Because loading both will take much cpu resources. It means that I will have a flag somewhere that will determine which database should load. Both these database will contain roughly the same data, the only difference is one is live(which is used by other applications as well), and the other one is a local copy(we can modify everything here). Please note that separating the database into different environments is not the answer we hope for. Because we have both databases for every environments(most likely DEV and TEST)
Any idea on how I should do this will be very helpful.
<datasources>
<datasource jndi-name="java:/jdbc/dataSource/database1" pool-name="database1">
<connection-url>jdbc:sybase:Tds:host:port/schema</connection-url>
<driver>sybase</driver>
<pool>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
<min-pool-size>10</min-pool-size>
<max-pool-size>10</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
</datasource>
<datasource jndi-name="java:/jdbc/dataSource/database2" pool-name="database2">
<connection-url>jdbc:sybase:Tds:host:port/schema</connection-url>
<driver>sybase</driver>
<pool>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
<min-pool-size>10</min-pool-size>
<max-pool-size>10</max-pool-size>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
</datasource>
</datasources>
In JBoss, Datasources always bound and register the persistent context when deploying.
It does not take much memory when deploying.
You must remove the local datasource when your application going to production.
Related
I'm trying to figure out if I should package multiple blueprint.xml files in a single OSGi bundle that I want to deploy into karaf. Each blueprint.xml file has one camel context. I've tried to just throw all my blueprints into the OSGI-INF/blueprint folder, but I got an error saying
Name 'jms' is already in use by a registered component
That seems to make sense, because I do this in every blueprint.xml
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://0.0.0.0:61616"/>
<property name="userName" value="karaf"/>
<property name="password" value="karaf"/>
</bean>
</property>
</bean>
Should I even do that? Or would it be better for each CamelContext to be it's own bundle? I've seen this https://camel.apache.org/manual/latest/faq/why-use-multiple-camelcontext.html and it says that multiple CamelContexts would make sense when they're deployed as isolated bundles. So what's the best practice here:
Each CamelContext with it's own blueprint.xml, bundled with the necessary beans into an osgi-bundle?
One bundle for all necessary beans, and just drop the blueprint.xml files in karaf's deploy folder?
One CamelContext which imports all the other CamelContexts, bundled with all necessary beans?
This is more of a question about service design, not Camel.
Since a bundle is a deployment unit, I would first of all look at the different lifecycles of your code.
If some things must always be deployed together, if they cannot evolve individually, you can make one bundle containing them. Simply because, in terms of releasing and deployment, you cannot profit from dividing the code into smaller units.
On the other hand, if something is evolving faster or slower and must therefore be deployed more often (or less often), you should put it in its own bundle.
This way you are able to deploy code only when it really changes. In contrast to a giant EAR file to deploy a big monolithic application when only a small bugfix was implemented.
So, in summary, you can use more or less the microservice principles to "cut" your code into units.
I am making a WPF application in Visual Studio 2015. The database layer is using Entity Framework, which generated a connection string in the app.config file. The database connection works and the app runs. Nonetheless, at design-time, Visual Studio complains about there being "no connection string named in the application configuration file" -- but there is.
Since it seems to resolve itself as run-time, I ignored the warnings up until now. However, now the issue is interfering with the design process -- Visual Studio is claiming not being able to make instances of classes that use the connection.
I have tried moving the app.config around into various positions in the project structure, renaming it to match the app's name, cleaning and rebuilding the project.
I believe that, at design-time, not all files are referencing the same app.config. Something about my project structure must be off.
How can I determine and/or change the path that EF is following to the app.config?
The XML from the app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="MYAPPSNAME" connectionString="metadata=res://*/MYDBNAME.csdl|res://*/MYDBNAME.ssdl|res://*/MYDBNAME.msl;provider=MySql.Data.MySqlClient;provider connection string="server=193.169.2.123;user id=devs;password=*********;persistsecurityinfo=True;convertzerodatetime=True;database=MYDBNAME"" providerName="System.Data.EntityClient" /></connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
I found a solution to my problem here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/257ca21a-15cd-4d21-84df-79cc6bcbe546/getting-a-no-connection-string-named-cound-be-found-in-the-application-config-file-error-and-i?forum=wpf
Essentially, I add the following to the constructors of classes that establish a database connection; it checks if the project is in Designer Mode, and if so, returns before trying to make a database connection.
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
return;
In this way, I avoid the issue of Visual Studio trying to make a db connection from the designer, so it doesn't complain and allows me to design freely. At run-time, still no issues. :)
Still not entirely sure of the source of the problem -- I am still guessing that at design-time, the app.config file is not fully read/parsed, so the designer is complaining about not having enough information to construct such classes.
If it shows up in Solution Explorer then properties will show you where it is. You should be able to open and edit it right there.
If app.config is not in Solution Explorer it should be in the same folder has the MainWindow. Make sure you also add (Add Existing) in the project in Visual Studio. The file should show up in the Solution Explorer.
I want to build a programm, which connects to a database. Inprinciple, my code works. I use "Hibernante-4.3.1" and a postgresql-driver "postgresql-9.3-1100.jdbc41.jar".
My persistence.xml looks like this:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence" version="1.0">
<persistence-unit name="******" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.username" value="******"/>
<property name="hibernate.connection.password" value="******"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/*******"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
For localhost, it's okeyishly fast, but if I want to connect to a external server via internet, it takes about 30-60 seconds to establish the connection. Once it is initialised, all subsequent requests are executed fast enough, but the first call is taking way to long.
I could restructure the whole project as a WEB-Project and make a JBoss Datasource via JTA. That way, the connection is established before the programm starts and all would be fine. But I'd would like it a lot more to have if I didn't have to do that. What's the right way to connect like this?
Edit: Some more information: The line which takes the long time is:
javax.persistence.EntityManagerFactory emf = Persistence.createEntityManagerFactory("OneGramService");
Greetings,
Rhodarus
Try to set hibernate.temp.use_jdbc_metadata_defaults property to false.
Guys i am actively working on migrating an application running on JBoss AS 5 to JBoss AS 7.
After migration, I have noticed that the database calls took a huge performance hit.
I was using ojdbc14 with a pool(min - 5 max - 100) on JBoss 5 and it was working pretty good for us.
With JBoss AS 7, I have installed the driver as a module.
All my queries are nto taking 10 times longer.
For ex, if a query took 30ms while I was on JBoss AS 5 , it is taking 400-600ms on JBoss AS 7.
I have tried with both the drivers shown in the config below (ojdbc6, ojdbc14)
An Observation is that , the perfomance decrease is more noticable on a linux box machine than a OS X box.
FYI. I have tried running JBoss AS 7 on both Java 1.6 and 1.7
My application itself contains:
struts 2 front end (used for request processing, no web ui involved)
Session Beans in the backend
QuartzPlugin for batch jobs.
a custom MBean
I have tried
lowering and increasing the pool size
prefill = true and false
switching between ojdbc6 and ojdbc14
standalone.xml
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jta="true" jndi-name="java:jboss/datasources/MyDS" pool-name="hive-datasource" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:oracle:thin:#host:port:service</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<connection-property name="defaultRowPrefetch">
50
</connection-property>
<driver>oracle14</driver>
<pool>
<min-pool-size>20</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>theusername</user-name>
<password>thepassword</password>
</security>
<validation>
<check-valid-connection-sql>select * from dual</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<use-fast-fail>false</use-fast-fail>
<exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter"/>
</validation>
<timeout>
<set-tx-query-timeout>true</set-tx-query-timeout>
<blocking-timeout-millis>300000</blocking-timeout-millis>
<idle-timeout-minutes>30</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>false</track-statements>
<prepared-statement-cache-size>0</prepared-statement-cache-size>
</statement>
</datasource>
<drivers>
<driver name="oracle6" module="com.oracle.ojdbc6">
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
<driver name="oracle14" module="com.oracle.ojdbc14">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
We see issues with upgrades changing database performance quite often. The key is to pin down how database queries have changed between JBoss 5 and JBoss7. The fact that you are seeing a more substantial degradation on one OS and lesser on another is not surprising since every OS has its strengths and weakness when it comes to processing efficiency.
My suggestion would be to ascertain high visibility on the database, including the queries that are causing the biggest bottlenecks with JBoss 7 and the top Wait Events. In case you are not familiar, Oracle breaks query execution down into discrete steps called Wait Events. These can be anything from waiting on a table lock to Disk I/O time taking events. There are close to 1000 Wait Events in Oracle, so getting this information manually and correlating the wait event with the query and hardware resources can be very difficult.
Here is a link to a free version of the Ignite database monitoring software that should help you out http://www.ignitefree.com
For example, an operation that took 2ms on JBoss5/Java6 is taking 2-5sec on JBoss7/Java6 or 7. This happens only when i run on a linux machine. the machine itself have 8Gig+ free memory and is a Xeon processor. Everything runs normal when i run it on an OS X server/laptop
I have been experimenting with GAE (1.7.0) for a couple of weeks now and I am having some issues with STRONG consistancy.
I have been researching the issue, but I am still unclear.
Is some able to definately say that if using JDO within GAE then the consistancy will be EVENTUAL.
The only way to achieve STRONG consistancy is not use JDO and to use the GAE entity classes with Ancestry.
At this stage I dont know if it is my code at fault or just not supported within the environment. In any case I am losing my fragile little mind :-)
My jdoconfig.xml file
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.appengine.datastoreReadConsistency" value="STRONG" />
</persistence-manager-factory>
Thanks
I do not think that you can be assured of consistency by specifying the datastoreReadConsistency to STRONG in the jdoconfig.xml file.
Google App Engine's High Replication Datastore (HRD) is now the default data repository for App Engine applications. This model is guaranteed to work for eventual consistency only.
What you have mentioned is correct and also as per the documentation, which states that "To obtain strongly consistent query results, you need to use an ancestor query limiting the results to a single entity group."
See note : https://developers.google.com/appengine/docs/java/datastore/structuring_for_strong_consistency