logConfiguratorsConfigImpl = new ArrayList<>();
- ServiceLoader.load(LogConfigurator.class).forEach(logConfiguratorsConfigImpl::add);
-
- if (loggerImpl.isEmpty() || loggerImpl.size() > 1) {
- throw new IllegalArgumentException(
- " Please provide exactly one implementation " +
- " of class com.kumuluz.ee.logs.Logger");
- }
-
- if (logCommonsImpl.isEmpty() || logCommonsImpl.size() > 1) {
- throw new IllegalArgumentException(" Please provide exactly one implementation " +
- "of class com.kumuluz.ee.logs.LogCommons");
- }
-
- if (logConfiguratorsConfigImpl.isEmpty() || logConfiguratorsConfigImpl.size() > 1) {
- throw new IllegalArgumentException(" Please provide exactly one implementation " +
- "of class com.kumuluz.ee.logs.LogConfigurator");
- }
-
- loggerInstance = loggerImpl.get(0);
- logCommonsInstance = logCommonsImpl.get(0);
- logConfigurator = logConfiguratorsConfigImpl.get(0);
- }
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/Logger.java b/common/src/main/java/com/kumuluz/ee/logs/Logger.java
deleted file mode 100644
index 88b8e989..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/Logger.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
- * and other contributors as indicated by the @author tags and
- * the contributor list.
- *
- * Licensed under the MIT License (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/MIT
- *
- * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
- * implied, including but not limited to the warranties of merchantability,
- * fitness for a particular purpose and noninfringement. in no event shall the
- * authors or copyright holders be liable for any claim, damages or other
- * liability, whether in an action of contract, tort or otherwise, arising from,
- * out of or in connection with the software or the use or other dealings in the
- * software. See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package com.kumuluz.ee.logs;
-
-import com.kumuluz.ee.logs.enums.LogLevel;
-import com.kumuluz.ee.logs.messages.LogMessage;
-
-/**
- * Kumuluz-logs logger interface
- *
- * @author Rok Povse
- * @author Marko Skrjanec
- */
-public interface Logger {
-
- Logger getLogger(String logName);
-
- String getName();
-
- void log(LogLevel level, String message);
-
- void log(LogLevel level, String message, Object... args);
-
- void log(LogLevel level, String message, Throwable thrown);
-
- void log(LogLevel level, Throwable thrown);
-
- void log(LogLevel level, LogMessage message);
-
- void log(LogLevel level, LogMessage message, Throwable thrown);
-
- void trace(String message);
-
- void trace(String message, Object... args);
-
- void trace(String message, Throwable thrown);
-
- void trace(Throwable thrown);
-
- void trace(LogMessage message);
-
- void trace(LogMessage message, Throwable thrown);
-
- void info(String message);
-
- void info(String message, Object... args);
-
- void info(String message, Throwable thrown);
-
- void info(Throwable thrown);
-
- void info(LogMessage message);
-
- void info(LogMessage message, Throwable thrown);
-
- void debug(String message);
-
- void debug(String message, Object... args);
-
- void debug(String message, Throwable thrown);
-
- void debug(Throwable thrown);
-
- void debug(LogMessage message);
-
- void debug(LogMessage message, Throwable thrown);
-
- void warn(String message);
-
- void warn(String message, Object... args);
-
- void warn(String message, Throwable thrown);
-
- void warn(Throwable thrown);
-
- void warn(LogMessage message);
-
- void warn(LogMessage message, Throwable thrown);
-
- void error(String message);
-
- void error(String message, Object... args);
-
- void error(String message, Throwable thrown);
-
- void error(Throwable thrown);
-
- void error(LogMessage message);
-
- void error(LogMessage message, Throwable thrown);
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilConsoleHandler.java b/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilConsoleHandler.java
new file mode 100644
index 00000000..d66b7fcb
--- /dev/null
+++ b/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilConsoleHandler.java
@@ -0,0 +1,48 @@
+package com.kumuluz.ee.logs.impl;
+
+import java.io.UnsupportedEncodingException;
+import java.util.logging.*;
+
+public class JavaUtilConsoleHandler extends StreamHandler {
+
+ /**
+ * Create a JavaUtilConsoleHandler for System.out.
+ */
+ public JavaUtilConsoleHandler() {
+
+ setLevel(Level.INFO);
+ setFormatter(new JavaUtilFormatter());
+ setOutputStream(System.out);
+
+ try {
+ setEncoding(null);
+ } catch (UnsupportedEncodingException ignored) {
+ }
+ }
+
+ /**
+ * Publish a LogRecord.
+ *
+ * The logging request was made initially to a Logger object,
+ * which initialized the LogRecord and forwarded it here.
+ *
+ * @param record description of the log event. A null record is
+ * silently ignored and is not published
+ */
+ @Override
+ public void publish(LogRecord record) {
+ super.publish(record);
+
+ flush();
+ }
+
+ /**
+ * Override StreamHandler.close to do a flush but not
+ * to close the output stream. That is, we do not
+ * close System.out.
+ */
+ @Override
+ public void close() {
+ flush();
+ }
+}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilDefaultLogConfigurator.java b/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilDefaultLogConfigurator.java
new file mode 100644
index 00000000..f340f229
--- /dev/null
+++ b/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilDefaultLogConfigurator.java
@@ -0,0 +1,44 @@
+package com.kumuluz.ee.logs.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.logging.*;
+
+public class JavaUtilDefaultLogConfigurator {
+
+ public static void init() {
+
+ String javaUtilConfig = System.getProperty("java.util.logging.config.file");
+
+ if (javaUtilConfig == null) {
+
+ LogManager.getLogManager().reset();
+
+ Logger rootLogger = LogManager.getLogManager().getLogger("");
+
+ JavaUtilConsoleHandler handler = new JavaUtilConsoleHandler();
+
+ rootLogger.addHandler(handler);
+ } else {
+
+ InputStream javaUtilConfigStream = JavaUtilDefaultLogConfigurator.class.getClassLoader()
+ .getResourceAsStream(javaUtilConfig);
+
+ if (javaUtilConfigStream != null) {
+
+ try {
+ LogManager.getLogManager().readConfiguration(javaUtilConfigStream);
+ } catch (IOException ignored) {
+ }
+ }
+ }
+ }
+
+ public static void initSoleHandler(Handler handler) {
+
+ LogManager.getLogManager().reset();
+
+ Logger rootLogger = LogManager.getLogManager().getLogger("");
+ rootLogger.addHandler(handler);
+ }
+}
\ No newline at end of file
diff --git a/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilFormatter.java b/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilFormatter.java
new file mode 100644
index 00000000..4a658b10
--- /dev/null
+++ b/common/src/main/java/com/kumuluz/ee/logs/impl/JavaUtilFormatter.java
@@ -0,0 +1,41 @@
+package com.kumuluz.ee.logs.impl;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+public class JavaUtilFormatter extends Formatter {
+
+ private static final DateTimeFormatter timestampFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
+
+ @Override
+ public String format(LogRecord record) {
+
+ ZonedDateTime zonedDateTime = Instant.ofEpochMilli(record.getMillis()).atZone(ZoneId.systemDefault());
+
+ String source = record.getSourceClassName() != null ? record.getSourceClassName() : record.getLoggerName();
+ String message = formatMessage(record);
+ String throwable = "";
+
+ if (record.getThrown() != null) {
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ pw.println();
+ record.getThrown().printStackTrace(pw);
+ pw.close();
+ throwable = sw.toString();
+ }
+
+ return zonedDateTime.format(timestampFormat) + " " +
+ record.getLevel().getName() + " -- " +
+ source + " -- " +
+ message + throwable + "\n";
+ }
+}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/messages/ResourceInvokeEndLogMessage.java b/common/src/main/java/com/kumuluz/ee/logs/messages/ResourceInvokeEndLogMessage.java
deleted file mode 100644
index a7c2c821..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/messages/ResourceInvokeEndLogMessage.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
- * and other contributors as indicated by the @author tags and
- * the contributor list.
- *
- * Licensed under the MIT License (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/MIT
- *
- * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
- * implied, including but not limited to the warranties of merchantability,
- * fitness for a particular purpose and noninfringement. in no event shall the
- * authors or copyright holders be liable for any claim, damages or other
- * liability, whether in an action of contract, tort or otherwise, arising from,
- * out of or in connection with the software or the use or other dealings in the
- * software. See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package com.kumuluz.ee.logs.messages;
-
-/**
- * @author Rok Povse
- * @author Marko Skrjanec
- */
-public interface ResourceInvokeEndLogMessage extends LogMessage {
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/messages/ResourceInvokeLogMessage.java b/common/src/main/java/com/kumuluz/ee/logs/messages/ResourceInvokeLogMessage.java
deleted file mode 100644
index be6ece71..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/messages/ResourceInvokeLogMessage.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
- * and other contributors as indicated by the @author tags and
- * the contributor list.
- *
- * Licensed under the MIT License (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://opensource.org/licenses/MIT
- *
- * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
- * implied, including but not limited to the warranties of merchantability,
- * fitness for a particular purpose and noninfringement. in no event shall the
- * authors or copyright holders be liable for any claim, damages or other
- * liability, whether in an action of contract, tort or otherwise, arising from,
- * out of or in connection with the software or the use or other dealings in the
- * software. See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package com.kumuluz.ee.logs.messages;
-
-/**
- * @author Rok Povse
- * @author Marko Skrjanec
- */
-public interface ResourceInvokeLogMessage extends LogMessage {
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/types/LogMethodContext.java b/common/src/main/java/com/kumuluz/ee/logs/types/LogMethodContext.java
deleted file mode 100644
index 627d7e5a..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/types/LogMethodContext.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.kumuluz.ee.logs.types;
-
-import com.kumuluz.ee.logs.enums.LogLevel;
-import com.kumuluz.ee.logs.markers.Marker;
-import com.kumuluz.ee.logs.messages.MethodCallExitLogMessage;
-import com.kumuluz.ee.logs.messages.MethodCallLogMessage;
-
-/**
- * @author Tilen Faganel
- */
-public class LogMethodContext {
-
- private LogLevel level;
- private Marker marker;
-
- private Boolean callEnabled;
- private Boolean metricsEnabled;
-
- private MethodCallLogMessage callMessage;
-
- private MethodCallExitLogMessage callExitMessage;
- private LogMetrics logMetrics;
-
- public LogMethodContext(LogMethodMessage entryMessage, LogLevel level, Marker marker) {
-
- this.callEnabled = entryMessage.isCallEnabled();
- this.metricsEnabled = entryMessage.isMetricsEnabled();
-
- if (this.metricsEnabled != null && this.metricsEnabled) {
- this.logMetrics = new LogMetrics();
- }
-
- this.callMessage = entryMessage.getCallMessage();
-
- this.level = level;
-
- this.marker = marker;
- }
-
- public LogMethodContext(LogMethodMessage entryMessage, LogLevel level) {
- this(entryMessage,level,null);
- }
-
- public Boolean isCallEnabled() {
- return callEnabled;
- }
-
- public Boolean isMetricsEnabled() {
- return metricsEnabled;
- }
-
- public MethodCallLogMessage getCallMessage() {
- return callMessage;
- }
-
- public MethodCallExitLogMessage getCallExitMessage() {
- return callExitMessage;
- }
-
- public void setCallExitMessage(MethodCallExitLogMessage callExitMessage) {
- this.callExitMessage = callExitMessage;
- }
-
- public LogLevel getLevel() {
- return level;
- }
-
- public LogMetrics getLogMetrics() {
- return logMetrics;
- }
-
- public Marker getMarker() {
- return marker;
- }
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/types/LogMethodMessage.java b/common/src/main/java/com/kumuluz/ee/logs/types/LogMethodMessage.java
deleted file mode 100644
index 3d4f60fa..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/types/LogMethodMessage.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.kumuluz.ee.logs.types;
-
-import com.kumuluz.ee.logs.messages.MethodCallLogMessage;
-
-/**
- * @author Tilen Faganel
- */
-public class LogMethodMessage {
-
- private Boolean callEnabled;
- private Boolean metricsEnabled;
-
- private MethodCallLogMessage callMessage;
-
- public LogMethodMessage enableCall(MethodCallLogMessage callMessage) {
- this.callMessage = callMessage;
- this.callEnabled = true;
-
- return this;
- }
-
- public LogMethodMessage enableMetrics() {
- this.metricsEnabled = true;
-
- return this;
- }
-
- public Boolean isCallEnabled() {
- return callEnabled;
- }
-
- public Boolean isMetricsEnabled() {
- return metricsEnabled;
- }
-
- public MethodCallLogMessage getCallMessage() {
- return callMessage;
- }
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/types/LogMetrics.java b/common/src/main/java/com/kumuluz/ee/logs/types/LogMetrics.java
deleted file mode 100644
index c8397768..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/types/LogMetrics.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Copyright (c) Sunesis d.o.o.
- */
-package com.kumuluz.ee.logs.types;
-
-/**
- * Kumuluz-logs logger interface
- *
- * @author Rok Povse
- * @author Marko Skrjanec
- */
-public class LogMetrics {
-
- private Long timerStart;
-
- public LogMetrics() {
- this.timerStart = System.currentTimeMillis();
- }
-
- public Long getTimeElapsed() {
- return System.currentTimeMillis()-this.timerStart;
- }
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/types/LogResourceContext.java b/common/src/main/java/com/kumuluz/ee/logs/types/LogResourceContext.java
deleted file mode 100644
index a3d4635f..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/types/LogResourceContext.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Copyright (c) Sunesis d.o.o.
- */
-package com.kumuluz.ee.logs.types;
-
-import com.kumuluz.ee.logs.enums.LogLevel;
-import com.kumuluz.ee.logs.markers.Marker;
-import com.kumuluz.ee.logs.messages.ResourceInvokeEndLogMessage;
-import com.kumuluz.ee.logs.messages.ResourceInvokeLogMessage;
-
-/**
- * @author Tilen Faganel
- */
-public class LogResourceContext {
-
- private LogLevel level;
- private Marker marker;
-
- private Boolean invokeEnabled;
- private Boolean metricsEnabled;
-
- private ResourceInvokeLogMessage invokeMessage;
-
- private ResourceInvokeEndLogMessage invokeEndMessage;
- private LogMetrics logMetrics;
-
- public LogResourceContext(LogResourceMessage resourceMessage, LogLevel level, Marker marker) {
- this.invokeEnabled = resourceMessage.isInvokeEnabled();
- this.metricsEnabled = resourceMessage.isMetricsEnabled();
-
- if (this.metricsEnabled != null && this.metricsEnabled) {
- this.logMetrics = new LogMetrics();
- }
-
- this.invokeMessage = resourceMessage.getInvokeMessage();
-
- this.level = level;
- this.marker = marker;
- }
-
- public Boolean isInvokeEnabled() {
- return invokeEnabled;
- }
-
- public Boolean isMetricsEnabled() {
- return metricsEnabled;
- }
-
- public ResourceInvokeLogMessage getInvokeMessage() {
- return invokeMessage;
- }
-
- public ResourceInvokeEndLogMessage getInvokeEndMessage() {
- return invokeEndMessage;
- }
-
- public void setInvokeEndMessage(ResourceInvokeEndLogMessage invokeEndMessage) {
- this.invokeEndMessage = invokeEndMessage;
- }
-
- public LogLevel getLevel() {
- return level;
- }
-
- public Marker getMarker() {
- return marker;
- }
-
- public LogMetrics getLogMetrics() {
- return logMetrics;
- }
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/types/LogResourceMessage.java b/common/src/main/java/com/kumuluz/ee/logs/types/LogResourceMessage.java
deleted file mode 100644
index 4676c309..00000000
--- a/common/src/main/java/com/kumuluz/ee/logs/types/LogResourceMessage.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Copyright (c) Sunesis d.o.o.
- */
-package com.kumuluz.ee.logs.types;
-
-
-import com.kumuluz.ee.logs.messages.ResourceInvokeLogMessage;
-
-/**
- * @author Tilen Faganel
- */
-public class LogResourceMessage {
-
- private Boolean invokeEnabled;
- private Boolean metricsEnabled;
-
- private ResourceInvokeLogMessage invokeMessage;
-
- public LogResourceMessage enableInvoke(ResourceInvokeLogMessage invokeMessage) {
- this.invokeMessage = invokeMessage;
- this.invokeEnabled = true;
-
- return this;
- }
-
- public LogResourceMessage enableMetrics() {
- this.metricsEnabled = true;
-
- return this;
- }
-
- public Boolean isInvokeEnabled() {
- return invokeEnabled;
- }
-
- public Boolean isMetricsEnabled() {
- return metricsEnabled;
- }
-
- public ResourceInvokeLogMessage getInvokeMessage() {
- return invokeMessage;
- }
-}
diff --git a/common/src/main/resources/version.properties b/common/src/main/resources/META-INF/kumuluzee/versions.properties
similarity index 100%
rename from common/src/main/resources/version.properties
rename to common/src/main/resources/META-INF/kumuluzee/versions.properties
diff --git a/components/bean-validation/hibernate-validator/pom.xml b/components/bean-validation/hibernate-validator/pom.xml
index 7331289e..a63dd5da 100644
--- a/components/bean-validation/hibernate-validator/pom.xml
+++ b/components/bean-validation/hibernate-validator/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-bean-validation
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
@@ -14,10 +14,6 @@
KumuluzEE Bean Validation Hibernate Validator
KumuluzEE Bean Validation component implemented by Hibernate Validator
-
- 5.3.3.Final
-
-
com.kumuluz.ee
@@ -33,6 +29,52 @@
org.hibernate
hibernate-validator
${hibernate.validator.version}
+
+
+ org.jboss.logging
+ jboss-logging
+
+
+
+
+ org.jboss.logging
+ jboss-logging
+
+
+
+ org.glassfish.jersey.ext
+ jersey-bean-validation
+ ${jersey.version}
+
+
+ org.glassfish.hk2.external
+ javax.inject
+
+
+ org.glassfish.jersey.core
+ jersey-common
+
+
+ org.glassfish.jersey.core
+ jersey-server
+
+
+ javax.validation
+ validation-api
+
+
+ org.hibernate
+ hibernate-validator
+
+
+ javax.el
+ javax.el-api
+
+
+ org.glassfish.web
+ javax.el
+
+
diff --git a/components/bean-validation/hibernate-validator/src/main/java/com/kumuluz/ee/beanvalidation/BeanValidationComponent.java b/components/bean-validation/hibernate-validator/src/main/java/com/kumuluz/ee/beanvalidation/BeanValidationComponent.java
index 1bf69177..e20bfb9e 100644
--- a/components/bean-validation/hibernate-validator/src/main/java/com/kumuluz/ee/beanvalidation/BeanValidationComponent.java
+++ b/components/bean-validation/hibernate-validator/src/main/java/com/kumuluz/ee/beanvalidation/BeanValidationComponent.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.beanvalidation;
import com.kumuluz.ee.common.Component;
diff --git a/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/HibernateValidatorTest.java b/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/HibernateValidatorTest.java
index 75c63cb8..f34ea9fa 100644
--- a/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/HibernateValidatorTest.java
+++ b/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/HibernateValidatorTest.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.beanvalidation.test;
import com.kumuluz.ee.beanvalidation.test.beans.Project;
diff --git a/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/Project.java b/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/Project.java
index cff1b3d5..426c2376 100644
--- a/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/Project.java
+++ b/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/Project.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.beanvalidation.test.beans;
import javax.validation.constraints.NotNull;
diff --git a/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/User.java b/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/User.java
index 21f601a8..457599ac 100644
--- a/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/User.java
+++ b/components/bean-validation/hibernate-validator/src/test/java/com/kumuluz/ee/beanvalidation/test/beans/User.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.beanvalidation.test.beans;
import java.util.Date;
diff --git a/components/bean-validation/pom.xml b/components/bean-validation/pom.xml
index 1fd7ad2a..69f223ff 100644
--- a/components/bean-validation/pom.xml
+++ b/components/bean-validation/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-components
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
pom
diff --git a/components/cdi/pom.xml b/components/cdi/pom.xml
index f688117c..27913f26 100644
--- a/components/cdi/pom.xml
+++ b/components/cdi/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-components
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
pom
diff --git a/components/cdi/weld/pom.xml b/components/cdi/weld/pom.xml
index ad2bfb8c..379ad9a3 100644
--- a/components/cdi/weld/pom.xml
+++ b/components/cdi/weld/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-cdi
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
@@ -14,11 +14,6 @@
kumuluzee-cdi-weld
-
- 2.4.1.Final
- 2.24.1
-
-
com.kumuluz.ee
@@ -47,12 +42,21 @@
org.jboss.spec.javax.interceptor
jboss-interceptors-api_1.2_spec
+
+ org.jboss.logging
+ jboss-logging
+
org.jboss
jandex
+
+ org.jboss.logging
+ jboss-logging
+
+
org.glassfish.jersey.ext.cdi
jersey-cdi1x
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/cdi/CdiComponent.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/cdi/CdiComponent.java
index adbc7bc1..182126cd 100644
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/cdi/CdiComponent.java
+++ b/components/cdi/weld/src/main/java/com/kumuluz/ee/cdi/CdiComponent.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.cdi;
import com.kumuluz.ee.common.Component;
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigBundle.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigBundle.java
index 07e1169a..79754cbc 100644
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigBundle.java
+++ b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigBundle.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.configuration.cdi;
import javax.enterprise.util.Nonbinding;
@@ -16,4 +36,6 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface ConfigBundle {
@Nonbinding String value() default "";
+
+ @Nonbinding boolean watch() default false;
}
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigValue.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigValue.java
index 4a95d03b..7f74bc45 100644
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigValue.java
+++ b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/ConfigValue.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.configuration.cdi;
import javax.enterprise.util.Nonbinding;
@@ -7,7 +27,8 @@
import java.lang.annotation.Target;
/**
- * Annotation specifies key name for automatic initialisation of a field from configuration.
+ * Annotation specifies key name for automatic initialisation of a field from configuration. If attribute watch is
+ * set to true, key is subscribed to dynamic configuration events.
*
* @author Tilen Faganel
* @since 2.1.0
@@ -16,4 +37,6 @@
@Target({ElementType.FIELD})
public @interface ConfigValue {
@Nonbinding String value() default "";
+
+ @Nonbinding boolean watch() default false;
}
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/interceptors/ConfigBundleInterceptor.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/interceptors/ConfigBundleInterceptor.java
index 40e6025c..8ea64150 100644
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/interceptors/ConfigBundleInterceptor.java
+++ b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/interceptors/ConfigBundleInterceptor.java
@@ -1,5 +1,26 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.configuration.cdi.interceptors;
+import com.kumuluz.ee.common.utils.StringUtils;
import com.kumuluz.ee.configuration.cdi.ConfigBundle;
import com.kumuluz.ee.configuration.cdi.ConfigValue;
import com.kumuluz.ee.configuration.utils.ConfigurationUtil;
@@ -8,14 +29,18 @@
import javax.annotation.Priority;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
+import java.lang.reflect.Array;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Optional;
+import java.util.*;
+import java.util.logging.Logger;
/**
* Interceptor class for ConfigBundle annotation.
*
* @author Tilen Faganel
+ * @author Jan Meznaric
* @since 2.1.0
*/
@Interceptor
@@ -23,6 +48,11 @@
@Priority(Interceptor.Priority.LIBRARY_BEFORE)
public class ConfigBundleInterceptor {
+ private static final Logger log = Logger.getLogger(ConfigBundleInterceptor.class.getName());
+ private static final ConfigurationUtil configurationUtil = ConfigurationUtil.getInstance();
+ private final Class[] primitives = {String.class, Boolean.class, Float.class, Double.class, Integer.class, Long
+ .class, boolean.class, float.class, double.class, int.class, long.class};
+
/**
* Method initialises class fields from configuration.
*/
@@ -36,58 +66,185 @@ public Object loadConfiguration(InvocationContext ic) throws Exception {
targetClass = targetClass.getSuperclass();
}
- ConfigurationUtil configurationUtil = ConfigurationUtil.getInstance();
+ ConfigBundle configBundleAnnotation = (ConfigBundle) targetClass.getDeclaredAnnotation(ConfigBundle.class);
- // invoke setters for fields which are defined in configuration
- for (Method m : targetClass.getMethods()) {
+ processConfigBundleBeanSetters(target, targetClass, getKeyPrefix(targetClass), new HashMap<>(),
+ configBundleAnnotation.watch());
- if (m.getName().substring(0, 3).equals("set") && m.getParameters().length == 1) {
+ return ic.proceed();
+ }
- if (m.getParameters()[0].getType().equals(String.class)) {
+ /**
+ * Processes and invokes all setters in Bean annotated with @ConfigBundle
+ *
+ * @param target target object
+ * @param targetClass target class
+ * @param keyPrefix a prefix for generating key names
+ * @param processedClassRelations class pairs that have already been processed (for cycle detection)
+ * @param watchAllFields if true, enable watch on all fields
+ * @return returns true, if at least one field was successfully populated from configuration sources
+ * @throws Exception
+ */
+ private boolean processConfigBundleBeanSetters(Object target, Class targetClass, String keyPrefix, Map
+ processedClassRelations, boolean watchAllFields) throws Exception {
- Optional value = configurationUtil.get(getKeyName(targetClass, m.getName()));
+ boolean isConfigBundleEmpty = true;
- if (value.isPresent()) {
- m.invoke(target, value.get());
- }
+ // invoke setters
+ for (Method method : targetClass.getMethods()) {
- } else if (m.getParameters()[0].getType().equals(Boolean.class)) {
+ if (method.getName().substring(0, 3).equals("set") && method.getParameters().length == 1) {
- Optional value = configurationUtil.getBoolean(getKeyName(targetClass, m.getName()));
+ Class parameterType = method.getParameters()[0].getType();
- if (value.isPresent()) {
- m.invoke(target, value.get());
+ // get field annotation - @ConfigValue
+ Field field = targetClass.getDeclaredField(setterToField(method.getName()));
+ ConfigValue fieldAnnotation = null;
+ if (field != null) {
+ fieldAnnotation = field.getAnnotation(ConfigValue.class);
+ }
+
+ // watch nested class or list if all fields in the bean are annotated with watch or if a field is
+ // annotated with watch
+ boolean watchNestedClass = watchAllFields;
+ if (watchNestedClass == false) {
+ if (fieldAnnotation != null) {
+ watchNestedClass = fieldAnnotation.watch();
}
+ }
- } else if (m.getParameters()[0].getType().equals(Float.class)) {
+ // process primitives
+ if (Arrays.asList(primitives).contains(parameterType)) {
- Optional value = configurationUtil.getFloat(getKeyName(targetClass, m.getName()));
+ Optional value = getValueOfPrimitive(parameterType, getKeyName(targetClass, method
+ .getName(), keyPrefix));
if (value.isPresent()) {
- m.invoke(target, value.get());
+ isConfigBundleEmpty = false;
+ method.invoke(target, value.get());
+ }
+
+ if (watchAllFields || (fieldAnnotation != null && fieldAnnotation.watch())) {
+ deployWatcher(target, method, getKeyName(targetClass, method.getName(), keyPrefix));
}
- } else if (m.getParameters()[0].getType().equals(Double.class)) {
+ // process nested objeccts
+ } else if (!parameterType.isArray()) {
- Optional value = configurationUtil.getDouble(getKeyName(targetClass, m.getName()));
+ processedClassRelations.put(targetClass, parameterType);
- if (value.isPresent()) {
- m.invoke(target, value.get());
+ Object nestedTarget = processNestedObject(targetClass, method, parameterType, keyPrefix,
+ processedClassRelations, -1, watchNestedClass);
+
+ // invoke setter method with initialised instance
+ if (nestedTarget != null) {
+ method.invoke(target, nestedTarget);
}
- } else if (m.getParameters()[0].getType().equals(Integer.class)) {
+ // process arrays
+ } else {
- Optional value = configurationUtil.getInteger(getKeyName(targetClass, m.getName()));
+ Class componentType = parameterType.getComponentType();
- if (value.isPresent()) {
- m.invoke(target, value.get());
+ Object array = Array.newInstance(componentType, configurationUtil.getListSize(getKeyName
+ (targetClass, method.getName(), keyPrefix)).orElse(0));
+
+ // process list of primitives
+ if (Arrays.asList(primitives).contains(componentType)) {
+ for (int i = 0; i < Array.getLength(array); i++) {
+ Array.set(array, i, getValueOfPrimitive(componentType, getKeyName(targetClass, method
+ .getName(), keyPrefix) + "[" + i + "]").get());
+ }
+
+ // process list of nested classes
+ } else {
+ for (int i = 0; i < Array.getLength(array); i++) {
+ Object nestedTarget = processNestedObject(targetClass, method, componentType, keyPrefix,
+ processedClassRelations, i, watchNestedClass);
+ if (nestedTarget != null) {
+ Array.set(array, i, nestedTarget);
+ }
+
+ }
}
+ method.invoke(target, array);
+
}
}
}
+ return isConfigBundleEmpty;
+ }
+
+ /**
+ * Returns a value of a primitive configuration type
+ *
+ * @param type configuration value type
+ * @param key configuration value key
+ * @return
+ */
+ private Optional getValueOfPrimitive(Class type, String key) {
+
+ if (type.equals(String.class)) {
+ return configurationUtil.get(key);
+ } else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
+ return configurationUtil.getBoolean(key);
+ } else if (type.equals(Float.class) || type.equals(float.class)) {
+ return configurationUtil.getFloat(key);
+ } else if (type.equals(Double.class) || type.equals(double.class)) {
+ return configurationUtil.getDouble(key);
+ } else if (type.equals(Integer.class) || type.equals(int.class)) {
+ return configurationUtil.getInteger(key);
+ } else if (type.equals(Long.class) || type.equals(long.class)) {
+ return configurationUtil.getLong(key);
+ } else {
+ return Optional.empty();
+ }
- return ic.proceed();
+ }
+
+ /**
+ * Create a new instance for nested class, check for cycles and populate nested instance.
+ *
+ * @param targetClass target class
+ * @param method processed method
+ * @param parameterType parameter type
+ * @param keyPrefix prefix used for generation of a configuration key
+ * @param processedClassRelations class pairs that have already been processed (for cycle detection)
+ * @param arrayIndex array index for arrays of nested objects
+ * @param watchAllFields if true, enable watch on all fields
+ * @return
+ * @throws Exception
+ */
+ private Object processNestedObject(Class targetClass, Method method, Class parameterType, String keyPrefix,
+ Map processedClassRelations, int arrayIndex, boolean
+ watchAllFields) throws Exception {
+
+ Object nestedTarget = parameterType.getConstructor().newInstance();
+ Class nestedTargetClass = nestedTarget.getClass();
+
+ // check for cycles
+ if (processedClassRelations.containsKey(nestedTargetClass) && processedClassRelations.get(nestedTargetClass)
+ .equals(targetClass)) {
+ log.warning("There is a cycle in the configuration class tree. ConfigBundle class may not " +
+ "be populated as expected.");
+ } else {
+
+ String key = getKeyName(targetClass, method.getName(), keyPrefix);
+
+ if (arrayIndex >= 0) {
+ key += "[" + arrayIndex + "]";
+ }
+
+ boolean isEmpty = processConfigBundleBeanSetters(nestedTarget, nestedTargetClass, key,
+ processedClassRelations, watchAllFields);
+
+ if (isEmpty) {
+ return null;
+ }
+ }
+
+ return nestedTarget;
}
/**
@@ -95,16 +252,15 @@ public Object loadConfiguration(InvocationContext ic) throws Exception {
*
* @param targetClass target class
* @param setter name of the setter method
+ * @param keyPrefix prefix used for generation of a configuration key
* @return key in format prefix.key-name
*/
- private String getKeyName(Class targetClass, String setter) throws Exception {
-
- String key;
+ private String getKeyName(Class targetClass, String setter, String keyPrefix) throws Exception {
- // get prefix
- String prefix = ((ConfigBundle) targetClass.getAnnotation(ConfigBundle.class)).value();
- if (prefix.isEmpty()) {
- prefix = camelCaseToHyphenCase(targetClass.getSimpleName());
+ StringBuilder key = new StringBuilder();
+ key.append(keyPrefix);
+ if (!key.toString().isEmpty()) {
+ key.append(".");
}
// get ConfigValue
@@ -115,48 +271,45 @@ private String getKeyName(Class targetClass, String setter) throws Exception {
}
if (fieldAnnotation != null && !fieldAnnotation.value().isEmpty()) {
- key = prefix + "." + camelCaseToHyphenCase(fieldAnnotation.value());
+ key.append(StringUtils.camelCaseToHyphenCase(fieldAnnotation.value()));
} else {
- key = prefix + "." + camelCaseToHyphenCase(setter.substring(3));
+ key.append(StringUtils.camelCaseToHyphenCase(setter.substring(3)));
}
- return key;
+ return key.toString();
}
/**
- * Parse setter name to field name.
+ * Generate a key prefix from annotation, class name, or parent prefix in case of nested classes.
*
- * @param setter name of the setter method
- * @return field name
- */
- private String setterToField(String setter) {
- return Character.toLowerCase(setter.charAt(3)) + setter.substring(4);
- }
-
- /**
- * Parse upper camel case to lower hyphen case.
- *
- * @param s string in upper camel case format
- * @return string in lower hyphen case format
+ * @param targetClass target class
+ * @return key prefix
*/
- private String camelCaseToHyphenCase(String s) {
-
- String parsedString = s.substring(0, 1).toLowerCase();
+ private String getKeyPrefix(Class targetClass) {
- for (char c : s.substring(1).toCharArray()) {
+ String prefix = ((ConfigBundle) targetClass.getAnnotation(ConfigBundle.class)).value();
- if (Character.isUpperCase(c)) {
- parsedString += "-" + Character.toLowerCase(c);
- } else {
- parsedString += c;
- }
+ if (prefix.isEmpty()) {
+ prefix = StringUtils.camelCaseToHyphenCase(targetClass.getSimpleName());
+ }
+ if (".".equals(prefix)) {
+ prefix = "";
}
- return parsedString;
+ return prefix;
+ }
+ /**
+ * Parse setter name to field name.
+ *
+ * @param setter name of the setter method
+ * @return field name
+ */
+ private String setterToField(String setter) {
+ return Character.toLowerCase(setter.charAt(3)) + setter.substring(4);
}
/**
@@ -168,6 +321,69 @@ private String camelCaseToHyphenCase(String s) {
private boolean targetClassIsProxied(Class targetClass) {
return targetClass.getCanonicalName().contains("$Proxy");
}
+
+ /**
+ * Subscribes to an event dispatcher and starts a watch for a given key.
+ *
+ * @param target target instance
+ * @param method method to invoke
+ * @param watchedKey watched key
+ * @throws Exception
+ */
+ private void deployWatcher(Object target, Method method, String watchedKey) throws Exception {
+
+ configurationUtil.subscribe(watchedKey, (key, value) -> {
+
+ if (Objects.equals(watchedKey, key)) {
+
+ try {
+ if (String.class.equals(method.getParameters()[0].getType())) {
+ method.invoke(target, value);
+ } else if (Boolean.class.equals(method.getParameters()[0].getType()) || boolean.class.equals(method
+ .getParameters()[0].getType())) {
+ method.invoke(target, Boolean.parseBoolean(value));
+ } else if (Float.class.equals(method.getParameters()[0].getType()) || float.class.equals(method
+ .getParameters()[0].getType())) {
+ try {
+ method.invoke(target, Float.parseFloat(value));
+ } catch (NumberFormatException e) {
+ log.severe("Exception while storing new value: Number format exception. " +
+ "Expected: Float. Value: " + value);
+ }
+ } else if (Double.class.equals(method.getParameters()[0].getType()) || double.class.equals(method
+ .getParameters()[0].getType())) {
+ try {
+ method.invoke(target, Double.parseDouble(value));
+ } catch (NumberFormatException e) {
+ log.severe("Exception while storing new value: Number format exception. Expected:" +
+ " Double. Value: " + value);
+ }
+ } else if (Integer.class.equals(method.getParameters()[0].getType()) || int.class.equals(method
+ .getParameters()[0].getType())) {
+ try {
+ method.invoke(target, Integer.parseInt(value));
+ } catch (NumberFormatException e) {
+ log.severe("Exception while storing new value: Number format exception. Expected:" +
+ " Integer. Value: " + value);
+ }
+ } else if (Long.class.equals(method.getParameters()[0].getType()) || long.class.equals(method
+ .getParameters()[0].getType())) {
+ try {
+ method.invoke(target, Long.parseLong(value));
+ } catch (NumberFormatException e) {
+ log.severe("Exception while storing new value: Number format exception. Expected:" +
+ " Long. Value: " + value);
+ }
+ }
+ } catch (IllegalAccessException e) {
+ log.severe("Illegal access exception: " + e.toString());
+ } catch (InvocationTargetException e) {
+ log.severe("Invocation target exception: " + e.toString());
+ }
+
+ }
+ });
+ }
}
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/producers/ConfigurationUtilProducer.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/producers/ConfigurationUtilProducer.java
index 5f3c1756..3ae8e60d 100644
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/producers/ConfigurationUtilProducer.java
+++ b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/producers/ConfigurationUtilProducer.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.configuration.cdi.producers;
import com.kumuluz.ee.configuration.utils.ConfigurationUtil;
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/producers/EeConfigProducer.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/producers/EeConfigProducer.java
new file mode 100644
index 00000000..685b3384
--- /dev/null
+++ b/components/cdi/weld/src/main/java/com/kumuluz/ee/configuration/cdi/producers/EeConfigProducer.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.configuration.cdi.producers;
+
+import com.kumuluz.ee.common.config.EeConfig;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public class EeConfigProducer {
+
+ @Produces
+ @ApplicationScoped
+ public EeConfig getConfigurationUtil() {
+ return EeConfig.getInstance();
+ }
+}
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/Log.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/Log.java
deleted file mode 100644
index cc903d67..00000000
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/Log.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (c) Sunesis d.o.o.
- */
-package com.kumuluz.ee.logs.cdi;
-
-import javax.enterprise.util.Nonbinding;
-import javax.interceptor.InterceptorBinding;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * @author Rok Povse
- * @author Marko Skrjanec
- */
-@Inherited
-@InterceptorBinding
-@Retention(RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
-public @interface Log {
- @Nonbinding LogParams[] value() default {};
- @Nonbinding boolean methodCall() default true;
-}
\ No newline at end of file
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/LogParams.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/LogParams.java
deleted file mode 100644
index 7f51c64b..00000000
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/LogParams.java
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- * Copyright (c) Sunesis d.o.o.
- */
-package com.kumuluz.ee.logs.cdi;
-
-/**
- * @author Rok Povse
- * @author Marko Skrjanec
- */
-public enum LogParams {
- METRICS,
-}
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/interceptors/LogInterceptor.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/interceptors/LogInterceptor.java
deleted file mode 100644
index d72f289b..00000000
--- a/components/cdi/weld/src/main/java/com/kumuluz/ee/logs/cdi/interceptors/LogInterceptor.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * Copyright (c) Sunesis d.o.o.
- */
-package com.kumuluz.ee.logs.cdi.interceptors;
-
-import com.kumuluz.ee.logs.LogCommons;
-import com.kumuluz.ee.logs.LogManager;
-import com.kumuluz.ee.logs.cdi.Log;
-import com.kumuluz.ee.logs.cdi.LogParams;
-import com.kumuluz.ee.logs.messages.SimpleLogMessage;
-import com.kumuluz.ee.logs.types.LogMethodContext;
-import com.kumuluz.ee.logs.types.LogMethodMessage;
-
-import javax.annotation.Priority;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InvocationContext;
-import java.util.Arrays;
-import java.util.HashMap;
-
-
-/**
- * @author Rok Povse
- * @author Marko Skrjanec
- */
-@Log
-@Interceptor
-@Priority(Interceptor.Priority.APPLICATION)
-public class LogInterceptor {
-
- @AroundInvoke
- public Object logMethodEntryAndExit(InvocationContext context) throws Exception {
-
- // get annotation either from class or method
- Log annotation = context.getMethod().getDeclaredAnnotation(Log.class) != null ? context.getMethod()
- .getDeclaredAnnotation(Log.class) : context.getMethod().getDeclaringClass().getDeclaredAnnotation(Log
- .class);
-
- // get annotation params
- LogParams[] value = annotation.value();
- boolean methodCall = annotation.methodCall();
-
- // get logger
- LogCommons logger = LogManager.getCommonsLogger(context.getTarget().getClass().getSuperclass().getName());
-
- // set message
- LogMethodMessage message = new LogMethodMessage();
-
- // set metrics
- for (LogParams logParam : value) {
- if (LogParams.METRICS.equals(logParam)) {
- message.enableMetrics();
- break;
- }
- }
-
- SimpleLogMessage msg = new SimpleLogMessage();
- msg.setMessage("Entering method.");
- msg.setFields(new HashMap());
-
- // set method call
- if (methodCall) {
- msg.getFields().put("class", context.getMethod().getDeclaringClass().getName());
- msg.getFields().put("method", context.getMethod().getName());
-
- if (context.getParameters() != null && context.getParameters().length > 0) {
- msg.getFields().put("parameters", Arrays.toString(context.getParameters()));
- }
-
- }
- message.enableCall(msg);
-
- // log entry
- LogMethodContext logMethodContext = logger.logMethodEntry(message);
-
- Object result = context.proceed();
-
- // set method call
- msg.setMessage("Exiting method.");
- msg.getFields().put("result", result != null ? result.toString() : null);
- logMethodContext.setCallExitMessage(msg);
-
- // log exit
- logger.logMethodExit(logMethodContext);
-
- return result;
- }
-}
\ No newline at end of file
diff --git a/components/cdi/weld/src/main/java/com/kumuluz/ee/runtime/cdi/producers/EeRuntimeProducer.java b/components/cdi/weld/src/main/java/com/kumuluz/ee/runtime/cdi/producers/EeRuntimeProducer.java
new file mode 100644
index 00000000..7b5297a6
--- /dev/null
+++ b/components/cdi/weld/src/main/java/com/kumuluz/ee/runtime/cdi/producers/EeRuntimeProducer.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.runtime.cdi.producers;
+
+import com.kumuluz.ee.common.runtime.EeRuntime;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public class EeRuntimeProducer {
+
+ @Produces
+ @ApplicationScoped
+ public EeRuntime getConfigurationUtil() {
+ return EeRuntime.getInstance();
+ }
+}
diff --git a/components/ejb/openejb/pom.xml b/components/ejb/openejb/pom.xml
index e7011ffd..ebf5bbd5 100644
--- a/components/ejb/openejb/pom.xml
+++ b/components/ejb/openejb/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-ejb
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
diff --git a/components/ejb/pom.xml b/components/ejb/pom.xml
index a5b6ccf3..02d8a621 100644
--- a/components/ejb/pom.xml
+++ b/components/ejb/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-components
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
pom
diff --git a/components/el/pom.xml b/components/el/pom.xml
index 3c862585..2d5ca3dd 100644
--- a/components/el/pom.xml
+++ b/components/el/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-components
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
pom
diff --git a/components/el/uel/pom.xml b/components/el/uel/pom.xml
index 110addfe..f663aa7a 100644
--- a/components/el/uel/pom.xml
+++ b/components/el/uel/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-el
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
@@ -14,10 +14,6 @@
kumuluzee-el-uel
-
- 3.0.0
-
-
com.kumuluz.ee
diff --git a/components/el/uel/src/main/java/com/kumuluz/ee/el/ElComponent.java b/components/el/uel/src/main/java/com/kumuluz/ee/el/ElComponent.java
index f607df76..541ed991 100644
--- a/components/el/uel/src/main/java/com/kumuluz/ee/el/ElComponent.java
+++ b/components/el/uel/src/main/java/com/kumuluz/ee/el/ElComponent.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.el;
import com.kumuluz.ee.common.Component;
diff --git a/components/jax-rs/jersey/pom.xml b/components/jax-rs/jersey/pom.xml
index ea8815d1..38d6cae2 100644
--- a/components/jax-rs/jersey/pom.xml
+++ b/components/jax-rs/jersey/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-jax-rs
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
@@ -14,11 +14,6 @@
kumuluzee-jax-rs-jersey
-
- 2.24.1
- 2.8.5
-
-
com.kumuluz.ee
@@ -69,23 +64,6 @@
jackson-annotations
${jackson.version}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/components/jax-rs/jersey/src/main/java/com/kumuluz/ee/jaxrs/JaxRsComponent.java b/components/jax-rs/jersey/src/main/java/com/kumuluz/ee/jaxrs/JaxRsComponent.java
index 787f9d5f..80b3a385 100644
--- a/components/jax-rs/jersey/src/main/java/com/kumuluz/ee/jaxrs/JaxRsComponent.java
+++ b/components/jax-rs/jersey/src/main/java/com/kumuluz/ee/jaxrs/JaxRsComponent.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.jaxrs;
import com.kumuluz.ee.common.Component;
diff --git a/components/jax-rs/pom.xml b/components/jax-rs/pom.xml
index c2f559d1..95c61c9c 100644
--- a/components/jax-rs/pom.xml
+++ b/components/jax-rs/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-components
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
pom
diff --git a/components/jax-ws/metro/pom.xml b/components/jax-ws/metro/pom.xml
index c015d87d..599e654c 100644
--- a/components/jax-ws/metro/pom.xml
+++ b/components/jax-ws/metro/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-jax-ws
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
@@ -14,10 +14,6 @@
kumuluzee-jax-ws-metro
-
- 2.3.1
-
-
com.kumuluz.ee
diff --git a/components/jax-ws/metro/src/main/java/com/kumuluz/ee/jaxws/metro/JaxWsComponent.java b/components/jax-ws/metro/src/main/java/com/kumuluz/ee/jaxws/metro/JaxWsComponent.java
index eccd773b..3b5a9998 100644
--- a/components/jax-ws/metro/src/main/java/com/kumuluz/ee/jaxws/metro/JaxWsComponent.java
+++ b/components/jax-ws/metro/src/main/java/com/kumuluz/ee/jaxws/metro/JaxWsComponent.java
@@ -1,3 +1,23 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
package com.kumuluz.ee.jaxws.metro;
import com.kumuluz.ee.common.Component;
diff --git a/components/jax-ws/pom.xml b/components/jax-ws/pom.xml
index 34167233..f1c2b13c 100644
--- a/components/jax-ws/pom.xml
+++ b/components/jax-ws/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-components
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
pom
diff --git a/components/jpa/common/pom.xml b/components/jpa/common/pom.xml
index 351a26d7..fb3aef28 100644
--- a/components/jpa/common/pom.xml
+++ b/components/jpa/common/pom.xml
@@ -5,7 +5,7 @@
kumuluzee-jpa
com.kumuluz.ee
- 2.3.0-SNAPSHOT
+ 2.5.0-SNAPSHOT
4.0.0
@@ -19,15 +19,21 @@
com.kumuluz.ee
kumuluzee-common
+
+
+ org.eclipse.persistence
+ javax.persistence
+
+
com.kumuluz.ee
kumuluzee-cdi-weld
provided
-
- org.eclipse.persistence
- javax.persistence
+ com.kumuluz.ee
+ kumuluzee-jta-common
+ provided
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/JpaService.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/JpaService.java
deleted file mode 100644
index f9f33ddd..00000000
--- a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/JpaService.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.kumuluz.ee.jpa.common;
-
-import com.kumuluz.ee.jpa.common.resources.PersistenceContextResourceFactory;
-import com.kumuluz.ee.jpa.common.resources.PersistenceUnitHolder;
-import com.kumuluz.ee.jpa.common.resources.PersistenceUnitResourceFactory;
-import org.jboss.weld.injection.spi.JpaInjectionServices;
-import org.jboss.weld.injection.spi.ResourceReferenceFactory;
-
-import javax.annotation.Priority;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
-
-/**
- * @author Tilen Faganel
- * @since 1.0.0
- */
-@Priority(1)
-public class JpaService implements JpaInjectionServices {
-
- @Override
- public ResourceReferenceFactory registerPersistenceContextInjectionPoint
- (InjectionPoint injectionPoint) {
-
- PersistenceContext pc = injectionPoint.getAnnotated().getAnnotation(PersistenceContext
- .class);
-
- EntityManagerFactory factory = PersistenceUnitHolder.getInstance()
- .getEntityManagerFactory(pc.unitName());
-
- return new PersistenceContextResourceFactory(factory);
- }
-
- @Override
- public ResourceReferenceFactory registerPersistenceUnitInjectionPoint
- (InjectionPoint injectionPoint) {
-
- PersistenceUnit pu = injectionPoint.getAnnotated().getAnnotation(PersistenceUnit.class);
-
- EntityManagerFactory factory = PersistenceUnitHolder.getInstance()
- .getEntityManagerFactory(pu.unitName());
-
- return new PersistenceUnitResourceFactory(factory);
- }
-
- @Override
- public EntityManager resolvePersistenceContext(InjectionPoint injectionPoint) {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint) {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void cleanup() {
- }
-}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/messages/LogMessage.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceSettings.java
similarity index 84%
rename from common/src/main/java/com/kumuluz/ee/logs/messages/LogMessage.java
rename to components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceSettings.java
index 8ec2501b..1ee1c6a7 100644
--- a/common/src/main/java/com/kumuluz/ee/logs/messages/LogMessage.java
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceSettings.java
@@ -18,17 +18,15 @@
* software. See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.kumuluz.ee.logs.messages;
+package com.kumuluz.ee.jpa.common;
import java.util.Map;
/**
- * @author Rok Povse
- * @author Marko Skrjanec
+ * @author Tilen Faganel
+ * @since 2.3.0
*/
-public interface LogMessage {
+public interface PersistenceSettings {
- Map getFields();
- String getMessage();
+ Map getPersistenceUnitProperties();
}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceUnitHolder.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceUnitHolder.java
new file mode 100644
index 00000000..d21e9122
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceUnitHolder.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common;
+
+import com.kumuluz.ee.common.config.PersistenceConfig;
+import com.kumuluz.ee.jpa.common.utils.PersistenceUtils;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import java.util.*;
+
+/**
+ * @author Tilen Faganel
+ * @since 1.0.0
+ */
+public class PersistenceUnitHolder {
+
+ private PersistenceSettings providerProperties;
+ private PersistenceConfig config;
+
+ private String defaultUnitName;
+
+ private Map factories = new HashMap<>();
+
+ private static final PersistenceUnitHolder instance = new PersistenceUnitHolder();
+
+ private PersistenceUnitHolder() {
+
+ defaultUnitName = PersistenceUtils.getDefaultUnitName().orElse("");
+ }
+
+ public static PersistenceUnitHolder getInstance() {
+ return instance;
+ }
+
+ public synchronized PersistenceWrapper getEntityManagerFactory(String unitName) {
+
+ PersistenceWrapper wrapper = factories.get(unitName);
+
+ if (wrapper == null) {
+
+ Properties properties = new Properties();
+
+ if (providerProperties != null && providerProperties.getPersistenceUnitProperties() != null) {
+ properties.putAll(providerProperties.getPersistenceUnitProperties());
+ }
+
+ if (config != null && unitName.equals(config.getUnitName())) {
+
+ Optional.ofNullable(config.getUrl()).ifPresent(u -> properties.put("javax.persistence.jdbc.url", u));
+ Optional.ofNullable(config.getUsername()).ifPresent(u -> properties.put("javax.persistence.jdbc.user", u));
+ Optional.ofNullable(config.getPassword()).ifPresent(p -> properties.put("javax.persistence.jdbc.password", p));
+ }
+
+ EntityManagerFactory factory = Persistence.createEntityManagerFactory(unitName, properties);
+ TransactionType transactionType = PersistenceUtils.getEntityManagerFactoryTransactionType(factory);
+
+ wrapper = new PersistenceWrapper(factory, transactionType);
+
+ factories.put(unitName, wrapper);
+ }
+
+ return wrapper;
+ }
+
+ public String getDefaultUnitName() {
+ return defaultUnitName;
+ }
+
+ public void setConfig(PersistenceConfig config) {
+ this.config = config;
+ }
+
+ public void setProviderProperties(PersistenceSettings providerProperties) {
+ this.providerProperties = providerProperties;
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceWrapper.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceWrapper.java
new file mode 100644
index 00000000..307d8c50
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/PersistenceWrapper.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common;
+
+import javax.persistence.EntityManagerFactory;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.3.0
+ */
+public class PersistenceWrapper {
+
+ private EntityManagerFactory entityManagerFactory;
+ private TransactionType transactionType;
+
+ public PersistenceWrapper(EntityManagerFactory entityManagerFactory, TransactionType transactionType) {
+ this.entityManagerFactory = entityManagerFactory;
+ this.transactionType = transactionType;
+ }
+
+ public EntityManagerFactory getEntityManagerFactory() {
+ return entityManagerFactory;
+ }
+
+ public TransactionType getTransactionType() {
+ return transactionType;
+ }
+}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/messages/MethodCallLogMessage.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/TransactionType.java
similarity index 87%
rename from common/src/main/java/com/kumuluz/ee/logs/messages/MethodCallLogMessage.java
rename to components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/TransactionType.java
index feaffd9b..b557f506 100644
--- a/common/src/main/java/com/kumuluz/ee/logs/messages/MethodCallLogMessage.java
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/TransactionType.java
@@ -18,12 +18,14 @@
* software. See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.kumuluz.ee.logs.messages;
+package com.kumuluz.ee.jpa.common;
/**
- * @author Rok Povse
- * @author Marko Skrjanec
+ * @author Tilen Faganel
+ * @since 2.3.0
*/
-public interface MethodCallLogMessage extends LogMessage {
+public enum TransactionType {
+
+ RESOURCE_LOCAL,
+ JTA
}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/markers/StatusMarker.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/exceptions/NoDefaultPersistenceUnit.java
similarity index 72%
rename from common/src/main/java/com/kumuluz/ee/logs/markers/StatusMarker.java
rename to components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/exceptions/NoDefaultPersistenceUnit.java
index 897bcbf7..a8eb584c 100644
--- a/common/src/main/java/com/kumuluz/ee/logs/markers/StatusMarker.java
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/exceptions/NoDefaultPersistenceUnit.java
@@ -18,23 +18,16 @@
* software. See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package com.kumuluz.ee.logs.markers;
+package com.kumuluz.ee.jpa.common.exceptions;
/**
- * @author Rok Povse
- * @author Marko Skrjanec
+ * @author Tilen Faganel
+ * @since 2.3.0
*/
-public enum StatusMarker implements Marker {
- ENTRY("ENTRY"), EXIT("EXIT"), INVOKE("INVOKE"), RESPOND("RESPOND");
-
- private String marker;
-
- private StatusMarker(String marker) {
- this.marker = marker;
- }
+public class NoDefaultPersistenceUnit extends RuntimeException {
- public String toString() {
- return marker;
+ public NoDefaultPersistenceUnit() {
+ super("Cannot determine a default persistence unit. Either the configuration does not exist or " +
+ "there are more then one configurations or units defined");
}
}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/EntityManagerWrapper.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/EntityManagerWrapper.java
new file mode 100644
index 00000000..659c76a8
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/EntityManagerWrapper.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.injection;
+
+import javax.persistence.EntityManager;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public interface EntityManagerWrapper {
+
+ EntityManager getEntityManager();
+
+ void close();
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/JpaService.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/JpaService.java
new file mode 100644
index 00000000..d271c9e6
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/JpaService.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.injection;
+
+import com.kumuluz.ee.jpa.common.PersistenceUnitHolder;
+import com.kumuluz.ee.jpa.common.PersistenceWrapper;
+import com.kumuluz.ee.jpa.common.exceptions.NoDefaultPersistenceUnit;
+import org.jboss.weld.injection.spi.JpaInjectionServices;
+import org.jboss.weld.injection.spi.ResourceReferenceFactory;
+
+import javax.annotation.Priority;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+
+/**
+ * @author Tilen Faganel
+ * @since 1.0.0
+ */
+@Priority(1)
+public class JpaService implements JpaInjectionServices {
+
+ @Override
+ public ResourceReferenceFactory registerPersistenceContextInjectionPoint
+ (InjectionPoint injectionPoint) {
+
+ PersistenceUnitHolder holder = PersistenceUnitHolder.getInstance();
+
+ PersistenceContext pc = injectionPoint.getAnnotated().getAnnotation(PersistenceContext
+ .class);
+ String unitName = pc.unitName();
+
+ if (unitName.isEmpty()) {
+
+ unitName = holder.getDefaultUnitName();
+
+ if (unitName.isEmpty()) {
+ throw new NoDefaultPersistenceUnit();
+ }
+ }
+
+ PersistenceWrapper wrapper = holder.getEntityManagerFactory(unitName);
+
+ return new PersistenceContextResourceFactory(unitName, wrapper.getEntityManagerFactory(),
+ wrapper.getTransactionType(), pc.synchronization());
+ }
+
+ @Override
+ public ResourceReferenceFactory registerPersistenceUnitInjectionPoint
+ (InjectionPoint injectionPoint) {
+
+ PersistenceUnitHolder holder = PersistenceUnitHolder.getInstance();
+
+ PersistenceUnit pu = injectionPoint.getAnnotated().getAnnotation(PersistenceUnit.class);
+ String unitName = pu.unitName();
+
+ if (unitName.isEmpty()) {
+
+ unitName = holder.getDefaultUnitName();
+
+ if (unitName.isEmpty()) {
+ throw new NoDefaultPersistenceUnit();
+ }
+ }
+
+ PersistenceWrapper wrapper = holder.getEntityManagerFactory(unitName);
+
+ return new PersistenceUnitResourceFactory(wrapper.getEntityManagerFactory());
+ }
+
+ @Override
+ public EntityManager resolvePersistenceContext(InjectionPoint injectionPoint) {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint) {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void cleanup() {
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/NonTxEntityManagerWrapper.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/NonTxEntityManagerWrapper.java
new file mode 100644
index 00000000..a9167dc3
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/NonTxEntityManagerWrapper.java
@@ -0,0 +1,29 @@
+package com.kumuluz.ee.jpa.common.injection;
+
+import javax.persistence.EntityManager;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public class NonTxEntityManagerWrapper implements EntityManagerWrapper {
+
+ private EntityManager em;
+
+ public NonTxEntityManagerWrapper(EntityManager em) {
+ this.em = em;
+ }
+
+ @Override
+ public EntityManager getEntityManager() {
+ return em;
+ }
+
+ @Override
+ public void close() {
+
+ if (em.isOpen()) {
+ em.close();
+ }
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceContextResource.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceContextResource.java
new file mode 100644
index 00000000..0c9eeaf9
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceContextResource.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.injection;
+
+import org.jboss.weld.injection.spi.ResourceReference;
+
+import javax.persistence.EntityManager;
+
+/**
+ * @author Tilen Faganel
+ * @since 1.0.0
+ */
+public class PersistenceContextResource implements ResourceReference {
+
+ private EntityManagerWrapper entityManagerWrapper;
+
+ public PersistenceContextResource(EntityManagerWrapper entityManagerWrapper) {
+
+ this.entityManagerWrapper = entityManagerWrapper;
+ }
+
+ @Override
+ public EntityManager getInstance() {
+
+ return entityManagerWrapper.getEntityManager();
+ }
+
+ @Override
+ public void release() {
+
+ entityManagerWrapper.close();
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceContextResourceFactory.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceContextResourceFactory.java
new file mode 100644
index 00000000..b6c3117c
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceContextResourceFactory.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.injection;
+
+import com.kumuluz.ee.jpa.common.TransactionType;
+import com.kumuluz.ee.jpa.common.jta.TxScopedEntityManagerFactory;
+import com.kumuluz.ee.jta.common.JtaTransactionHolder;
+import com.kumuluz.ee.jpa.common.jta.TxScopedEntityManager;
+import org.jboss.weld.injection.spi.ResourceReference;
+import org.jboss.weld.injection.spi.ResourceReferenceFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.SynchronizationType;
+import javax.transaction.TransactionManager;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+/**
+ * @author Tilen Faganel
+ * @since 1.0.0
+ */
+public class PersistenceContextResourceFactory implements ResourceReferenceFactory {
+
+ private String unitName;
+ private EntityManagerFactory emf;
+ private SynchronizationType sync;
+ private TransactionType transactionType;
+
+ public PersistenceContextResourceFactory(String unitName, EntityManagerFactory emf, TransactionType transactionType, SynchronizationType sync) {
+ this.unitName = unitName;
+ this.emf = emf;
+ this.sync = sync;
+ this.transactionType = transactionType;
+ }
+
+ @Override
+ public ResourceReference createResource() {
+
+ EntityManagerWrapper emWrapper;
+
+ if (transactionType == TransactionType.JTA) {
+
+ emWrapper = TxScopedEntityManagerFactory.buildEntityManagerWrapper(unitName, emf, sync);
+ } else {
+ emWrapper = new NonTxEntityManagerWrapper(emf.createEntityManager());
+ }
+
+ return new PersistenceContextResource(emWrapper);
+ }
+}
\ No newline at end of file
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceUnitResource.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceUnitResource.java
new file mode 100644
index 00000000..809f47c8
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceUnitResource.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.injection;
+
+import org.jboss.weld.injection.spi.ResourceReference;
+
+import javax.persistence.EntityManagerFactory;
+
+/**
+ * @author Tilen Faganel
+ * @since 1.0.0
+ */
+public class PersistenceUnitResource implements ResourceReference {
+
+ private EntityManagerFactory emf;
+
+ public PersistenceUnitResource(EntityManagerFactory emf) {
+
+ this.emf = emf;
+ }
+
+ @Override
+ public EntityManagerFactory getInstance() {
+
+ return emf;
+ }
+
+ @Override
+ public void release() {
+
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceUnitResourceFactory.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceUnitResourceFactory.java
new file mode 100644
index 00000000..c813d832
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/injection/PersistenceUnitResourceFactory.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.injection;
+
+import org.jboss.weld.injection.spi.ResourceReference;
+import org.jboss.weld.injection.spi.ResourceReferenceFactory;
+
+import javax.persistence.EntityManagerFactory;
+
+/**
+ * @author Tilen Faganel
+ * @since 1.0.0
+ */
+public class PersistenceUnitResourceFactory implements
+ ResourceReferenceFactory {
+
+ private EntityManagerFactory emf;
+
+ public PersistenceUnitResourceFactory(EntityManagerFactory emf) {
+
+ this.emf = emf;
+ }
+
+ @Override
+ public ResourceReference createResource() {
+
+ return new PersistenceUnitResource(emf);
+ }
+}
diff --git a/common/src/main/java/com/kumuluz/ee/logs/markers/CommonsMarker.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxEntityManagerHolder.java
similarity index 74%
rename from common/src/main/java/com/kumuluz/ee/logs/markers/CommonsMarker.java
rename to components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxEntityManagerHolder.java
index d8e7b0c1..9b455860 100644
--- a/common/src/main/java/com/kumuluz/ee/logs/markers/CommonsMarker.java
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxEntityManagerHolder.java
@@ -18,23 +18,23 @@
* software. See the License for the specific language governing permissions and
* limitations under the License.
*/
+package com.kumuluz.ee.jpa.common.jta;
-package com.kumuluz.ee.logs.markers;
+import javax.persistence.EntityManager;
/**
- * @author Rok Povse
- * @author Marko Skrjanec
+ * @author Tilen Faganel
+ * @since 2.4.0
*/
-public enum CommonsMarker implements Marker {
- METHOD("METHOD"), RESOURCE("RESOURCE");
+public class NonTxEntityManagerHolder {
- private String marker;
+ private EntityManager em;
- private CommonsMarker(String marker) {
- this.marker = marker;
+ public EntityManager getEntityManager() {
+ return em;
}
- public String toString() {
- return marker;
+ public void setEntityManager(EntityManager em) {
+ this.em = em;
}
}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxQueryWrapper.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxQueryWrapper.java
new file mode 100644
index 00000000..14afe7e1
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxQueryWrapper.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.jta;
+
+import javax.persistence.*;
+import java.util.*;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public class NonTxQueryWrapper implements Query {
+
+ private Query query;
+ private EntityManager em;
+
+ public NonTxQueryWrapper(Query query, EntityManager em) {
+ this.query = query;
+ this.em = em;
+ }
+
+ @Override
+ public List getResultList() {
+
+ List resultList = query.getResultList();
+
+ em.clear();
+
+ return resultList;
+ }
+
+ @Override
+ public Object getSingleResult() {
+
+ Object singleResult = query.getSingleResult();
+
+ em.clear();
+
+ return singleResult;
+ }
+
+ @Override
+ public int executeUpdate() {
+ return query.executeUpdate();
+ }
+
+ @Override
+ public Query setMaxResults(int maxResult) {
+ query.setMaxResults(maxResult);
+ return this;
+ }
+
+ @Override
+ public int getMaxResults() {
+ return query.getMaxResults();
+ }
+
+ @Override
+ public Query setFirstResult(int startPosition) {
+ query.setFirstResult(startPosition);
+ return this;
+ }
+
+ @Override
+ public int getFirstResult() {
+ return query.getFirstResult();
+ }
+
+ @Override
+ public Query setHint(String hintName, Object value) {
+ query.setHint(hintName, value);
+ return this;
+ }
+
+ @Override
+ public Map getHints() {
+ return query.getHints();
+ }
+
+ @Override
+ public Query setParameter(Parameter param, T value) {
+ query.setParameter(param, value);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(Parameter param, Calendar value, TemporalType temporalType) {
+ query.setParameter(param, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(Parameter param, Date value, TemporalType temporalType) {
+ query.setParameter(param, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(String name, Object value) {
+ query.setParameter(name, value);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(String name, Calendar value, TemporalType temporalType) {
+ query.setParameter(name, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(String name, Date value, TemporalType temporalType) {
+ query.setParameter(name, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(int position, Object value) {
+ query.setParameter(position, value);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(int position, Calendar value, TemporalType temporalType) {
+ query.setParameter(position, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Query setParameter(int position, Date value, TemporalType temporalType) {
+ query.setParameter(position, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Set> getParameters() {
+ return query.getParameters();
+ }
+
+ @Override
+ public Parameter> getParameter(String name) {
+ return query.getParameter(name);
+ }
+
+ @Override
+ public Parameter getParameter(String name, Class type) {
+ return query.getParameter(name, type);
+ }
+
+ @Override
+ public Parameter> getParameter(int position) {
+ return query.getParameter(position);
+ }
+
+ @Override
+ public Parameter getParameter(int position, Class type) {
+ return query.getParameter(position, type);
+ }
+
+ @Override
+ public boolean isBound(Parameter> param) {
+ return query.isBound(param);
+ }
+
+ @Override
+ public T getParameterValue(Parameter param) {
+ return query.getParameterValue(param);
+ }
+
+ @Override
+ public Object getParameterValue(String name) {
+ return query.getParameterValue(name);
+ }
+
+ @Override
+ public Object getParameterValue(int position) {
+ return query.getParameterValue(position);
+ }
+
+ @Override
+ public Query setFlushMode(FlushModeType flushMode) {
+ query.setFlushMode(flushMode);
+ return this;
+ }
+
+ @Override
+ public FlushModeType getFlushMode() {
+ return query.getFlushMode();
+ }
+
+ @Override
+ public Query setLockMode(LockModeType lockMode) {
+ query.setLockMode(lockMode);
+ return this;
+ }
+
+ @Override
+ public LockModeType getLockMode() {
+ return query.getLockMode();
+ }
+
+ @Override
+ public T unwrap(Class cls) {
+ return query.unwrap(cls);
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxStoredProcedureQueryWrapper.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxStoredProcedureQueryWrapper.java
new file mode 100644
index 00000000..89eb36be
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxStoredProcedureQueryWrapper.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.jta;
+
+import javax.persistence.*;
+import java.util.*;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public class NonTxStoredProcedureQueryWrapper implements StoredProcedureQuery {
+
+ private StoredProcedureQuery storedProcedureQuery;
+ private EntityManager em;
+
+ public NonTxStoredProcedureQueryWrapper(StoredProcedureQuery storedProcedureQuery, EntityManager em) {
+ this.storedProcedureQuery = storedProcedureQuery;
+ this.em = em;
+ }
+
+ @Override
+ public StoredProcedureQuery setHint(String hintName, Object value) {
+ storedProcedureQuery.setHint(hintName, value);
+ return this;
+ }
+
+ @Override
+ public Map getHints() {
+ return storedProcedureQuery.getHints();
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(Parameter param, T value) {
+ storedProcedureQuery.setParameter(param, value);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(Parameter param, Calendar value, TemporalType temporalType) {
+ storedProcedureQuery.setParameter(param, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(Parameter param, Date value, TemporalType temporalType) {
+ storedProcedureQuery.setParameter(param, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(String name, Object value) {
+ storedProcedureQuery.setParameter(name, value);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(String name, Calendar value, TemporalType temporalType) {
+ storedProcedureQuery.setParameter(name, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(String name, Date value, TemporalType temporalType) {
+ storedProcedureQuery.setParameter(name, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(int position, Object value) {
+ storedProcedureQuery.setParameter(position, value);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(int position, Calendar value, TemporalType temporalType) {
+ storedProcedureQuery.setParameter(position, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery setParameter(int position, Date value, TemporalType temporalType) {
+ storedProcedureQuery.setParameter(position, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Set> getParameters() {
+ return storedProcedureQuery.getParameters();
+ }
+
+ @Override
+ public Parameter> getParameter(String name) {
+ return storedProcedureQuery.getParameter(name);
+ }
+
+ @Override
+ public Parameter getParameter(String name, Class type) {
+ return storedProcedureQuery.getParameter(name, type);
+ }
+
+ @Override
+ public Parameter> getParameter(int position) {
+ return storedProcedureQuery.getParameter(position);
+ }
+
+ @Override
+ public Parameter getParameter(int position, Class type) {
+ return storedProcedureQuery.getParameter(position, type);
+ }
+
+ @Override
+ public boolean isBound(Parameter> param) {
+ return storedProcedureQuery.isBound(param);
+ }
+
+ @Override
+ public T getParameterValue(Parameter param) {
+ return storedProcedureQuery.getParameterValue(param);
+ }
+
+ @Override
+ public Object getParameterValue(String name) {
+ return storedProcedureQuery.getParameterValue(name);
+ }
+
+ @Override
+ public Object getParameterValue(int position) {
+ return storedProcedureQuery.getParameterValue(position);
+ }
+
+ @Override
+ public StoredProcedureQuery setFlushMode(FlushModeType flushMode) {
+ storedProcedureQuery.setFlushMode(flushMode);
+ return this;
+ }
+
+ @Override
+ public FlushModeType getFlushMode() {
+ return storedProcedureQuery.getFlushMode();
+ }
+
+ @Override
+ public Query setLockMode(LockModeType lockMode) {
+ storedProcedureQuery.setLockMode(lockMode);
+ return this;
+ }
+
+ @Override
+ public LockModeType getLockMode() {
+ return storedProcedureQuery.getLockMode();
+ }
+
+ @Override
+ public T unwrap(Class cls) {
+ return storedProcedureQuery.unwrap(cls);
+ }
+
+ @Override
+ public StoredProcedureQuery registerStoredProcedureParameter(int position, Class type, ParameterMode mode) {
+ storedProcedureQuery.registerStoredProcedureParameter(position, type, mode);
+ return this;
+ }
+
+ @Override
+ public StoredProcedureQuery registerStoredProcedureParameter(String parameterName, Class type, ParameterMode mode) {
+ storedProcedureQuery.registerStoredProcedureParameter(parameterName, type, mode);
+ return this;
+ }
+
+ @Override
+ public Object getOutputParameterValue(int position) {
+ return storedProcedureQuery.getOutputParameterValue(position);
+ }
+
+ @Override
+ public Object getOutputParameterValue(String parameterName) {
+ return storedProcedureQuery.getOutputParameterValue(parameterName);
+ }
+
+ @Override
+ public boolean execute() {
+ return storedProcedureQuery.execute();
+ }
+
+ @Override
+ public int executeUpdate() {
+ return storedProcedureQuery.executeUpdate();
+ }
+
+ @Override
+ public Query setMaxResults(int maxResult) {
+ storedProcedureQuery.setMaxResults(maxResult);
+ return this;
+ }
+
+ @Override
+ public int getMaxResults() {
+ return storedProcedureQuery.getMaxResults();
+ }
+
+ @Override
+ public Query setFirstResult(int startPosition) {
+ storedProcedureQuery.setFirstResult(startPosition);
+ return this;
+ }
+
+ @Override
+ public int getFirstResult() {
+ return storedProcedureQuery.getFirstResult();
+ }
+
+ @Override
+ public List getResultList() {
+
+ List resultList = storedProcedureQuery.getResultList();
+
+ em.clear();
+
+ return resultList;
+ }
+
+ @Override
+ public Object getSingleResult() {
+
+ Object singleResult = storedProcedureQuery.getSingleResult();
+
+ em.clear();
+
+ return singleResult;
+ }
+
+ @Override
+ public boolean hasMoreResults() {
+ return storedProcedureQuery.hasMoreResults();
+ }
+
+ @Override
+ public int getUpdateCount() {
+ return storedProcedureQuery.getUpdateCount();
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxTypedQueryWrapper.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxTypedQueryWrapper.java
new file mode 100644
index 00000000..dccfbc24
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/NonTxTypedQueryWrapper.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.jta;
+
+import javax.persistence.*;
+import java.util.*;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public class NonTxTypedQueryWrapper implements TypedQuery {
+
+ private TypedQuery typedQuery;
+ private EntityManager em;
+
+ public NonTxTypedQueryWrapper(TypedQuery typedQuery, EntityManager em) {
+ this.typedQuery = typedQuery;
+ this.em = em;
+ }
+
+ @Override
+ public List getResultList() {
+
+ List resultList = typedQuery.getResultList();
+
+ em.clear();
+
+ return resultList;
+ }
+
+ @Override
+ public X getSingleResult() {
+
+ X singleResult = typedQuery.getSingleResult();
+
+ em.clear();
+
+ return singleResult;
+ }
+
+ @Override
+ public int executeUpdate() {
+ return typedQuery.executeUpdate();
+ }
+
+ @Override
+ public TypedQuery setMaxResults(int maxResult) {
+ typedQuery.setMaxResults(maxResult);
+ return this;
+ }
+
+ @Override
+ public int getMaxResults() {
+ return typedQuery.getMaxResults();
+ }
+
+ @Override
+ public TypedQuery setFirstResult(int startPosition) {
+ typedQuery.setFirstResult(startPosition);
+ return this;
+ }
+
+ @Override
+ public int getFirstResult() {
+ return typedQuery.getFirstResult();
+ }
+
+ @Override
+ public TypedQuery setHint(String hintName, Object value) {
+ typedQuery.setHint(hintName, value);
+ return this;
+ }
+
+ @Override
+ public Map getHints() {
+ return typedQuery.getHints();
+ }
+
+ @Override
+ public TypedQuery setParameter(Parameter param, T value) {
+ typedQuery.setParameter(param, value);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(Parameter param, Calendar value, TemporalType temporalType) {
+ typedQuery.setParameter(param, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(Parameter param, Date value, TemporalType temporalType) {
+ typedQuery.setParameter(param, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(String name, Object value) {
+ typedQuery.setParameter(name, value);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(String name, Calendar value, TemporalType temporalType) {
+ typedQuery.setParameter(name, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(String name, Date value, TemporalType temporalType) {
+ typedQuery.setParameter(name, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(int position, Object value) {
+ typedQuery.setParameter(position, value);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(int position, Calendar value, TemporalType temporalType) {
+ typedQuery.setParameter(position, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public TypedQuery setParameter(int position, Date value, TemporalType temporalType) {
+ typedQuery.setParameter(position, value, temporalType);
+ return this;
+ }
+
+ @Override
+ public Set> getParameters() {
+ return typedQuery.getParameters();
+ }
+
+ @Override
+ public Parameter> getParameter(String name) {
+ return typedQuery.getParameter(name);
+ }
+
+ @Override
+ public Parameter getParameter(String name, Class type) {
+ return typedQuery.getParameter(name, type);
+ }
+
+ @Override
+ public Parameter> getParameter(int position) {
+ return typedQuery.getParameter(position);
+ }
+
+ @Override
+ public Parameter getParameter(int position, Class type) {
+ return typedQuery.getParameter(position, type);
+ }
+
+ @Override
+ public boolean isBound(Parameter> param) {
+ return typedQuery.isBound(param);
+ }
+
+ @Override
+ public T getParameterValue(Parameter param) {
+ return typedQuery.getParameterValue(param);
+ }
+
+ @Override
+ public Object getParameterValue(String name) {
+ return typedQuery.getParameterValue(name);
+ }
+
+ @Override
+ public Object getParameterValue(int position) {
+ return typedQuery.getParameterValue(position);
+ }
+
+ @Override
+ public TypedQuery setFlushMode(FlushModeType flushMode) {
+ typedQuery.setFlushMode(flushMode);
+ return this;
+ }
+
+ @Override
+ public FlushModeType getFlushMode() {
+ return typedQuery.getFlushMode();
+ }
+
+ @Override
+ public TypedQuery setLockMode(LockModeType lockMode) {
+ typedQuery.setLockMode(lockMode);
+ return this;
+ }
+
+ @Override
+ public LockModeType getLockMode() {
+ return typedQuery.getLockMode();
+ }
+
+ @Override
+ public T unwrap(Class cls) {
+ return typedQuery.unwrap(cls);
+ }
+}
diff --git a/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/SyncEntityManagerWrapper.java b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/SyncEntityManagerWrapper.java
new file mode 100644
index 00000000..bf82d13a
--- /dev/null
+++ b/components/jpa/common/src/main/java/com/kumuluz/ee/jpa/common/jta/SyncEntityManagerWrapper.java
@@ -0,0 +1,304 @@
+/*
+ * Copyright (c) 2014-2017 Kumuluz and/or its affiliates
+ * and other contributors as indicated by the @author tags and
+ * the contributor list.
+ *
+ * Licensed under the MIT License (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/MIT
+ *
+ * The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
+ * implied, including but not limited to the warranties of merchantability,
+ * fitness for a particular purpose and noninfringement. in no event shall the
+ * authors or copyright holders be liable for any claim, damages or other
+ * liability, whether in an action of contract, tort or otherwise, arising from,
+ * out of or in connection with the software or the use or other dealings in the
+ * software. See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+package com.kumuluz.ee.jpa.common.jta;
+
+import javax.persistence.*;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaDelete;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.CriteriaUpdate;
+import javax.persistence.metamodel.Metamodel;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Tilen Faganel
+ * @since 2.4.0
+ */
+public class SyncEntityManagerWrapper implements EntityManager {
+
+ private EntityManager em;
+ private SynchronizationType sync;
+
+ public SyncEntityManagerWrapper(EntityManager em, SynchronizationType sync) {
+ this.em = em;
+ this.sync = sync;
+ }
+
+ public SynchronizationType getSynchronizationType() {
+ return sync;
+ }
+
+ @Override
+ public void persist(Object entity) {
+ em.persist(entity);
+ }
+
+ @Override
+ public T merge(T entity) {
+ return em.merge(entity);
+ }
+
+ @Override
+ public void remove(Object entity) {
+ em.remove(entity);
+ }
+
+ @Override
+ public T find(Class entityClass, Object primaryKey) {
+ return em.find(entityClass, primaryKey);
+ }
+
+ @Override
+ public T find(Class entityClass, Object primaryKey, Map properties) {
+ return em.find(entityClass, primaryKey, properties);
+ }
+
+ @Override
+ public T find(Class entityClass, Object primaryKey, LockModeType lockMode) {
+ return em.find(entityClass, primaryKey, lockMode);
+ }
+
+ @Override
+ public