summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/db/DbSatellite.java
blob: fb35fb5265ce778ef3bda686d190d314dbb60fe3 (plain) (tree)
1
2
3
4
5
6
7
8

                                   

                                              



                                          


                        
                                                           

                                                           
                                                                                           
         


                                                 
                                     

         

                                                                         


                                                                  
                                                                                                                                                                                             
                                                               

         

                                  


                               

                               


                            

                                       

                                    


                                 

                                   








                                                                                                                                                                                       



                                                                                                                                               
         
 
package org.openslx.imagemaster.db;

import org.openslx.imagemaster.util.ByteArray;

/**
 * Represents a satellite in the database.
 * Is used to authenticate the satellite.
 */
public class DbSatellite
{

	private String organization, address, name, prefix;

	// needs to be public in order to be found by MySQL
	public DbSatellite(String organization, String address, String name, String prefix)
	{
		this.organization = organization;
		this.address = address;
		this.name = name;
		this.prefix = prefix;
	}

	public static DbSatellite fromOrganization( String organization )
	{
		return MySQL
				.findUniqueOrNull(
						DbSatellite.class,
						"SELECT satellite.organization, satellite.address, satellite.name, satellite.prefix FROM satellite WHERE satellite.organization = ? LIMIT 1",
						organization );
	}

	public String getAddress()
	{
		return address;
	}

	public String getName()
	{
		return name;
	}

	public String getOrganization()
	{
		return organization;
	}

	public String getPrefix()
	{
		return this.prefix;
	}

	public static DbSatellite fromPrefix( String prefix )
	{
		return MySQL
				.findUniqueOrNull(
						DbSatellite.class,
						"SELECT satellite.organization, satellite.address, satellite.name, satellite.prefix FROM satellite WHERE satellite.prefix = ? LIMIT 1",
						prefix );
	}

	public static byte[] getKeyfromOrganization( String organization )
	{
		return MySQL.findUniqueOrNull( ByteArray.class, "SELECT publickey FROM satellite WHERE organization = ?", organization ).array;
	}
}