Commit acb4395f authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added web runner functionality

parent 8e78f5af
......@@ -69,15 +69,15 @@ public class MetricOutputDAO extends AbstractOutput {
*/
@XMLConfigurableConstructor({ "table" })
public MetricOutputDAO(String table) {
DAO.database = table;
DAO.setDatabase(table);
}
public void setUser(String user) {
DAO.username = user;
DAO.setUsername(user);
}
public void setPassword(String password) {
DAO.password = password;
DAO.setPassword(password);
}
public void setTimeEnableDao(long timeEnableDao) {
......
......@@ -2,17 +2,17 @@
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
......@@ -44,7 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent;
/**
* New Monitor-Component to work with the simonstrator-API (provides
* overlay-access to analyzers)
*
*
* @author Bjoern Richerzhagen
* @version 1.0, Jul 8, 2013
*/
......@@ -119,7 +119,7 @@ public class DefaultMonitor implements MonitorComponent, EventHandler,
/**
* Called by the Configurator
*
*
* @param analyzer
*/
public void setAnalyzer(Analyzer analyzer) {
......@@ -128,7 +128,7 @@ public class DefaultMonitor implements MonitorComponent, EventHandler,
/**
* Specifies where to write the monitoring results to.
*
*
* @param output
* writer (e.g. FileWriter, StringWriter, ...)
*/
......@@ -143,7 +143,7 @@ public class DefaultMonitor implements MonitorComponent, EventHandler,
public void setTableName(String tableName) {
System.out.println("Table Name is set to: " + tableName);
if (tableName != null && !tableName.equals("")) {
DAO.database = tableName;
DAO.setDatabase(tableName);
}
}
......
......@@ -475,7 +475,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
*/
@Deprecated
public void setDatabase(String database) {
DAO.database = database;
DAO.setDatabase(database);
}
/**
......
......@@ -23,6 +23,7 @@ package de.tud.kom.p2psim.impl.util.db.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
......@@ -30,6 +31,7 @@ import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.commons.math3.analysis.function.Exp;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
......@@ -54,6 +56,7 @@ import de.tud.kom.p2psim.impl.util.db.metric.Metric;
import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.web.WebConfigurationManager;
/**
* This class represents a simple access to persist objects with Hibernate. It
......@@ -100,23 +103,23 @@ public class DAO {
// public static Map<String, Object> configOverwrites = new HashMap<String, Object>();
private static ArrayList<Class<?>> daoClasses = new ArrayList<Class<?>>();
public static String database;
public static String username;
public static String password;
private static String database;
private static String username;
private static String password;
private static SessionFactory sessionFactory;
private static final ThreadLocal<Session> session = new ThreadLocal<Session>();
private static ServiceRegistry serviceRegistry;
/**
* Hibernate-only implementation to support annotated classes without active
* binding
*
*
* @return
*/
public static Session getSession() {
......@@ -134,17 +137,17 @@ public class DAO {
cfg.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/"+database);
cfg.setProperty("hibernate.connection.username", username);
cfg.setProperty("hibernate.connection.password", password);
// mySQL 5
cfg.setProperty("hibernate.dialect",
"org.hibernate.dialect.MySQL5InnoDBDialect");
cfg.setProperty("hibernate.transaction.factory_class",
"org.hibernate.transaction.JDBCTransactionFactory");
cfg.setProperty("hibernate.pool_size", "1");
cfg.setProperty("hibernate.hbm2ddl.auto", "update");
cfg.setProperty("hibernate.current_session_context_class", "thread");
// Add core classes
cfg.addAnnotatedClass(CustomMeasurement.class);
cfg.addAnnotatedClass(Experiment.class);
......@@ -160,7 +163,7 @@ public class DAO {
cfg.addAnnotatedClass(MeasurementStatistic.class);
cfg.addAnnotatedClass(Metric.class);
cfg.addAnnotatedClass(MetricDescription.class);
for (Class<?> clazz : daoClasses) {
cfg.addAnnotatedClass(clazz);
}
......@@ -179,6 +182,30 @@ public class DAO {
return currSession;
}
public static void setDatabase(String pDatabase) {
if (!WebConfigurationManager.isActive()) {
database = pDatabase;
} else {
database = WebConfigurationManager.getConfig().getOptions().getDatabase();
}
}
public static void setUsername(String pUsername) {
if (!WebConfigurationManager.isActive()) {
username = pUsername;
} else {
username = WebConfigurationManager.getConfig().getOptions().getUsername();
}
}
public static void setPassword(String pPassword) {
if (!WebConfigurationManager.isActive()) {
password = pPassword;
} else {
password = WebConfigurationManager.getConfig().getOptions().getPassword();
}
}
/**
* Gets the session
*
......@@ -286,6 +313,14 @@ public class DAO {
DAO.session.remove();
}
public static List<Object> retrieve(Class<?> pClass) {
begin();
List<Object> objects = getSession().createCriteria(pClass).list();
commit();
return objects;
}
/**
* Persist the given POJO directly to the DB. Should be make, if it exists
* relationships between tables.
......@@ -401,7 +436,7 @@ public class DAO {
*
* @param o
* The same object, which is already used to persist.
*
*
* @return The object attached to the persistence context
*/
public static <T> T update(T o) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment