com.manydesigns.portofino.model.database.PrimaryKeyColumn Maven / Gradle / Ivy
/*
* Copyright (C) 2005-2015 ManyDesigns srl. All rights reserved.
* http://www.manydesigns.com/
*
* This 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.
*
* This software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package com.manydesigns.portofino.model.database;
import com.manydesigns.portofino.model.Model;
import com.manydesigns.portofino.model.ModelObject;
import com.manydesigns.portofino.model.ModelObjectVisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.*;
/*
* @author Paolo Predonzani - [email protected]
* @author Angelo Lupo - [email protected]
* @author Giampiero Granatella - [email protected]
* @author Alessio Stalla - [email protected]
*/
@XmlAccessorType(XmlAccessType.NONE)
public class PrimaryKeyColumn implements ModelObject {
public static final String copyright =
"Copyright (c) 2005-2015, ManyDesigns srl";
//**************************************************************************
// Fields
//**************************************************************************
protected PrimaryKey primaryKey;
protected String columnName;
protected Generator generator;
//**************************************************************************
// Fields for wire-up
//**************************************************************************
protected Column actualColumn;
//**************************************************************************
// Logging
//**************************************************************************
public static final Logger logger =
LoggerFactory.getLogger(PrimaryKeyColumn.class);
//**************************************************************************
// Constructors
//**************************************************************************
public PrimaryKeyColumn() {}
public PrimaryKeyColumn(PrimaryKey primaryKey) {
this();
this.primaryKey = primaryKey;
}
//**************************************************************************
// ModelObject implementation
//**************************************************************************
public void afterUnmarshal(Unmarshaller u, Object parent) {
primaryKey = (PrimaryKey) parent;
}
public void reset() {
actualColumn = null;
}
public void link(Model model) {}
public void visitChildren(ModelObjectVisitor visitor) {}
public void init(Model model) {
assert primaryKey != null;
assert columnName != null;
actualColumn = DatabaseLogic.findColumnByName(primaryKey.getTable(), columnName);
if (actualColumn == null) {
logger.warn("Cannor wire primary key column '{}' to primary key '{}'",
columnName, primaryKey);
}
}
//**************************************************************************
// Getters/setter
//**************************************************************************
public PrimaryKey getPrimaryKey() {
return primaryKey;
}
public void setPrimaryKey(PrimaryKey primaryKey) {
this.primaryKey = primaryKey;
}
@XmlAttribute(required = true)
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public Column getActualColumn() {
return actualColumn;
}
@XmlElements({
@XmlElement(name="sequenceGenerator",type=SequenceGenerator.class),
@XmlElement(name="incrementGenerator",type=IncrementGenerator.class),
@XmlElement(name="tableGenerator",type=TableGenerator.class)
})
public Generator getGenerator() {
return generator;
}
public void setGenerator(Generator generator) {
this.generator = generator;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy