summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
blob: 5169173e398db18ada34ba487b2f00948cc2d8f8 (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
package org.openslx.satellitedaemon.db;

import java.util.List;

/**
 * Represents an image in the satellite's database (mostly from
 * m_VLData_imageInfo)
 */
public class DbImage
{
	
	public final String guid;
	public final String name;
	public final int rid;
	public final String path;
	public final String creator;
	public final long fileSize;
	
	public DbImage(String guid, String name, Integer rid, String path, String creator, Long fileSize)
	{
		if (rid == null) rid = -1;
		if (fileSize == null) fileSize = (long) -1;
		this.guid = guid;
		this.name = name;
		this.rid = rid;
		this.path = path;
		this.creator = creator;
		this.fileSize = fileSize;
	}

	/**
	 * Returns a list of all images on this satellite that should be
	 * uploaded to the central server.
	 * 
	 * @return list of images that are marked for upload, where the upload
	 *         was either not started yet, or is incomplete
	 */
	public static List<DbImage> getAllMarkedForUpload()
	{
		return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," +
				" Concat(user.loginName, '@', institution.name) AS userID, image.image_filesize" +
				" FROM m_VLData_imageInfo image" +
				" INNER JOIN m_user user ON (image.image_owner = user.userID)" +
				" INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" +
				" WHERE image_syncMode = 'to_be_published'" );
	}
	
	
	public static List<DbImage> getAllMarkedForDownload()
	{
		return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," +
				" Concat(user.loginName, '@', institution.name) AS userID, image.image_filesize" +
				" FROM m_VLData_imageInfo image" +
				" INNER JOIN m_user user ON (image.image_owner = user.userID)" +
				" INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" +
				" WHERE image_syncMode = 'to_be_decentralized'" );
	}

}