Merge remote-tracking branch 'central/master'
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.stackify</groupId>
|
||||
<artifactId>logback-example</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.janino</groupId>
|
||||
<artifactId>janino</artifactId>
|
||||
<version>3.0.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.stackify.logging;
|
||||
|
||||
import org.slf4j.Marker;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.turbo.TurboFilter;
|
||||
import ch.qos.logback.core.spi.FilterReply;
|
||||
|
||||
public class IgnoreLoggerFilter extends TurboFilter {
|
||||
|
||||
private String loggerName;
|
||||
|
||||
@Override
|
||||
public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
|
||||
if (loggerName == null) {
|
||||
return FilterReply.NEUTRAL;
|
||||
} else if (loggerName.equals(logger.getName())) {
|
||||
return FilterReply.DENY;
|
||||
} else
|
||||
return FilterReply.NEUTRAL;
|
||||
}
|
||||
|
||||
public void setLoggerName(String loggerName) {
|
||||
this.loggerName = loggerName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.stackify.models;
|
||||
|
||||
public class Employee {
|
||||
|
||||
private String email;
|
||||
private String name;
|
||||
|
||||
private double salary;
|
||||
|
||||
public Employee() {
|
||||
}
|
||||
|
||||
public Employee(String email, String name, double salary) {
|
||||
this.email = email;
|
||||
this.name = name;
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(double salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.stackify.services;
|
||||
|
||||
import com.stackify.models.Employee;
|
||||
|
||||
public class EmployeeService {
|
||||
|
||||
public double calculateBonus(Employee user) {
|
||||
return 0.1 * user.getSalary();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
env=dev
|
||||
@@ -0,0 +1,151 @@
|
||||
<configuration debug="true">
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<target>System.out</target>
|
||||
</appender>
|
||||
|
||||
<property name="fileName" value="file.log" />
|
||||
<property scope="context" resource="application.properties" />
|
||||
|
||||
<!-- configure appenders -->
|
||||
<appender name="rollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>log-%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
<totalSizeCap>3GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||
<maxFileSize>3MB</maxFileSize>
|
||||
</triggeringPolicy>
|
||||
<encoder>
|
||||
<pattern>%d [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="roleSiftingAppender" class="ch.qos.logback.classic.sift.SiftingAppender">
|
||||
<discriminator>
|
||||
<key>userRole</key>
|
||||
<defaultValue>ANONYMOUS</defaultValue>
|
||||
</discriminator>
|
||||
<sift>
|
||||
<appender name="fileAppender" class="ch.qos.logback.core.FileAppender">
|
||||
<file>${userRole}.log</file>
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<pattern>%d [%thread] %level %mdc %logger{50} - %msg%n</pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
</sift>
|
||||
</appender>
|
||||
|
||||
<!-- configure layouts -->
|
||||
<appender name="colorAppender" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>%d %green([%thread]) %highlight(%level) %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="htmlAppender" class="ch.qos.logback.core.FileAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="ch.qos.logback.classic.html.HTMLLayout">
|
||||
<pattern>%thread%level%logger%msg</pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
<file>log.html</file>
|
||||
</appender>
|
||||
|
||||
<!-- configure filters -->
|
||||
<appender name="STDOUT_LEVEL_FILTER_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<target>System.err</target>
|
||||
</appender>
|
||||
|
||||
<appender name="STDOUT_THRESHOLD_FILTER_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>WARN</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="STDOUT_EVALUATOR_FILTER_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
|
||||
<evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
|
||||
<expression>return (level > DEBUG && message.toLowerCase().contains("employee"));</expression>
|
||||
</evaluator>
|
||||
<OnMismatch>DENY</OnMismatch>
|
||||
<OnMatch>NEUTRAL</OnMatch>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- configure turbo filters -->
|
||||
<turboFilter class="ch.qos.logback.classic.turbo.DuplicateMessageFilter">
|
||||
<AllowedRepetitions>2</AllowedRepetitions>
|
||||
</turboFilter>
|
||||
|
||||
<turboFilter class="com.stackify.logging.IgnoreLoggerFilter">
|
||||
<LoggerName>ignoredColorLogger</LoggerName>
|
||||
</turboFilter>
|
||||
|
||||
<!-- configure loggers -->
|
||||
<logger level="info" name="rollingFileLogger" additivity="false">
|
||||
<appender-ref ref="rollingFileAppender" />
|
||||
</logger>
|
||||
|
||||
<logger level="info" name="htmlLogger" additivity="false">
|
||||
<appender-ref ref="htmlAppender" />
|
||||
</logger>
|
||||
|
||||
<logger level="info" name="roleSiftingLogger" additivity="false">
|
||||
<appender-ref ref="roleSiftingAppender" />
|
||||
</logger>
|
||||
|
||||
<logger level="info" name="colorLogger" additivity="false">
|
||||
<appender-ref ref="colorAppender" />
|
||||
</logger>
|
||||
|
||||
<logger level="info" name="ignoredColorLogger">
|
||||
<appender-ref ref="colorAppender" />
|
||||
</logger>
|
||||
|
||||
<logger level="info" name="levelFilterLogger" additivity="false">
|
||||
<appender-ref ref="STDOUT_LEVEL_FILTER_APPENDER" />
|
||||
</logger>
|
||||
|
||||
<logger level="info" name="thresholdFilterLogger" additivity="false">
|
||||
<appender-ref ref="STDOUT_THRESHOLD_FILTER_APPENDER" />
|
||||
</logger>
|
||||
|
||||
<logger level="info" name="evaluatorFilterLogger" additivity="false">
|
||||
<appender-ref ref="STDOUT_EVALUATOR_FILTER_APPENDER" />
|
||||
</logger>
|
||||
|
||||
<!-- configure root logger -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
<!-- configure root logger conditionally -->
|
||||
<property scope="context" resource="application.properties" />
|
||||
|
||||
<if condition='property("env").equals("dev")'>
|
||||
<then>
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</then>
|
||||
</if>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.stackify.services;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import com.stackify.models.Employee;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
|
||||
public class EmployeeServiceTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||
|
||||
private EmployeeService employeeService = new EmployeeService();
|
||||
|
||||
@Test
|
||||
public void testAppenders() {
|
||||
Logger rollingFileLogger = LoggerFactory.getLogger("rollingFileLogger");
|
||||
rollingFileLogger.info("Testing rolling file logger");
|
||||
|
||||
MDC.put("userRole", "ADMIN");
|
||||
Logger siftingLogger = LoggerFactory.getLogger("roleSiftingLogger");
|
||||
siftingLogger.info("Admin Action");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLayouts() {
|
||||
Logger htmlLogger = LoggerFactory.getLogger("htmlLogger");
|
||||
htmlLogger.error("Employee Information Update Failed");
|
||||
htmlLogger.info("New Account Created");
|
||||
|
||||
Logger colorLogger = LoggerFactory.getLogger("colorLogger");
|
||||
colorLogger.error("Employee Information Update Failed");
|
||||
colorLogger.info("New Account Created");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogLevel() {
|
||||
ch.qos.logback.classic.Logger rollingFileLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("rollingFileLogger");
|
||||
rollingFileLogger.setLevel(Level.DEBUG);
|
||||
rollingFileLogger.debug("Testing Log Level");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameter() {
|
||||
Employee employee = new Employee("[email protected]", "John", 2000);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("The bonus for employee: " + employee.getName() + " is " + employeeService.calculateBonus(employee));
|
||||
}
|
||||
logger.debug("The bonus for employee {} is {}", employee.getName(), employeeService.calculateBonus(employee));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilters() {
|
||||
Logger levelFilterLogger = LoggerFactory.getLogger("levelFilterLogger");
|
||||
levelFilterLogger.error("Employee Information Update Failed");
|
||||
Logger thresholdFilterLogger = LoggerFactory.getLogger("thresholdFilterLogger");
|
||||
thresholdFilterLogger.trace("Employee record inserted");
|
||||
Logger evaluatorFilterLogger = LoggerFactory.getLogger("evaluatorFilterLogger");
|
||||
evaluatorFilterLogger.debug("Employee account deactivated");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoredLogger() {
|
||||
Logger colorLogger = LoggerFactory.getLogger("ignoredColorLogger");
|
||||
colorLogger.info("Ignored Log Message");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditionalConfiguration() {
|
||||
logger.trace("Employee record updated");
|
||||
}
|
||||
}
|
||||
+98
-2
@@ -105,6 +105,92 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- /Neuroph -->
|
||||
|
||||
<!-- Reladomo -->
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generateMithra</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<property name="plugin_classpath" refid="maven.plugin.classpath" />
|
||||
<taskdef name="gen-reladomo" classpath="plugin_classpath"
|
||||
classname="com.gs.fw.common.mithra.generator.MithraGenerator" />
|
||||
<gen-reladomo
|
||||
xml="${project.basedir}/src/main/resources/reladomo/ReladomoClassList.xml"
|
||||
generateGscListMethod="true"
|
||||
generatedDir="${project.build.directory}/generated-sources/reladomo"
|
||||
nonGeneratedDir="${project.basedir}/src/main/java" />
|
||||
|
||||
<taskdef name="gen-ddl"
|
||||
classname="com.gs.fw.common.mithra.generator.dbgenerator.MithraDbDefinitionGenerator"
|
||||
loaderRef="reladomoGenerator">
|
||||
<classpath refid="maven.plugin.classpath" />
|
||||
</taskdef>
|
||||
<gen-ddl
|
||||
xml="${project.basedir}/src/main/resources/reladomo/ReladomoClassList.xml"
|
||||
generatedDir="${project.build.directory}/generated-db/sql"
|
||||
databaseType="postgres" />
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.goldmansachs.reladomo</groupId>
|
||||
<artifactId>reladomogen</artifactId>
|
||||
<version>${reladomo.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.goldmansachs.reladomo</groupId>
|
||||
<artifactId>reladomo-gen-util</artifactId>
|
||||
<version>${reladomo.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>${project.build.directory}/generated-sources/reladomo</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add-resource</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>add-resource</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/generated-db/</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- /Reladomo-->
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
@@ -497,6 +583,16 @@
|
||||
<artifactId>gt-swing</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.goldmansachs.reladomo</groupId>
|
||||
<artifactId>reladomo</artifactId>
|
||||
<version>${reladomo.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.goldmansachs.reladomo</groupId>
|
||||
<artifactId>reladomo-test-util</artifactId>
|
||||
<version>${reladomo.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
@@ -563,6 +659,6 @@
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<vavr.version>0.9.0</vavr.version>
|
||||
<geotools.version>15.2</geotools.version>
|
||||
<reladomo.version>16.5.1</reladomo.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
</project>
|
||||
@@ -7,7 +7,7 @@ import net.openhft.chronicle.ExcerptAppender;
|
||||
|
||||
public class ChronicleQueue {
|
||||
|
||||
public static void writeToQueue(
|
||||
static void writeToQueue(
|
||||
Chronicle chronicle, String stringValue, int intValue, long longValue, double doubleValue)
|
||||
throws IOException {
|
||||
ExcerptAppender appender = chronicle.createAppender();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.reladomo;
|
||||
|
||||
public class Department extends DepartmentAbstract {
|
||||
public Department() {
|
||||
super();
|
||||
// You must not modify this constructor. Mithra calls this internally.
|
||||
// You can call this constructor. You can also add new constructors.
|
||||
}
|
||||
|
||||
public Department(long id, String name) {
|
||||
super();
|
||||
this.setId(id);
|
||||
this.setName(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.reladomo;
|
||||
public class DepartmentDatabaseObject extends DepartmentDatabaseObjectAbstract
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.reladomo;
|
||||
import com.gs.fw.finder.Operation;
|
||||
import java.util.*;
|
||||
public class DepartmentList extends DepartmentListAbstract
|
||||
{
|
||||
public DepartmentList()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public DepartmentList(int initialSize)
|
||||
{
|
||||
super(initialSize);
|
||||
}
|
||||
|
||||
public DepartmentList(Collection c)
|
||||
{
|
||||
super(c);
|
||||
}
|
||||
|
||||
public DepartmentList(Operation operation)
|
||||
{
|
||||
super(operation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.reladomo;
|
||||
public class Employee extends EmployeeAbstract
|
||||
{
|
||||
public Employee()
|
||||
{
|
||||
super();
|
||||
// You must not modify this constructor. Mithra calls this internally.
|
||||
// You can call this constructor. You can also add new constructors.
|
||||
}
|
||||
|
||||
public Employee(long id, String name){
|
||||
super();
|
||||
this.setId(id);
|
||||
this.setName(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.reladomo;
|
||||
public class EmployeeDatabaseObject extends EmployeeDatabaseObjectAbstract
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.reladomo;
|
||||
import com.gs.fw.finder.Operation;
|
||||
import java.util.*;
|
||||
public class EmployeeList extends EmployeeListAbstract
|
||||
{
|
||||
public EmployeeList()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public EmployeeList(int initialSize)
|
||||
{
|
||||
super(initialSize);
|
||||
}
|
||||
|
||||
public EmployeeList(Collection c)
|
||||
{
|
||||
super(c);
|
||||
}
|
||||
|
||||
public EmployeeList(Operation operation)
|
||||
{
|
||||
super(operation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.reladomo;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.gs.fw.common.mithra.MithraManager;
|
||||
import com.gs.fw.common.mithra.MithraManagerProvider;
|
||||
|
||||
public class ReladomoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
ReladomoConnectionManager.getInstance().createTables();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
MithraManager mithraManager = MithraManagerProvider.getMithraManager();
|
||||
mithraManager.setTransactionTimeout(120);
|
||||
|
||||
try (InputStream is = ReladomoApplication.class.getClassLoader().getResourceAsStream("ReladomoRuntimeConfig.xml")) {
|
||||
MithraManagerProvider.getMithraManager().readConfiguration(is);
|
||||
|
||||
Department department = new Department(1, "IT");
|
||||
Employee employee = new Employee(1, "John");
|
||||
department.getEmployees().add(employee);
|
||||
department.cascadeInsert();
|
||||
|
||||
Department depFound = DepartmentFinder.findByPrimaryKey(1);
|
||||
System.out.println("Department Name:" + department.getName());
|
||||
|
||||
Employee empFound = EmployeeFinder.findOne(EmployeeFinder.name().eq("John"));
|
||||
System.out.println("Employee Id:" + empFound.getId());
|
||||
empFound.setName("Steven");
|
||||
empFound.delete();
|
||||
Department depDetached = DepartmentFinder.findByPrimaryKey(1).getDetachedCopy();
|
||||
|
||||
mithraManager.executeTransactionalCommand(tx -> {
|
||||
Department dep = new Department(2, "HR");
|
||||
Employee emp = new Employee(2, "Jim");
|
||||
dep.getEmployees().add(emp);
|
||||
dep.cascadeInsert();
|
||||
return null;
|
||||
});
|
||||
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.baeldung.reladomo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.TimeZone;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.h2.tools.RunScript;
|
||||
|
||||
import com.gs.fw.common.mithra.bulkloader.BulkLoader;
|
||||
import com.gs.fw.common.mithra.bulkloader.BulkLoaderException;
|
||||
import com.gs.fw.common.mithra.connectionmanager.SourcelessConnectionManager;
|
||||
import com.gs.fw.common.mithra.connectionmanager.XAConnectionManager;
|
||||
import com.gs.fw.common.mithra.databasetype.DatabaseType;
|
||||
import com.gs.fw.common.mithra.databasetype.H2DatabaseType;
|
||||
|
||||
public class ReladomoConnectionManager implements SourcelessConnectionManager {
|
||||
|
||||
private static ReladomoConnectionManager instance;
|
||||
|
||||
private XAConnectionManager xaConnectionManager;
|
||||
|
||||
private final String databaseName = "myDb";
|
||||
|
||||
public static synchronized ReladomoConnectionManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ReladomoConnectionManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ReladomoConnectionManager() {
|
||||
this.createConnectionManager();
|
||||
}
|
||||
|
||||
private XAConnectionManager createConnectionManager() {
|
||||
xaConnectionManager = new XAConnectionManager();
|
||||
xaConnectionManager.setDriverClassName("org.h2.Driver");
|
||||
xaConnectionManager.setJdbcConnectionString("jdbc:h2:mem:" + databaseName);
|
||||
xaConnectionManager.setJdbcUser("sa");
|
||||
xaConnectionManager.setJdbcPassword("");
|
||||
xaConnectionManager.setPoolName("My Connection Pool");
|
||||
xaConnectionManager.setInitialSize(1);
|
||||
xaConnectionManager.setPoolSize(10);
|
||||
xaConnectionManager.initialisePool();
|
||||
return xaConnectionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BulkLoader createBulkLoader() throws BulkLoaderException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return xaConnectionManager.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseType getDatabaseType() {
|
||||
return H2DatabaseType.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone getDatabaseTimeZone() {
|
||||
return TimeZone.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDatabaseIdentifier() {
|
||||
return databaseName;
|
||||
}
|
||||
|
||||
public void createTables() throws Exception {
|
||||
Path ddlPath = Paths.get(ClassLoader.getSystemResource("sql").toURI());
|
||||
|
||||
try (Connection conn = xaConnectionManager.getConnection(); Stream<Path> list = Files.list(ddlPath);) {
|
||||
list.forEach(path -> {
|
||||
try {
|
||||
RunScript.execute(conn, Files.newBufferedReader(path));
|
||||
} catch (SQLException | IOException exc) {
|
||||
exc.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<MithraRuntime>
|
||||
<ConnectionManager className="com.baeldung.reladomo.ReladomoConnectionManager ">
|
||||
<MithraObjectConfiguration className="com.baeldung.reladomo.Department" cacheType="partial"/>
|
||||
<MithraObjectConfiguration className="com.baeldung.reladomo.Employee " cacheType="partial"/>
|
||||
</ConnectionManager>
|
||||
</MithraRuntime>
|
||||
@@ -0,0 +1,11 @@
|
||||
<MithraObject objectType="transactional">
|
||||
<PackageName>com.baeldung.reladomo</PackageName>
|
||||
<ClassName>Department</ClassName>
|
||||
<DefaultTable>departments</DefaultTable>
|
||||
|
||||
<Attribute name="id" javaType="long" columnName="department_id" primaryKey="true"/>
|
||||
<Attribute name="name" javaType="String" columnName="name" maxLength="50" truncate="true"/>
|
||||
<Relationship name="employees" relatedObject="Employee" cardinality="one-to-many" reverseRelationshipName="department" relatedIsDependent="true">
|
||||
Employee.departmentId = this.id
|
||||
</Relationship>
|
||||
</MithraObject>
|
||||
@@ -0,0 +1,9 @@
|
||||
<MithraObject objectType="transactional">
|
||||
<PackageName>com.baeldung.reladomo</PackageName>
|
||||
<ClassName>Employee</ClassName>
|
||||
<DefaultTable>employees</DefaultTable>
|
||||
|
||||
<Attribute name="id" javaType="long" columnName="employee_id" primaryKey="true"/>
|
||||
<Attribute name="name" javaType="String" columnName="name" maxLength="50" truncate="true"/>
|
||||
<Attribute name="departmentId" javaType="long" columnName="department_id"/>
|
||||
</MithraObject>
|
||||
@@ -0,0 +1,4 @@
|
||||
<Mithra>
|
||||
<MithraObjectResource name="Department"/>
|
||||
<MithraObjectResource name="Employee"/>
|
||||
</Mithra>
|
||||
+7
-4
@@ -11,10 +11,13 @@ import java.util.concurrent.TimeUnit;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.awaitility.Awaitility.fieldIn;
|
||||
import static org.awaitility.Awaitility.given;
|
||||
import static org.awaitility.Awaitility.setDefaultPollDelay;
|
||||
import static org.awaitility.Awaitility.setDefaultPollInterval;
|
||||
import static org.awaitility.Awaitility.setDefaultTimeout;
|
||||
import static org.awaitility.proxy.AwaitilityClassProxy.to;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class AsyncServiceUnitTest {
|
||||
public class AsyncServiceLongRunningUnitTest {
|
||||
private AsyncService asyncService;
|
||||
|
||||
@Before
|
||||
@@ -41,9 +44,9 @@ public class AsyncServiceUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAsyncService_whenInitialize_thenInitOccurs_withDefualts() {
|
||||
Awaitility.setDefaultPollInterval(10, TimeUnit.MILLISECONDS);
|
||||
Awaitility.setDefaultPollDelay(Duration.ZERO);
|
||||
Awaitility.setDefaultTimeout(Duration.ONE_MINUTE);
|
||||
setDefaultPollInterval(10, TimeUnit.MILLISECONDS);
|
||||
setDefaultPollDelay(Duration.ZERO);
|
||||
setDefaultTimeout(Duration.ONE_MINUTE);
|
||||
|
||||
asyncService.initialize();
|
||||
await().until(asyncService::isInitialized);
|
||||
+1
-1
@@ -13,7 +13,7 @@ import net.openhft.chronicle.ChronicleQueueBuilder;
|
||||
import net.openhft.chronicle.ExcerptTailer;
|
||||
import net.openhft.chronicle.tools.ChronicleTools;
|
||||
|
||||
public class ChronicleQueueTest {
|
||||
public class ChronicleQueueIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenSetOfValues_whenWriteToQueue_thenWriteSuccesfully() throws IOException {
|
||||
+1
-1
@@ -11,7 +11,7 @@ import java.util.stream.LongStream;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
public class HLLUnitTest {
|
||||
public class HLLLongRunningUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenHLL_whenAddHugeAmountOfNumbers_thenShouldReturnEstimatedCardinality() {
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.reladomo;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gs.fw.common.mithra.test.ConnectionManagerForTests;
|
||||
import com.gs.fw.common.mithra.test.MithraTestResource;
|
||||
|
||||
public class ReladomoTest {
|
||||
private MithraTestResource mithraTestResource;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.mithraTestResource = new MithraTestResource("reladomo/ReladomoTestConfig.xml");
|
||||
|
||||
final ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstanceForDbName("testDb");
|
||||
this.mithraTestResource.createSingleDatabase(connectionManager);
|
||||
|
||||
mithraTestResource.addTestDataToDatabase("reladomo/test-data.txt", connectionManager);
|
||||
|
||||
this.mithraTestResource.setUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetTestData_thenOk() {
|
||||
Employee employee = EmployeeFinder.findByPrimaryKey(1);
|
||||
assertEquals(employee.getName(), "Paul");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
this.mithraTestResource.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<MithraRuntime>
|
||||
<ConnectionManager className="com.gs.fw.common.mithra.test.ConnectionManagerForTests">
|
||||
<Property name="resourceName" value="testDb"/>
|
||||
<MithraObjectConfiguration className="com.baeldung.reladomo.Department" cacheType="partial"/>
|
||||
<MithraObjectConfiguration className="com.baeldung.reladomo.Employee " cacheType="partial"/>
|
||||
</ConnectionManager>
|
||||
</MithraRuntime>
|
||||
@@ -0,0 +1,7 @@
|
||||
class com.baeldung.reladomo.Department
|
||||
id, name
|
||||
1, "Marketing"
|
||||
|
||||
class com.baeldung.reladomo.Employee
|
||||
id, name
|
||||
1, "Paul"
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.logging.log4j2.tests;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LambdaExpressionsIntegrationTest {
|
||||
|
||||
private static final Logger logger = LogManager.getRootLogger();
|
||||
|
||||
@Test
|
||||
public void whenCheckLogMessage_thenOk() {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Numer is {}", getRandomNumber());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUseLambdaExpression_thenOk() {
|
||||
logger.trace("Number is {}", () -> getRandomNumber());
|
||||
logger.trace("Name is {} and age is {}", () -> getName(), () -> getRandomNumber());
|
||||
}
|
||||
|
||||
private int getRandomNumber() {
|
||||
return (new Random()).nextInt(10);
|
||||
}
|
||||
|
||||
private String getName() {
|
||||
return "John";
|
||||
}
|
||||
}
|
||||
@@ -40,16 +40,38 @@
|
||||
<artifactId>ratpack-hikari</artifactId>
|
||||
<version>${ratpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.ratpack</groupId>
|
||||
<artifactId>ratpack-hystrix</artifactId>
|
||||
<version>${ratpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.ratpack</groupId>
|
||||
<artifactId>ratpack-rx</artifactId>
|
||||
<version>${ratpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.ratpack</groupId>
|
||||
<artifactId>ratpack-test</artifactId>
|
||||
<version>${ratpack.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.193</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.hystrix;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandGroupKey;
|
||||
import com.netflix.hystrix.HystrixCommandProperties;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class HystrixAsyncHttpCommand extends HystrixCommand<String> {
|
||||
|
||||
private URI uri;
|
||||
private RequestConfig requestConfig;
|
||||
|
||||
HystrixAsyncHttpCommand(URI uri, int timeoutMillis) {
|
||||
super(Setter
|
||||
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-async"))
|
||||
.andCommandPropertiesDefaults(HystrixCommandProperties
|
||||
.Setter()
|
||||
.withExecutionTimeoutInMilliseconds(timeoutMillis)));
|
||||
requestConfig = RequestConfig
|
||||
.custom()
|
||||
.setSocketTimeout(timeoutMillis)
|
||||
.setConnectTimeout(timeoutMillis)
|
||||
.setConnectionRequestTimeout(timeoutMillis)
|
||||
.build();
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String run() throws Exception {
|
||||
return EntityUtils.toString(HttpClientBuilder
|
||||
.create()
|
||||
.setDefaultRequestConfig(requestConfig)
|
||||
.setDefaultHeaders(Collections.singleton(new BasicHeader("User-Agent", "Baeldung Blocking HttpClient")))
|
||||
.build()
|
||||
.execute(new HttpGet(uri))
|
||||
.getEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFallback() {
|
||||
return "eugenp's async fallback profile";
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user