library upgrades
This commit is contained in:
50
src/main/java/de/jooqfaces/EJooqFacesApplicationScope.java
Normal file
50
src/main/java/de/jooqfaces/EJooqFacesApplicationScope.java
Normal file
@ -0,0 +1,50 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
public enum EJooqFacesApplicationScope {
|
||||
/**
|
||||
* jooqFacesUrl
|
||||
*/
|
||||
JOOQ_FACES_URL("jooqFacesUrl"),
|
||||
/**
|
||||
* jooqFacesDriver
|
||||
*/
|
||||
JOOQ_FACES_DRIVER("jooqFacesDriver"),
|
||||
/**
|
||||
* jooqFacesSqldialect
|
||||
*/
|
||||
JOOQ_FACES_SQLDIALECT("jooqFacesSqldialect"),
|
||||
/**
|
||||
* jooqFacesProperties
|
||||
*/
|
||||
JOOQ_FACES_PROPERTIES("jooqFacesProperties"),
|
||||
/**
|
||||
* jooqFacesConnectionPool
|
||||
*/
|
||||
JOOQ_FACES_CONNECTIONPOOL("jooqFacesConnectionPool"),
|
||||
/**
|
||||
* jooqFacesMaxPoolSize
|
||||
*/
|
||||
JOOQ_FACES_MAXPOOLSIZE("jooqFacesMaxPoolSize"),
|
||||
/**
|
||||
* jooqFacesParamAutocommit
|
||||
*/
|
||||
JOOQ_FACES_PARAM_AUTOCOMMIT("jooqFacesParamAutocommit");
|
||||
|
||||
private final String s;
|
||||
|
||||
private EJooqFacesApplicationScope(String s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public final String get() {
|
||||
return s;
|
||||
}
|
||||
}
|
24
src/main/java/de/jooqfaces/EJooqFacesConnectionPool.java
Normal file
24
src/main/java/de/jooqfaces/EJooqFacesConnectionPool.java
Normal file
@ -0,0 +1,24 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public enum EJooqFacesConnectionPool {
|
||||
CP_HIKARI("hikari");
|
||||
|
||||
private final String value;
|
||||
|
||||
private EJooqFacesConnectionPool(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static final String getHikari() {
|
||||
return CP_HIKARI.get();
|
||||
}
|
||||
}
|
20
src/main/java/de/jooqfaces/EJooqFacesSessionScope.java
Normal file
20
src/main/java/de/jooqfaces/EJooqFacesSessionScope.java
Normal file
@ -0,0 +1,20 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
public enum EJooqFacesSessionScope {
|
||||
CONNECTION("connection");
|
||||
|
||||
private final String value;
|
||||
|
||||
private EJooqFacesSessionScope(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String get() {
|
||||
return value;
|
||||
}
|
||||
}
|
350
src/main/java/de/jooqfaces/JooqFacesContext.java
Normal file
350
src/main/java/de/jooqfaces/JooqFacesContext.java
Normal file
@ -0,0 +1,350 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.faces.application.*;
|
||||
import javax.faces.application.FacesMessage.*;
|
||||
import javax.faces.component.*;
|
||||
import javax.faces.context.*;
|
||||
import javax.faces.render.*;
|
||||
import javax.servlet.*;
|
||||
import javax.sql.*;
|
||||
|
||||
import org.apache.logging.log4j.*;
|
||||
import org.jooq.*;
|
||||
import org.jooq.impl.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class JooqFacesContext extends FacesContext {
|
||||
private static final Logger LOGGER = LogManager.getLogger(JooqFacesContext.class);
|
||||
private FacesContext facesContext;
|
||||
private Connection connection;
|
||||
|
||||
public JooqFacesContext(FacesContext facesContext) {
|
||||
this.facesContext = facesContext;
|
||||
setCurrentInstance(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the jooq dsl context from the faces context session map<br />
|
||||
* <br />
|
||||
* <b>Always</b> call getJooq() within a <b>try-catch closure</b>, as the DSLContext is a closure; if not, your
|
||||
* connections might run out
|
||||
*
|
||||
* @return the jooq context
|
||||
* @throws ClassNotFoundException
|
||||
* on driver errors; check if you have attached the correct jdbc driver class
|
||||
* @throws SQLException
|
||||
* on sql errors
|
||||
*/
|
||||
public CloseableDSLContext getJooq() throws ClassNotFoundException, SQLException {
|
||||
ExternalContext externalContext = facesContext.getExternalContext();
|
||||
if (externalContext == null) {
|
||||
throw new JooqFacesException("external context of current faces context is null");
|
||||
}
|
||||
ServletContext servletContext = (ServletContext) externalContext.getContext();
|
||||
if (servletContext == null) {
|
||||
throw new JooqFacesException("servlet context of current faces context is null");
|
||||
}
|
||||
SQLDialect dialect = getSqlDialect(servletContext);
|
||||
createConnectionIfNull(externalContext, servletContext);
|
||||
return new DefaultCloseableDSLContext(new DefaultConnectionProvider(connection), dialect);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the database connection from the session map; if not found, create a new one and add it to the session map
|
||||
*
|
||||
* @param sessionMap
|
||||
* the session map
|
||||
* @param externalContext
|
||||
* the external context
|
||||
* @param servletContext
|
||||
* the servlet context
|
||||
* @return the connection
|
||||
* @throws ClassNotFoundException
|
||||
* on driver errors (e.g. missing jdbc lib)
|
||||
* @throws SQLException
|
||||
* on sql errors
|
||||
*/
|
||||
private void createConnectionIfNull(ExternalContext externalContext, ServletContext servletContext)
|
||||
throws ClassNotFoundException, SQLException {
|
||||
if (connection == null) { // caching the connection within the faces context makes it faster on the jsf life cycle
|
||||
Map<String, Object> sessionMap = externalContext.getSessionMap();
|
||||
if (sessionMap == null) {
|
||||
throw new JooqFacesException("session map of current faces context is null");
|
||||
}
|
||||
DataSource dataSource = (DataSource) sessionMap.get(EJooqFacesSessionScope.CONNECTION.get());
|
||||
if (dataSource == null || dataSource.getConnection() == null || dataSource.getConnection().isClosed()) {
|
||||
LOGGER.debug("creating new connection pool");
|
||||
dataSource = getDataSourceFromServletContext(servletContext);
|
||||
externalContext.getSessionMap().put(EJooqFacesSessionScope.CONNECTION.get(), dataSource);
|
||||
}
|
||||
connection = dataSource.getConnection();
|
||||
String autoCommit = servletContext.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_PARAM_AUTOCOMMIT.get());
|
||||
connection.setAutoCommit("true".equals(autoCommit)); // default false for postgreSQL, the database of my choice
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get data source from connection pool if defined in servlet context (see
|
||||
* EJooqFacesApplicationScope.CONNECTION_POOL); if not defined, return a plain data source
|
||||
*
|
||||
* @param servletContext
|
||||
* @return
|
||||
*/
|
||||
private static final DataSource getDataSourceFromServletContext(ServletContext servletContext)
|
||||
throws ClassNotFoundException {
|
||||
String driver = getDriver(servletContext);
|
||||
if (driver == null) {
|
||||
throw new JooqFacesException(
|
||||
"undefined driver in application scope, define it in your web.xml's context-param on name "
|
||||
+ EJooqFacesApplicationScope.JOOQ_FACES_DRIVER.get());
|
||||
}
|
||||
String url = getUrl(servletContext);
|
||||
if (url == null) {
|
||||
throw new JooqFacesException(
|
||||
"undefined connection data url in application scope, define it in your web.xml's context-param on name "
|
||||
+ EJooqFacesApplicationScope.JOOQ_FACES_URL.get());
|
||||
}
|
||||
Integer maxPoolSize = getMaxPoolSize(servletContext);
|
||||
if (maxPoolSize == null) {
|
||||
LOGGER.debug("maxPoolSize not set, setting it to 20");
|
||||
maxPoolSize = 20;
|
||||
}
|
||||
String connectionPool = getConnectionPool(servletContext);
|
||||
if (connectionPool == null) {
|
||||
LOGGER.warn(
|
||||
"no connection pool set in servlet context (see EJooqFacesApplicationScope.JOOQ_FACES_CONNECTIONPOOL), using plain connection");
|
||||
}
|
||||
return new PoollessDataSource(driver, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the connection from the servlet context
|
||||
*
|
||||
* @param servletContext
|
||||
* the servlet context
|
||||
* @return the connection
|
||||
* @throws ClassNotFoundException
|
||||
* on driver errors (e.g. missing jdbc lib)
|
||||
* @throws SQLException
|
||||
* on sql errors
|
||||
*/
|
||||
private static final Connection getConnectionFromServletContext(ServletContext servletContext)
|
||||
throws ClassNotFoundException, SQLException {
|
||||
DataSource dataSource = getDataSourceFromServletContext(servletContext);
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* get a jooq connection from servlet context (for such cases as the deployment phase where the faces context is still
|
||||
* not available)
|
||||
*
|
||||
* @param servletContext
|
||||
* the servlet context
|
||||
* @return a jooq connection
|
||||
* @throws ClassNotFoundException
|
||||
* on driver errors (e.g. missing jdbc lib)
|
||||
* @throws SQLException
|
||||
* on sql errors
|
||||
*/
|
||||
public static final DSLContext getJooqFromServletContext(ServletContext servletContext)
|
||||
throws ClassNotFoundException, SQLException {
|
||||
SQLDialect dialect = getSqlDialect(servletContext);
|
||||
Connection con = getConnectionFromServletContext(servletContext);
|
||||
return DSL.using(con, dialect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMessage(String clientId, FacesMessage message) {
|
||||
facesContext.addMessage(clientId, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Application getApplication() {
|
||||
return facesContext.getApplication();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<String> getClientIdsWithMessages() {
|
||||
return facesContext.getClientIdsWithMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalContext getExternalContext() {
|
||||
return facesContext.getExternalContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Severity getMaximumSeverity() {
|
||||
return facesContext.getMaximumSeverity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<FacesMessage> getMessages() {
|
||||
return facesContext.getMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<FacesMessage> getMessages(String clientId) {
|
||||
return facesContext.getMessages(clientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderKit getRenderKit() {
|
||||
return facesContext.getRenderKit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRenderResponse() {
|
||||
return facesContext.getRenderResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResponseComplete() {
|
||||
|
||||
return facesContext.getResponseComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseStream getResponseStream() {
|
||||
return facesContext.getResponseStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseWriter getResponseWriter() {
|
||||
return facesContext.getResponseWriter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UIViewRoot getViewRoot() {
|
||||
return facesContext.getViewRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
facesContext.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderResponse() {
|
||||
facesContext.renderResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void responseComplete() {
|
||||
facesContext.responseComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResponseStream(ResponseStream responseStream) {
|
||||
facesContext.setResponseStream(responseStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResponseWriter(ResponseWriter responseWriter) {
|
||||
facesContext.setResponseWriter(responseWriter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setViewRoot(UIViewRoot root) {
|
||||
facesContext.setViewRoot(root);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the connection pool from initial context
|
||||
*
|
||||
* @param servletContext
|
||||
* the context
|
||||
* @return the connection pool string or null
|
||||
*/
|
||||
private static final String getConnectionPool(ServletContext servletContext) {
|
||||
return servletContext.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_CONNECTIONPOOL.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* get the max pool size from initial context if any
|
||||
*
|
||||
* @param servletContext
|
||||
* the context of this function call
|
||||
* @return the max pool size or null
|
||||
*/
|
||||
private static final Integer getMaxPoolSize(ServletContext servletContext) {
|
||||
String maxPoolSize = servletContext.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_MAXPOOLSIZE.get());
|
||||
return maxPoolSize == null ? null : Integer.valueOf(maxPoolSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* get driver from initial context
|
||||
*
|
||||
* @param servletContext
|
||||
* the context of this function call
|
||||
* @return the parameter value of the jooq faces driver
|
||||
*/
|
||||
private static final String getDriver(ServletContext servletContext) {
|
||||
return servletContext.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_DRIVER.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* get driver connection url from initial context
|
||||
*
|
||||
* @param servletContext
|
||||
* the context of this function call
|
||||
* @return the parameter value of the jooq faces url
|
||||
*/
|
||||
private static final String getUrl(ServletContext servletContext) {
|
||||
return servletContext.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_URL.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* find jooq sql dialect class for dialectName
|
||||
*
|
||||
* @param dialectName
|
||||
* name of dialect
|
||||
* @return SQLDialect if found, null otherwise
|
||||
*/
|
||||
private static final SQLDialect findDialect(String dialectName) {
|
||||
if (dialectName == null) {
|
||||
LOGGER.error("Sql dialect name is null");
|
||||
return null;
|
||||
} else {
|
||||
for (SQLDialect dialect : SQLDialect.values()) {
|
||||
LOGGER.trace("Sql dialect comparing: dialectName={}, loopDialect={}", dialectName, dialect);
|
||||
if (dialectName.equalsIgnoreCase(dialect.name())) {
|
||||
LOGGER.debug("Sql dialect found: dialectName={}, foundDialect={}", dialectName, dialect);
|
||||
return dialect;
|
||||
}
|
||||
}
|
||||
LOGGER.error("Sql dialect not found: dialectName={}", dialectName);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get jooq sql dialect from initial context
|
||||
*
|
||||
* @param servletContext
|
||||
* the context of this function call
|
||||
* @return the dialect or null
|
||||
*/
|
||||
private static final SQLDialect getSqlDialect(ServletContext servletContext) {
|
||||
String dialectName = servletContext.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_SQLDIALECT.get());
|
||||
return getSqlDialect(dialectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* get sql dialect from name
|
||||
*
|
||||
* @param name
|
||||
* the dialect name
|
||||
* @return the dialect or null
|
||||
*/
|
||||
public static final SQLDialect getSqlDialect(String name) {
|
||||
return findDialect(name);
|
||||
}
|
||||
}
|
26
src/main/java/de/jooqfaces/JooqFacesContextFactory.java
Normal file
26
src/main/java/de/jooqfaces/JooqFacesContextFactory.java
Normal file
@ -0,0 +1,26 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
import javax.faces.*;
|
||||
import javax.faces.context.*;
|
||||
import javax.faces.lifecycle.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class JooqFacesContextFactory extends FacesContextFactory {
|
||||
|
||||
private FacesContextFactory facesContextFactory;
|
||||
|
||||
public JooqFacesContextFactory(FacesContextFactory facesContextFactory) {
|
||||
this.facesContextFactory = facesContextFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle)
|
||||
throws FacesException {
|
||||
FacesContext facesContext = facesContextFactory.getFacesContext(context, request, response, lifecycle);
|
||||
return new JooqFacesContext(facesContext);
|
||||
}
|
||||
}
|
18
src/main/java/de/jooqfaces/JooqFacesException.java
Normal file
18
src/main/java/de/jooqfaces/JooqFacesException.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class JooqFacesException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public JooqFacesException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JooqFacesException(Exception e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
72
src/main/java/de/jooqfaces/PoollessDataSource.java
Normal file
72
src/main/java/de/jooqfaces/PoollessDataSource.java
Normal file
@ -0,0 +1,72 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.logging.*;
|
||||
|
||||
import javax.sql.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class PoollessDataSource implements DataSource {
|
||||
|
||||
private final String driver;
|
||||
private final String url;
|
||||
|
||||
public PoollessDataSource(String driver, String url) {
|
||||
this.driver = driver;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getLogWriter() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoginTimeout() throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLogWriter(PrintWriter out) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginTimeout(int seconds) throws SQLException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName(driver);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new SQLException(e);
|
||||
}
|
||||
return DriverManager.getConnection(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
}
|
90
src/main/java/de/jooqfaces/PropertiesDeploymentListener.java
Normal file
90
src/main/java/de/jooqfaces/PropertiesDeploymentListener.java
Normal file
@ -0,0 +1,90 @@
|
||||
package de.jooqfaces;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;import javax.servlet.*;
|
||||
|
||||
import org.apache.logging.log4j.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
public class PropertiesDeploymentListener implements ServletContextListener {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(PropertiesDeploymentListener.class);
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
try {
|
||||
Enumeration<Driver> drivers = DriverManager.getDrivers();
|
||||
while (drivers.hasMoreElements()) {
|
||||
DriverManager.deregisterDriver(drivers.nextElement());
|
||||
}
|
||||
} catch (SQLException | SecurityException e) {
|
||||
LOGGER.error("Error deregistering drivers", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
try {
|
||||
ServletContext ctx = event.getServletContext();
|
||||
beforeInitialization(ctx);
|
||||
String propertiesFileName = (String) ctx.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_PROPERTIES.get());
|
||||
if (propertiesFileName == null) {
|
||||
throw new IOException(
|
||||
"undefined properties file name in application scope, define it in your web.xml's context-param on name "
|
||||
+ EJooqFacesApplicationScope.JOOQ_FACES_PROPERTIES.get());
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.load(new FileInputStream(propertiesFileName));
|
||||
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
|
||||
String key = (String) entry.getKey();
|
||||
String value = (String) entry.getValue();
|
||||
ctx.setInitParameter(key, value);
|
||||
}
|
||||
// ensure to have all needed parameters loaded
|
||||
if (ctx.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_SQLDIALECT.get()) == null) {
|
||||
throw new IOException("no " + EJooqFacesApplicationScope.JOOQ_FACES_SQLDIALECT.get()
|
||||
+ " defined in your properties file " + propertiesFileName);
|
||||
}
|
||||
if (ctx.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_URL.get()) == null) {
|
||||
throw new IOException("no " + EJooqFacesApplicationScope.JOOQ_FACES_URL.get() + " defined in your properties file "
|
||||
+ propertiesFileName);
|
||||
}
|
||||
if (ctx.getInitParameter(EJooqFacesApplicationScope.JOOQ_FACES_DRIVER.get()) == null) {
|
||||
throw new IOException("no " + EJooqFacesApplicationScope.JOOQ_FACES_DRIVER.get()
|
||||
+ " defined in your properties file " + propertiesFileName);
|
||||
}
|
||||
afterInitialization(ctx);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error loading needed parameters from properties file", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* executed directly after initialization if no exception is thrown
|
||||
*
|
||||
* @param ctx
|
||||
* the context to use
|
||||
* @throws IOException
|
||||
* for input output exceptions
|
||||
*/
|
||||
public void afterInitialization(ServletContext ctx) throws IOException {
|
||||
// to be implemented in extending classes
|
||||
}
|
||||
|
||||
/**
|
||||
* executed directly before initialization after getting the context from the servlet
|
||||
*
|
||||
* @param ctx
|
||||
* the context to use
|
||||
* @throws IOException
|
||||
* for input output exceptions
|
||||
*/
|
||||
public void beforeInitialization(ServletContext ctx) throws IOException {
|
||||
// to be implemented in extending classes
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ import java.sql.SQLException;
|
||||
|
||||
import javax.faces.application.FacesMessage;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.CloseableDSLContext;
|
||||
import org.jooq.TableLike;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -21,8 +21,8 @@ public class JooqGateway {
|
||||
this.facesContext = facesContext;
|
||||
}
|
||||
|
||||
public DSLContext getJooq() throws ClassNotFoundException, SQLException {
|
||||
return (DSLContext) facesContext.getJooq();
|
||||
public CloseableDSLContext getJooq() throws ClassNotFoundException, SQLException {
|
||||
return facesContext.getJooq();
|
||||
}
|
||||
|
||||
public void addToSessionMap(String key, Object value) {
|
||||
|
@ -9,7 +9,7 @@ import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.help.Pages;
|
||||
|
||||
/**
|
||||
|
@ -7,14 +7,14 @@ import java.sql.SQLException;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.CloseableDSLContext;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Record4;
|
||||
import org.jooq.SelectConditionStep;
|
||||
import org.jooq.UpdateConditionStep;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.db.profile.tables.records.TLoginRecord;
|
||||
|
||||
/**
|
||||
@ -40,7 +40,7 @@ public class SessionGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public boolean seekAndSetLogin(SessionBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<Record4<Integer, String, String, String>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(T_LOGIN.PK,
|
||||
@ -94,7 +94,7 @@ public class SessionGateway extends JooqGateway {
|
||||
throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
bean.setSecret(newPassword);
|
||||
String encryptedPassword = bean.getSecret();
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
UpdateConditionStep<TLoginRecord> sql = jooq
|
||||
// @formatter:off
|
||||
.update(T_LOGIN)
|
||||
|
@ -6,7 +6,7 @@ import javax.faces.application.FacesMessage;
|
||||
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -7,7 +7,7 @@ import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.help.Navigation;
|
||||
import de.jottyfan.timetrack.help.Pages;
|
||||
import de.jottyfan.timetrack.modules.ControlInterface;
|
||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.CloseableDSLContext;
|
||||
import org.jooq.DeleteConditionStep;
|
||||
import org.jooq.InsertValuesStep4;
|
||||
import org.jooq.Record1;
|
||||
@ -19,7 +19,7 @@ import org.jooq.UpdateConditionStep;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.db.contact.enums.EnumContacttype;
|
||||
import de.jottyfan.timetrack.db.contact.tables.records.TContactRecord;
|
||||
import de.jottyfan.timetrack.modules.JooqGateway;
|
||||
@ -45,7 +45,7 @@ public class ContactGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public List<ContactBean> getAll() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectJoinStep<Record5<Integer, String, String, String, EnumContacttype>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(T_CONTACT.PK,
|
||||
@ -81,7 +81,7 @@ public class ContactGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public Integer delete(Integer pk) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
DeleteConditionStep<TContactRecord> sql = jooq
|
||||
// @formatter:off
|
||||
.deleteFrom(T_CONTACT)
|
||||
@ -104,7 +104,7 @@ public class ContactGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public Integer add(ContactBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
InsertValuesStep4<TContactRecord, String, String, String, EnumContacttype> sql = jooq
|
||||
// @formatter:off
|
||||
.insertInto(T_CONTACT,
|
||||
@ -130,7 +130,7 @@ public class ContactGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public Integer update(ContactBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
UpdateConditionStep<TContactRecord> sql = jooq
|
||||
// @formatter:off
|
||||
.update(T_CONTACT)
|
||||
@ -154,7 +154,7 @@ public class ContactGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public Integer getAmount() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectJoinStep<Record1<Integer>> sql = jooq
|
||||
// @formatter:off
|
||||
.selectCount()
|
||||
|
@ -11,7 +11,7 @@ import javax.inject.Named;
|
||||
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.db.contact.enums.EnumContacttype;
|
||||
import de.jottyfan.timetrack.modules.Model;
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
package de.jottyfan.timetrack.modules.done;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@ -25,9 +23,11 @@ import de.jottyfan.timetrack.modules.Bean;
|
||||
public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final DateTimeFormatter hhmm = DateTimeFormatter.ofPattern("HH:mm");
|
||||
|
||||
private Integer pk;
|
||||
private Timestamp timeFrom;
|
||||
private Timestamp timeUntil;
|
||||
private LocalDateTime timeFrom;
|
||||
private LocalDateTime timeUntil;
|
||||
private TProjectRecord project;
|
||||
private TModuleRecord module;
|
||||
private TJobRecord activity;
|
||||
@ -55,27 +55,27 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
*/
|
||||
public void setDay(Date day) {
|
||||
if (timeFrom != null) {
|
||||
LocalDateTime ldt = timeFrom.toLocalDateTime();
|
||||
LocalDateTime ldt = timeFrom;
|
||||
LocalDate date = day.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
ldt = ldt.withYear(date.getYear()).withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth());
|
||||
timeFrom = Timestamp.from(ldt.toInstant(OffsetDateTime.now().getOffset()));
|
||||
timeFrom = ldt;
|
||||
}
|
||||
if (timeUntil != null) {
|
||||
LocalDateTime ldt = timeUntil.toLocalDateTime();
|
||||
LocalDateTime ldt = timeUntil;
|
||||
LocalDate date = day.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
ldt = ldt.withYear(date.getYear()).withMonth(date.getMonthValue()).withDayOfMonth(date.getDayOfMonth());
|
||||
timeUntil = Timestamp.from(ldt.toInstant(OffsetDateTime.now().getOffset()));
|
||||
timeUntil = ldt;
|
||||
}
|
||||
}
|
||||
|
||||
public String getTimeSummary() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (timeFrom != null) {
|
||||
buf.append(new SimpleDateFormat("HH:mm").format(timeFrom));
|
||||
buf.append(timeFrom.format(hhmm));
|
||||
}
|
||||
if (timeUntil != null) {
|
||||
buf.append(" - ");
|
||||
buf.append(new SimpleDateFormat("HH:mm").format(timeUntil));
|
||||
buf.append(timeUntil.format(hhmm));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
@ -86,8 +86,8 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
}
|
||||
|
||||
public String getTimeDiff() {
|
||||
LocalDateTime earlier = timeFrom != null ? timeFrom.toLocalDateTime() : LocalDateTime.now();
|
||||
LocalDateTime later = timeUntil != null ? timeUntil.toLocalDateTime() : LocalDateTime.now();
|
||||
LocalDateTime earlier = timeFrom != null ? timeFrom : LocalDateTime.now();
|
||||
LocalDateTime later = timeUntil != null ? timeUntil : LocalDateTime.now();
|
||||
Duration diff = Duration.between(earlier, later);
|
||||
return String.format("%02d:%02d", diff.toHours(), diff.toMinutes() % 60);
|
||||
}
|
||||
@ -143,21 +143,19 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
}
|
||||
|
||||
public String getTimeFromString() {
|
||||
return timeFrom == null ? "" : new SimpleDateFormat("HH:mm").format(timeFrom);
|
||||
return timeFrom == null ? "" : timeFrom.format(hhmm);
|
||||
}
|
||||
|
||||
public void setTimeFromString(String s) {
|
||||
LocalDateTime ldt = getLocalDateTimeFromHHmm(s, null); // use setDay instead
|
||||
this.timeFrom = ldt == null ? null : Timestamp.valueOf(ldt);
|
||||
this.timeFrom = getLocalDateTimeFromHHmm(s, null); // use setDay instead
|
||||
}
|
||||
|
||||
public String getTimeUntilString() {
|
||||
return timeUntil == null ? "" : new SimpleDateFormat("HH:mm").format(timeUntil);
|
||||
return timeUntil == null ? "" : timeUntil.format(hhmm);
|
||||
}
|
||||
|
||||
public void setTimeUntilString(String s) {
|
||||
LocalDateTime ldt = getLocalDateTimeFromHHmm(s, null); // use setDay instead
|
||||
this.timeUntil = ldt == null ? null : Timestamp.valueOf(ldt);
|
||||
this.timeUntil = getLocalDateTimeFromHHmm(s, null); // use setDay instead
|
||||
}
|
||||
|
||||
public Integer getPk() {
|
||||
@ -168,19 +166,19 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
|
||||
this.pk = pk;
|
||||
}
|
||||
|
||||
public Timestamp getTimeFrom() {
|
||||
public LocalDateTime getTimeFrom() {
|
||||
return timeFrom;
|
||||
}
|
||||
|
||||
public void setTimeFrom(Timestamp timeFrom) {
|
||||
public void setTimeFrom(LocalDateTime timeFrom) {
|
||||
this.timeFrom = timeFrom;
|
||||
}
|
||||
|
||||
public Timestamp getTimeUntil() {
|
||||
public LocalDateTime getTimeUntil() {
|
||||
return timeUntil;
|
||||
}
|
||||
|
||||
public void setTimeUntil(Timestamp timeUntil) {
|
||||
public void setTimeUntil(LocalDateTime timeUntil) {
|
||||
this.timeUntil = timeUntil;
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
package de.jottyfan.timetrack.modules.done;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.help.Navigation;
|
||||
import de.jottyfan.timetrack.help.Pages;
|
||||
import de.jottyfan.timetrack.modules.ControlInterface;
|
||||
@ -40,7 +39,7 @@ public class DoneControl extends Navigation implements ControlInterface, Seriali
|
||||
|
||||
public String toAdd() {
|
||||
DoneBean bean = new DoneBean();
|
||||
bean.setTimeFrom(getCurrentDate());
|
||||
bean.setTimeFrom(LocalDateTime.now());
|
||||
model.setBean(bean);
|
||||
boolean ready = model.loadDefaults((JooqFacesContext) FacesContext.getCurrentInstance());
|
||||
return ready ? navigateTo(Pages.DONE_ADD) : toList();
|
||||
@ -83,10 +82,7 @@ public class DoneControl extends Navigation implements ControlInterface, Seriali
|
||||
}
|
||||
|
||||
public String getCurrentTimeAsString() {
|
||||
return new SimpleDateFormat("HH:mm:ss").format(getCurrentDate());
|
||||
}
|
||||
|
||||
public Timestamp getCurrentDate() {
|
||||
return Timestamp.valueOf(LocalDateTime.now());
|
||||
DateTimeFormatter hhmmss = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
return LocalDateTime.now().format(hhmmss);
|
||||
}
|
||||
}
|
||||
|
@ -9,19 +9,21 @@ import static de.jottyfan.timetrack.db.done.Tables.V_TOTALOFDAY;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.V_WORKTIME;
|
||||
import static de.jottyfan.timetrack.db.profile.Tables.T_LOGIN;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.CloseableDSLContext;
|
||||
import org.jooq.DeleteConditionStep;
|
||||
import org.jooq.InsertValuesStep7;
|
||||
import org.jooq.Record;
|
||||
@ -35,7 +37,7 @@ import org.jooq.SelectWhereStep;
|
||||
import org.jooq.UpdateConditionStep;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TDoneRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TJobRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
||||
@ -67,7 +69,7 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public List<TModuleRecord> getAllModules() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
List<TModuleRecord> list = new ArrayList<>();
|
||||
SelectWhereStep<TModuleRecord> sql = jooq.selectFrom(T_MODULE);
|
||||
LOGGER.debug(sql.toString());
|
||||
@ -88,7 +90,7 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public List<TJobRecord> getAllActivities() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
List<TJobRecord> list = new ArrayList<>();
|
||||
SelectWhereStep<TJobRecord> sql = jooq.selectFrom(T_JOB);
|
||||
LOGGER.debug(sql.toString());
|
||||
@ -109,7 +111,7 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public List<TProjectRecord> getAllProjects() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
List<TProjectRecord> list = new ArrayList<>();
|
||||
SelectWhereStep<TProjectRecord> sql = jooq.selectFrom(T_PROJECT);
|
||||
LOGGER.debug(sql.toString());
|
||||
@ -168,17 +170,17 @@ public class DoneGateway extends JooqGateway {
|
||||
LocalDateTime tomorrow = day.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
|
||||
|
||||
List<DoneBean> list = new ArrayList<>();
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<TDoneRecord> sql = getJooq()
|
||||
// @formatter:off
|
||||
.selectFrom(T_DONE)
|
||||
.where(T_DONE.FK_LOGIN.eq(getFkLogin()))
|
||||
.and(T_DONE.TIME_FROM.isNull()
|
||||
.or(T_DONE.TIME_FROM.greaterThan(Timestamp.valueOf(yesterday))
|
||||
.and(T_DONE.TIME_FROM.lessThan(Timestamp.valueOf(tomorrow)))))
|
||||
.or(T_DONE.TIME_FROM.greaterThan(yesterday)
|
||||
.and(T_DONE.TIME_FROM.lessThan(tomorrow))))
|
||||
.and(T_DONE.TIME_UNTIL.isNull()
|
||||
.or(T_DONE.TIME_UNTIL.lessThan(Timestamp.valueOf(tomorrow))
|
||||
.and(T_DONE.TIME_UNTIL.greaterThan(Timestamp.valueOf(yesterday)))));
|
||||
.or(T_DONE.TIME_UNTIL.lessThan(tomorrow)
|
||||
.and(T_DONE.TIME_UNTIL.greaterThan(yesterday))));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
for (TDoneRecord r : sql.fetch()) {
|
||||
@ -202,8 +204,8 @@ public class DoneGateway extends JooqGateway {
|
||||
Integer fkJob = bean.getActivity() == null ? null : bean.getActivity().getPk();
|
||||
Integer fkLogin = getFkLogin();
|
||||
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
InsertValuesStep7<TDoneRecord, Timestamp, Timestamp, Integer, Integer, Integer, String, Integer> sql = jooq
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
InsertValuesStep7<TDoneRecord, LocalDateTime, LocalDateTime, Integer, Integer, Integer, String, Integer> sql = jooq
|
||||
// @formatter:off
|
||||
.insertInto(T_DONE,
|
||||
T_DONE.TIME_FROM,
|
||||
@ -228,7 +230,7 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public void update(DoneBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
UpdateConditionStep<TDoneRecord> sql = jooq
|
||||
// @formatter:off
|
||||
.update(T_DONE)
|
||||
@ -253,7 +255,7 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public void delete(DoneBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
DeleteConditionStep<TDoneRecord> sql = jooq.deleteFrom(T_DONE).where(T_DONE.PK.eq(bean.getPk()));
|
||||
LOGGER.debug(sql.toString());
|
||||
sql.execute();
|
||||
@ -271,7 +273,7 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public WholeDaySummaryBean getDaySummary(java.util.Date day) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<Record4<String, String, String, String>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(V_TOTALOFDAY.STARTTIME,
|
||||
@ -306,7 +308,7 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public List<DailySummaryBean> getAllJobs(java.util.Date day) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<Record6<String, Double, String, String, String, String>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(V_WORKTIME.DURATION,
|
||||
@ -343,8 +345,8 @@ public class DoneGateway extends JooqGateway {
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public String getAllCalendarEvents() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<Record6<Timestamp, Timestamp, String, String, String, String>> sql = jooq
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<Record6<LocalDateTime, LocalDateTime, String, String, String, String>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(T_DONE.TIME_FROM,
|
||||
T_DONE.TIME_UNTIL,
|
||||
@ -365,8 +367,8 @@ public class DoneGateway extends JooqGateway {
|
||||
String moduleName = r.get(T_MODULE.NAME);
|
||||
String jobName = r.get(T_JOB.NAME);
|
||||
String wp = r.get(T_DONE.WP);
|
||||
java.util.Date timeFrom = r.get(T_DONE.TIME_FROM);
|
||||
java.util.Date timeUntil = r.get(T_DONE.TIME_UNTIL);
|
||||
LocalDateTime timeFrom = r.get(T_DONE.TIME_FROM);
|
||||
LocalDateTime timeUntil = r.get(T_DONE.TIME_UNTIL);
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(projectName);
|
||||
@ -378,14 +380,15 @@ public class DoneGateway extends JooqGateway {
|
||||
buf.append(": ");
|
||||
buf.append(jobName);
|
||||
|
||||
FullCalendarEventBean bean = new FullCalendarEventBean(buf.toString(), timeFrom) {
|
||||
FullCalendarEventBean bean = new FullCalendarEventBean(buf.toString(), java.util.Date.from(timeFrom.atZone(ZoneId.systemDefault()).toInstant())) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void addExtendedFields(StringBuilder buf) {
|
||||
}
|
||||
};
|
||||
bean.setEnd(timeUntil);
|
||||
Date endDate = timeUntil == null ? null : Date.from(timeUntil.atZone(ZoneId.systemDefault()).toInstant());
|
||||
bean.setEnd(endDate);
|
||||
bean.setColor(new RgbColor().determineRgbColor(projectName, moduleName, jobName));
|
||||
list.getList().add(bean);
|
||||
}
|
||||
@ -395,7 +398,7 @@ public class DoneGateway extends JooqGateway {
|
||||
|
||||
public List<UserBean> getAllUsers() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
List<UserBean> list = new ArrayList<>();
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectJoinStep<Record3<String, String, String>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(T_LOGIN.LOGIN,
|
||||
@ -416,8 +419,8 @@ public class DoneGateway extends JooqGateway {
|
||||
|
||||
public String download(DownloadBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<Record5<Date, String, String, String, String>> sql = jooq
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectConditionStep<Record5<LocalDate, String, String, String, String>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(V_HAMSTERSUMMARY.WORKDAY,
|
||||
V_HAMSTERSUMMARY.DURATION,
|
||||
@ -426,14 +429,15 @@ public class DoneGateway extends JooqGateway {
|
||||
V_HAMSTERSUMMARY.JOB_NAME)
|
||||
.from(V_HAMSTERSUMMARY)
|
||||
.where(V_HAMSTERSUMMARY.LOGIN.eq(bean.getUsername()))
|
||||
.and(V_HAMSTERSUMMARY.WORKDAY.le(Date.valueOf(bean.getUntilDate()))
|
||||
.and(V_HAMSTERSUMMARY.WORKDAY.ge(Date.valueOf(bean.getFromDate()))));
|
||||
.and(V_HAMSTERSUMMARY.WORKDAY.le(bean.getUntilDate())
|
||||
.and(V_HAMSTERSUMMARY.WORKDAY.ge(bean.getFromDate())));
|
||||
// @formatter:on
|
||||
LOGGER.debug(sql.toString());
|
||||
String sep = ";";
|
||||
buf.append("day").append(sep).append("duration").append(sep).append("project").append(sep).append("module").append(sep).append("activity\n");
|
||||
for (Record r : sql.fetch()) {
|
||||
String date = new SimpleDateFormat("dd.MM.yyyy").format(r.get(V_HAMSTERSUMMARY.WORKDAY));
|
||||
LocalDate workday = r.get(V_HAMSTERSUMMARY.WORKDAY);
|
||||
String date = workday.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"));
|
||||
buf.append(date).append(sep);
|
||||
buf.append(r.get(V_HAMSTERSUMMARY.DURATION)).append(sep);
|
||||
buf.append(r.get(V_HAMSTERSUMMARY.PROJECT_NAME)).append(sep);
|
||||
|
@ -20,7 +20,7 @@ import javax.inject.Named;
|
||||
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TJobRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
|
||||
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package de.jottyfan.timetrack.modules.note;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import de.jottyfan.timetrack.db.note.enums.EnumCategory;
|
||||
import de.jottyfan.timetrack.db.note.enums.EnumNotetype;
|
||||
@ -21,7 +21,7 @@ public class NoteBean implements Bean, Serializable
|
||||
private EnumCategory category;
|
||||
private EnumNotetype type;
|
||||
private String content;
|
||||
private Date lastchange;
|
||||
private LocalDateTime lastchange;
|
||||
|
||||
public NoteBean(Integer pk)
|
||||
{
|
||||
@ -69,12 +69,12 @@ public class NoteBean implements Bean, Serializable
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Date getLastchange()
|
||||
public LocalDateTime getLastchange()
|
||||
{
|
||||
return lastchange;
|
||||
}
|
||||
|
||||
public void setLastchange(Date lastchange)
|
||||
public void setLastchange(LocalDateTime lastchange)
|
||||
{
|
||||
this.lastchange = lastchange;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.help.Navigation;
|
||||
import de.jottyfan.timetrack.help.Pages;
|
||||
import de.jottyfan.timetrack.modules.ControlInterface;
|
||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.CloseableDSLContext;
|
||||
import org.jooq.DeleteConditionStep;
|
||||
import org.jooq.InsertValuesStep4;
|
||||
import org.jooq.Record;
|
||||
@ -16,7 +16,7 @@ import org.jooq.SelectJoinStep;
|
||||
import org.jooq.UpdateConditionStep;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.db.note.enums.EnumCategory;
|
||||
import de.jottyfan.timetrack.db.note.enums.EnumNotetype;
|
||||
import de.jottyfan.timetrack.db.note.tables.records.TNoteRecord;
|
||||
@ -44,7 +44,7 @@ public class NoteGateway extends JooqGateway {
|
||||
* @returns amount of affected rows in db
|
||||
*/
|
||||
public void insert(NoteBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
InsertValuesStep4<TNoteRecord, String, EnumCategory, EnumNotetype, String> sql = jooq
|
||||
// @formatter:off
|
||||
.insertInto(T_NOTE,
|
||||
@ -68,7 +68,7 @@ public class NoteGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public void update(NoteBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
UpdateConditionStep<TNoteRecord> sql = jooq
|
||||
// @formatter:off
|
||||
.update(T_NOTE)
|
||||
@ -90,7 +90,7 @@ public class NoteGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public void delete(Integer pk) throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
DeleteConditionStep<TNoteRecord> sql = jooq.deleteFrom(T_NOTE).where(T_NOTE.PK.eq(pk));
|
||||
LOGGER.debug(sql.toString());
|
||||
sql.execute();
|
||||
@ -106,7 +106,7 @@ public class NoteGateway extends JooqGateway {
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public List<NoteBean> getAll() throws DataAccessException, ClassNotFoundException, SQLException {
|
||||
try (DSLContext jooq = getJooq()) {
|
||||
try (CloseableDSLContext jooq = getJooq()) {
|
||||
SelectJoinStep<Record> sql = jooq.select().from(T_NOTE);
|
||||
LOGGER.debug(sql.toString());
|
||||
List<NoteBean> list = new ArrayList<>();
|
||||
|
@ -10,7 +10,7 @@ import javax.inject.Named;
|
||||
|
||||
import org.jooq.exception.DataAccessException;
|
||||
|
||||
import de.jooqFaces.JooqFacesContext;
|
||||
import de.jooqfaces.JooqFacesContext;
|
||||
import de.jottyfan.timetrack.db.note.Tables;
|
||||
import de.jottyfan.timetrack.modules.Model;
|
||||
|
||||
|
Reference in New Issue
Block a user