1 package org.openslx.imagemaster.db.mappers;
3 import java.sql.ResultSet;
4 import java.sql.SQLException;
5 import java.util.ArrayList;
6 import java.util.HashMap;
10 import org.apache.logging.log4j.LogManager;
11 import org.apache.logging.log4j.Logger;
12 import org.
openslx.bwlp.thrift.iface.OperatingSystem;
13 import org.
openslx.bwlp.thrift.iface.Virtualizer;
24 public static List<OperatingSystem>
getOsList() throws SQLException
29 +
" osid, displayname, architecture, maxmem, maxcpu" +
" FROM operatingsystem" );
31 List<OperatingSystem> list =
new ArrayList<>();
32 Map<Integer, Map<String, String>> osVirtMappings =
getOsVirtMappings( connection );
34 int osId = rs.getInt(
"osid" );
35 list.add(
new OperatingSystem( osId, rs.getString(
"displayname" ), osVirtMappings.get( osId ),
36 rs.getString(
"architecture" ), rs.getInt(
"maxmem" ), rs.getInt(
"maxcpu" ) ) );
39 }
catch ( SQLException e ) {
40 LOGGER.error(
"Query failed in DbOsVirt.getOsList()", e );
48 MysqlStatement stmt = connection.prepareStatement(
"SELECT osid, virtid, virtoskeyword FROM os_x_virt" );
50 Map<Integer, Map<String, String>> map =
new HashMap<>();
52 Integer osId = rs.getInt(
"osid" );
53 Map<String, String> osMap = map.get( osId );
54 if ( osMap == null ) {
55 osMap =
new HashMap<>();
56 map.put( osId, osMap );
58 osMap.put( rs.getString(
"virtid" ), rs.getString(
"virtoskeyword" ) );
66 MysqlStatement stmt = connection.prepareStatement(
"SELECT virtid, virtname" +
" FROM virtualizer" );
68 List<Virtualizer> list =
new ArrayList<>();
70 list.add(
new Virtualizer( rs.getString(
"virtid" ), rs.getString(
"virtname" ) ) );
73 }
catch ( SQLException e ) {
74 LOGGER.error(
"Query failed in DbOsVirt.getVirtualizerList()", e );
84 MysqlStatement stmt = connection.prepareStatement(
"SELECT osid FROM operatingsystem WHERE osid = :osid" );
85 stmt.
setInt(
"osid", osId );
88 }
catch ( SQLException e ) {
89 LOGGER.error(
"Query failed in DbOsVirt.exists()", e );
99 MysqlStatement stmt = connection.prepareStatement(
"SELECT virtid FROM virtualizer WHERE virtid = :virtid" );
103 }
catch ( SQLException e ) {
104 LOGGER.error(
"Query failed in DbOsVirt.virtExists()", e );
static List< Virtualizer > getVirtualizerList()
static MysqlConnection getConnection()
Get a connection to the database.
ResultSet executeQuery()
Executes the statement, which must be a query.
static List< OperatingSystem > getOsList()
void setInt(String name, int value)
Sets a parameter.
void setString(String name, String value)
Sets a parameter.
static boolean virtExists(String virtId)
static boolean osExists(int osId)
Class for creating PreparedStatements with named parameters.
static final Logger LOGGER
Some utilities to make our lives easier.
static Map< Integer, Map< String, String > > getOsVirtMappings(MysqlConnection connection)
static boolean isEmpty(String str)