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

com.aoindustries.aoserv.client.TechnologyVersionTable Maven / Gradle / Ivy

There is a newer version: 1.92.0
Show newest version
/*
 * aoserv-client - Java client for the AOServ platform.
 * Copyright (C) 2001-2009, 2016  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;

import com.aoindustries.util.StringUtility;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @see  TechnologyVersion
 *
 * @author  AO Industries, Inc.
 */
final public class TechnologyVersionTable extends GlobalTableIntegerKey {

	/**
	 * Fields used in an order by search.
	 */
	public static final int NONE = 0, NAME = 1, VERSION = 2, UPDATED = 3;

	/**
	 * Labels for the different sort orders.
	 */
	static final String[] orderLabels = { "None", "Name", "Version", "Updated" };

	public static final int NUM_ORDER_LABELS=4;

	private static long maximumUpdatedTime=-1;

	TechnologyVersionTable(AOServConnector connector) {
		super(connector, TechnologyVersion.class);
	}

	private static final OrderBy[] defaultOrderBy = {
		new OrderBy(TechnologyVersion.COLUMN_NAME_name, ASCENDING),
		new OrderBy(TechnologyVersion.COLUMN_VERSION_name, ASCENDING)
	};
	@Override
	OrderBy[] getDefaultOrderBy() {
		return defaultOrderBy;
	}

	@Override
	public void clearCache() {
		super.clearCache();
		synchronized(TechnologyVersionTable.class) {
			maximumUpdatedTime=-1;
		}
	}

	@Override
	public TechnologyVersion get(int pkey) throws IOException, SQLException {
		return getUniqueRow(TechnologyVersion.COLUMN_PKEY, pkey);
	}

	public long getMaximumUpdatedTime() throws IOException, SQLException {
		synchronized(TechnologyVersionTable.class) {
			if(maximumUpdatedTime==-1) {
				List versions=getRows();
				int size=versions.size();
				long max=-1;
				for(int c=0;cmax) max=mod;
				}
				maximumUpdatedTime=max;
			}
			return maximumUpdatedTime;
		}
	}

	public static String getOrderLabel(int index) {
		return orderLabels[index];
	}

	@Override
	public SchemaTable.TableID getTableID() {
		return SchemaTable.TableID.TECHNOLOGY_VERSIONS;
	}

	TechnologyVersion getTechnologyVersion(TechnologyName techName, String version, OperatingSystemVersion osv) throws IOException, SQLException {
		String name=techName.getName();
		int osvPKey=osv.pkey;
		List table=getRows();
		int size=table.size();
		for(int c=0;cnull only the technologies that have every word in their name are selected
	 * @param  classes  a ArrayList of TechnologyClasses.
	 *                  Only the technologies that have any class are selected.
	 *                  If empty, all are selected.
	 * @param  version  if not null only the technologies that have every word in their version are selected
	 * @param  orderBy  the column that the results will be ordered by
	 *
	 * @return  a TechnologyVersion[] of all the matches
	 */
	public List getTechnologyVersions(OperatingSystemVersion osv, String name, List classes, String version, int orderBy) throws IOException, SQLException {
		// Prepare names
		String[] nameWords = null;
		if (name != null) {
			nameWords=StringUtility.splitString(name);
			int len = nameWords.length;
			for (int c = 0; c < len; c++) nameWords[c]=nameWords[c].toLowerCase();
		}

		// Version
		String[] versionWords = null;
		if (version != null) {
			versionWords = StringUtility.splitString(version);
			int len = versionWords.length;
			for (int c = 0; c < len; c++) versionWords[c]=versionWords[c].toLowerCase();
		}

		List table=getRows();
		List matches=new ArrayList<>();
		int tableSize=table.size();
		for(int c=0;c0) {
							List rowClasses=TV.getTechnologyName(connector).getTechnologies(connector);
							found=false;
						Loop:
							for (TechnologyClass matchClass : classes) {
								for (Technology rowClass : rowClasses) {
									if (rowClass.getTechnologyClass(connector).equals(matchClass)) {
										found=true;
										break Loop;
									}
								}
							}
						}

						// Insert sorted to the correct place
						// This is a simple sort algorithm, not the fastest
						if(found) {
							int len=matches.size();
							int addAt=-1;
							for(int d=0;dcompVersion.updated) addAt=d;
								} else throw new IllegalArgumentException("Invalid value for orderBy: " + orderBy);
							}
							matches.add(addAt==-1?len:addAt, TV);
						}
					}
				}
			}
		}
		// Convert and return the matches
		return matches;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy