bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
DbSatellite.java
Go to the documentation of this file.
1 package org.openslx.imagemaster.db.mappers;
2 
3 import java.nio.ByteBuffer;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
6 import java.util.ArrayList;
7 import java.util.Arrays;
8 import java.util.List;
9 
10 import org.apache.logging.log4j.LogManager;
11 import org.apache.logging.log4j.Logger;
12 import org.openslx.bwlp.thrift.iface.Satellite;
13 import org.openslx.bwlp.thrift.iface.UserInfo;
18 import org.openslx.util.Json;
19 
20 public class DbSatellite
21 {
22 
23  private static final Logger LOGGER = LogManager.getLogger( DbSatellite.class );
24 
25  public static LocalSatellite get( int satelliteId )
26  {
27  return null;
28  }
29 
30  public static List<Satellite> getSatellites( UserInfo ui ) throws SQLException
31  {
32  if ( ui == null )
33  return null;
34  return getSatellites( ui.organizationId );
35  }
36 
37  public static List<Satellite> getSatellites( String organizationId ) throws SQLException
38  {
39  if ( organizationId == null )
40  return null;
41  try ( MysqlConnection connection = Database.getConnection() ) {
42  MysqlStatement stmt = connection.prepareStatement( "SELECT satellitename, addresses, certsha256"
43  + " FROM satellite WHERE organizationid = :organizationid" );
44  stmt.setString( "organizationid", organizationId );
45  ResultSet rs = stmt.executeQuery();
46  List<Satellite> list = new ArrayList<>();
47  while ( rs.next() ) {
48  List<String> al = Arrays.asList( Json.deserialize( rs.getString( "addresses" ), String[].class ) );
49  byte[] certBytes = rs.getBytes( "certsha256" );
50  ByteBuffer cert = null;
51  if ( certBytes != null ) {
52  cert = ByteBuffer.wrap( certBytes );
53  }
54  list.add( new Satellite( al, rs.getString( "satellitename" ), cert ) );
55  }
56  return list;
57  } catch ( SQLException e ) {
58  LOGGER.error( "Query failed in DbSatellite.getSatellites()", e );
59  throw e;
60  }
61  }
62 
63  public static LocalSatellite get( String organizationId, String displayName )
64  {
65  // TODO Auto-generated method stub
66  return null;
67  }
68 }
static List< Satellite > getSatellites(String organizationId)
static MysqlConnection getConnection()
Get a connection to the database.
Definition: Database.java:92
ResultSet executeQuery()
Executes the statement, which must be a query.
static List< Satellite > getSatellites(UserInfo ui)
void setString(String name, String value)
Sets a parameter.
Class for creating PreparedStatements with named parameters.