All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aoindustries.aoserv.client.dns.RecordTable Maven / Gradle / Ivy

/*
 * aoserv-client - Java client for the AOServ Platform.
 * Copyright (C) 2001-2012, 2014, 2015, 2016, 2017, 2018, 2019  AO Industries, Inc.
 *     [email protected]
 *     7262 Bull Pen Cir
 *     Mobile, AL 36695
 *
 * This file is part of aoserv-client.
 *
 * aoserv-client is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aoserv-client is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with aoserv-client.  If not, see .
 */
package com.aoindustries.aoserv.client.dns;

import com.aoindustries.aoserv.client.AOServConnector;
import com.aoindustries.aoserv.client.CachedTableIntegerKey;
import com.aoindustries.aoserv.client.aosh.AOSH;
import com.aoindustries.aoserv.client.aosh.Command;
import com.aoindustries.aoserv.client.schema.AoservProtocol;
import com.aoindustries.aoserv.client.schema.Table;
import com.aoindustries.io.TerminalWriter;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @see  Record
 *
 * @author  AO Industries, Inc.
 */
final public class RecordTable extends CachedTableIntegerKey {

	RecordTable(AOServConnector connector) {
		super(connector, Record.class);
	}

	private static final OrderBy[] defaultOrderBy = {
		new OrderBy(Record.COLUMN_ZONE_name, ASCENDING),
		new OrderBy(Record.COLUMN_DOMAIN_name, ASCENDING),
		new OrderBy(Record.COLUMN_TYPE_name, ASCENDING),
		new OrderBy(Record.COLUMN_PRIORITY_name, ASCENDING),
		new OrderBy(Record.COLUMN_WEIGHT_name, ASCENDING),
		new OrderBy(Record.COLUMN_DESTINATION_name, ASCENDING)
	};
	@Override
	protected OrderBy[] getDefaultOrderBy() {
		return defaultOrderBy;
	}

	int addDNSRecord(
		Zone zone,
		String domain,
		RecordType type,
		int priority,
		int weight,
		int port,
		String destination,
		int ttl
	) throws IOException, SQLException {
		return connector.requestIntQueryIL(
			true,
			AoservProtocol.CommandID.ADD,
			Table.TableID.DNS_RECORDS,
			zone.getZone(),
			domain,
			type.getType(),
			priority,
			weight,
			port,
			destination,
			ttl
		);
	}

	@Override
	public Record get(int id) throws IOException, SQLException {
		return getUniqueRow(Record.COLUMN_ID, id);
	}

	List getDNSRecords(Zone dnsZone) throws IOException, SQLException {
		return getIndexedRows(Record.COLUMN_ZONE, dnsZone.getZone());
	}

	List getDNSRecords(Zone dnsZone, String domain, RecordType dnsType) throws IOException, SQLException {
		String type=dnsType.getType();

		// Use the index first
		List cached=getDNSRecords(dnsZone);
		int size=cached.size();
		List matches=new ArrayList<>(size);
		for(int c=0;c




© 2015 - 2025 Weber Informatics LLC | Privacy Policy