Система вложенных тегов (ECI), связь с базой данных
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user