Konfigurace pro provoz s více firmami.
This commit is contained in:
@@ -48,7 +48,7 @@ public class AppInitListener implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent evt) {
|
||||
Logger logger = LoggerFactory.getLogger(AppInitListener.class);
|
||||
/*Logger logger = LoggerFactory.getLogger(AppInitListener.class);
|
||||
logger.info("Initializing database");
|
||||
|
||||
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(evt.getServletContext());
|
||||
@@ -71,7 +71,7 @@ public class AppInitListener implements ServletContextListener {
|
||||
this.checkGlobalSettings();
|
||||
userService.removeAccess();
|
||||
|
||||
loadModuleReports();
|
||||
loadModuleReports();*/
|
||||
}
|
||||
|
||||
private void checkMUnits()
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider;
|
||||
|
||||
public class ClientConnectionPrivider implements MultiTenantConnectionProvider {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2142963179208004018L;
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
public ClientConnectionPrivider(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean isUnwrappableAs(Class unwrapType) {
|
||||
return ConnectionProvider.class.equals( unwrapType ) || MultiTenantConnectionProvider.class.equals( unwrapType ) || ClientConnectionPrivider.class.isAssignableFrom( unwrapType );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> unwrapType) {
|
||||
if ( isUnwrappableAs( unwrapType ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
else {
|
||||
throw new UnknownUnwrapTypeException( unwrapType );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getAnyConnection() throws SQLException {
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseAnyConnection(Connection connection) throws SQLException {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String tenantIdentifier)
|
||||
throws SQLException {
|
||||
|
||||
Connection con = getAnyConnection();
|
||||
try {
|
||||
con.createStatement().execute("SET schema '" + tenantIdentifier + "'");
|
||||
} catch ( SQLException e ) {
|
||||
throw new HibernateException("Could not alter JDBC connection to specified schema [" + tenantIdentifier + "]", e);
|
||||
}
|
||||
|
||||
return con;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseConnection(String tenantIdentifier, Connection connection)
|
||||
throws SQLException {
|
||||
releaseAnyConnection(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsAggressiveRelease() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class ClientResolver implements CurrentTenantIdentifierResolver {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
private static final String TOP_DOMAIN = "localhost"; // Bude se tahat z konfigurace...
|
||||
|
||||
@Override
|
||||
public String resolveCurrentTenantIdentifier() {
|
||||
String hostName = request.getServerName();
|
||||
String tenant = "";
|
||||
|
||||
if (hostName.contains(".")) {
|
||||
tenant = hostName.substring(0, hostName.indexOf("." + TOP_DOMAIN));
|
||||
}
|
||||
|
||||
if (tenant.isEmpty()) {
|
||||
tenant = "public";
|
||||
}
|
||||
|
||||
return tenant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateExistingCurrentSessions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class TripRequirement extends RequirementBase {
|
||||
private String to;
|
||||
@Column(name = "TRIP_DATE")
|
||||
private Date tripDate;
|
||||
@Column(name = "END")
|
||||
@Column(name = "TRIP_END")
|
||||
private String end;
|
||||
@Column(name = "END_DATE")
|
||||
private Date endDate;
|
||||
|
||||
@@ -17,7 +17,7 @@ import javax.persistence.Table;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
@Entity
|
||||
@Table(name="USER")
|
||||
@Table(name="USER_LOGIN")
|
||||
public class User extends Member implements UserDetails, DataModel {
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user