rsanchez
2014-11-14 5beef4e86aa5355342e4e128752f40c51a493765
#2021 fix - Problem with MySQL y NOT NULL creation_timestamp column
1 files added
6 files modified
changed files
securis/src/main/java/net/curisit/securis/db/Application.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java patch | view | blame | history
securis/src/main/resources/META-INF/persistence.xml patch | view | blame | history
securis/src/main/resources/db/create_db.sql patch | view | blame | history
securis/src/main/resources/db/schema.sql patch | view | blame | history
securis/src/main/resources/log4j2.xml patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Application.java
....@@ -15,6 +15,9 @@
1515 import javax.persistence.OneToMany;
1616 import javax.persistence.Table;
1717
18
+import org.apache.logging.log4j.LogManager;
19
+import org.apache.logging.log4j.Logger;
20
+
1821 import com.fasterxml.jackson.annotation.JsonAutoDetect;
1922 import com.fasterxml.jackson.annotation.JsonIgnore;
2023 import com.fasterxml.jackson.annotation.JsonInclude;
....@@ -33,6 +36,8 @@
3336 @NamedQuery(name = "list-applications", query = "SELECT a FROM Application a")
3437 })
3538 public class Application implements Serializable {
39
+
40
+ private static final Logger LOG = LogManager.getLogger(Application.class);
3641
3742 private static final long serialVersionUID = 1L;
3843
....@@ -85,6 +90,7 @@
8590 }
8691
8792 public Date getCreationTimestamp() {
93
+ LOG.info("APP {} TS: {}", this.id, this.creationTimestamp);
8894 return creationTimestamp;
8995 }
9096
securis/src/main/java/net/curisit/securis/db/ApplicationMetadata.java
....@@ -12,6 +12,9 @@
1212 import javax.persistence.NamedQuery;
1313 import javax.persistence.Table;
1414
15
+import org.apache.logging.log4j.LogManager;
16
+import org.apache.logging.log4j.Logger;
17
+
1518 import com.fasterxml.jackson.annotation.JsonAutoDetect;
1619 import com.fasterxml.jackson.annotation.JsonIgnore;
1720 import com.fasterxml.jackson.annotation.JsonInclude;
....@@ -30,6 +33,8 @@
3033 @NamedQuery(name = "list-application-metadata", query = "SELECT a FROM ApplicationMetadata a where a.application.id = :applicationId")
3134 })
3235 public class ApplicationMetadata implements Serializable {
36
+
37
+ private static final Logger LOG = LogManager.getLogger(ApplicationMetadata.class);
3338
3439 private static final long serialVersionUID = 1L;
3540
....@@ -68,6 +73,7 @@
6873 }
6974
7075 public Date getCreationTimestamp() {
76
+ LOG.info("APP_MD (app: {}) {} TS: {}", this.application.getId(), this.key, this.creationTimestamp);
7177 return creationTimestamp;
7278 }
7379
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
....@@ -123,8 +123,9 @@
123123 if (app.getApplicationMetadata() != null) {
124124 for (ApplicationMetadata md : app.getApplicationMetadata()) {
125125 md.setApplication(app);
126
- md.setCreationTimestamp(app.getCreationTimestamp());
126
+ md.setCreationTimestamp(new Date());
127127 em.persist(md);
128
+ LOG.info("Creating METADATA: '{}' -> {}", md.getKey(), md.getCreationTimestamp());
128129 }
129130 }
130131 LOG.info("Creating application with date: " + app.getCreationTimestamp());
securis/src/main/resources/META-INF/persistence.xml
....@@ -14,7 +14,9 @@
1414 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
1515 <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/SeCurisDS" />
1616
17
- <property name="hibernate.show_sql" value="true" />
17
+<!-- <property name="hibernate.show_sql" value="true" />
18
+ <property name="hibernate.format_sql" value="true"/>
19
+ -->
1820 </properties>
1921
2022 </persistence-unit>
securis/src/main/resources/db/create_db.sql
....@@ -0,0 +1,7 @@
1
+create database securis CHARACTER SET utf8 COLLATE utf8_bin;
2
+create user securis identified by 'securis';
3
+create user securis@localhost identified by 'securis';
4
+grant all on securis.* to securis;
5
+grant all on securis.* to securis@localhost;
6
+#Update passwords
7
+flush privileges;
securis/src/main/resources/db/schema.sql
....@@ -35,7 +35,7 @@
3535 `key` VARCHAR(100) NOT NULL ,
3636 value VARCHAR(200) NULL ,
3737 mandatory BOOLEAN NOT NULL default true,
38
- creation_timestamp DATETIME NOT NULL default now(),
38
+ creation_timestamp DATETIME NULL default now(),
3939 PRIMARY KEY (application_id, `key`));
4040
4141
securis/src/main/resources/log4j2.xml
....@@ -1,42 +1,49 @@
11 <?xml version="1.0" encoding="UTF-8"?>
22 <Configuration>
3
- <Appenders>
3
+ <Appenders>
44
5
- <RollingFile name="defaultFile" fileName="${sys:user.home}/.SeCuris/logs/securis-server.log" append="true"
6
- filePattern="${sys:user.home}/.SeCuris/logs/securis-server-%d{yyyy-MM-dd-HH}.log.gz">
7
- <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
8
- <Policies>
9
- <TimeBasedTriggeringPolicy interval="1" modulate="true" />
10
- </Policies>
11
- <DefaultRolloverStrategy max="10"/>
12
- </RollingFile>
13
- <Async name="defaultFileAsync" includeLocation="true">
14
- <AppenderRef ref="defaultFile"/>
15
- </Async>
16
-
17
- <Console name="stdout" target="SYSTEM_OUT">
18
- <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
19
- </Console>
5
+ <RollingFile name="defaultFile"
6
+ fileName="${sys:user.home}/.SeCuris/logs/securis-server.log" append="true"
7
+ filePattern="${sys:user.home}/.SeCuris/logs/securis-server-%d{yyyy-MM-dd-HH}.log.gz">
8
+ <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n" />
9
+ <Policies>
10
+ <TimeBasedTriggeringPolicy interval="1"
11
+ modulate="true" />
12
+ </Policies>
13
+ <DefaultRolloverStrategy max="10" />
14
+ </RollingFile>
15
+ <Async name="defaultFileAsync" includeLocation="true">
16
+ <AppenderRef ref="defaultFile" />
17
+ </Async>
2018
21
- <Console name="console" target="SYSTEM_OUT">
22
- <PatternLayout pattern="%m%n"/>
23
- </Console>
19
+ <Console name="stdout" target="SYSTEM_OUT">
20
+ <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n" />
21
+ </Console>
2422
25
- </Appenders>
26
- <Loggers>
27
-
28
- <Logger name="net.curisit" level="INFO" additivity="false">
29
- <AppenderRef ref="defaultFileAsync"/>
30
- <AppenderRef ref="stdout"/>
31
- </Logger>
32
-
33
- <Logger name="console" level="INFO" additivity="false">
34
- <AppenderRef ref="console"/>
35
- </Logger>
36
-
37
- <Root level="INFO" >
38
- <AppenderRef ref="stdout"/>
39
- </Root>
23
+ <Console name="console" target="SYSTEM_OUT">
24
+ <PatternLayout pattern="%m%n" />
25
+ </Console>
4026
41
- </Loggers>
27
+ </Appenders>
28
+ <Loggers>
29
+
30
+ <Logger name="net.curisit" level="INFO" additivity="false">
31
+ <AppenderRef ref="defaultFileAsync" />
32
+ <AppenderRef ref="stdout" />
33
+ </Logger>
34
+
35
+ <Logger name="console" level="INFO" additivity="false">
36
+ <AppenderRef ref="console" />
37
+ </Logger>
38
+
39
+<!-- <logger name="org.hibernate.type.descriptor.sql.BasicBinder"
40
+ level="TRACE" additivity="false">
41
+ <appender-ref ref="stdout" />
42
+ </logger> -->
43
+
44
+ <Root level="INFO">
45
+ <AppenderRef ref="stdout" />
46
+ </Root>
47
+
48
+ </Loggers>
4249 </Configuration>