Skip to content

Commit 4941a70

Browse files
committed
Polishing
1 parent e376990 commit 4941a70

File tree

10 files changed

+83
-50
lines changed

10 files changed

+83
-50
lines changed

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<artifactId>audit4j-db</artifactId>
66
<packaging>jar</packaging>
77
<name>Audit4j - Database Handler</name>
8-
<version>2.2.0</version>
8+
<version>2.3.1</version>
99
<url>http://audit4j.org</url>
10-
<description>Audit4j - An open-source auditing framework for Java, Spring Integration</description>
10+
<description>Audit4j - An open-source auditing framework, Database handler</description>
1111
<organization>
1212
<name>Audit4j</name>
1313
<url>http://audit4j.org</url>
@@ -51,8 +51,7 @@
5151
</parent>
5252

5353
<properties>
54-
<spring.version>3.0.5.RELEASE</spring.version>
55-
<aspectj.version>1.6.11</aspectj.version>
54+
<audit4j.version>2.3.1</audit4j.version>
5655
</properties>
5756

5857
<dependencies>
@@ -65,12 +64,13 @@
6564
<dependency>
6665
<groupId>org.audit4j</groupId>
6766
<artifactId>audit4j-core</artifactId>
68-
<version>2.2.0</version>
67+
<version>${audit4j.version}</version>
68+
<scope>provided</scope>
6969
</dependency>
7070
<dependency>
7171
<groupId>c3p0</groupId>
7272
<artifactId>c3p0</artifactId>
73-
<version>0.9.1</version>
73+
<version>0.9.1.2</version>
7474
</dependency>
7575
<dependency>
7676
<groupId>org.hsqldb</groupId>

src/main/java/org/audit4j/handler/db/AuditBaseDao.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
4-
* http://mechanizedspace.com/audit4j
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
54
* http://audit4j.org
65
*
76
* Licensed under the Apache License, Version 2.0 (the "License");

src/main/java/org/audit4j/handler/db/AuditLogDao.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
4-
* http://mechanizedspace.com/audit4j
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
54
* http://audit4j.org
65
*
76
* Licensed under the Apache License, Version 2.0 (the "License");

src/main/java/org/audit4j/handler/db/AuditLogDaoImpl.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
4-
* http://mechanizedspace.com/audit4j
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
54
* http://audit4j.org
65
*
76
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,7 +53,7 @@ private AuditLogDaoImpl() {
5453
public boolean writeEvent(AuditEvent event) throws HandlerException {
5554
String uuid;
5655
String timestamp;
57-
StringBuffer elements = new StringBuffer();
56+
StringBuilder elements = new StringBuilder();
5857

5958
if (event.getUuid() == null) {
6059
uuid = String.valueOf(UUID.randomUUID().getMostSignificantBits());
@@ -129,12 +128,10 @@ public boolean createAuditTableIFNotExist() {
129128
}
130129

131130
public static AuditLogDao getInstance() {
132-
if (!initialized) {
133-
synchronized (AuditLogDaoImpl.class) {
134-
if (!initialized) {
135-
auditDao = new AuditLogDaoImpl();
136-
initialized = true;
137-
}
131+
synchronized (AuditLogDaoImpl.class) {
132+
if (!initialized) {
133+
auditDao = new AuditLogDaoImpl();
134+
initialized = true;
138135
}
139136
}
140137
return auditDao;

src/main/java/org/audit4j/handler/db/ConnectionFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
44
* http://audit4j.org
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,8 +28,8 @@
2828
import javax.naming.NamingException;
2929
import javax.sql.DataSource;
3030

31-
import org.audit4j.core.Log;
3231
import org.audit4j.core.exception.InitializationException;
32+
import org.audit4j.core.util.Log;
3333

3434
import com.mchange.v2.c3p0.ComboPooledDataSource;
3535

@@ -199,7 +199,7 @@ void stop() {
199199
}
200200
datasource = null;
201201
}
202-
202+
203203
/**
204204
* Sets the driver.
205205
*
@@ -266,8 +266,10 @@ public void setConnectionType(ConnectionType connectionType) {
266266
* @return single instance of ConnectionFactory
267267
*/
268268
static ConnectionFactory getInstance() {
269-
if (instance == null) {
270-
instance = new ConnectionFactory();
269+
synchronized (ConnectionFactory.class) {
270+
if (instance == null) {
271+
instance = new ConnectionFactory();
272+
}
271273
}
272274
return instance;
273275
}

src/main/java/org/audit4j/handler/db/ConnectionType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
44
* http://audit4j.org
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");

src/main/java/org/audit4j/handler/db/DatabaseAuditHandler.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
44
* http://audit4j.org
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -66,6 +66,8 @@ public class DatabaseAuditHandler extends Handler {
6666

6767
/** The factory. */
6868
private ConnectionFactory factory;
69+
70+
private AuditLogDao logDao;
6971

7072
/**
7173
* Initialize database handler.
@@ -80,10 +82,10 @@ public void init() throws InitializationException {
8082
db_driver = server.getDriver();
8183
db_url = server.getNetworkProtocol() + "://localhost/audit4j";
8284
if (db_user == null) {
83-
db_user = "audit4jdbuser";
85+
db_user = Utils.EMBEDED_DB_USER;
8486
}
8587
if (db_password == null) {
86-
db_password = "audit4jdbpassword";
88+
db_password = Utils.EMBEDED_DB_PASSWORD;
8789
}
8890
server.setUname(db_user);
8991
server.setPassword(db_password);
@@ -107,9 +109,9 @@ public void init() throws InitializationException {
107109

108110
factory.init();
109111

110-
AuditLogDao dao = AuditLogDaoImpl.getInstance();
112+
logDao = AuditLogDaoImpl.getInstance();
111113
try {
112-
dao.createAuditTableIFNotExist();
114+
logDao.createAuditTableIFNotExist();
113115
} catch (SQLException e) {
114116
throw new InitializationException("Could not create the audit table structure.", e);
115117
}
@@ -122,9 +124,8 @@ public void init() throws InitializationException {
122124
*/
123125
@Override
124126
public void handle() throws HandlerException {
125-
AuditLogDao dao = AuditLogDaoImpl.getInstance();
126127
try {
127-
dao.writeEvent(getAuditEvent());
128+
logDao.writeEvent(getAuditEvent());
128129
} catch (SQLException e) {
129130
throw new HandlerException("SQL exception occured while writing the event", DatabaseAuditHandler.class, e);
130131
}

src/main/java/org/audit4j/handler/db/EmbededDBServer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
4-
* http://mechanizedspace.com/audit4j
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
54
* http://audit4j.org
65
*
76
* Licensed under the Apache License, Version 2.0 (the "License");

src/main/java/org/audit4j/handler/db/HSQLEmbededDBServer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3-
* An open-source audit platform for Enterprise java platform.
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
44
* http://audit4j.org
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,8 +37,8 @@ final class HSQLEmbededDBServer extends EmbededDBServer {
3737

3838
/** The hsql server. */
3939
private Server hsqlServer = null;
40-
41-
private HSQLEmbededDBServer(){
40+
41+
private HSQLEmbededDBServer() {
4242
// Singalton private constructor.
4343
}
4444

@@ -78,9 +78,10 @@ void shutdown() {
7878
* @return single instance of HSQLEmbededDBServer
7979
*/
8080
static EmbededDBServer getInstance() {
81-
if (instance == null) {
82-
instance = new HSQLEmbededDBServer();
83-
return instance;
81+
synchronized (EmbededDBServer.class) {
82+
if (instance == null) {
83+
instance = new HSQLEmbededDBServer();
84+
}
8485
}
8586
return instance;
8687
}
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
1+
/*
2+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
3+
* Audit4j - An open source auditing framework.
4+
* http://audit4j.org
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
119
package org.audit4j.handler.db;
220

21+
/**
22+
* The Class Utils.
23+
*
24+
* @author <a href="mailto:[email protected]">Janith Bandara</a>
25+
*/
326
public class Utils {
27+
428
/** The Constant EMBEDED_DB_NAME. */
529
static final String EMBEDED_DB_NAME = "audit4j";
630

31+
/** The Constant EMBEDED_DB_USER. */
32+
static final String EMBEDED_DB_USER = "audit4jdbuser";
33+
34+
/** The Constant EMBEDED_DB_PASSWORD. */
35+
static final String EMBEDED_DB_PASSWORD = "audit4jdbpassword";
36+
37+
/**
38+
* Gets the dB name.
39+
*
40+
* @param userName the user name
41+
* @return the dB name
42+
*/
743
public static String getDBName(String userName) {
8-
StringBuffer buffer = new StringBuffer();
44+
StringBuilder buffer = new StringBuilder();
945
buffer.append(EMBEDED_DB_NAME);
1046
buffer.append("@");
1147
buffer.append(userName);
1248
return buffer.toString();
1349
}
14-
1550
}

0 commit comments

Comments
 (0)