Compare commits

..
Author SHA1 Message Date
Claude 1aa0887fa9 Implement database connection initialization
- Created DatabaseManager class in config package to manage database connections
- Implemented singleton pattern with JPA EntityManagerFactory and HikariCP connection pooling
- Initialized database connection in MediaManagerApplication on startup
- Added proper shutdown cleanup for database resources in shutdown hook
- Uncommented Media entity class in persistence.xml to enable JPA mapping
- Resolved TODO: Initialize database connection (MediaManagerApplication.java:21)
2025-11-23 19:30:42 +00:00
6 changed files with 84 additions and 129 deletions
-100
View File
@@ -1,100 +0,0 @@
name: Qodana
on:
workflow_dispatch:
inputs:
target_ref:
description: 'Branch, tag, or commit SHA to analyze (default: develop)'
required: false
default: 'develop'
type: string
pull_request:
push:
branches: # Specify your branches here
- master
- main # The 'main' branch
- develop
- 'releases/*' # The release branches
jobs:
qodana:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
checks: write
steps:
# Checkout for pull_request events: use the PR head SHA for accurate analysis
- name: Checkout (pull_request)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # a full history is required for pull request analysis
# Checkout for manual runs: use the selected branch/ref (default: develop)
- name: Checkout (workflow_dispatch)
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.target_ref }}
fetch-depth: 0
# Checkout for push events (e.g., merges to develop): use the current commit
- name: Checkout (push)
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
# Set up JDK for potential code generation (e.g., protobuf) prior to Qodana analysis
- name: Set up Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
# Generate sources so that Qodana resolves imports from generated code
- name: Generate sources (protobuf)
shell: bash
run: |
if [ -f ./mvnw ]; then chmod +x ./mvnw || true; fi
if [ -x ./mvnw ]; then
./mvnw -B -DskipTests -DskipITs=true generate-sources || true
elif command -v mvn >/dev/null 2>&1; then
mvn -B -DskipTests -DskipITs=true generate-sources || true
else
echo "[Qodana prep] Maven not available; skipping generate-sources"
fi
# Optionally compile (skip tests) to ensure classes are available for resolution
- name: Compile (skip tests)
shell: bash
run: |
if [ -x ./mvnw ]; then
./mvnw -B -DskipTests -DskipITs=true compile || true
elif command -v mvn >/dev/null 2>&1; then
mvn -B -DskipTests -DskipITs=true compile || true
else
echo "[Qodana prep] Maven not available; skipping compile"
fi
# Helpful debug: list generated sources if present
- name: Show generated sources
shell: bash
run: |
echo "=== target/generated-sources (tree) ===" || true
if [ -d target/generated-sources ]; then
find target/generated-sources -maxdepth 3 -type d -print || true
else
echo "(none)" || true
fi
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2025.2
with:
# Enable PR-specific reporting only for pull_request events
pr-mode: ${{ github.event_name == 'pull_request' }}
# No extra args needed; linter is defined in qodana.yaml (qodana-jvm)
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_268690425 }}
QODANA_ENDPOINT: 'https://qodana.cloud'
-5
View File
@@ -1,5 +0,0 @@
# Contributor Code of Conduct
This project adheres to No Code of Conduct. We are all adults. We accept anyone's contributions. Nothing else matters.
For more information please visit the [No Code of Conduct](https://nocodeofconduct.com) homepage.
-21
View File
@@ -1,21 +0,0 @@
####################################################################################################################
# WARNING: Do not store sensitive information in this file, as its contents will be included in the Qodana report. #
####################################################################################################################
version: "1.0"
# Use canonical linter name to avoid image warnings and CLI flag issues
linter: qodana-jvm
profile:
name: qodana.recommended
bootstrap: |
# Disabled bootstrap to avoid shell parsing issues in CI. If you need code generation,
# we can re-enable a robust script later. For now, do nothing and let Qodana run.
:
include:
- name: CheckDependencyLicenses
exclude:
# Exclude generated sources from inspections to reduce noise
- name: All
paths:
- target/protoc-dependencies/**
# Keep generated sources included for indexing/resolution; excluding them can cause unresolved imports
@@ -1,5 +1,6 @@
package com.mediamanager;
import com.mediamanager.config.DatabaseManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -10,6 +11,7 @@ import java.util.Properties;
public class MediaManagerApplication {
private static final Logger logger = LogManager.getLogger(MediaManagerApplication.class);
private static Properties config;
private static DatabaseManager databaseManager;
public static void main(String[] args) {
logger.info("Starting MediaManager Core Application...");
@@ -18,7 +20,9 @@ public class MediaManagerApplication {
// Load configuration
loadConfiguration();
// TODO: Initialize database connection
// Initialize database connection
databaseManager = DatabaseManager.getInstance(config);
// TODO: Initialize IPC server with named pipes
// TODO: Start application services
@@ -28,7 +32,9 @@ public class MediaManagerApplication {
// Keep application running
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
logger.info("Shutting down MediaManager Core...");
// TODO: Cleanup resources
if (databaseManager != null) {
databaseManager.shutdown();
}
}));
} catch (Exception e) {
@@ -52,4 +58,8 @@ public class MediaManagerApplication {
public static Properties getConfig() {
return config;
}
public static DatabaseManager getDatabaseManager() {
return databaseManager;
}
}
@@ -0,0 +1,71 @@
package com.mediamanager.config;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class DatabaseManager {
private static final Logger logger = LogManager.getLogger(DatabaseManager.class);
private static DatabaseManager instance;
private EntityManagerFactory entityManagerFactory;
private DatabaseManager(Properties config) {
initializeEntityManagerFactory(config);
}
public static synchronized DatabaseManager getInstance(Properties config) {
if (instance == null) {
instance = new DatabaseManager(config);
}
return instance;
}
private void initializeEntityManagerFactory(Properties config) {
try {
logger.info("Initializing database connection...");
Map<String, String> properties = new HashMap<>();
properties.put("jakarta.persistence.jdbc.url", config.getProperty("db.url"));
properties.put("jakarta.persistence.jdbc.user", config.getProperty("db.username"));
properties.put("jakarta.persistence.jdbc.password", config.getProperty("db.password"));
properties.put("jakarta.persistence.jdbc.driver", config.getProperty("db.driver"));
properties.put("hibernate.hikari.maximumPoolSize", config.getProperty("db.pool.maximum-pool-size"));
properties.put("hibernate.hikari.minimumIdle", config.getProperty("db.pool.minimum-idle"));
properties.put("hibernate.hikari.connectionTimeout", config.getProperty("db.pool.connection-timeout"));
properties.put("hibernate.hikari.idleTimeout", config.getProperty("db.pool.idle-timeout"));
properties.put("hibernate.hikari.maxLifetime", config.getProperty("db.pool.max-lifetime"));
entityManagerFactory = Persistence.createEntityManagerFactory("MediaManagerPU", properties);
logger.info("Database connection initialized successfully");
} catch (Exception e) {
logger.error("Failed to initialize database connection", e);
throw new RuntimeException("Failed to initialize database connection", e);
}
}
public EntityManager createEntityManager() {
if (entityManagerFactory == null) {
throw new IllegalStateException("EntityManagerFactory is not initialized");
}
return entityManagerFactory.createEntityManager();
}
public void shutdown() {
if (entityManagerFactory != null && entityManagerFactory.isOpen()) {
logger.info("Closing database connection...");
entityManagerFactory.close();
logger.info("Database connection closed successfully");
}
}
public boolean isInitialized() {
return entityManagerFactory != null && entityManagerFactory.isOpen();
}
}
+1 -1
View File
@@ -9,7 +9,7 @@
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- Add entity classes here as they are created -->
<!-- <class>com.mediamanager.model.Media</class> -->
<class>com.mediamanager.model.Media</class>
<properties>
<!-- Database connection properties will be set programmatically -->