Simple code cleanup
This commit is contained in:
parent
baa649c802
commit
85c63dbaf0
|
@ -26,6 +26,7 @@ package org.hibernate.metamodel.relational;
|
|||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
|
||||
/**
|
||||
|
@ -67,8 +68,18 @@ public abstract class AbstractConstraint implements Constraint {
|
|||
}
|
||||
|
||||
public void addColumn(Column column) {
|
||||
internalAddColumn( column );
|
||||
}
|
||||
|
||||
protected void internalAddColumn(Column column) {
|
||||
if ( column.getTable() != getTable() ) {
|
||||
throw new IllegalArgumentException( "Unable to add column to constraint; tables did not match" );
|
||||
throw new AssertionFailure(
|
||||
String.format(
|
||||
"Unable to add column to constraint; tables [%s, %s] did not match",
|
||||
column.getTable().toLoggableString(),
|
||||
getTable().toLoggableString()
|
||||
)
|
||||
);
|
||||
}
|
||||
columns.add( column );
|
||||
}
|
||||
|
|
|
@ -30,16 +30,18 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
|
||||
/**
|
||||
* Convenience base class for implementing the {@link ValueContainer} contract centralizing commonality
|
||||
* between modelling tables views and inline views.
|
||||
* between modeling tables, views and inline views.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractTableSpecification implements TableSpecification {
|
||||
private final static AtomicInteger tableCounter = new AtomicInteger( 0 );
|
||||
private final int tableNumber;
|
||||
|
||||
private final LinkedHashMap<String, SimpleValue> values = new LinkedHashMap<String, SimpleValue>();
|
||||
private PrimaryKey primaryKey = new PrimaryKey( this );
|
||||
private List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
|
||||
|
||||
private final PrimaryKey primaryKey = new PrimaryKey( this );
|
||||
private final List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
|
||||
|
||||
public AbstractTableSpecification() {
|
||||
this.tableNumber = tableCounter.getAndIncrement();
|
||||
|
@ -92,9 +94,7 @@ public abstract class AbstractTableSpecification implements TableSpecification {
|
|||
return fk;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public PrimaryKey getPrimaryKey() {
|
||||
return primaryKey;
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
|
@ -43,15 +43,16 @@ import org.jboss.logging.Logger;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ForeignKey extends AbstractConstraint implements Constraint, Exportable {
|
||||
private static final Logger LOG = Logger.getLogger( ForeignKey.class );
|
||||
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, AbstractConstraint.class.getName());
|
||||
private static final String ON_DELETE = " on delete ";
|
||||
private static final String ON_UPDATE = " on update ";
|
||||
|
||||
private final TableSpecification targetTable;
|
||||
private List<Column> targetColumns;
|
||||
|
||||
private ReferentialAction deleteRule = ReferentialAction.NO_ACTION;
|
||||
public ReferentialAction updateRule = ReferentialAction.NO_ACTION;
|
||||
private ReferentialAction updateRule = ReferentialAction.NO_ACTION;
|
||||
|
||||
protected ForeignKey(TableSpecification sourceTable, TableSpecification targetTable, String name) {
|
||||
super( sourceTable, name );
|
||||
|
@ -96,6 +97,7 @@ public class ForeignKey extends AbstractConstraint implements Constraint, Export
|
|||
}
|
||||
}
|
||||
else {
|
||||
checkTargetTable( targetColumn );
|
||||
if ( targetColumns == null ) {
|
||||
if (!internalColumnAccess().isEmpty()) {
|
||||
LOG.debugf(
|
||||
|
@ -109,7 +111,19 @@ public class ForeignKey extends AbstractConstraint implements Constraint, Export
|
|||
}
|
||||
targetColumns.add( targetColumn );
|
||||
}
|
||||
internalColumnAccess().add( sourceColumn );
|
||||
internalAddColumn( sourceColumn );
|
||||
}
|
||||
|
||||
private void checkTargetTable(Column targetColumn) {
|
||||
if ( targetColumn.getTable() != getTargetTable() ) {
|
||||
throw new AssertionFailure(
|
||||
String.format(
|
||||
"Unable to add column to constraint; tables [%s, %s] did not match",
|
||||
targetColumn.getTable().toLoggableString(),
|
||||
getTargetTable().toLoggableString()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,36 +197,20 @@ public class ForeignKey extends AbstractConstraint implements Constraint, Export
|
|||
}
|
||||
|
||||
public static enum ReferentialAction {
|
||||
NO_ACTION {
|
||||
private static final String ACTION_STRING = "no action";
|
||||
NO_ACTION( "no action" ),
|
||||
CASCADE( "cascade" ),
|
||||
SET_NULL( "set null" ),
|
||||
SET_DEFAULT( "set default" ),
|
||||
RESTRICT( "restrict" );
|
||||
|
||||
private final String actionString;
|
||||
|
||||
private ReferentialAction(String actionString) {
|
||||
this.actionString = actionString;
|
||||
}
|
||||
|
||||
public String getActionString() {
|
||||
return ACTION_STRING;
|
||||
}
|
||||
},
|
||||
CASCADE {
|
||||
private static final String ACTION_STRING = "cascade";
|
||||
public String getActionString() {
|
||||
return ACTION_STRING;
|
||||
}
|
||||
},
|
||||
SET_NULL {
|
||||
private static final String ACTION_STRING = "set null";
|
||||
public String getActionString() {
|
||||
return ACTION_STRING;
|
||||
}
|
||||
},
|
||||
SET_DEFAULT {
|
||||
private static final String ACTION_STRING = "set default";
|
||||
public String getActionString() {
|
||||
return ACTION_STRING;
|
||||
}
|
||||
},
|
||||
RESTRICT {
|
||||
private static final String ACTION_STRING = "restrict";
|
||||
public String getActionString() {
|
||||
return ACTION_STRING;
|
||||
}
|
||||
};
|
||||
public abstract String getActionString();
|
||||
return actionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue