Search in sources :

Example 1 with Updatable

use of com.manydesigns.elements.annotations.Updatable in project Portofino by ManyDesigns.

the class SessionFactoryBuilder method configureAnnotations.

protected void configureAnnotations(Table table, ConstPool constPool, AnnotationsAttribute classAnnotations) {
    Annotation annotation;
    annotation = new Annotation(javax.persistence.Table.class.getName(), constPool);
    annotation.addMemberValue("name", new StringMemberValue(jpaEscape(table.getTableName()), constPool));
    if (multiTenancyImplementation == null || multiTenancyImplementation.getStrategy() != MultiTenancyStrategy.SCHEMA) {
        // Don't configure the schema name if we're using schema-based multitenancy
        String schemaName = table.getSchema().getActualSchemaName();
        annotation.addMemberValue("schema", new StringMemberValue(jpaEscape(schemaName), constPool));
    }
    classAnnotations.addAnnotation(annotation);
    annotation = new Annotation(Entity.class.getName(), constPool);
    annotation.addMemberValue("name", new StringMemberValue(table.getActualEntityName(), constPool));
    classAnnotations.addAnnotation(annotation);
    table.getAnnotations().forEach(ann -> {
        Class annotationClass = ann.getJavaAnnotationClass();
        if (javax.persistence.Table.class.equals(annotationClass) || Entity.class.equals(annotationClass)) {
            logger.warn("@Table or @Entity specified on table {}, skipping annotation {}", table.getQualifiedName(), annotationClass);
            return;
        }
        Annotation classAnn = convertAnnotation(constPool, ann);
        if (classAnn != null) {
            classAnnotations.addAnnotation(classAnn);
        }
        if (annotationClass == Updatable.class && !((Updatable) ann.getJavaAnnotation()).value()) {
            classAnnotations.addAnnotation(new Annotation(Immutable.class.getName(), constPool));
        }
    });
}
Also used : Table(com.manydesigns.portofino.model.database.Table) Updatable(com.manydesigns.elements.annotations.Updatable) javax.persistence(javax.persistence) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

Updatable (com.manydesigns.elements.annotations.Updatable)1 Table (com.manydesigns.portofino.model.database.Table)1 javax.persistence (javax.persistence)1 PersistentClass (org.hibernate.mapping.PersistentClass)1