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

schemacrawler.crawl.MutablePrivilege Maven / Gradle / Ivy

Go to download

SchemaCrawler is an open-source Java API that makes working with database metadata as easy as working with plain old Java objects. SchemaCrawler is also a database schema discovery and comprehension, and schema documentation tool. You can search for database schema objects using regular expressions, and output the schema and data in a readable text format. The output is designed to be diff-ed against other database schemas.

There is a newer version: 16.22.2
Show newest version
/*
 *
 * SchemaCrawler
 * http://sourceforge.net/projects/schemacrawler
 * Copyright (c) 2000-2014, Sualeh Fatehi.
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */

package schemacrawler.crawl;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import schemacrawler.schema.DatabaseObject;
import schemacrawler.schema.Privilege;
import sf.util.Utility;

/**
 * Represents a privilege of a table or column.
 *
 * @author Sualeh Fatehi
 */
final class MutablePrivilege

extends AbstractNamedObject implements Privilege

{ private final class PrivilegeGrant implements Grant { private static final long serialVersionUID = 356151825191631484L; private final String grantor; private final String grantee; private final boolean isGrantable; PrivilegeGrant(final String grantor, final String grantee, final boolean isGrantable) { this.grantor = grantor; this.grantee = grantee; this.isGrantable = isGrantable; } @Override public int compareTo(final Grant otherGrant) { int compare = 0; if (compare == 0) { compare = grantor.compareTo(otherGrant.getGrantor()); } if (compare == 0) { compare = grantee.compareTo(otherGrant.getGrantee()); } return compare; } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final PrivilegeGrant other = (PrivilegeGrant) obj; if (!getParent().equals(other.getParent())) { return false; } if (grantee == null) { if (other.grantee != null) { return false; } } else if (!grantee.equals(other.grantee)) { return false; } if (grantor == null) { if (other.grantor != null) { return false; } } else if (!grantor.equals(other.grantor)) { return false; } if (isGrantable != other.isGrantable) { return false; } return true; } /** * {@inheritDoc} */ @Override public String getGrantee() { return grantee; } /** * {@inheritDoc} */ @Override public String getGrantor() { return grantor; } @Override public MutablePrivilege

getParent() { return MutablePrivilege.this; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + getParent().hashCode(); result = prime * result + (grantee == null? 0: grantee.hashCode()); result = prime * result + (grantor == null? 0: grantor.hashCode()); result = prime * result + (isGrantable? 1231: 1237); return result; } /** * {@inheritDoc} */ @Override public boolean isGrantable() { return isGrantable; } } private final P parent; private final Set grants = new HashSet<>(); private static final long serialVersionUID = -1117664231494271886L; MutablePrivilege(final P parent, final String name) { super(name); this.parent = parent; } @Override public Collection getGrants() { final List values = new ArrayList<>(grants); Collections.sort(values); return values; } @Override public P getParent() { return parent; } void addGrant(final String grantor, final String grantee, final boolean isGrantable) { if (!Utility.isBlank(grantor) && !Utility.isBlank(grantee)) { grants.add(new PrivilegeGrant(grantor, grantee, isGrantable)); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy