Система вложенных тегов (ECI), связь с базой данных

This commit is contained in:
RoyceDa
2026-02-02 05:13:32 +02:00
parent d1be8e7014
commit 14a8615746
24 changed files with 326 additions and 59 deletions

View File

@@ -3,6 +3,7 @@ package com.rosetta.im.database;
import org.hibernate.Session;
import org.hibernate.Transaction;
import java.util.HashMap;
import java.util.List;
public class DatabaseManager {
@@ -61,6 +62,28 @@ public class DatabaseManager {
}
}
public static <T> T findBy(Class<T> entity, HashMap<String, Object> params) {
Session session = HibernateUtil.openSession();
try {
StringBuilder queryString = new StringBuilder("FROM " + entity.getSimpleName() + " WHERE ");
int index = 0;
for (String key : params.keySet()) {
if (index > 0) {
queryString.append(" AND ");
}
queryString.append(key).append(" = :").append(key);
index++;
}
var query = session.createQuery(queryString.toString(), entity);
for (var entry : params.entrySet()) {
query.setParameter(entry.getKey(), entry.getValue());
}
return query.uniqueResult();
} finally {
session.close();
}
}
public static <T> void delete(T entity) {
Session session = HibernateUtil.openSession();
Transaction transaction = null;

View File

@@ -43,9 +43,6 @@ public class User extends BaseEntity {
@Column(name = "publicKey", nullable = false, unique = true)
private String publicKey;
@Column(name = "timestamp", nullable = false)
private long timestamp;
@Column(name = "createdTime", nullable = false, updatable = false)
private Date createdTime;
@@ -104,14 +101,6 @@ public class User extends BaseEntity {
this.publicKey = publicKey;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public Date getCreatedTime() {
return createdTime;
}