mirror of
https://github.com/gmbrax/MediaManager-core.git
synced 2026-11-09 22:10:17 +00:00
Compare commits
17
Commits
@@ -13,7 +13,7 @@
|
|||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<hibernate.version>7.1.7.Final</hibernate.version>
|
<hibernate.version>7.1.7.Final</hibernate.version>
|
||||||
<postgresql.version>42.7.5</postgresql.version>
|
<postgresql.version>42.7.7</postgresql.version>
|
||||||
<hikaricp.version>5.1.0</hikaricp.version>
|
<hikaricp.version>5.1.0</hikaricp.version>
|
||||||
<log4j.version>2.23.1</log4j.version>
|
<log4j.version>2.23.1</log4j.version>
|
||||||
<junit.version>5.10.2</junit.version>
|
<junit.version>5.10.2</junit.version>
|
||||||
@@ -35,6 +35,12 @@
|
|||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-community-dialects</artifactId>
|
||||||
|
<version>${hibernate.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- HikariCP for connection pooling -->
|
<!-- HikariCP for connection pooling -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
@@ -55,7 +61,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
<artifactId>log4j-slf4j2-impl</artifactId>
|
<artifactId>log4j-slf4j-impl</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -83,6 +89,16 @@
|
|||||||
<artifactId>protobuf-java</artifactId>
|
<artifactId>protobuf-java</artifactId>
|
||||||
<version>4.32.0</version>
|
<version>4.32.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.xerial</groupId>
|
||||||
|
<artifactId>sqlite-jdbc</artifactId>
|
||||||
|
<version>3.44.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>0.10.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.mediamanager;
|
package com.mediamanager;
|
||||||
|
|
||||||
|
import com.mediamanager.service.database.DatabaseManager;
|
||||||
import com.mediamanager.service.delegate.DelegateActionManager;
|
import com.mediamanager.service.delegate.DelegateActionManager;
|
||||||
import com.mediamanager.service.ipc.IPCManager;
|
import com.mediamanager.service.ipc.IPCManager;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -9,7 +10,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.mediamanager.service.database.DatabaseManager;
|
import com.mediamanager.service.database.SqliteDatabaseManager;
|
||||||
|
|
||||||
public class MediaManagerApplication {
|
public class MediaManagerApplication {
|
||||||
private static final Logger logger = LogManager.getLogger(MediaManagerApplication.class);
|
private static final Logger logger = LogManager.getLogger(MediaManagerApplication.class);
|
||||||
@@ -18,15 +19,48 @@ public class MediaManagerApplication {
|
|||||||
private static DelegateActionManager actionManager;
|
private static DelegateActionManager actionManager;
|
||||||
private static IPCManager ipcManager;
|
private static IPCManager ipcManager;
|
||||||
|
|
||||||
|
public enum ApplicationMode {
|
||||||
|
LOCAL("local"),
|
||||||
|
SERVER("server");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
ApplicationMode(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
logger.info("Starting MediaManager Core Application...");
|
logger.info("Starting MediaManager Core Application...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Load configuration
|
// Load configuration
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
databaseManager = new DatabaseManager(config);
|
String runTypeString = config.getProperty("runtype","local");
|
||||||
|
ApplicationMode mode = null;
|
||||||
|
|
||||||
|
for (ApplicationMode am : ApplicationMode.values()) {
|
||||||
|
if (am.value.equalsIgnoreCase(runTypeString)) {
|
||||||
|
mode = am;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mode == null) {
|
||||||
|
logger.error("Invalid run type: {}", runTypeString);
|
||||||
|
throw new Exception("Invalid run type: " + runTypeString);
|
||||||
|
}
|
||||||
|
logger.info("Run type: {}", mode);
|
||||||
|
switch (mode) {
|
||||||
|
case LOCAL:
|
||||||
|
logger.info("Starting local database...");
|
||||||
|
databaseManager = new SqliteDatabaseManager(config);
|
||||||
|
break;
|
||||||
|
case SERVER:
|
||||||
|
throw new Exception("Server mode not yet implemented");
|
||||||
|
default:
|
||||||
|
}
|
||||||
databaseManager.init();
|
databaseManager.init();
|
||||||
actionManager = new DelegateActionManager();
|
actionManager = new DelegateActionManager(databaseManager.getEntityManagerFactory());
|
||||||
actionManager.start();
|
actionManager.start();
|
||||||
ipcManager = new IPCManager(config,actionManager);
|
ipcManager = new IPCManager(config,actionManager);
|
||||||
ipcManager.init();
|
ipcManager.init();
|
||||||
@@ -102,4 +136,4 @@ public class MediaManagerApplication {
|
|||||||
public static Properties getConfig() {
|
public static Properties getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.mediamanager.mapper;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import com.mediamanager.protocol.messages.GenreMessages;
|
||||||
|
|
||||||
|
public class GenreMapper {
|
||||||
|
public static GenreMessages.Genre toProtobuf(Genre entity) {
|
||||||
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
GenreMessages.Genre.Builder builder = GenreMessages.Genre.newBuilder()
|
||||||
|
.setName(entity.getName());
|
||||||
|
|
||||||
|
// Only set ID when it's present and valid (> 0). Avoids NPE for null IDs.
|
||||||
|
Integer id = entity.getId();
|
||||||
|
if (id != null && id > 0) {
|
||||||
|
builder.setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
public static Genre toEntity(GenreMessages.Genre protobuf) {
|
||||||
|
if (protobuf == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Genre entity = new Genre();
|
||||||
|
|
||||||
|
// Só seta ID se for > 0 (protobuf default é 0)
|
||||||
|
if (protobuf.getId() > 0) {
|
||||||
|
entity.setId(protobuf.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setName(protobuf.getName());
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.mediamanager.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "genre")
|
||||||
|
public class Genre {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
package com.mediamanager.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "media")
|
|
||||||
public class Media {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
@Column(nullable = false, unique = true)
|
|
||||||
private String filePath;
|
|
||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
@Column(nullable = false)
|
|
||||||
private MediaType type;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private Long fileSize;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String mimeType;
|
|
||||||
|
|
||||||
@Column(name = "created_at", nullable = false, updatable = false)
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
|
|
||||||
@Column(name = "updated_at")
|
|
||||||
private LocalDateTime updatedAt;
|
|
||||||
|
|
||||||
@PrePersist
|
|
||||||
protected void onCreate() {
|
|
||||||
createdAt = LocalDateTime.now();
|
|
||||||
updatedAt = LocalDateTime.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreUpdate
|
|
||||||
protected void onUpdate() {
|
|
||||||
updatedAt = LocalDateTime.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
public Media() {}
|
|
||||||
|
|
||||||
public Media(String title, String filePath, MediaType type) {
|
|
||||||
this.title = title;
|
|
||||||
this.filePath = filePath;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFilePath() {
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilePath(String filePath) {
|
|
||||||
this.filePath = filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MediaType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(MediaType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getFileSize() {
|
|
||||||
return fileSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFileSize(Long fileSize) {
|
|
||||||
this.fileSize = fileSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMimeType() {
|
|
||||||
return mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMimeType(String mimeType) {
|
|
||||||
this.mimeType = mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getCreatedAt() {
|
|
||||||
return createdAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreatedAt(LocalDateTime createdAt) {
|
|
||||||
this.createdAt = createdAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getUpdatedAt() {
|
|
||||||
return updatedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
|
||||||
this.updatedAt = updatedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum MediaType {
|
|
||||||
VIDEO,
|
|
||||||
AUDIO,
|
|
||||||
IMAGE,
|
|
||||||
DOCUMENT,
|
|
||||||
OTHER
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package com.mediamanager.repository;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository para acesso a dados de Genre
|
||||||
|
* Encapsula todas as operações de banco de dados
|
||||||
|
*/
|
||||||
|
public class GenreRepository {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GenreRepository.class);
|
||||||
|
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
|
|
||||||
|
public GenreRepository(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Salva um novo genre
|
||||||
|
*/
|
||||||
|
public Genre save(Genre genre) {
|
||||||
|
logger.debug("Saving genre: {}", genre.getName());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
em.persist(genre);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Genre saved with ID: {}", genre.getId());
|
||||||
|
return genre;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error saving genre", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Busca todos os genres
|
||||||
|
*/
|
||||||
|
public List<Genre> findAll() {
|
||||||
|
logger.debug("Finding all genres");
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try {
|
||||||
|
return em
|
||||||
|
.createQuery("SELECT g FROM Genre g ORDER BY g.name", Genre.class)
|
||||||
|
.getResultList();
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Busca genre por ID
|
||||||
|
*/
|
||||||
|
public Optional<Genre> findById(Integer id) {
|
||||||
|
logger.debug("Finding genre by ID: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
try {
|
||||||
|
Genre genre = em.find(Genre.class, id);
|
||||||
|
return Optional.ofNullable(genre);
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atualiza um genre existente
|
||||||
|
*/
|
||||||
|
public Genre update(Genre genre) {
|
||||||
|
logger.debug("Updating genre ID: {}", genre.getId());
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
Genre updated = em.merge(genre);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Genre updated successfully");
|
||||||
|
return updated;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error updating genre", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deleta um genre por ID
|
||||||
|
*/
|
||||||
|
public boolean deleteById(Integer id) {
|
||||||
|
logger.debug("Deleting genre by ID: {}", id);
|
||||||
|
EntityManager em = entityManagerFactory.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
try {
|
||||||
|
Genre genre = em.find(Genre.class, id);
|
||||||
|
if (genre == null) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
em.remove(genre);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
logger.debug("Genre deleted successfully");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
logger.error("Error deleting genre", e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
if (em.isOpen()) em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,55 +1,36 @@
|
|||||||
package com.mediamanager.service.database;
|
package com.mediamanager.service.database;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
import org.reflections.scanners.Scanners;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import java.util.Set;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
public class DatabaseManager {
|
public abstract class DatabaseManager {
|
||||||
private final Properties configuration;
|
protected final Properties configuration;
|
||||||
private Connection connection;
|
protected Connection connection;
|
||||||
private static final Logger logger = LogManager.getLogger(DatabaseManager.class);
|
protected String connectionUrl;
|
||||||
|
protected EntityManagerFactory entityManagerFactory;
|
||||||
|
protected static final Logger logger = LogManager.getLogger(DatabaseManager.class);
|
||||||
|
|
||||||
public DatabaseManager(Properties config) {
|
public DatabaseManager(Properties config) {
|
||||||
this.configuration = config;
|
this.configuration = config;
|
||||||
logger.debug("DatabaseManager created with configuration:");
|
logger.debug("DatabaseManager created with configuration:");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() throws Exception {
|
public abstract void init() throws Exception;
|
||||||
logger.info("Initializing database connection...");
|
|
||||||
validateConfiguration();
|
|
||||||
|
|
||||||
String databaseType = configuration.getProperty("database.type");
|
protected abstract Connection createConnection() throws Exception;
|
||||||
String databaseUrl = configuration.getProperty("database.url");
|
|
||||||
String databaseUsername = configuration.getProperty("database.username");
|
|
||||||
String databasePassword = configuration.getProperty("database.password");
|
|
||||||
String databasePort = configuration.getProperty("database.port");
|
|
||||||
String databaseName = configuration.getProperty("database.name");
|
|
||||||
|
|
||||||
|
protected void performSanityChecks() throws SQLException {
|
||||||
String connectionString = String.format("jdbc:postgresql://%s:%s/%s", databaseUrl, databasePort, databaseName);
|
|
||||||
logger.debug("Attempting to connect to: {}", connectionString);
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(connectionString, databaseUsername, databasePassword);
|
|
||||||
logger.info("Database connection established successfully");
|
|
||||||
|
|
||||||
performSanityChecks();
|
|
||||||
logger.info("Database sanity checks passed successfully");
|
|
||||||
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
logger.error("Failed to connect to database", e);
|
|
||||||
throw new Exception("Database connection failed: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
private void performSanityChecks() throws SQLException {
|
|
||||||
logger.debug("Performing sanity checks...");
|
logger.debug("Performing sanity checks...");
|
||||||
try (Statement stmt = connection.createStatement()) {
|
try (Statement stmt = connection.createStatement()) {
|
||||||
stmt.execute("SELECT 1");
|
stmt.execute("SELECT 1");
|
||||||
@@ -59,33 +40,20 @@ public class DatabaseManager {
|
|||||||
String databaseProductVersion = connection.getMetaData().getDatabaseProductVersion();
|
String databaseProductVersion = connection.getMetaData().getDatabaseProductVersion();
|
||||||
logger.info("Connected to database: {} v{}", databaseProductName, databaseProductVersion);
|
logger.info("Connected to database: {} v{}", databaseProductName, databaseProductVersion);
|
||||||
}
|
}
|
||||||
private void validateConfiguration() throws Exception {
|
|
||||||
String[] requiredProperties = {
|
|
||||||
"database.url",
|
|
||||||
"database.username",
|
|
||||||
"database.password",
|
|
||||||
"database.port",
|
|
||||||
"database.name"
|
|
||||||
};
|
|
||||||
|
|
||||||
for (String property : requiredProperties) {
|
|
||||||
if (configuration.getProperty(property) == null ||
|
|
||||||
configuration.getProperty(property).trim().isEmpty()) {
|
|
||||||
throw new Exception("Required database configuration missing: " + property);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("Database configuration validated successfully");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
|
||||||
|
try {
|
||||||
|
entityManagerFactory.close();
|
||||||
|
logger.info("EntityManagerFactory closed");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error closing EntityManagerFactory: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
try {
|
try {
|
||||||
logger.info("Closing database connection...");
|
logger.info("Closing database connection...");
|
||||||
@@ -98,4 +66,77 @@ public class DatabaseManager {
|
|||||||
logger.debug("No database connection to close");
|
logger.debug("No database connection to close");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
protected boolean testConnection() {
|
||||||
|
try (Statement stmt = connection.createStatement()) {
|
||||||
|
stmt.execute("SELECT 1");
|
||||||
|
return true;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
logger.error("Connection test failed", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void initializeHibernate() {
|
||||||
|
logger.info("Initializing Hibernate ORM...");
|
||||||
|
|
||||||
|
Configuration hibernateConfig = new Configuration();
|
||||||
|
|
||||||
|
|
||||||
|
String dialect = configuration.getProperty("hibernate.dialect");
|
||||||
|
String hbm2ddl = configuration.getProperty("hibernate.hbm2ddl.auto");
|
||||||
|
String driver = configuration.getProperty("database.driver");
|
||||||
|
|
||||||
|
if (dialect == null || dialect.isEmpty()) {
|
||||||
|
throw new IllegalStateException("hibernate.dialect property is required but not configured");
|
||||||
|
}
|
||||||
|
if (driver == null || driver.isEmpty()) {
|
||||||
|
throw new IllegalStateException("database.driver property is required but not configured");
|
||||||
|
}
|
||||||
|
if (connectionUrl == null || connectionUrl.isEmpty()) {
|
||||||
|
throw new IllegalStateException("connectionUrl must be set before initializing Hibernate");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
hibernateConfig.setProperty("hibernate.connection.url", connectionUrl);
|
||||||
|
hibernateConfig.setProperty("hibernate.connection.driver_class", driver);
|
||||||
|
hibernateConfig.setProperty("hibernate.dialect", dialect);
|
||||||
|
hibernateConfig.setProperty("hibernate.hbm2ddl.auto", hbm2ddl);
|
||||||
|
hibernateConfig.setProperty("hibernate.show_sql",
|
||||||
|
configuration.getProperty("hibernate.show_sql", "false"));
|
||||||
|
hibernateConfig.setProperty("hibernate.format_sql",
|
||||||
|
configuration.getProperty("hibernate.format_sql", "true"));
|
||||||
|
|
||||||
|
logger.info("Scanning for entities in package: com.mediamanager.model");
|
||||||
|
|
||||||
|
Set<Class<?>> entityClasses;
|
||||||
|
try {
|
||||||
|
Reflections reflections = new Reflections("com.mediamanager.model", Scanners.TypesAnnotated);
|
||||||
|
entityClasses = reflections.getTypesAnnotatedWith(Entity.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to scan for entities: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("Entity scanning failed", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Found {} entities", entityClasses.size());
|
||||||
|
if (entityClasses.isEmpty()) {
|
||||||
|
logger.warn("No @Entity classes found in package com.mediamanager.model - is this expected?");
|
||||||
|
}
|
||||||
|
for (Class<?> entityClass : entityClasses) {
|
||||||
|
logger.debug("Registering entity: {}", entityClass.getSimpleName());
|
||||||
|
hibernateConfig.addAnnotatedClass(entityClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
entityManagerFactory = hibernateConfig.buildSessionFactory().unwrap(EntityManagerFactory.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to initialize Hibernate: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("Hibernate initialization failed", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Hibernate ORM initialized successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityManagerFactory getEntityManagerFactory() {
|
||||||
|
return entityManagerFactory;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package com.mediamanager.service.database;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class SqliteDatabaseManager extends DatabaseManager {
|
||||||
|
private static final Logger logger = LogManager.getLogger(SqliteDatabaseManager.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public SqliteDatabaseManager(Properties config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
|
||||||
|
logger.info("Initializing SQLite database...");
|
||||||
|
String dataDir = configuration.getProperty("database.dir",
|
||||||
|
System.getProperty("user.home") + "/.mediamanager/db");
|
||||||
|
String dbFilename = configuration.getProperty("database.filename", "mediamanager.db");
|
||||||
|
String driverClassName = configuration.getProperty("database.driver", "org.sqlite.JDBC");
|
||||||
|
try {
|
||||||
|
Class.forName(driverClassName);
|
||||||
|
}catch(ClassNotFoundException e) {
|
||||||
|
logger.error("Failed to load SQLite driver", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
Path dataPath = Paths.get(dataDir);
|
||||||
|
if (!Files.exists(dataPath)) {
|
||||||
|
Files.createDirectories(dataPath);
|
||||||
|
logger.debug("Created database directory: {}", dataDir);
|
||||||
|
}
|
||||||
|
Path dbFile = dataPath.resolve(dbFilename);
|
||||||
|
this.connectionUrl = "jdbc:sqlite:" + dbFile.toAbsolutePath().toString();
|
||||||
|
logger.info("Database file path: {}", dbFile);
|
||||||
|
logger.info("Connection URL: {}", this.connectionUrl);
|
||||||
|
initializeHibernate();
|
||||||
|
this.connection = createConnection();
|
||||||
|
configurePerformancePragmas();
|
||||||
|
performSanityChecks();
|
||||||
|
ensureSchemaExists();
|
||||||
|
logger.info("SQLite database initialized successfully");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Connection createConnection() throws Exception {
|
||||||
|
try {
|
||||||
|
// O driver org.xerial.sqlite-jdbc é carregado automaticamente aqui
|
||||||
|
Connection conn = DriverManager.getConnection(this.connectionUrl);
|
||||||
|
logger.debug("Got connection to SQLite file");
|
||||||
|
return conn;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
logger.error("Failed to create SQLite connection", e);
|
||||||
|
throw new Exception("SQLite connection failed: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void configurePerformancePragmas() throws SQLException {
|
||||||
|
try (Statement stmt = connection.createStatement()) {
|
||||||
|
|
||||||
|
stmt.execute("PRAGMA journal_mode=WAL;");
|
||||||
|
|
||||||
|
|
||||||
|
stmt.execute("PRAGMA foreign_keys=ON;");
|
||||||
|
|
||||||
|
|
||||||
|
stmt.execute("PRAGMA synchronous=NORMAL;");
|
||||||
|
|
||||||
|
stmt.execute("PRAGMA busy_timeout=5000;");
|
||||||
|
|
||||||
|
logger.debug("SQLite performance PRAGMAs applied (WAL, Synchronous, ForeignKeys).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureSchemaExists() throws SQLException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
|
||||||
|
super.close();
|
||||||
|
logger.info("SQLite resources released.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,13 @@ package com.mediamanager.service.delegate;
|
|||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.mediamanager.protocol.TransportProtocol;
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.repository.GenreRepository;
|
||||||
|
import com.mediamanager.service.delegate.handler.CloseHandler;
|
||||||
import com.mediamanager.service.delegate.handler.EchoHandler;
|
import com.mediamanager.service.delegate.handler.EchoHandler;
|
||||||
|
import com.mediamanager.service.delegate.handler.HeartbeatHandler;
|
||||||
|
import com.mediamanager.service.delegate.handler.genre.*;
|
||||||
|
import com.mediamanager.service.genre.GenreService;
|
||||||
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -13,9 +19,14 @@ public class DelegateActionManager {
|
|||||||
private static final Logger logger = LogManager.getLogger(DelegateActionManager.class);
|
private static final Logger logger = LogManager.getLogger(DelegateActionManager.class);
|
||||||
|
|
||||||
private final Map<String, ActionHandler> handlerRegistry;
|
private final Map<String, ActionHandler> handlerRegistry;
|
||||||
|
private final EntityManagerFactory entityManagerFactory;
|
||||||
public DelegateActionManager() {
|
private final GenreService genreService;
|
||||||
|
|
||||||
|
public DelegateActionManager(EntityManagerFactory entityManagerFactory) {
|
||||||
|
this.entityManagerFactory = entityManagerFactory;
|
||||||
|
|
||||||
|
GenreRepository genreRepository = new GenreRepository(entityManagerFactory);
|
||||||
|
this.genreService = new GenreService(genreRepository);
|
||||||
logger.debug("DelegateActionManager created");
|
logger.debug("DelegateActionManager created");
|
||||||
this.handlerRegistry = new HashMap<>();
|
this.handlerRegistry = new HashMap<>();
|
||||||
registerHandlers();
|
registerHandlers();
|
||||||
@@ -23,6 +34,13 @@ public class DelegateActionManager {
|
|||||||
|
|
||||||
private void registerHandlers() {
|
private void registerHandlers() {
|
||||||
handlerRegistry.put("echo",new EchoHandler());
|
handlerRegistry.put("echo",new EchoHandler());
|
||||||
|
handlerRegistry.put("heartbeat",new HeartbeatHandler());
|
||||||
|
handlerRegistry.put("close", new CloseHandler());
|
||||||
|
handlerRegistry.put("create_genre", new CreateGenreHandler(genreService));
|
||||||
|
handlerRegistry.put("get_genres", new GetGenreHandler(genreService));
|
||||||
|
handlerRegistry.put("get_genre_by_id", new GetGenreByIdHandler(genreService));
|
||||||
|
handlerRegistry.put("update_genre", new UpdateGenreHandler(genreService));
|
||||||
|
handlerRegistry.put("delete_genre", new DeleteGenreHandler(genreService));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(){
|
public void start(){
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TestProtocol.CloseCommand;
|
||||||
|
import com.mediamanager.protocol.TestProtocol.CloseResponse;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
public class CloseHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CloseHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
CloseCommand.parseFrom(requestPayload); // Valida
|
||||||
|
|
||||||
|
logger.info("Close command received - connection will close");
|
||||||
|
|
||||||
|
CloseResponse response = CloseResponse.newBuilder()
|
||||||
|
.setMessage("Connection closing. Goodbye!")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(ByteString.copyFrom(response.toByteArray()))
|
||||||
|
.setStatusCode(200)
|
||||||
|
.putHeaders("Connection", "close"); // ← Marca para fechar
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,39 @@
|
|||||||
package com.mediamanager.service.delegate.handler;
|
package com.mediamanager.service.delegate.handler;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TestProtocol.EchoCommand; // ← Import
|
||||||
|
import com.mediamanager.protocol.TestProtocol.EchoResponse; // ← Import
|
||||||
import com.mediamanager.protocol.TransportProtocol;
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
import com.mediamanager.service.delegate.ActionHandler;
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class EchoHandler implements ActionHandler {
|
public class EchoHandler implements ActionHandler {
|
||||||
@Override
|
private static final Logger logger = LogManager.getLogger(EchoHandler.class);
|
||||||
public TransportProtocol.Response.Builder handle(ByteString requestPayload) {
|
|
||||||
String payloadText = requestPayload.toStringUtf8();
|
|
||||||
String responseText = "Server received: " + payloadText;
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException { // ← Pode lançar exceção
|
||||||
|
|
||||||
|
// 1. Parse Protobuf bytes → EchoCommand
|
||||||
|
EchoCommand command = EchoCommand.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
logger.debug("Echo received: {}", command.getMessage());
|
||||||
|
|
||||||
|
// 2. Cria EchoResponse (Protobuf)
|
||||||
|
EchoResponse echoResponse = EchoResponse.newBuilder()
|
||||||
|
.setMessage(command.getMessage())
|
||||||
|
.setServerTimestamp(System.currentTimeMillis())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 3. Serializa EchoResponse → bytes
|
||||||
|
ByteString responsePayload = ByteString.copyFrom(echoResponse.toByteArray());
|
||||||
|
|
||||||
|
// 4. Retorna Response
|
||||||
return TransportProtocol.Response.newBuilder()
|
return TransportProtocol.Response.newBuilder()
|
||||||
.setPayload(ByteString.copyFromUtf8(responseText))
|
.setPayload(responsePayload)
|
||||||
.setStatusCode(200);
|
.setStatusCode(200);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TestProtocol.HeartbeatCommand;
|
||||||
|
import com.mediamanager.protocol.TestProtocol.HeartbeatResponse;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
public class HeartbeatHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(HeartbeatHandler.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
|
||||||
|
HeartbeatCommand command = HeartbeatCommand.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
long serverTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
logger.debug("Heartbeat received. Client T1={}, Server T2={}",
|
||||||
|
command.getClientTimestamp(), serverTime);
|
||||||
|
|
||||||
|
HeartbeatResponse response = HeartbeatResponse.newBuilder()
|
||||||
|
.setClientTimestamp(command.getClientTimestamp()) // Echo T1
|
||||||
|
.setServerTimestamp(serverTime) // T2
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(ByteString.copyFrom(response.toByteArray()))
|
||||||
|
.setStatusCode(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.genre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.GenreMapper;
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.GenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.genre.GenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
public class CreateGenreHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CreateGenreHandler.class);
|
||||||
|
|
||||||
|
private final GenreService genreService;
|
||||||
|
|
||||||
|
public CreateGenreHandler(GenreService genreService) {
|
||||||
|
this.genreService = genreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
// 1. Parse protobuf request
|
||||||
|
GenreMessages.CreateGenreRequest createRequest =
|
||||||
|
GenreMessages.CreateGenreRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
// 2. Chama service (lógica de negócio)
|
||||||
|
Genre genre = genreService.createGenre(createRequest.getName());
|
||||||
|
|
||||||
|
// 3. Converte entity para protobuf
|
||||||
|
GenreMessages.Genre genreProto = GenreMapper.toProtobuf(genre);
|
||||||
|
|
||||||
|
// 4. Cria response protobuf
|
||||||
|
GenreMessages.CreateGenreResponse createResponse =
|
||||||
|
GenreMessages.CreateGenreResponse.newBuilder()
|
||||||
|
.setGenre(genreProto)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 5. Retorna
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(createResponse.toByteString());
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.error("Validation error", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error creating genre", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.genre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.GenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.genre.GenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
public class DeleteGenreHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(DeleteGenreHandler.class);
|
||||||
|
|
||||||
|
private final GenreService genreService;
|
||||||
|
|
||||||
|
public DeleteGenreHandler(GenreService genreService) {
|
||||||
|
this.genreService = genreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
// 1. Parse protobuf request
|
||||||
|
GenreMessages.DeleteGenreRequest deleteRequest =
|
||||||
|
GenreMessages.DeleteGenreRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
int id = deleteRequest.getId();
|
||||||
|
|
||||||
|
// 2. Deleta via service
|
||||||
|
boolean success = genreService.deleteGenre(id);
|
||||||
|
|
||||||
|
// 3. Cria response
|
||||||
|
GenreMessages.DeleteGenreResponse deleteResponse;
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
deleteResponse = GenreMessages.DeleteGenreResponse.newBuilder()
|
||||||
|
.setSuccess(true)
|
||||||
|
.setMessage("Genre deleted successfully")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
} else {
|
||||||
|
deleteResponse = GenreMessages.DeleteGenreResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Genre not found")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting genre", e);
|
||||||
|
|
||||||
|
GenreMessages.DeleteGenreResponse deleteResponse =
|
||||||
|
GenreMessages.DeleteGenreResponse.newBuilder()
|
||||||
|
.setSuccess(false)
|
||||||
|
.setMessage("Error: " + e.getMessage())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(deleteResponse.toByteString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.genre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.GenreMapper;
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.GenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.genre.GenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class GetGenreByIdHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetGenreByIdHandler.class);
|
||||||
|
|
||||||
|
private final GenreService genreService;
|
||||||
|
|
||||||
|
public GetGenreByIdHandler(GenreService genreService) {
|
||||||
|
this.genreService = genreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
// 1. Parse protobuf request
|
||||||
|
GenreMessages.GetGenreByIdRequest getByIdRequest =
|
||||||
|
GenreMessages.GetGenreByIdRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
int id = getByIdRequest.getId();
|
||||||
|
|
||||||
|
// 2. Busca via service
|
||||||
|
Optional<Genre> genreOpt = genreService.getGenreById(id);
|
||||||
|
|
||||||
|
if (genreOpt.isEmpty()) {
|
||||||
|
logger.warn("Genre not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Genre not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Converte para protobuf
|
||||||
|
GenreMessages.Genre genreProto = GenreMapper.toProtobuf(genreOpt.get());
|
||||||
|
|
||||||
|
GenreMessages.GetGenreByIdResponse getByIdResponse =
|
||||||
|
GenreMessages.GetGenreByIdResponse.newBuilder()
|
||||||
|
.setGenre(genreProto)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 4. Retorna
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getByIdResponse.toByteString());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting genre by ID", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.genre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.GenreMapper;
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.GenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.genre.GenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetGenreHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GetGenreHandler.class);
|
||||||
|
|
||||||
|
private final GenreService genreService;
|
||||||
|
|
||||||
|
public GetGenreHandler(GenreService genreService) {
|
||||||
|
this.genreService = genreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
// 1. Busca todos os genres via service
|
||||||
|
List<Genre> genres = genreService.getAllGenres();
|
||||||
|
|
||||||
|
// 2. Converte cada Genre para protobuf
|
||||||
|
GenreMessages.GetGenresResponse.Builder responseBuilder =
|
||||||
|
GenreMessages.GetGenresResponse.newBuilder();
|
||||||
|
|
||||||
|
for (Genre genre : genres) {
|
||||||
|
GenreMessages.Genre genreProto = GenreMapper.toProtobuf(genre);
|
||||||
|
responseBuilder.addGenres(genreProto);
|
||||||
|
}
|
||||||
|
|
||||||
|
GenreMessages.GetGenresResponse getGenresResponse = responseBuilder.build();
|
||||||
|
|
||||||
|
// 3. Retorna
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(getGenresResponse.toByteString());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error getting genres", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.mediamanager.service.delegate.handler.genre;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
import com.mediamanager.mapper.GenreMapper;
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import com.mediamanager.protocol.TransportProtocol;
|
||||||
|
import com.mediamanager.protocol.messages.GenreMessages;
|
||||||
|
import com.mediamanager.service.delegate.ActionHandler;
|
||||||
|
import com.mediamanager.service.genre.GenreService;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class UpdateGenreHandler implements ActionHandler {
|
||||||
|
private static final Logger logger = LogManager.getLogger(UpdateGenreHandler.class);
|
||||||
|
|
||||||
|
private final GenreService genreService;
|
||||||
|
|
||||||
|
public UpdateGenreHandler(GenreService genreService) {
|
||||||
|
this.genreService = genreService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportProtocol.Response.Builder handle(ByteString requestPayload)
|
||||||
|
throws InvalidProtocolBufferException {
|
||||||
|
try {
|
||||||
|
// 1. Parse protobuf request
|
||||||
|
GenreMessages.UpdateGenreRequest updateRequest =
|
||||||
|
GenreMessages.UpdateGenreRequest.parseFrom(requestPayload);
|
||||||
|
|
||||||
|
int id = updateRequest.getId();
|
||||||
|
String newName = updateRequest.getName();
|
||||||
|
|
||||||
|
// 2. Atualiza via service
|
||||||
|
Optional<Genre> genreOpt = genreService.updateGenre(id, newName);
|
||||||
|
|
||||||
|
if (genreOpt.isEmpty()) {
|
||||||
|
logger.warn("Genre not found with ID: {}", id);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(404)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Genre not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Converte para protobuf
|
||||||
|
GenreMessages.Genre genreProto = GenreMapper.toProtobuf(genreOpt.get());
|
||||||
|
|
||||||
|
GenreMessages.UpdateGenreResponse updateResponse =
|
||||||
|
GenreMessages.UpdateGenreResponse.newBuilder()
|
||||||
|
.setGenre(genreProto)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 4. Retorna
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setPayload(updateResponse.toByteString());
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.error("Validation error", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(400)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Validation error: " + e.getMessage()));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error updating genre", e);
|
||||||
|
return TransportProtocol.Response.newBuilder()
|
||||||
|
.setStatusCode(500)
|
||||||
|
.setPayload(ByteString.copyFromUtf8("Error: " + e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.mediamanager.service.genre;
|
||||||
|
|
||||||
|
import com.mediamanager.model.Genre;
|
||||||
|
import com.mediamanager.repository.GenreRepository;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service para lógica de negócio relacionada a Genre
|
||||||
|
*/
|
||||||
|
public class GenreService {
|
||||||
|
private static final Logger logger = LogManager.getLogger(GenreService.class);
|
||||||
|
|
||||||
|
private final GenreRepository genreRepository;
|
||||||
|
|
||||||
|
public GenreService(GenreRepository genreRepository) {
|
||||||
|
this.genreRepository = genreRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cria um novo genre
|
||||||
|
*/
|
||||||
|
public Genre createGenre(String name) {
|
||||||
|
logger.info("Creating genre: {}", name);
|
||||||
|
|
||||||
|
// Aqui poderia ter validações de negócio
|
||||||
|
if (name == null || name.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Genre name cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Genre genre = new Genre();
|
||||||
|
genre.setName(name.trim());
|
||||||
|
|
||||||
|
return genreRepository.save(genre);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Busca todos os genres
|
||||||
|
*/
|
||||||
|
public List<Genre> getAllGenres() {
|
||||||
|
logger.info("Getting all genres");
|
||||||
|
return genreRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Busca genre por ID
|
||||||
|
*/
|
||||||
|
public Optional<Genre> getGenreById(Integer id) {
|
||||||
|
logger.info("Getting genre by ID: {}", id);
|
||||||
|
return genreRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atualiza um genre existente
|
||||||
|
*/
|
||||||
|
public Optional<Genre> updateGenre(Integer id, String name) {
|
||||||
|
logger.info("Updating genre ID {}: {}", id, name);
|
||||||
|
|
||||||
|
// Validação
|
||||||
|
if (name == null || name.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Genre name cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Genre> existingGenre = genreRepository.findById(id);
|
||||||
|
|
||||||
|
if (existingGenre.isEmpty()) {
|
||||||
|
logger.warn("Genre not found with ID: {}", id);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Genre genre = existingGenre.get();
|
||||||
|
genre.setName(name.trim());
|
||||||
|
|
||||||
|
Genre updated = genreRepository.update(genre);
|
||||||
|
return Optional.of(updated);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deleta um genre por ID
|
||||||
|
*/
|
||||||
|
public boolean deleteGenre(Integer id) {
|
||||||
|
logger.info("Deleting genre ID: {}", id);
|
||||||
|
return genreRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,7 +125,7 @@ public class IPCManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logger.info("Closing IPC connection...");
|
logger.info("Closing IPC connection...");
|
||||||
|
|
||||||
running.set(false);
|
running.set(false);
|
||||||
if (serverChannel != null && serverChannel.isOpen()) {
|
if (serverChannel != null && serverChannel.isOpen()) {
|
||||||
@@ -185,7 +185,7 @@ public class IPCManager {
|
|||||||
// Nenhum cliente conectado no momento
|
// Nenhum cliente conectado no momento
|
||||||
// Dorme por um curto período antes de verificar novamente
|
// Dorme por um curto período antes de verificar novamente
|
||||||
// Isso evita consumir CPU desnecessariamente em um loop vazio
|
// Isso evita consumir CPU desnecessariamente em um loop vazio
|
||||||
Thread.sleep(100); // 100 milissegundos
|
Thread.sleep(1); // 1 milissegundos
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -223,9 +223,16 @@ public class IPCManager {
|
|||||||
logger.debug("Client {} handler thread started", clientId);
|
logger.debug("Client {} handler thread started", clientId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
TransportProtocol.Request request = readRequest(channel);
|
// LOOP: processa múltiplas requests na mesma conexão
|
||||||
|
while (channel.isOpen()) {
|
||||||
|
TransportProtocol.Request request = readRequest(channel);
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
// Cliente desconectou gracefully
|
||||||
|
logger.info("Client {} disconnected (end of stream)", clientId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (request != null) {
|
|
||||||
logger.info("Client {} sent request {}", clientId, request.getRequestId());
|
logger.info("Client {} sent request {}", clientId, request.getRequestId());
|
||||||
|
|
||||||
// Processa usando o DelegateActionManager
|
// Processa usando o DelegateActionManager
|
||||||
@@ -233,17 +240,29 @@ public class IPCManager {
|
|||||||
|
|
||||||
// Envia resposta de volta
|
// Envia resposta de volta
|
||||||
writeResponse(channel, response);
|
writeResponse(channel, response);
|
||||||
|
|
||||||
logger.info("Client {} response sent", clientId);
|
logger.info("Client {} response sent", clientId);
|
||||||
} else {
|
|
||||||
logger.warn("Client {} sent null message", clientId);
|
// Verifica se é comando CLOSE
|
||||||
|
String connectionHeader = response.getHeadersOrDefault("Connection", "");
|
||||||
|
if ("close".equals(connectionHeader)) {
|
||||||
|
logger.info("Client {} requested connection close", clientId);
|
||||||
|
break; // Sai do loop e fecha
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (channel.isOpen()) {
|
||||||
|
logger.error("IO error handling client {}", clientId, e);
|
||||||
|
} else {
|
||||||
|
logger.debug("Client {} connection closed by peer", clientId);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error handling client {}", clientId, e);
|
logger.error("Unexpected error handling client {}", clientId, e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
channel.close();
|
if (channel.isOpen()) {
|
||||||
|
channel.close();
|
||||||
|
}
|
||||||
logger.debug("Client {} channel closed", clientId);
|
logger.debug("Client {} channel closed", clientId);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Error closing client {} channel", clientId, e);
|
logger.error("Error closing client {} channel", clientId, e);
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol.messages";
|
||||||
|
option java_outer_classname = "GenreMessages";
|
||||||
|
|
||||||
|
package mediamanager.messages;
|
||||||
|
|
||||||
|
message Genre {
|
||||||
|
int32 id = 1;
|
||||||
|
string name = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateGenreRequest {
|
||||||
|
string name = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateGenreResponse {
|
||||||
|
Genre genre = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetGenresRequest {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetGenresResponse {
|
||||||
|
repeated Genre genres = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetGenreByIdRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetGenreByIdResponse {
|
||||||
|
Genre genre = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateGenreRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
string name = 2; // Novo nome
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateGenreResponse {
|
||||||
|
Genre genre = 1; // Genre atualizado
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteGenreRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteGenreResponse {
|
||||||
|
bool success = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option java_package = "com.mediamanager.protocol";
|
||||||
|
option java_outer_classname = "TestProtocol";
|
||||||
|
|
||||||
|
package mediamanager.test;
|
||||||
|
|
||||||
|
message EchoCommand {
|
||||||
|
string message = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EchoResponse {
|
||||||
|
string message = 1;
|
||||||
|
int64 server_timestamp = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message HeartbeatCommand {
|
||||||
|
int64 client_timestamp = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message HeartbeatResponse {
|
||||||
|
int64 client_timestamp = 1;
|
||||||
|
int64 server_timestamp = 2;
|
||||||
|
}
|
||||||
|
message CloseCommand {
|
||||||
|
// Vazio - apenas sinaliza fechamento
|
||||||
|
}
|
||||||
|
message CloseResponse {
|
||||||
|
string message = 1;
|
||||||
|
}
|
||||||
@@ -21,6 +21,8 @@ hibernate.format_sql=true
|
|||||||
ipc.pipe.name=mediamanager-pipe
|
ipc.pipe.name=mediamanager-pipe
|
||||||
ipc.pipe.path=/tmp/mediamanager
|
ipc.pipe.path=/tmp/mediamanager
|
||||||
ipc.buffer.size=8192
|
ipc.buffer.size=8192
|
||||||
|
runtype=local
|
||||||
ipc.socket.path=/tmp/mediamanager
|
ipc.socket.path=/tmp/mediamanager
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,17 +18,17 @@
|
|||||||
</Appenders>
|
</Appenders>
|
||||||
|
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Logger name="com.mediamanager" level="debug" additivity="false">
|
<Logger name="com.mediamanager" level="INFO" additivity="false">
|
||||||
<AppenderRef ref="Console"/>
|
<AppenderRef ref="Console"/>
|
||||||
<AppenderRef ref="FileAppender"/>
|
<AppenderRef ref="FileAppender"/>
|
||||||
</Logger>
|
</Logger>
|
||||||
|
|
||||||
<Logger name="org.hibernate" level="info" additivity="false">
|
<Logger name="org.hibernate" level="INFO" additivity="false">
|
||||||
<AppenderRef ref="Console"/>
|
<AppenderRef ref="Console"/>
|
||||||
<AppenderRef ref="FileAppender"/>
|
<AppenderRef ref="FileAppender"/>
|
||||||
</Logger>
|
</Logger>
|
||||||
|
|
||||||
<Root level="info">
|
<Root level="INFO">
|
||||||
<AppenderRef ref="Console"/>
|
<AppenderRef ref="Console"/>
|
||||||
<AppenderRef ref="FileAppender"/>
|
<AppenderRef ref="FileAppender"/>
|
||||||
</Root>
|
</Root>
|
||||||
|
|||||||
Reference in New Issue
Block a user