X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2FProCoreServerReference.java;h=295d7c0a19b12b690cc4d944fb35ea841bdf7b7c;hp=7081eb24de7307b66776463e11175995d70f10ac;hb=6f11a60dee43d620d500c0cf5af34a1d91c80a8b;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/ProCoreServerReference.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/ProCoreServerReference.java index 7081eb24d..295d7c0a1 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/ProCoreServerReference.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/ProCoreServerReference.java @@ -1,113 +1,113 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package fi.vtt.simantics.procore; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.simantics.db.ServerReference; -import org.simantics.db.common.utils.Logger; - -/** - * @author Toni Kalajainen - */ -public final class ProCoreServerReference implements ServerReference { - public final Path dbFolder; // ProCoreServer is identified by database folder. - public final InetSocketAddress socketAddress; // deprecated - public final String dbid; // deprecated - - public ProCoreServerReference() { - dbFolder = Paths.get("/"); // Assuming we don't have write rights to root. - dbid = ""; - socketAddress = InetSocketAddress.createUnresolved("127.0.0.0", 0); - } - public ProCoreServerReference(Path dbFolder) { - if (null == dbFolder) // Null means that caller does not care what the value is. - dbFolder = Paths.get("/"); // Assuming we don't have write rights to root. - this.dbFolder = dbFolder; - dbid = ""; - socketAddress = InetSocketAddress.createUnresolved("127.0.0.0", 0); - } -// public ProCoreServerReference(ServerAddress address) throws InternalException { -// Path dbFolder = Paths.get(address.getDbid()); // Maybe it would be better to let address resolve folder? -// if (Files.isDirectory(dbFolder)) -// throw new ProCoreException("Server address does not contain valid database folder. address=" + address); -// if (null == dbFolder) // Null means that caller does not care what the value is. -// dbFolder = Paths.get("/"); // Assuming we don't have write rights to root. -// this.dbFolder = dbFolder; -// dbid = ""; -// socketAddress = InetSocketAddress.createUnresolved("127.0.0.0", 0); -// } - public ProCoreServerReference(Path dbFolder, String hostAndPort) { - this.dbFolder = dbFolder; - String[] split = hostAndPort.split(":"); - if (split.length != 2) - throw new IllegalArgumentException("address does not contain a port, missing ':' character"); - this.socketAddress = InetSocketAddress.createUnresolved(split[0], Integer.parseInt(split[1])); - this.dbid = null; - } - - public ProCoreServerReference(Path dbFolder, String host, int port) { - this.dbFolder = dbFolder; - this.socketAddress = new InetSocketAddress(host, port); - this.dbid = null; - } - - public ProCoreServerReference(Path dbFolder, String host, int port, String dbid) { - this.dbFolder = dbFolder; - this.socketAddress = InetSocketAddress.createUnresolved(host, port); - this.dbid = dbid; - } - - public ProCoreServerReference(Path dbFolder, InetSocketAddress socketAddress) { - this.dbFolder = dbFolder; - this.socketAddress = socketAddress; - this.dbid = null; - } - - public ProCoreServerReference(Path dbFolder, InetSocketAddress socketAddress, String dbid) { - this.dbFolder = dbFolder; - this.socketAddress = socketAddress; - this.dbid = dbid; - } - - @Override - public int hashCode() { - return dbFolder.hashCode(); - } - - @Override - public boolean equals(Object other) { - if (this == other) return true; - if (other == null || !(getClass().equals(other.getClass()))) return false; - ProCoreServerReference r = (ProCoreServerReference) other; - try { - return Files.isSameFile(dbFolder, r.dbFolder); - } catch (IOException e) { - Logger.defaultLogError("Failed to compare db folders. f1=" + dbFolder + " f2=" + r.dbFolder, e); - return false; - } - } - - @Override - public String toString() { - return dbFolder.toString(); - } - @Override - public Path getDBFolder() { - return dbFolder; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package fi.vtt.simantics.procore; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.simantics.db.ServerReference; +import org.simantics.db.common.utils.Logger; + +/** + * @author Toni Kalajainen + */ +public final class ProCoreServerReference implements ServerReference { + public final Path dbFolder; // ProCoreServer is identified by database folder. + public final InetSocketAddress socketAddress; // deprecated + public final String dbid; // deprecated + + public ProCoreServerReference() { + dbFolder = Paths.get("/"); // Assuming we don't have write rights to root. + dbid = ""; + socketAddress = InetSocketAddress.createUnresolved("127.0.0.0", 0); + } + public ProCoreServerReference(Path dbFolder) { + if (null == dbFolder) // Null means that caller does not care what the value is. + dbFolder = Paths.get("/"); // Assuming we don't have write rights to root. + this.dbFolder = dbFolder; + dbid = ""; + socketAddress = InetSocketAddress.createUnresolved("127.0.0.0", 0); + } +// public ProCoreServerReference(ServerAddress address) throws InternalException { +// Path dbFolder = Paths.get(address.getDbid()); // Maybe it would be better to let address resolve folder? +// if (Files.isDirectory(dbFolder)) +// throw new ProCoreException("Server address does not contain valid database folder. address=" + address); +// if (null == dbFolder) // Null means that caller does not care what the value is. +// dbFolder = Paths.get("/"); // Assuming we don't have write rights to root. +// this.dbFolder = dbFolder; +// dbid = ""; +// socketAddress = InetSocketAddress.createUnresolved("127.0.0.0", 0); +// } + public ProCoreServerReference(Path dbFolder, String hostAndPort) { + this.dbFolder = dbFolder; + String[] split = hostAndPort.split(":"); + if (split.length != 2) + throw new IllegalArgumentException("address does not contain a port, missing ':' character"); + this.socketAddress = InetSocketAddress.createUnresolved(split[0], Integer.parseInt(split[1])); + this.dbid = null; + } + + public ProCoreServerReference(Path dbFolder, String host, int port) { + this.dbFolder = dbFolder; + this.socketAddress = new InetSocketAddress(host, port); + this.dbid = null; + } + + public ProCoreServerReference(Path dbFolder, String host, int port, String dbid) { + this.dbFolder = dbFolder; + this.socketAddress = InetSocketAddress.createUnresolved(host, port); + this.dbid = dbid; + } + + public ProCoreServerReference(Path dbFolder, InetSocketAddress socketAddress) { + this.dbFolder = dbFolder; + this.socketAddress = socketAddress; + this.dbid = null; + } + + public ProCoreServerReference(Path dbFolder, InetSocketAddress socketAddress, String dbid) { + this.dbFolder = dbFolder; + this.socketAddress = socketAddress; + this.dbid = dbid; + } + + @Override + public int hashCode() { + return dbFolder.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + if (other == null || !(getClass().equals(other.getClass()))) return false; + ProCoreServerReference r = (ProCoreServerReference) other; + try { + return Files.isSameFile(dbFolder, r.dbFolder); + } catch (IOException e) { + Logger.defaultLogError("Failed to compare db folders. f1=" + dbFolder + " f2=" + r.dbFolder, e); + return false; + } + } + + @Override + public String toString() { + return dbFolder.toString(); + } + @Override + public Path getDBFolder() { + return dbFolder; + } + +}