Hi Alejandro,
Thanks for your help!!! and sorry for the delay in my answer.
I revised the different issues that you comment.
1.- Concurrent users: When I’m doing the test only there are one user who is the user was logged in the web. There are no concurrency.
- -VisualVM: I can’t connect to my localhost from Netbeans :S
The application runs in “localhost:8200/name-web/jsp/login.jsp”
Whe run Maven I use: tomcat7:run-war
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8200
I try with localhost and 127.0.0.1 (http://stackoverflow.com/questions/10173834/java-rmi-djava-rmi-server-hostname-localhost-still-opens-a-socket-listening-on) but doesn’t work.
From VisualVM I indicated localhost:8200
When I try a connection and put the parameters and press ok, vm returns the message “cannot connect to localhost:8200 …”
3.- Hibernate Queries: At the moment I only search if user exist in database, if user doesn’t exist System create it. The function returns a user object .
Class Provider implements AuthenticationProvider {
@Autowired
private FilterDbUtil filterDbUtil;
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
NEWCLASSAuthenticationDetails details =
(NEWCLASSAuthenticationDetails) authentication.getDetails();
String mCustomerId = details.getCustomerId();
String mUsername = (String) authentication.getPrincipal();
String mPassword = (String) authentication.getCredentials();
>>>>>> SmpUser smpUser = filterDbUtil.getUser(mCustomerId, mUsername);
}
public class FilterDbUtil {
@Autowired
private SessionFactory sessionFactory;
public SmpUser getUser(String customerId, String username) {
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
String identifier = getUserIdentifier(customerId, username);
Query query = session.createQuery(“from ManageUser where identifier = :identifier”);
query.setParameter(“identifier”, identifier);
ManageUser manageUser = (ManageUser) query.uniqueResult();
tx.commit();
if (manageUser == null) {
tx = session.beginTransaction();
manageUser = new ManageUser();
manageUser.setIdentifier(identifier);
saveUser(manageUser);
tx.commit();
}
return manageUser;
} catch (HibernateException e) {
session.getTransaction().rollback();
return null;
} finally {
if (session != null){
session.close();
}
}
}
public void saveUser(SmpUser user) {
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(user);
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
e.printStackTrace();
}
} finally {
session.close();
}
}
}
@Entity
public class ManageUser {
@Id
@Column(name = "USER_NAME")
private String identifier;
…..
}
Application.spring.xml
…
<!-- Data Access Objects -->
<bean id="filterDbUtil" class="………….db.FilterDbUtil" />
<!-- Hibernate settings -->
<bean id="dataSource"
class="org.apache.tomcat.dbcp.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.user}" />
<property name="password" value="${jdbc.pass}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="………..db.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.transaction.flush_before_completion">true</prop>
<!-- To show sql output on the screen -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!-- Connection pool C3P0 -->
<prop key="hibernate.c3p0.acquire_increment">2</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">100</prop>
<prop key="hibernate.c3p0.timeout">20</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.idle_test_period">60</prop>
</props>
</property>
</bean>
Hibernate.properties
jdbc.X
jdbc.driverClassName=org.apache.derby.jdbc.EmbeddedDriver
jdbc.url=jdbc:derby:${catalina.home}/FilterDB;create=true
jdbc.user=
jdbc.pass=
hibernate.X
hibernate.dialect=com…db.FixedDerbyDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
Thanks for advance!!!