/// <summary> /// Remove the key with keyName and its related certificates. If the key does /// not exist, do nothing. /// </summary> /// /// <param name="keyName">The name of the key.</param> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override void removeKey(Name keyName) { byte[] keyNameBytes = keyName.wireEncode().getImmutableArray(); try { // We don't use triggers, so manually delete from certificates. PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.DELETE_removeKey_certificates); statement.setBytes(1, keyNameBytes); try { statement.executeUpdate(); } finally { statement.close(); } // Now, delete from keys. statement = database_.prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.DELETE_removeKey_keys); statement.setBytes(1, keyNameBytes); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } }
/// <summary> /// Set the default identity. If the identityName does not exist, then clear /// the default identity so that getDefaultIdentity() throws an exception. /// </summary> /// /// <param name="identityName">The default identity name.</param> public sealed override void setDefaultIdentity(Name identityName) { try { // Reset the previous default identity. PreparedStatement statement = database_ .prepareStatement("UPDATE Identity SET default_identity=0 WHERE " + net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.WHERE_setDefaultIdentity_reset); try { statement.executeUpdate(); } finally { statement.close(); } // Set the current default identity. statement = database_ .prepareStatement("UPDATE Identity SET default_identity=1 WHERE " + net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.WHERE_setDefaultIdentity_set); statement.setString(1, identityName.toUri()); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new SecurityException("BasicIdentityStorage: SQLite error: " + exception); } }
/// <summary> /// Set the key with keyName as the default key for the identity with name /// identityName. /// </summary> /// /// <param name="identityName">The name of the identity. This copies the name.</param> /// <param name="keyName">The name of the key. This copies the name.</param> /// <exception cref="Pib.Error">if the key does not exist.</exception> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override void setDefaultKeyOfIdentity(Name identityName, Name keyName) { if (!hasKey(keyName)) { throw new Pib.Error("Key `" + keyName.toUri() + "` does not exist"); } try { // We don't use a trigger, so manually reset the previous default key. PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.UPDATE_setDefaultKeyOfIdentity_reset); try { statement.executeUpdate(); } finally { statement.close(); } // Now set the current default key. statement = database_ .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.UPDATE_setDefaultKeyOfIdentity_set); statement.setBytes(1, keyName.wireEncode().getImmutableArray()); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: System.Nullable<long> executeInsertStatement(java.sql.Connection paramConnection, String paramString, Object[] paramArrayOfObject) throws Exception internal virtual long?executeInsertStatement(Connection paramConnection, string paramString, object[] paramArrayOfObject) { long?long = null; PreparedStatement preparedStatement = null; try { StringBuilder stringBuilder = null; if (logger.DebugEnabled) { logger.debug("SINGLE INSERT:" + paramString); } preparedStatement = paramConnection.prepareStatement(paramString); if (logger.TraceEnabled) { stringBuilder = new StringBuilder("\n\tRow values:"); } int i; for (i = 0; i < paramArrayOfObject.Length; i++) { if (logger.TraceEnabled) { stringBuilder.Append("\n\t\t[").Append(i).Append("] => "); if (paramArrayOfObject[i] == null) { stringBuilder.Append("(null)"); } else { stringBuilder.Append(paramArrayOfObject[i] + " (" + paramArrayOfObject[i].GetType() + ")"); } } preparedStatement.setObject(i + 1, paramArrayOfObject[i]); } if (logger.TraceEnabled) { stringBuilder.Append("\n\tEnd of Row values:"); logger.debug(stringBuilder); } i = preparedStatement.executeUpdate(); long = getLastInsertedId(paramConnection); paramConnection.commit(); preparedStatement.close(); } catch (SQLException sQLException) { if (preparedStatement != null) { preparedStatement.close(); } throw new Exception(sQLException); } return(long); }
// TpmLocator management. /// <summary> /// Set the corresponding TPM information to tpmLocator. This method does not /// reset the contents of the PIB. /// </summary> /// /// <param name="tpmLocator">The TPM locator string.</param> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override void setTpmLocator(String tpmLocator) { try { if (getTpmLocator().equals("")) { // The tpmLocator does not exist. Insert it directly. PreparedStatement statement = database_ .prepareStatement("INSERT INTO tpmInfo (tpm_locator) values (?)"); statement.setString(1, tpmLocator); try { statement.executeUpdate(); } finally { statement.close(); } } else { // Update the existing tpmLocator. PreparedStatement statement_0 = database_ .prepareStatement("UPDATE tpmInfo SET tpm_locator=?"); statement_0.setString(1, tpmLocator); try { statement_0.executeUpdate(); } finally { statement_0.close(); } } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } }
/// <summary> /// Append all the certificate names of a particular key name to the nameList. /// </summary> /// /// <param name="keyName">The key name to search for.</param> /// <param name="nameList">Append result names to nameList.</param> /// <param name="isDefault"></param> public override void getAllCertificateNamesOfKey(Name keyName, ArrayList nameList, bool isDefault) { try { String sql = (isDefault) ? net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.SELECT_getAllCertificateNamesOfKey_default_true : net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.SELECT_getAllCertificateNamesOfKey_default_false; PreparedStatement statement = database_.prepareStatement(sql); statement.setString(1, keyName.getPrefix(-1).toUri()); statement.setString(2, keyName.get(-1).toEscapedString()); try { SqlDataReader result = statement.executeQuery(); while (result.NextResult()) { ILOG.J2CsMapping.Collections.Collections.Add(nameList, new Name((string)result["cert_name"])); } } finally { statement.close(); } } catch (SQLException exception) { throw new SecurityException("BasicIdentityStorage: SQLite error: " + exception); } }
////////////////////////////////////////////////////// Schedule management. /// <summary> /// Check if there is a schedule with the given name. /// </summary> /// /// <param name="name">The name of the schedule.</param> /// <returns>True if there is a schedule.</returns> /// <exception cref="GroupManagerDb.Error">for a database error.</exception> public override bool hasSchedule(String name) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.SELECT_hasSchedule); statement.setString(1, name); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(true); } else { return(false); } } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.hasSchedule: SQLite error: " + exception); } }
/// <summary> /// Get the group key pair with the name eKeyName from the database. /// </summary> /// /// <param name="eKeyName">The name of the EKey.</param> /// <param name="publicKey">Set publicKey[0] to the encoded public Key.</param> /// <param name="privateKey">Set publicKey[0] to the encoded private Key.</param> /// <exception cref="GroupManagerDb.Error">If the key with name eKeyName does not existin the database, or other database error.</exception> public override void getEKey(Name eKeyName, Blob[] publicKey, Blob[] privateKey) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.SELECT_getEKey); statement.setBytes(1, eKeyName.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()) .getImmutableArray()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { publicKey[0] = new Blob(result.getBytes(3), false); } else { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.getEKey: Cannot get the result from the database"); } } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.getEKey: SQLite error: " + exception); } privateKey[0] = ILOG.J2CsMapping.Collections.Collections.Get(privateKeyBase_, eKeyName); }
/// <summary> /// Add a new member with the given key named keyName into a schedule named /// scheduleName. The member's identity name is keyName.getPrefix(-1). /// </summary> /// /// <param name="scheduleName">The schedule name.</param> /// <param name="keyName">The name of the key.</param> /// <param name="key">A Blob of the public key DER.</param> /// <exception cref="GroupManagerDb.Error">If there's no schedule named scheduleName, ifthe member's identity name already exists, or other database error.</exception> public override void addMember(String scheduleName, Name keyName, Blob key) { int scheduleId = getScheduleId(scheduleName); if (scheduleId == -1) { throw new GroupManagerDb.Error("The schedule does not exist"); } // Needs to be changed in the future. Name memberName = keyName.getPrefix(-1); try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.INSERT_addMember); statement.setInt(1, scheduleId); statement.setBytes(2, memberName.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()) .getImmutableArray()); statement.setBytes(3, keyName.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()) .getImmutableArray()); statement.setBytes(4, key.getImmutableArray()); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.addMember: SQLite error: " + exception); } }
////////////////////////////////////////////////////// Member management. /// <summary> /// Check if there is a member with the given identity name. /// </summary> /// /// <param name="identity">The member's identity name.</param> /// <returns>True if there is a member.</returns> /// <exception cref="GroupManagerDb.Error">for a database error.</exception> public override bool hasMember(Name identity) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.SELECT_hasMember); statement.setBytes(1, identity.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()) .getImmutableArray()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(true); } else { return(false); } } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.hasMember: SQLite error: " + exception); } }
/// <summary> /// Get a list of certificate names of the key with id keyName. The returned /// certificate names can be used to create a PibCertificateContainer. With a /// certificate name and a backend implementation, one can obtain the /// certificate. /// </summary> /// /// <param name="keyName">The name of the key.</param> /// <returns>The set of certificate names. The Name objects are fresh copies. If /// the key does not exist, return an empty set.</returns> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override HashedSet <Name> getCertificatesOfKey(Name keyName) { HashedSet <Name> certNames = new HashedSet <Name>(); try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.SELECT_getCertificatesOfKey); statement.setBytes(1, keyName.wireEncode().getImmutableArray()); try { SqlDataReader result = statement.executeQuery(); while (result.NextResult()) { Name name = new Name(); try { name.wireDecode(new Blob(result.getBytes(1))); } catch (EncodingException ex) { throw new PibImpl.Error( "PibSqlite3: Error decoding name: " + ex); } ILOG.J2CsMapping.Collections.Collections.Add(certNames, name); } } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } return(certNames); }
/// <summary> /// Get the certificate with name certificateName. /// </summary> /// /// <param name="certificateName">The name of the certificate.</param> /// <returns>A copy of the certificate.</returns> /// <exception cref="Pib.Error">if the certificate does not exist.</exception> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override CertificateV2 getCertificate(Name certificateName) { try { PreparedStatement statement = database_ .prepareStatement("SELECT certificate_data FROM certificates WHERE certificate_name=?"); statement.setBytes(1, certificateName.wireEncode() .getImmutableArray()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { CertificateV2 certificate = new CertificateV2(); try { certificate.wireDecode(new Blob(result.getBytes(1))); } catch (EncodingException ex) { throw new PibImpl.Error( "PibSqlite3: Error decoding certificate: " + ex); } return(certificate); } else { throw new Pib.Error("Certificate `" + certificateName.toUri() + "` does not exit"); } } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } }
/// <summary> /// Get the key bits of a key with name keyName. /// </summary> /// /// <param name="keyName">The name of the key.</param> /// <returns>The key bits.</returns> /// <exception cref="Pib.Error">if the key does not exist.</exception> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override Blob getKeyBits(Name keyName) { try { PreparedStatement statement = database_ .prepareStatement("SELECT key_bits " + net.named_data.jndn.security.pib.PibSqlite3Base.FROM_WHERE_getKeyBits); statement.setBytes(1, keyName.wireEncode().getImmutableArray()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(new Blob(result.getBytes(1), false)); } else { throw new Pib.Error("Key `" + keyName.toUri() + "` does not exist"); } } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } }
/// <summary> /// Add the identity. If the identity already exists, do nothing. If no default /// identity has been set, set the added identity as the default. /// </summary> /// /// <param name="identityName">The name of the identity to add. This copies the name.</param> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override void addIdentity(Name identityName) { if (!hasIdentity(identityName)) { try { PreparedStatement statement = database_ .prepareStatement("INSERT INTO identities (identity) values (?)"); statement.setBytes(1, identityName.wireEncode() .getImmutableArray()); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } } if (!hasDefaultIdentity()) { setDefaultIdentity(identityName); } }
/// <summary> /// List all the names of the schedules. /// </summary> /// /// <returns>A new List of String with the names of all schedules. (Use List /// without generics so it works with older Java compilers.)</returns> /// <exception cref="GroupManagerDb.Error">for a database error.</exception> public override IList listAllScheduleNames() { IList list = new ArrayList(); try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.SELECT_listAllScheduleNames); try { SqlDataReader result = statement.executeQuery(); while (result.NextResult()) { ILOG.J2CsMapping.Collections.Collections.Add(list, result.getString(1)); } } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.listAllScheduleNames: SQLite error: " + exception); } return(list); }
/// <summary> /// Add a public key to the identity storage. Also call addIdentity to ensure /// that the identityName for the key exists. However, if the key already /// exists, do nothing. /// </summary> /// /// <param name="keyName">The name of the public key to be added.</param> /// <param name="keyType">Type of the public key to be added.</param> /// <param name="publicKeyDer">A blob of the public key DER to be added.</param> public sealed override void addKey(Name keyName, KeyType keyType, Blob publicKeyDer) { if (keyName.size() == 0) { return; } if (doesKeyExist(keyName)) { return; } String keyId = keyName.get(-1).toEscapedString(); Name identityName = keyName.getPrefix(-1); addIdentity(identityName); try { PreparedStatement statement = database_ .prepareStatement("INSERT INTO Key (identity_name, key_identifier, key_type, public_key) values (?, ?, ?, ?)"); statement.setString(1, identityName.toUri()); statement.setString(2, keyId); statement.setInt(3, keyType.getNumericType()); statement.setBytes(4, publicKeyDer.getImmutableArray()); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new SecurityException("BasicIdentityStorage: SQLite error: " + exception); } }
/// <summary> /// Update the schedule with name and replace the old object with the given /// schedule. Otherwise, if no schedule with name exists, a new schedule /// with name and the given schedule will be added to database. /// </summary> /// /// <param name="name">The name of the schedule. The name cannot be empty.</param> /// <param name="schedule">The Schedule to update or add.</param> /// <exception cref="GroupManagerDb.Error">if the name is empty, or other database error.</exception> public override void updateSchedule(String name, Schedule schedule) { if (!hasSchedule(name)) { addSchedule(name, schedule); return; } try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.UPDATE_updateSchedule); statement.setBytes(1, schedule.wireEncode().getImmutableArray()); statement.setString(2, name); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.updateSchedule: SQLite error: " + exception); } }
/// <summary> /// Check if the specified certificate already exists. /// </summary> /// /// <param name="certificateName">The name of the certificate.</param> /// <returns>True if the certificate exists, otherwise false.</returns> public sealed override bool doesCertificateExist(Name certificateName) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.SELECT_doesCertificateExist); statement.setString(1, certificateName.toUri()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(result.getInt(1) > 0); } else { return(false); } } finally { statement.close(); } } catch (SQLException exception) { throw new SecurityException("BasicIdentityStorage: SQLite error: " + exception); } }
/// <summary> /// Get the name of the schedule for the given member's identity name. /// </summary> /// /// <param name="identity">The member's identity name.</param> /// <returns>The name of the schedule.</returns> /// <exception cref="GroupManagerDb.Error">if there's no member with the given identityname in the database, or other database error.</exception> public override String getMemberSchedule(Name identity) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.SELECT_getMemberSchedule); statement.setBytes(1, identity.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()) .getImmutableArray()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(result.getString(1)); } else { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.getMemberSchedule: Cannot get the result from the database"); } } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.getMemberSchedule: SQLite error: " + exception); } }
/// <summary> /// Get the default key name for the specified identity. /// </summary> /// /// <param name="identityName">The identity name.</param> /// <returns>The default key name.</returns> /// <exception cref="System.Security.SecurityException">if the default key name for the identity is not set.</exception> public sealed override Name getDefaultKeyNameForIdentity(Name identityName) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.SELECT_getDefaultKeyNameForIdentity); statement.setString(1, identityName.toUri()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(new Name(identityName).append((string)result["key_identifier"])); } else { throw new SecurityException( "BasicIdentityStorage.getDefaultKeyNameForIdentity: The default key for the identity is not defined"); } } finally { statement.close(); } } catch (SQLException exception) { throw new SecurityException("BasicIdentityStorage: SQLite error: " + exception); } }
/// <summary> /// Change the name of the schedule for the given member's identity name. /// </summary> /// /// <param name="identity">The member's identity name.</param> /// <param name="scheduleName">The new schedule name.</param> /// <exception cref="GroupManagerDb.Error">if there's no member with the given identityname in the database, or there's no schedule named scheduleName, or otherdatabase error.</exception> public override void updateMemberSchedule(Name identity, String scheduleName) { int scheduleId = getScheduleId(scheduleName); if (scheduleId == -1) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.updateMemberSchedule: The schedule does not exist"); } try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.UPDATE_updateMemberSchedule); statement.setInt(1, scheduleId); statement.setBytes(2, identity.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()) .getImmutableArray()); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.updateMemberSchedule: SQLite error: " + exception); } }
/// <summary> /// Get the default certificate name for the specified key. /// </summary> /// /// <param name="keyName">The key name.</param> /// <returns>The default certificate name.</returns> /// <exception cref="System.Security.SecurityException">if the default certificate name for the key nameis not set.</exception> public sealed override Name getDefaultCertificateNameForKey(Name keyName) { String keyId = keyName.get(-1).toEscapedString(); Name identityName = keyName.getPrefix(-1); try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.SELECT_getDefaultCertificateNameForKey); statement.setString(1, identityName.toUri()); statement.setString(2, keyId); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(new Name((string)result["cert_name"])); } else { throw new SecurityException( "BasicIdentityStorage.getDefaultCertificateNameForKey: The default certificate for the key name is not defined"); } } finally { statement.close(); } } catch (SQLException exception) { throw new SecurityException("BasicIdentityStorage: SQLite error: " + exception); } }
/// <summary> /// Get the ID for the schedule. /// </summary> /// /// <param name="name">The schedule name.</param> /// <returns>The ID, or -1 if the schedule name is not found.</returns> /// <exception cref="GroupManagerDb.Error">for a database error.</exception> private int getScheduleId(String name) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3GroupManagerDbBase.SELECT_getScheduleId); statement.setString(1, name); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(result.getInt(1)); } else { return(-1); } } finally { statement.close(); } } catch (SQLException exception) { throw new GroupManagerDb.Error( "Sqlite3GroupManagerDb.getScheduleId: SQLite error: " + exception); } }
/// <summary> /// Check if a content key exists for the hour covering timeSlot. /// </summary> /// /// <param name="timeSlot">The time slot as milliseconds since Jan 1, 1970 UTC.</param> /// <returns>True if there is a content key for timeSlot.</returns> /// <exception cref="ProducerDb.Error">for a database error.</exception> public override bool hasContentKey(double timeSlot) { int fixedTimeSlot = net.named_data.jndn.encrypt.ProducerDb.getFixedTimeSlot(timeSlot); try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3ProducerDbBase.SELECT_hasContentKey); statement.setInt(1, fixedTimeSlot); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { return(true); } else { return(false); } } finally { statement.close(); } } catch (SQLException exception) { throw new ProducerDb.Error( "Sqlite3ProducerDb.hasContentKey: SQLite error: " + exception); } }
/// <summary> /// Get the default certificate for the key with eyName. /// </summary> /// /// <param name="keyName">The name of the key.</param> /// <returns>A copy of the default certificate.</returns> /// <exception cref="Pib.Error">if the default certificate does not exist.</exception> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override CertificateV2 getDefaultCertificateOfKey(Name keyName) { try { PreparedStatement statement = database_ .prepareStatement("SELECT certificate_data " + net.named_data.jndn.security.pib.PibSqlite3Base.FROM_WHERE_getDefaultCertificateOfKey); statement.setBytes(1, keyName.wireEncode().getImmutableArray()); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { CertificateV2 certificate = new CertificateV2(); try { certificate.wireDecode(new Blob(result.getBytes(1))); } catch (EncodingException ex) { throw new PibImpl.Error( "PibSqlite3: Error decoding certificate: " + ex); } return(certificate); } else { throw new Pib.Error("No default certificate for key `" + keyName.toUri() + "`"); } } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } }
/// <summary> /// Get the key with keyName from the database. /// </summary> /// /// <param name="keyName">The key name.</param> /// <returns>A Blob with the encoded key, or an isNull Blob if cannot find the /// key with keyName.</returns> /// <exception cref="ConsumerDb.Error">for a database error.</exception> public override Blob getKey(Name keyName) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.encrypt.Sqlite3ConsumerDbBase.SELECT_getKey); statement.setBytes(1, keyName.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()) .getImmutableArray()); Blob key = new Blob(); try { SqlDataReader result = statement.executeQuery(); if (result.NextResult()) { key = new Blob(result.getBytes(1), false); } } finally { statement.close(); } return(key); } catch (SQLException exception) { throw new ConsumerDb.Error( "Sqlite3ConsumerDb.getKey: SQLite error: " + exception); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: long executeCountQuery(java.sql.Connection paramConnection, String paramString) throws Exception internal virtual long executeCountQuery(Connection paramConnection, string paramString) { PreparedStatement preparedStatement = null; try { if (logger.DebugEnabled) { logger.debug("COUNT: " + paramString); } preparedStatement = paramConnection.prepareStatement(paramString); ResultSet resultSet = preparedStatement.executeQuery(); resultSet.next(); long l = resultSet.getLong(1); if (logger.DebugEnabled) { logger.debug("\tCount returned " + l + " rows"); } return(l); } catch (SQLException sQLException) { if (preparedStatement != null) { preparedStatement.close(); } throw new Exception(sQLException); } }
private string getAuthType(string paramString) { PreparedStatement preparedStatement = null; ResultSet resultSet = null; Connection connection = null; string str = null; try { InitialContext initialContext = new InitialContext(); DataSource dataSource = (DataSource)initialContext.lookup(this.dsJndiName); connection = dataSource.Connection; preparedStatement = connection.prepareStatement("SELECT AUTHTYPE FROM PRINCIPALS WHERE ENBL = 1 AND PRINCIPALID = ? COLLATE SQL_Latin1_General_CP1_CS_AS"); preparedStatement.setString(1, paramString); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { str = resultSet.getString(1); } } catch (Exception exception) { Console.WriteLine(exception.ToString()); Console.Write(exception.StackTrace); } if (resultSet != null) { try { resultSet.close(); } catch (SQLException) { } } if (preparedStatement != null) { try { preparedStatement.close(); } catch (SQLException) { } } if (connection != null) { try { connection.close(); } catch (SQLException) { } } return(str); }
private void CreateStatement() { if (statement != null) { statement.close(); } try { statement = connection.connection.prepareStatement(template.TrueSql); } catch (org.h2.jdbc.JdbcSQLException ex) { throw new H2Exception(ex); } if (timeoutSet) { statement.setQueryTimeout(commandTimeout); } }
/// <summary> /// Add the key. If a key with the same name already exists, overwrite the key. /// If the identity does not exist, it will be created. If no default key for /// the identity has been set, then set the added key as the default for the /// identity. If no default identity has been set, identity becomes the /// default. /// </summary> /// /// <param name="identityName"></param> /// <param name="keyName">The name of the key. This copies the name.</param> /// <param name="key">The public key bits. This copies the array.</param> /// <exception cref="PibImpl.Error">for a non-semantic (database access) error.</exception> public override void addKey(Name identityName, Name keyName, ByteBuffer key) { // Ensure the identity exists. addIdentity(identityName); if (!hasKey(keyName)) { try { PreparedStatement statement = database_ .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.INSERT_addKey); statement.setBytes(1, identityName.wireEncode() .getImmutableArray()); statement.setBytes(2, keyName.wireEncode().getImmutableArray()); statement.setBytes(3, new Blob(key, false).getImmutableArray()); try { statement.executeUpdate(); } finally { statement.close(); } } catch (SQLException exception) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception); } } else { try { PreparedStatement statement_0 = database_ .prepareStatement(net.named_data.jndn.security.pib.PibSqlite3Base.UPDATE_addKey); statement_0.setBytes(1, new Blob(key, false).getImmutableArray()); statement_0.setBytes(2, keyName.wireEncode().getImmutableArray()); try { statement_0.executeUpdate(); } finally { statement_0.close(); } } catch (SQLException exception_1) { throw new PibImpl.Error("PibSqlite3: SQLite error: " + exception_1); } } if (!hasDefaultKeyOfIdentity(identityName)) { try { setDefaultKeyOfIdentity(identityName, keyName); } catch (Pib.Error ex) { throw new PibImpl.Error( "PibSqlite3: Error setting the default key: " + ex); } } }