com.microsoft.azure.management.sql.implementation.SqlServerDnsAliasImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-sql Show documentation
Show all versions of azure-mgmt-sql Show documentation
This package contains Microsoft Azure Sql Management SDK. A new set of management libraries are now Generally Available. For documentation on how to use the new libraries, please see https://aka.ms/azsdk/java/mgmt
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.sql.implementation;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceId;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ExternalChildResourceImpl;
import com.microsoft.azure.management.sql.SqlServer;
import com.microsoft.azure.management.sql.SqlServerDnsAlias;
import com.microsoft.azure.management.sql.SqlServerDnsAliasOperations;
import rx.Completable;
import rx.Observable;
import rx.functions.Func1;
import java.util.Objects;
/**
* Implementation for SqlServerDnsAlias.
*/
@LangDefinition
public class SqlServerDnsAliasImpl
extends
ExternalChildResourceImpl
implements
SqlServerDnsAlias,
SqlServerDnsAliasOperations.SqlServerDnsAliasOperationsDefinition {
private SqlServerManager sqlServerManager;
private String resourceGroupName;
private String sqlServerName;
/**
* Creates an instance of external child resource in-memory.
*
* @param name the name of this external child resource
* @param parent reference to the parent of this external child resource
* @param innerObject reference to the inner object representing this external child resource
* @param sqlServerManager reference to the SQL server manager that accesses DNS alias operations
*/
SqlServerDnsAliasImpl(String name, SqlServerImpl parent, ServerDnsAliasInner innerObject, SqlServerManager sqlServerManager) {
super(name, parent, innerObject);
Objects.requireNonNull(parent);
Objects.requireNonNull(sqlServerManager);
this.sqlServerManager = sqlServerManager;
this.resourceGroupName = parent.resourceGroupName();
this.sqlServerName = parent.name();
}
/**
* Creates an instance of external child resource in-memory.
*
* @param resourceGroupName the resource group name
* @param sqlServerName the parent SQL server name
* @param name the name of this external child resource
* @param innerObject reference to the inner object representing this external child resource
* @param sqlServerManager reference to the SQL server manager that accesses DNS alias operations
*/
SqlServerDnsAliasImpl(String resourceGroupName, String sqlServerName, String name, ServerDnsAliasInner innerObject, SqlServerManager sqlServerManager) {
super(name, null, innerObject);
Objects.requireNonNull(sqlServerManager);
this.sqlServerManager = sqlServerManager;
this.resourceGroupName = resourceGroupName;
this.sqlServerName = sqlServerName;
}
/**
* Creates an instance of external child resource in-memory.
*
* @param name the name of this external child resource
* @param innerObject reference to the inner object representing this external child resource
* @param sqlServerManager reference to the SQL server manager that accesses DNS alias operations
*/
SqlServerDnsAliasImpl(String name, ServerDnsAliasInner innerObject, SqlServerManager sqlServerManager) {
super(name, null, innerObject);
Objects.requireNonNull(sqlServerManager);
this.sqlServerManager = sqlServerManager;
if (innerObject != null && innerObject.id() != null) {
try {
ResourceId resourceId = ResourceId.fromString(innerObject.id());
this.resourceGroupName = resourceId.resourceGroupName();
this.sqlServerName = resourceId.parent().name();
} catch (NullPointerException e) {
}
}
}
@Override
public String resourceGroupName() {
return this.resourceGroupName;
}
@Override
public String id() {
return this.inner().id();
}
@Override
public String sqlServerName() {
return this.sqlServerName;
}
@Override
public String azureDnsRecord() {
return this.inner().azureDnsRecord();
}
@Override
public String parentId() {
return ResourceUtils.parentResourceIdFromResourceId(this.inner().id());
}
@Override
public void delete() {
this.sqlServerManager.inner().serverDnsAliases()
.delete(this.resourceGroupName, this.sqlServerName, this.name());
}
@Override
public Completable deleteAsync() {
return this.deleteResourceAsync().toCompletable();
}
@Override
public SqlServerDnsAliasImpl withExistingSqlServer(String resourceGroupName, String sqlServerName) {
this.resourceGroupName = resourceGroupName;
this.sqlServerName = sqlServerName;
return this;
}
@Override
public SqlServerDnsAliasImpl withExistingSqlServerId(String sqlServerId) {
Objects.requireNonNull(sqlServerId);
ResourceId resourceId = ResourceId.fromString(sqlServerId);
this.resourceGroupName = resourceId.resourceGroupName();
this.sqlServerName = resourceId.name();
return this;
}
@Override
public SqlServerDnsAliasImpl withExistingSqlServer(SqlServer sqlServer) {
Objects.requireNonNull(sqlServer);
this.resourceGroupName = sqlServer.resourceGroupName();
this.sqlServerName = sqlServer.name();
return this;
}
@Override
public Observable createResourceAsync() {
final SqlServerDnsAliasImpl self = this;
return this.sqlServerManager.inner().serverDnsAliases()
.createOrUpdateAsync(self.resourceGroupName, self.sqlServerName, self.name())
.map(new Func1() {
@Override
public SqlServerDnsAlias call(ServerDnsAliasInner serverDnsAliasInner) {
self.setInner(serverDnsAliasInner);
return self;
}
});
}
@Override
public Observable updateResourceAsync() {
return this.createResourceAsync();
}
@Override
public Observable deleteResourceAsync() {
return this.sqlServerManager.inner().serverDnsAliases()
.deleteAsync(this.resourceGroupName, this.sqlServerName, this.name());
}
@Override
protected Observable getInnerAsync() {
return this.sqlServerManager.inner().serverDnsAliases()
.getAsync(this.resourceGroupName, this.sqlServerName, this.name());
}
}