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.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.lib.meta.XMLMetaDataSerializer;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.StringUtil;
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
*/
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));
}
@Override
public Table[] getTables() {
return (Table[]) _tables.toArray(new Table[_tables.size()]);
}
@Override
public void addTable(Table table) {
if (table != null)
_tables.add(table);
}
@Override
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);
}
@Override
public void addAll(Schema schema) {
if (schema == null)
return;
Table[] tables = schema.getTables();
for (Table table : tables) {
addTable(table);
}
Sequence[] seqs = schema.getSequences();
for (Sequence seq : seqs) {
addSequence(seq);
}
}
@Override
public void addAll(SchemaGroup group) {
if (group == null)
return;
Schema[] schemas = group.getSchemas();
for (Schema schema : schemas) {
addAll(schema);
}
}
@Override
public boolean removeAll(Schema schema) {
if (schema == null)
return false;
boolean removed = false;
Table[] tables = schema.getTables();
for (Table table : tables) {
removed |= removeTable(table);
}
Sequence[] seqs = schema.getSequences();
for (Sequence seq : seqs) {
removed |= removeSequence(seq);
}
return removed;
}
@Override
public boolean removeAll(SchemaGroup group) {
if (group == null)
return false;
boolean removed = false;
Schema[] schemas = group.getSchemas();
for (Schema schema : schemas) {
removed |= removeAll(schema);
}
return removed;
}
@Override
public void clear() {
_tables.clear();
_seqs.clear();
}
@Override
protected Collection getObjects() {
if (_seqs.isEmpty())
return _tables;
if (_tables.isEmpty())
return _seqs;
List