Dave Ward ff2ae89c08 Merged V4.0-BUG-FIX to HEAD
36915: ALF-12874: Schema reference files are out of date
   - Difference: expected primary key .alf_tenant.PRIMARY.columnNames[0]="id", but was .alf_tenant.PRIMARY.columnNames[0]="tenant_domain"
   - fixed the rename of alf_tenant PK "id" -> "tenant_domain" (for all 5 DB types)
   36950: Merged V4.0 to V4.0-BUG-FIX (RECORD ONLY)
      36917: Merged V4.0-BUG-FIX to V4.0
         36915: ALF-12874: Schema reference files are out of date
         - Difference: expected primary key .alf_tenant.PRIMARY.columnNames[0]="id", but was .alf_tenant.PRIMARY.columnNames[0]="tenant_domain"
         - fixed the rename of alf_tenant PK "id" -> "tenant_domain" (for all 5 DB types)
   36951: Merged V4.0 (4.0.2) to V4.0-BUG-FIX (4.0.3)
      36949: ALF-13745: Merged V3.4-BUG-FIX (3.4.10) to V4.0 (4.0.2)
         36948: ALF-13667 Additional OpenOffice mimetypes to be added to the mime-type maps
            - On reflection the maxSourceSizeKBytes limits for power point files were too small. Did not take into account
              images in the files rather than just text.
      36923: Merged DEV to V4.0
         36600: ALF-14129 : Failed to do upgrade from 3.4.8 to 4.0.2
            Statements from ActivitiTaskIdIndexes.sql script were marked as optional.
      36922: Merged DEV to V4.0
         36729: ALF-14129 : Failed to do upgrade from 3.4.8 to 4.0.2
            Outdated Schema-Reference-ACT.xml were updated for all dialects and regression after ALF-12874 was fixed.
   36953: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
      36905: ALF-14178 Share - Path issue with number of character limitation. Updated qname to max DB limit of 255 chars.
   36954: ALF-14209 SOLR - does not support query for all stores
   - it is now possible for SOLR to track any store and Alfresco to execute queries against that store (no federation or sharding yet ....)
   36965: Extra debugging after review of ALF-14238
   37032: ALF-12723: Missing mergeinfo for r34655
   37033: Merged V4.0 to V4.0-BUG-FIX
      36999: ALF-5285: Reverse merging r26226, as it causes regressions ALF-14202, ALF-14242 and ALF-14245
      37001: ALF-14169: Alfresco startup fails if XAM module was deployed
         Jan approved fix
      37005: ALF-14169: Fix unit test compilation
      37020: Resolved some "Patch description is not available" warnings in 4.0.2
      37022: ALF-12874: Schema reference files are out of date
      - Fixed up PostgreSQL diffs
      37027: ALF-12874: Schema reference files are out of date
      - DB2 fixes by Dmitry


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@37036 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-05-25 17:19:13 +00:00

213 lines
6.3 KiB
Java

/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco 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.
*
* Alfresco 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 Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.util.schemacomp.model;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.schemacomp.DbObjectVisitor;
import org.alfresco.util.schemacomp.DbProperty;
import org.alfresco.util.schemacomp.DiffContext;
import org.alfresco.util.schemacomp.validator.NameValidator;
import org.alfresco.util.schemacomp.validator.SchemaVersionValidator;
/**
* Instances of this class represent a database schema.
*
* @author Matt Ward
*/
public class Schema extends AbstractDbObject implements Iterable<DbObject>
{
protected final List<DbObject> objects = new ArrayList<DbObject>();
protected final String dbPrefix;
protected final int version;
/**
* Construct a schema with the given name and no database prefix.
*
* @param name
*/
public Schema(String name)
{
this(name, "", 0);
}
/**
* Construct a schema with the given name and database prefix. The database
* prefix specifies what filtering applies to the high-level (tables and sequences)
* objects in the schema. If for example dbPrefix is "alf_" then only tables and sequences
* whose names begin with "alf_" will be represented by this schema. Therefore any comparisons
* should be performed against another similarly filtered Schema object.
*
* @param name
* @param dbPrefix
*/
public Schema(String name, String dbPrefix, int schemaVersion)
{
super(null, name);
ParameterCheck.mandatory("dbPrefix", dbPrefix);
this.dbPrefix = dbPrefix;
this.version = schemaVersion;
addDefaultValidators();
}
/**
* Add a set of validators that should be present by default on Schema objects.
*/
private void addDefaultValidators()
{
// We expect the user's database to have a different schema name to the reference schema.
NameValidator nameValidator = new NameValidator();
nameValidator.setPattern(Pattern.compile(".*"));
getValidators().add(nameValidator);
// The schema version shouldn't have to match exactly.
SchemaVersionValidator versionValidator = new SchemaVersionValidator();
getValidators().add(versionValidator);
}
/**
* Add an object to this schema - this method will set this schema
* as the object's parent.
*
* @param dbObject
*/
public void add(DbObject dbObject)
{
dbObject.setParent(this);
objects.add(dbObject);
}
@Override
public Iterator<DbObject> iterator()
{
return objects.iterator();
}
/**
* @param identifier
* @return
*/
public boolean contains(DbObject object)
{
return objects.contains(object);
}
/**
* @return the dbPrefix
*/
public String getDbPrefix()
{
return this.dbPrefix;
}
/**
* @return the version
*/
public int getVersion()
{
return this.version;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.dbPrefix == null) ? 0 : this.dbPrefix.hashCode());
result = prime * result + ((this.objects == null) ? 0 : this.objects.hashCode());
result = prime * result + this.version;
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (!super.equals(obj)) return false;
if (getClass() != obj.getClass()) return false;
Schema other = (Schema) obj;
if (this.dbPrefix == null)
{
if (other.dbPrefix != null) return false;
}
else if (!this.dbPrefix.equals(other.dbPrefix)) return false;
if (this.objects == null)
{
if (other.objects != null) return false;
}
else if (!this.objects.equals(other.objects)) return false;
if (this.version != other.version) return false;
return true;
}
@Override
protected void doDiff(DbObject right, DiffContext ctx)
{
Schema rightSchema = (Schema) right;
comparisonUtils.compareSimple(
new DbProperty(this, "version"),
new DbProperty(rightSchema, "version"), ctx);
comparisonUtils.compareCollections(objects, rightSchema.objects, ctx);
}
@Override
public void accept(DbObjectVisitor visitor)
{
visitor.visit(this);
for (DbObject child : objects)
{
child.accept(visitor);
}
}
@Override
public boolean sameAs(DbObject other)
{
if (other == null || (!other.getClass().equals(getClass())))
{
return false;
}
return true;
}
/*
* ALF-14129 fix, checks whether the schema already contains object with provided name.
* (this method is case insensitive to object's name)
*/
public boolean containsByName(String name)
{
Iterator<DbObject> iterator = iterator();
while (iterator.hasNext())
{
if (iterator.next().getName().equalsIgnoreCase(name))
{
return true;
}
}
return false;
}
}