summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbSoftwareTag.java
blob: 44e50090cd8c9c0c07fa465a780d14f91cc2e278 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.openslx.bwlp.sat.database.mappers;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.openslx.bwlp.sat.database.Database;
import org.openslx.bwlp.sat.database.MysqlConnection;
import org.openslx.bwlp.sat.database.MysqlStatement;

public class DbSoftwareTag {

	private static final Logger LOGGER = Logger.getLogger(DbSoftwareTag.class);

	/**
	 * Get list of software installed in a certain image version.
	 * 
	 * @param connection database connection to use
	 * @param imageVersionId UUID of image version
	 * @return list of software products
	 * @throws SQLException
	 */
	public static List<String> getImageVersionSoftwareList(MysqlConnection connection, String imageVersionId)
			throws SQLException {
		MysqlStatement stmt = connection.prepareStatement("SELECT softwarestring FROM software"
				+ " INNER JOIN imageversion_x_software USING (softwareid)"
				+ " WHERE imageversionid = :imageversionid");
		stmt.setString("imageversionid", imageVersionId);
		ResultSet rs = stmt.executeQuery();
		List<String> softwareList = new ArrayList<>();
		while (rs.next()) {
			softwareList.add(rs.getString("softwarestring"));
		}
		stmt.close();
		return softwareList;
	}

	/**
	 * Get list of software installed in a certain image version.
	 * 
	 * @param imageVersionId UUID of image version
	 * @return list of software products
	 * @throws SQLException
	 */
	public static List<String> getImageVersionSoftwareList(String imageVersionId) throws SQLException {
		try (MysqlConnection connection = Database.getConnection()) {
			return getImageVersionSoftwareList(connection, imageVersionId);
		} catch (SQLException e) {
			LOGGER.error("Query failed in DbSoftware.getImageVersionSoftwareList()", e);
			throw e;
		}
	}
	
	public static List<String> getImageTags(MysqlConnection connection, String imageBaseId) throws SQLException {
		MysqlStatement stmt = connection.prepareStatement("SELECT tagname FROM imagetag"
				+ " WHERE imagebaseid = :imagebaseid");
		stmt.setString("imagebaseid", imageBaseId);
		ResultSet rs = stmt.executeQuery();
		List<String> tagList = new ArrayList<>();
		while (rs.next()) {
			tagList.add(rs.getString("displayname"));
		}
		stmt.close();
		return tagList;
	}

}