bwLehrpool Masterserver
Manages authentication and sharing of virtual machines between participating institutions
DbPendingSatellite.java
Go to the documentation of this file.
1 package org.openslx.imagemaster.db.mappers;
2 
3 import java.sql.SQLException;
4 import java.util.List;
5 
6 import org.apache.logging.log4j.LogManager;
7 import org.apache.logging.log4j.Logger;
8 import org.openslx.bwlp.thrift.iface.UserInfo;
12 import org.openslx.util.Json;
13 
14 import com.google.gson.annotations.SerializedName;
15 
16 public class DbPendingSatellite
17 {
18 
19  private static final Logger LOGGER = LogManager.getLogger( DbPendingSatellite.class );
20 
21  public static int add( UserInfo user, String displayName, List<String> address, String modulus, String exponent )
22  throws SQLException
23  {
24  try ( MysqlConnection connection = Database.getConnection() ) {
25  MysqlStatement stmt = connection.prepareStatement( "INSERT INTO satellite"
26  + " (dateline, userid, organizationid, satellitename, addresses, publickey)"
27  + " VALUES (UNIX_TIMESTAMP(), :userid, :organizationid, :satellitename, :addresses, :pubkey)" );
28  stmt.setString( "userid", user.userId );
29  stmt.setString( "organizationid", user.organizationId );
30  stmt.setString( "satellitename", displayName );
31  stmt.setString( "addresses", Json.serialize( address ) );
32  stmt.setString( "pubkey", Json.serialize( new KeyWrapper( modulus, exponent ) ) );
33  stmt.executeUpdate();
34  int key = stmt.lastInsertId();
35  connection.commit();
36  return key;
37  } catch ( SQLException e ) {
38  LOGGER.error( "Query failed in DbPendingSatellite.add()", e );
39  throw e;
40  }
41  }
42 
43  private static class KeyWrapper
44  {
45  @SerializedName( "type" )
46  public String type;
47  @SerializedName( "modulus" )
48  public String modulus;
49  @SerializedName( "exponent" )
50  public String exponent;
51 
52  public KeyWrapper( String modulus, String exponent )
53  {
54  this.type = "RSA";
55  this.modulus = modulus;
56  this.exponent = exponent;
57  }
58  }
59 
60 }
static int add(UserInfo user, String displayName, List< String > address, String modulus, String exponent)
static MysqlConnection getConnection()
Get a connection to the database.
Definition: Database.java:92
int executeUpdate()
Executes the statement, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement ...
void setString(String name, String value)
Sets a parameter.
Class for creating PreparedStatements with named parameters.