annotation.setValue( "schema", table.schema() ); annotation.setValue( "catalog", table.catalog() ); annotation.setValue( "uniqueConstraints", table.uniqueConstraints() ); annotation.setValue( "indexes", table.indexes() );
if (table != null) { assertNotADuplicateName(table.name(), theNames); for (UniqueConstraint nextConstraint : table.uniqueConstraints()) { assertNotADuplicateName(nextConstraint.name(), theNames); Validate.isTrue(nextConstraint.name().startsWith("IDX_"), nextConstraint.name() + " must start with IDX_");
schema = tabAnn.schema(); catalog = tabAnn.catalog(); uniqueConstraints = TableBinder.buildUniqueConstraintHolders( tabAnn.uniqueConstraints() );
@Override public void initialize(UniqueProperties constraintAnnotation) { clazz = constraintAnnotation.value(); Table table = clazz.getAnnotation(Table.class); if (table == null) { return; } uniqueConstraints = table.uniqueConstraints(); }
String getUniqueKey() { Table table = this.entityClass.getAnnotation(Table.class); if (table != null) { return Arrays.stream(table.uniqueConstraints()).map((c) -> { String name = c.name().isEmpty() ? "UNI_" + String.join("_", c.columnNames()) : c.name(); return " CONSTRAINT " + name + " UNIQUE (" + String.join(", ", c.columnNames()) + "),\n"; }).reduce("", (acc, s) -> { return acc + s; }); } return ""; }
private List<String> validateCompositeUniqueConstraints(Identifiable<?> entity) { Class<?> entityClass = getClassWithoutInitializingProxy(entity); Table table = entityClass.getAnnotation(Table.class); if (table == null) { return emptyList(); } List<String> errors = newArrayList(); for (UniqueConstraint uniqueConstraint : table.uniqueConstraints()) { if (!checkCompositeUniqueConstraint(entity, entityClass, uniqueConstraint)) { errors.add(compositeUniqueConstraintErrorCode(entity, uniqueConstraint)); } } return errors; }
private List<String> validateCompositeUniqueConstraints(Identifiable<?> entity) { Class<?> entityClass = getClassWithoutInitializingProxy(entity); Table table = entityClass.getAnnotation(Table.class); if (table == null) { return emptyList(); } List<String> errors = newArrayList(); for (UniqueConstraint uniqueConstraint : table.uniqueConstraints()) { if (!checkCompositeUniqueConstraint(entity, entityClass, uniqueConstraint)) { errors.add(compositeUniqueConstraintErrorCode(entity, uniqueConstraint)); } } return errors; }
public Table(final Class<?> entityClass) { this.entityClass = entityClass; final Entity entity = entityClass.getAnnotation(Entity.class); final javax.persistence.Table table = entityClass.getAnnotation(javax.persistence.Table.class); final DiscriminatorValue discriminatorValue = entityClass.getAnnotation(DiscriminatorValue.class); discriminatorColumn = entityClass.getAnnotation(DiscriminatorColumn.class); if (entity == null) { log.info("Unsupported class (@Entity expected): " + entityClass); return; } if (table != null && StringUtils.isNotEmpty(table.name()) == true) { this.name = table.name(); uniqueConstraints = table.uniqueConstraints(); } else if (discriminatorValue != null) { this.superTable = new Table(entityClass.getSuperclass()); } else { log.info("Unsupported class (@Table and @Table.name or @DiscriminatorValue expected): " + entityClass); } }
/** * Devuelve una lista conteniendo los campos que conforman la clave unica. * * @param <T> * @param classType * @return lista conteniendo los campos que conforman la clave unica. */ public static <T extends IDataRow> String[] getUniqueFields(Class<T> classType) { try { String[] uniqueConst = classType.getAnnotation(Table.class).uniqueConstraints()[0].columnNames(); if (uniqueConst != null) { return uniqueConst; } } catch (Exception ex) { ErrorManager.showError(ex, LOGGER); } return null; }
UniqueConstraint[] uniqueConstraints = table.uniqueConstraints(); for (UniqueConstraint c : uniqueConstraints) { descriptor.addIndex(new IndexDefinition(c.columnNames()));
/** * @param locator * the java locator * @param annotation * the annotation * * @since 2.0.0 */ public TableMetadataImpl(AbstractLocator locator, Table annotation) { super(); this.locator = locator; this.catalog = annotation.catalog(); this.schema = annotation.schema(); this.name = annotation.name(); for (final UniqueConstraint constraint : annotation.uniqueConstraints()) { this.uniqueConstraints.add(new UniqueConstraintMetadataImpl(locator, constraint)); } }
/** * @param locator * the java locator * @param annotation * the annotation * * @since 2.0.0 */ public TableMetadataImpl(AbstractLocator locator, Table annotation) { super(); this.locator = locator; this.catalog = annotation.catalog(); this.schema = annotation.schema(); this.name = annotation.name(); for (final UniqueConstraint constraint : annotation.uniqueConstraints()) { this.uniqueConstraints.add(new UniqueConstraintMetadataImpl(locator, constraint)); } }
/** * @param locator * the java locator * @param annotation * the annotation * * @since 2.0.0 */ public TableMetadataImpl(AbstractLocator locator, Table annotation) { super(); this.locator = locator; this.catalog = annotation.catalog(); this.schema = annotation.schema(); this.name = annotation.name(); for (final UniqueConstraint constraint : annotation.uniqueConstraints()) { this.uniqueConstraints.add(new UniqueConstraintMetadataImpl(locator, constraint)); } }
annotation.setValue( "schema", table.schema() ); annotation.setValue( "catalog", table.catalog() ); annotation.setValue( "uniqueConstraints", table.uniqueConstraints() );
/** * INTERNAL: */ public MetadataTable(Table table, MetadataLogger logger) { this(logger); if (table != null) { m_name = table.name(); m_schema = table.schema(); m_catalog = table.catalog(); processName(); processUniqueConstraints(table.uniqueConstraints()); } }
schema = tabAnn.schema(); catalog = tabAnn.catalog(); uniqueConstraints = TableBinder.buildUniqueConstraintHolders( tabAnn.uniqueConstraints() );
/** * Set class table. */ private void parseTable(ClassMapping cm, Table table) { String tableName = toTableName(table.schema(), table.name()); if (tableName != null) cm.getMappingInfo().setTableName(tableName); for (UniqueConstraint uniqueConstraint:table.uniqueConstraints()) { Unique unique = newUnique(cm, null, uniqueConstraint.columnNames()); cm.getMappingInfo().addUnique(unique); } }
/** * Set class table. */ private void parseTable(ClassMapping cm, Table table) { if (cm.isAbstract()) throw new UserException(_loc.get("table-not-allowed", cm)); DBIdentifier tName = toTableIdentifier(table.schema(), table.name()); if (!DBIdentifier.isNull(tName)) { cm.getMappingInfo().setTableIdentifier(tName); } addUniqueConstraints(tName.getName(), cm, cm.getMappingInfo(), table.uniqueConstraints()); }
/** * Set class table. */ private void parseTable(ClassMapping cm, Table table) { if (cm.isAbstract()) throw new UserException(_loc.get("table-not-allowed", cm)); DBIdentifier tName = toTableIdentifier(table.schema(), table.name()); if (!DBIdentifier.isNull(tName)) { cm.getMappingInfo().setTableIdentifier(tName); } addUniqueConstraints(tName.getName(), cm, cm.getMappingInfo(), table.uniqueConstraints()); }
/** * Set class table. */ private void parseTable(ClassMapping cm, Table table) { if (cm.isAbstract()) throw new UserException(_loc.get("table-not-allowed", cm)); DBIdentifier tName = toTableIdentifier(table.schema(), table.name()); if (!DBIdentifier.isNull(tName)) { cm.getMappingInfo().setTableIdentifier(tName); } addUniqueConstraints(tName.getName(), cm, cm.getMappingInfo(), table.uniqueConstraints()); }