org.hibernate.AnnotationException Java Examples

The following examples show how to use org.hibernate.AnnotationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void bindDiscriminatorValue() {
	if ( StringHelper.isEmpty( discriminatorValue ) ) {
		Value discriminator = persistentClass.getDiscriminator();
		if ( discriminator == null ) {
			persistentClass.setDiscriminatorValue( name );
		}
		else if ( "character".equals( discriminator.getType().getName() ) ) {
			throw new AnnotationException(
					"Using default @DiscriminatorValue for a discriminator of type CHAR is not safe"
			);
		}
		else if ( "integer".equals( discriminator.getType().getName() ) ) {
			persistentClass.setDiscriminatorValue( String.valueOf( name.hashCode() ) );
		}
		else {
			persistentClass.setDiscriminatorValue( name ); //Spec compliant
		}
	}
	else {
		//persistentClass.getDiscriminator()
		persistentClass.setDiscriminatorValue( discriminatorValue );
	}
}
 
Example #2
Source File: ComponentPropertyHolder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void addProperty(Property prop, Ejb3Column[] columns, XClass declaringClass) {
	//Ejb3Column.checkPropertyConsistency( ); //already called earlier
	/*
	 * Check table matches between the component and the columns
	 * if not, change the component table if no properties are set
	 * if a property is set already the core cannot support that
	 */
	if (columns != null) {
		Table table = columns[0].getTable();
		if ( !table.equals( component.getTable() ) ) {
			if ( component.getPropertySpan() == 0 ) {
				component.setTable( table );
			}
			else {
				throw new AnnotationException(
						"A component cannot hold properties split into 2 different tables: "
								+ this.getPath()
				);
			}
		}
	}
	addProperty( prop, declaringClass );
}
 
Example #3
Source File: Ejb3Column.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Join getJoin() {
	Join join = joins.get( explicitTableName );
	if ( join == null ) {
		// annotation binding seems to use logical and physical naming somewhat inconsistently...
		final String physicalTableName = getBuildingContext().getMetadataCollector().getPhysicalTableName( explicitTableName );
		if ( physicalTableName != null ) {
			join = joins.get( physicalTableName );
		}
	}

	if ( join == null ) {
		throw new AnnotationException(
				"Cannot find the expected secondary table: no "
						+ explicitTableName + " available for " + propertyHolder.getClassName()
		);
	}

	return join;
}
 
Example #4
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Recursively builds a list of FkSecondPass instances ready to be processed in this order.
 * Checking all dependencies recursively seems quite expensive, but the original code just relied
 * on some sort of table name sorting which failed in certain circumstances.
 * <p/>
 * See <tt>ANN-722</tt> and <tt>ANN-730</tt>
 *
 * @param orderedFkSecondPasses The list containing the <code>FkSecondPass<code> instances ready
 * for processing.
 * @param isADependencyOf Our lookup data structure to determine dependencies between tables
 * @param startTable Table name to start recursive algorithm.
 * @param currentTable The current table name used to check for 'new' dependencies.
 */
private void buildRecursiveOrderedFkSecondPasses(
		List<FkSecondPass> orderedFkSecondPasses,
		Map<String, Set<FkSecondPass>> isADependencyOf,
		String startTable,
		String currentTable) {

	Set<FkSecondPass> dependencies = isADependencyOf.get( currentTable );

	// bottom out
	if ( dependencies == null || dependencies.size() == 0 ) {
		return;
	}

	for ( FkSecondPass sp : dependencies ) {
		String dependentTable = sp.getValue().getTable().getQualifiedTableName().render();
		if ( dependentTable.compareTo( startTable ) == 0 ) {
			throw new AnnotationException( "Foreign key circularity dependency involving the following tables: " + startTable + ", " + dependentTable );
		}
		buildRecursiveOrderedFkSecondPasses( orderedFkSecondPasses, isADependencyOf, startTable, dependentTable );
		if ( !orderedFkSecondPasses.contains( sp ) ) {
			orderedFkSecondPasses.add( 0, sp );
		}
	}
}
 
Example #5
Source File: IndexOrUniqueKeySecondPass.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void addConstraintToColumn(final String columnName ) {
	Column column = table.getColumn(
			new Column(
					buildingContext.getMetadataCollector().getPhysicalColumnName( table, columnName )
			)
	);
	if ( column == null ) {
		throw new AnnotationException(
				"@Index references a unknown column: " + columnName
		);
	}
	if ( unique ) {
		table.getOrCreateUniqueKey( indexName ).addColumn( column );
	}
	else {
		table.getOrCreateIndex( indexName ).addColumn( column );
	}
}
 
Example #6
Source File: QueryBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static void bindNamedStoredProcedureQuery(
		NamedStoredProcedureQuery annotation,
		MetadataBuildingContext context,
		boolean isDefault) {
	if ( annotation == null ) {
		return;
	}

	if ( BinderHelper.isEmptyAnnotationValue( annotation.name() ) ) {
		throw new AnnotationException( "A named query must have a name when used in class or package level" );
	}

	final NamedProcedureCallDefinition def = new NamedProcedureCallDefinition( annotation );

	if (isDefault) {
		context.getMetadataCollector().addDefaultNamedProcedureCallDefinition( def );
	}
	else {
		context.getMetadataCollector().addNamedProcedureCallDefinition( def );
	}
	LOG.debugf( "Bound named stored procedure query : %s => %s", def.getRegisteredName(), def.getProcedureName() );
}
 
Example #7
Source File: SpannerTableExporterTests.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void generateCreateStringsNoPkEntityTest() {
  assertThatThrownBy(() -> {
    Metadata metadata = new MetadataSources(this.registry)
        .addAnnotatedClass(NoPkEntity.class)
        .buildMetadata();

    new SchemaExport()
        .setOutputFile("unused")
        .createOnly(EnumSet.of(TargetType.STDOUT, TargetType.SCRIPT), metadata);
  })
      .isInstanceOf(AnnotationException.class)
      .hasMessage(
          "No identifier specified for entity: "
              + "com.google.cloud.spanner.hibernate.SpannerTableExporterTests$NoPkEntity");
}
 
Example #8
Source File: QueryHintDefinition.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public boolean getBoolean(String query, String hintName) {
	String value =(String)  hintsMap.get( hintName );
	if ( value == null ) {
		return false;
	}
	if ( value.equalsIgnoreCase( "true" ) ) {
		return true;
	}
	else if ( value.equalsIgnoreCase( "false" ) ) {
		return false;
	}
	else {
		throw new AnnotationException( "Not a boolean in hint: " + query + ":" + hintName );
	}

}
 
Example #9
Source File: AnnotationBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isEntityClassType(XClass clazzToProcess, AnnotatedClassType classType) {
	if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) //will be processed by their subentities
			|| AnnotatedClassType.NONE.equals( classType ) //to be ignored
			|| AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element declaration
			) {
		if ( AnnotatedClassType.NONE.equals( classType )
				&& clazzToProcess.isAnnotationPresent( org.hibernate.annotations.Entity.class ) ) {
			LOG.missingEntityAnnotation( clazzToProcess.getName() );
		}
		return false;
	}

	if ( !classType.equals( AnnotatedClassType.ENTITY ) ) {
		throw new AnnotationException(
				"Annotated class should have a @javax.persistence.Entity, @javax.persistence.Embeddable or @javax.persistence.EmbeddedSuperclass annotation: " + clazzToProcess
						.getName()
		);
	}

	return true;
}
 
Example #10
Source File: PropertyBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the value generation strategy for the given property, if any.
 */
private ValueGeneration getValueGenerationFromAnnotations(XProperty property) {
	AnnotationValueGeneration<?> valueGeneration = null;

	for ( Annotation annotation : property.getAnnotations() ) {
		AnnotationValueGeneration<?> candidate = getValueGenerationFromAnnotation( property, annotation );

		if ( candidate != null ) {
			if ( valueGeneration != null ) {
				throw new AnnotationException(
						"Only one generator annotation is allowed:" + StringHelper.qualify(
								holder.getPath(),
								name
						)
				);
			}
			else {
				valueGeneration = candidate;
			}
		}
	}

	return valueGeneration;
}
 
