
dk.eobjects.metamodel.schema.JdbcTable Maven / Gradle / Ivy
The newest version!
/**
* This file is part of MetaModel.
*
* MetaModel is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MetaModel 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MetaModel. If not, see .
*/
package dk.eobjects.metamodel.schema;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import dk.eobjects.metamodel.JdbcDataContextStrategy;
public class JdbcTable extends Table {
private static final long serialVersionUID = 5952310469458880330L;
private transient JdbcDataContextStrategy _strategy;
private transient boolean _columnsLoaded = false;
private transient boolean _indexesLoaded = false;
public JdbcTable(String name, TableType type, JdbcSchema schema,
JdbcDataContextStrategy strategy) {
super(name, type, schema);
_strategy = strategy;
}
@Override
protected List getColumnsInternal() {
if (!_columnsLoaded) {
_columnsLoaded = true;
if (_strategy != null) {
_strategy.loadColumns(this);
}
}
return super.getColumnsInternal();
}
@Override
protected List getRelationshipsInternal() {
Schema schema = getSchema();
if (schema instanceof JdbcSchema) {
((JdbcSchema) schema).loadRelations();
}
return super.getRelationshipsInternal();
}
protected void loadIndexes() {
if (!_indexesLoaded) {
_indexesLoaded = true;
if (_strategy != null) {
_strategy.loadIndexes(this);
}
}
}
/**
* Called by the Java Serialization API to serialize the object.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
Schema schema = getSchema();
if (schema instanceof JdbcSchema) {
schema = ((JdbcSchema) schema).toSerializableForm();
}
stream.writeObject(schema);
stream.writeObject(getName());
}
/**
* Called by the Java Serialization API to deserialize the object.
*/
private void readObject(ObjectInputStream stream) throws IOException,
ClassNotFoundException {
Schema schema = (Schema) stream.readObject();
String tableName = (String) stream.readObject();
Table table = schema.getTableByName(tableName);
setName(tableName);
setSchema(schema);
setQuote(table.getQuote());
setRemarks(table.getRemarks());
setType(table.getType());
setColumns(table.getColumns());
_columnsLoaded = true;
_indexesLoaded = true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy