Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.jdbc.schema;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.lib.meta.XMLMetaDataSerializer;
import org.apache.openjpa.lib.util.Localizer;
import org.xml.sax.SAXException;
/**
* Serializes {@link Schema}s to XML matching the document
* type definition defined by the {@link XMLSchemaParser}. The serializer
* actually works at the fine-grained table level to allow you to split
* schemas among multiple files.
* Serializers are not thread safe.
*
* @author Abe White
* @nojavadoc
*/
public class XMLSchemaSerializer
extends XMLMetaDataSerializer
implements SchemaSerializer {
private static final Localizer _loc = Localizer.forPackage
(XMLSchemaSerializer.class);
private final Collection
_tables = new TreeSet
();
private final Collection _seqs = new TreeSet();
/**
* Constructor. Supply configuration.
*/
public XMLSchemaSerializer(JDBCConfiguration conf) {
setLog(conf.getLog(JDBCConfiguration.LOG_SCHEMA));
}
public Table[] getTables() {
return (Table[]) _tables.toArray(new Table[_tables.size()]);
}
public void addTable(Table table) {
if (table != null)
_tables.add(table);
}
public boolean removeTable(Table table) {
return _tables.remove(table);
}
public Sequence[] getSequences() {
return (Sequence[]) _seqs.toArray(new Sequence[_seqs.size()]);
}
public void addSequence(Sequence seq) {
if (seq != null)
_seqs.add(seq);
}
public boolean removeSequence(Sequence seq) {
return _seqs.remove(seq);
}
public void addAll(Schema schema) {
if (schema == null)
return;
Table[] tables = schema.getTables();
for (int i = 0; i < tables.length; i++)
addTable(tables[i]);
Sequence[] seqs = schema.getSequences();
for (int i = 0; i < seqs.length; i++)
addSequence(seqs[i]);
}
public void addAll(SchemaGroup group) {
if (group == null)
return;
Schema[] schemas = group.getSchemas();
for (int i = 0; i < schemas.length; i++)
addAll(schemas[i]);
}
public boolean removeAll(Schema schema) {
if (schema == null)
return false;
boolean removed = false;
Table[] tables = schema.getTables();
for (int i = 0; i < tables.length; i++)
removed |= removeTable(tables[i]);
Sequence[] seqs = schema.getSequences();
for (int i = 0; i < seqs.length; i++)
removed |= removeSequence(seqs[i]);
return removed;
}
public boolean removeAll(SchemaGroup group) {
if (group == null)
return false;
boolean removed = false;
Schema[] schemas = group.getSchemas();
for (int i = 0; i < schemas.length; i++)
removed |= removeAll(schemas[i]);
return removed;
}
public void clear() {
_tables.clear();
_seqs.clear();
}
protected Collection getObjects() {
if (_seqs.isEmpty())
return _tables;
if (_tables.isEmpty())
return _seqs;
List