Example #11
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void copyIntegerAttribute(AnnotationDescriptor annotation, Element element, String attributeName) {
	String attribute = element.attributeValue( attributeName );
	if ( attribute != null ) {
		String annotationAttributeName = getJavaAttributeNameFromXMLOne( attributeName );
		annotation.setValue( annotationAttributeName, attribute );
		try {
			int length = Integer.parseInt( attribute );
			annotation.setValue( annotationAttributeName, length );
		}
		catch ( NumberFormatException e ) {
			throw new AnnotationException(
					element.getPath() + attributeName + " not parseable: " + attribute + " (" + SCHEMA_VALIDATION + ")"
			);
		}
	}
}
 
Example #12
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copy a string attribute from an XML element to an annotation descriptor. The name of the annotation attribute is
 * explicitely given.
 *
 * @param annotation annotation where to copy to the attribute.
 * @param element XML element from where to copy the attribute.
 * @param annotationAttributeName name of the annotation attribute where to copy.
 * @param attributeName name of the XML attribute to copy.
 * @param mandatory whether the attribute is mandatory.
 */
private static void copyStringAttribute(
		final AnnotationDescriptor annotation, final Element element,
		final String annotationAttributeName, final String attributeName, boolean mandatory) {
	String attribute = element.attributeValue( attributeName );
	if ( attribute != null ) {
		annotation.setValue( annotationAttributeName, attribute );
	}
	else {
		if ( mandatory ) {
			throw new AnnotationException(
					element.getName() + "." + attributeName + " is mandatory in XML overriding. " + SCHEMA_VALIDATION
			);
		}
	}
}
 
Example #13
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void buildQueryHints(List<Element> elements, AnnotationDescriptor ann){
	List<QueryHint> queryHints = new ArrayList<>( elements.size() );
	for ( Element hint : elements ) {
		AnnotationDescriptor hintDescriptor = new AnnotationDescriptor( QueryHint.class );
		String value = hint.attributeValue( "name" );
		if ( value == null ) {
			throw new AnnotationException( "<hint> without name. " + SCHEMA_VALIDATION );
		}
		hintDescriptor.setValue( "name", value );
		value = hint.attributeValue( "value" );
		if ( value == null ) {
			throw new AnnotationException( "<hint> without value. " + SCHEMA_VALIDATION );
		}
		hintDescriptor.setValue( "value", value );
		queryHints.add( AnnotationFactory.create( hintDescriptor ) );
	}
	ann.setValue( "hints", queryHints.toArray( new QueryHint[queryHints.size()] ) );
}
 
Example #14
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getMapKeyClass(List<Annotation> annotationList, Element element, XMLContext.Default defaults) {
	String nodeName = "map-key-class";
	Element subelement = element != null ? element.element( nodeName ) : null;
	if ( subelement != null ) {
		String mapKeyClassName = subelement.attributeValue( "class" );
		AnnotationDescriptor ad = new AnnotationDescriptor( MapKeyClass.class );
		if ( StringHelper.isNotEmpty( mapKeyClassName ) ) {
			Class clazz;
			try {
				clazz = classLoaderAccess.classForName(
						XMLContext.buildSafeClassName( mapKeyClassName, defaults )
				);
			}
			catch ( ClassLoadingException e ) {
				throw new AnnotationException(
						"Unable to find " + element.getPath() + " " + nodeName + ": " + mapKeyClassName, e
				);
			}
			ad.setValue( "value", clazz );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example #15
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getEnumerated(List<Annotation> annotationList, Element element) {
	Element subElement = element != null ? element.element( "enumerated" ) : null;
	if ( subElement != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Enumerated.class );
		String enumerated = subElement.getTextTrim();
		if ( "ORDINAL".equalsIgnoreCase( enumerated ) ) {
			ad.setValue( "value", EnumType.ORDINAL );
		}
		else if ( "STRING".equalsIgnoreCase( enumerated ) ) {
			ad.setValue( "value", EnumType.STRING );
		}
		else if ( StringHelper.isNotEmpty( enumerated ) ) {
			throw new AnnotationException( "Unknown EnumType: " + enumerated + ". " + SCHEMA_VALIDATION );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example #16
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static Class resolveClassReference(
		String className,
		XMLContext.Default defaults,
		ClassLoaderAccess classLoaderAccess) {
	if ( className == null ) {
		throw new AnnotationException( "<entity-result> without entity-class. " + SCHEMA_VALIDATION );
	}
	try {
		return classLoaderAccess.classForName(
				XMLContext.buildSafeClassName( className, defaults )
		);
	}
	catch ( ClassLoadingException e ) {
		throw new AnnotationException( "Unable to find specified class: " + className, e );
	}
}
 
Example #17
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getTemporal(List<Annotation> annotationList, Element element) {
	Element subElement = element != null ? element.element( "temporal" ) : null;
	if ( subElement != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Temporal.class );
		String temporal = subElement.getTextTrim();
		if ( "DATE".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.DATE );
		}
		else if ( "TIME".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.TIME );
		}
		else if ( "TIMESTAMP".equalsIgnoreCase( temporal ) ) {
			ad.setValue( "value", TemporalType.TIMESTAMP );
		}
		else if ( StringHelper.isNotEmpty( temporal ) ) {
			throw new AnnotationException( "Unknown TemporalType: " + temporal + ". " + SCHEMA_VALIDATION );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example #18
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getAccessType(List<Annotation> annotationList, Element element) {
	if ( element == null ) {
		return;
	}
	String access = element.attributeValue( "access" );
	if ( access != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Access.class );
		AccessType type;
		try {
			type = AccessType.valueOf( access );
		}
		catch ( IllegalArgumentException e ) {
			throw new AnnotationException( access + " is not a valid access type. Check you xml confguration." );
		}

		if ( ( AccessType.PROPERTY.equals( type ) && this.element instanceof Method ) ||
				( AccessType.FIELD.equals( type ) && this.element instanceof Field ) ) {
			return;
		}

		ad.setValue( "value", type );
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example #19
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Column getColumn(Element element, boolean isMandatory, Element current) {
	//Element subelement = element != null ? element.element( "column" ) : null;
	if ( element != null ) {
		AnnotationDescriptor column = new AnnotationDescriptor( Column.class );
		copyStringAttribute( column, element, "name", false );
		copyBooleanAttribute( column, element, "unique" );
		copyBooleanAttribute( column, element, "nullable" );
		copyBooleanAttribute( column, element, "insertable" );
		copyBooleanAttribute( column, element, "updatable" );
		copyStringAttribute( column, element, "column-definition", false );
		copyStringAttribute( column, element, "table", false );
		copyIntegerAttribute( column, element, "length" );
		copyIntegerAttribute( column, element, "precision" );
		copyIntegerAttribute( column, element, "scale" );
		return (Column) AnnotationFactory.create( column );
	}
	else {
		if ( isMandatory ) {
			throw new AnnotationException( current.getPath() + ".column is mandatory. " + SCHEMA_VALIDATION );
		}
		return null;
	}
}
 
Example #20
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void bindNamedSubgraph(
		XMLContext.Default defaults,
		AnnotationDescriptor ann,
		List<Element> subgraphNodes,
		ClassLoaderAccess classLoaderAccess) {
	List<NamedSubgraph> annSubgraphNodes = new ArrayList<>(  );
	for(Element subgraphNode : subgraphNodes){
		AnnotationDescriptor annSubgraphNode = new AnnotationDescriptor( NamedSubgraph.class );
		copyStringAttribute( annSubgraphNode, subgraphNode, "name", true );
		String clazzName = subgraphNode.attributeValue( "class" );
		Class clazz;
		try {
			clazz = classLoaderAccess.classForName(
					XMLContext.buildSafeClassName( clazzName, defaults )
			);
		}
		catch ( ClassLoadingException e ) {
			throw new AnnotationException( "Unable to find entity-class: " + clazzName, e );
		}
		annSubgraphNode.setValue( "type", clazz );
		bindNamedAttributeNodes(subgraphNode, annSubgraphNode);
		annSubgraphNodes.add( AnnotationFactory.create( annSubgraphNode ) );
	}

	ann.setValue( "subgraphs", annSubgraphNodes.toArray( new NamedSubgraph[annSubgraphNodes.size()] ) );
}
 
Example #21
Source File: QueryHintDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public LockMode getLockMode(String query) {
	String hitName = QueryHints.NATIVE_LOCKMODE;
	String value =(String) hintsMap.get( hitName );
	if ( value == null ) {
		return null;
	}
	try {
		return LockMode.fromExternalForm( value );
	}
	catch ( MappingException e ) {
		throw new AnnotationException( "Unknown LockMode in hint: " + query + ":" + hitName, e );
	}
}
 
Example #22
Source File: QueryHintDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Integer getInteger(String query, String hintName) {
	String value = (String) hintsMap.get( hintName );
	if ( value == null ) {
		return null;
	}
	try {
		return Integer.decode( value );
	}
	catch ( NumberFormatException nfe ) {
		throw new AnnotationException( "Not an integer in hint: " + query + ":" + hintName, nfe );
	}
}
 
Example #23
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( "inheritance" ) : null;
	if ( element != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Inheritance.class );
		Attribute attr = element.attribute( "strategy" );
		InheritanceType strategy = InheritanceType.SINGLE_TABLE;
		if ( attr != null ) {
			String value = attr.getValue();
			if ( "SINGLE_TABLE".equals( value ) ) {
				strategy = InheritanceType.SINGLE_TABLE;
			}
			else if ( "JOINED".equals( value ) ) {
				strategy = InheritanceType.JOINED;
			}
			else if ( "TABLE_PER_CLASS".equals( value ) ) {
				strategy = InheritanceType.TABLE_PER_CLASS;
			}
			else {
				throw new AnnotationException(
						"Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
				);
			}
		}
		ad.setValue( "strategy", strategy );
		return AnnotationFactory.create( ad );
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( Inheritance.class );
	}
	else {
		return null;
	}
}
 
Example #24
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private DiscriminatorColumn getDiscriminatorColumn(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( "discriminator-column" ) : null;
	if ( element != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( DiscriminatorColumn.class );
		copyStringAttribute( ad, element, "name", false );
		copyStringAttribute( ad, element, "column-definition", false );
		String value = element.attributeValue( "discriminator-type" );
		DiscriminatorType type = DiscriminatorType.STRING;
		if ( value != null ) {
			if ( "STRING".equals( value ) ) {
				type = DiscriminatorType.STRING;
			}
			else if ( "CHAR".equals( value ) ) {
				type = DiscriminatorType.CHAR;
			}
			else if ( "INTEGER".equals( value ) ) {
				type = DiscriminatorType.INTEGER;
			}
			else {
				throw new AnnotationException(
						"Unknown DiscrimiatorType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
				);
			}
		}
		ad.setValue( "discriminatorType", type );
		copyIntegerAttribute( ad, element, "length" );
		return AnnotationFactory.create( ad );
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( DiscriminatorColumn.class );
	}
	else {
		return null;
	}
}
 
Example #25
Source File: Ejb3Column.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static void checkPropertyConsistency(Ejb3Column[] columns, String propertyName) {
	int nbrOfColumns = columns.length;

	if ( nbrOfColumns > 1 ) {
		for (int currentIndex = 1; currentIndex < nbrOfColumns; currentIndex++) {

			if (columns[currentIndex].isFormula() || columns[currentIndex - 1].isFormula()) {
				continue;
			}

			if ( columns[currentIndex].isInsertable() != columns[currentIndex - 1].isInsertable() ) {
				throw new AnnotationException(
						"Mixing insertable and non insertable columns in a property is not allowed: " + propertyName
				);
			}
			if ( columns[currentIndex].isNullable() != columns[currentIndex - 1].isNullable() ) {
				throw new AnnotationException(
						"Mixing nullable and non nullable columns in a property is not allowed: " + propertyName
				);
			}
			if ( columns[currentIndex].isUpdatable() != columns[currentIndex - 1].isUpdatable() ) {
				throw new AnnotationException(
						"Mixing updatable and non updatable columns in a property is not allowed: " + propertyName
				);
			}
			if ( !columns[currentIndex].getTable().equals( columns[currentIndex - 1].getTable() ) ) {
				throw new AnnotationException(
						"Mixing different tables in a property is not allowed: " + propertyName
				);
			}
		}
	}

}
 
Example #26
Source File: AbstractConverterDescriptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("WeakerAccess")
public AbstractConverterDescriptor(
		Class<? extends AttributeConverter> converterClass,
		Boolean forceAutoApply,
		ClassmateContext classmateContext) {
	this.converterClass = converterClass;

	final ResolvedType converterType = classmateContext.getTypeResolver().resolve( converterClass );
	final List<ResolvedType> converterParamTypes = converterType.typeParametersFor( AttributeConverter.class );
	if ( converterParamTypes == null ) {
		throw new AnnotationException(
				"Could not extract type parameter information from AttributeConverter implementation ["
						+ converterClass.getName() + "]"
		);
	}
	else if ( converterParamTypes.size() != 2 ) {
		throw new AnnotationException(
				"Unexpected type parameter information for AttributeConverter implementation [" +
						converterClass.getName() + "]; expected 2 parameter types, but found " + converterParamTypes.size()
		);
	}

	this.domainType = converterParamTypes.get( 0 );
	this.jdbcType = converterParamTypes.get( 1 );

	this.autoApplicableDescriptor = resolveAutoApplicableDescriptor( converterClass, forceAutoApply );
}
 
Example #27
Source File: AnnotationMetadataSourceProcessorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private XClass toXClass(String className, ReflectionManager reflectionManager) {
	try {
		return reflectionManager.classForName( className );
	}
	catch ( ClassLoadingException e ) {
		throw new AnnotationException( "Unable to load class defined in XML: " + className, e );
	}
}
 
Example #28
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addAnyMetaDef(AnyMetaDef defAnn) {
	if ( anyMetaDefs == null ) {
		anyMetaDefs = new HashMap<>();
	}
	else {
		if ( anyMetaDefs.containsKey( defAnn.name() ) ) {
			throw new AnnotationException( "Two @AnyMetaDef with the same name defined: " + defAnn.name() );
		}
	}

	anyMetaDefs.put( defAnn.name(), defAnn );
}
 
Example #29
Source File: HibernatePropertyParser.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/**
 * 构造Hibernate的乐观锁
 */
private void handleVersion(Property prop, PersistentClass pclazz) {
	if (!(pclazz instanceof RootClass)) {
		throw new AnnotationException(
				"Unable to define/override @Version on a subclass: "
						+ pclazz.getEntityName());
	}
	RootClass root = (RootClass) pclazz;
	root.setVersion(prop);
	root.setDeclaredVersion(prop);
	root.setOptimisticLockStyle(OptimisticLockStyle.VERSION);
}
 
Example #30
Source File: Ejb3Column.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void initMappingColumn(
		String columnName,
		String propertyName,
		int length,
		int precision,
		int scale,
		boolean nullable,
		String sqlType,
		boolean unique,
		boolean applyNamingStrategy) {
	if ( StringHelper.isNotEmpty( formulaString ) ) {
		this.formula = new Formula();
		this.formula.setFormula( formulaString );
	}
	else {
		this.mappingColumn = new Column();
		redefineColumnName( columnName, propertyName, applyNamingStrategy );
		this.mappingColumn.setLength( length );
		if ( precision > 0 ) {  //revelent precision
			this.mappingColumn.setPrecision( precision );
			this.mappingColumn.setScale( scale );
		}
		this.mappingColumn.setNullable( nullable );
		this.mappingColumn.setSqlType( sqlType );
		this.mappingColumn.setUnique( unique );

		if(writeExpression != null && !writeExpression.matches("[^?]*\\?[^?]*")) {
			throw new AnnotationException(
					"@WriteExpression must contain exactly one value placeholder ('?') character: property ["
							+ propertyName + "] and column [" + logicalColumnName + "]"
			);
		}
		if ( readExpression != null) {
			this.mappingColumn.setCustomRead( readExpression );
		}
		if ( writeExpression != null) {
			this.mappingColumn.setCustomWrite( writeExpression );
		}
	}
}