Search in sources :

Example 1 with Database

use of org.springframework.roo.addon.dbre.addon.model.Database in project spring-roo by spring-projects.

the class DbreDatabaseListenerImpl method deserializeDatabase.

private void deserializeDatabase() {
    final Database database = getDbreModelService().getDatabase(true);
    if (database != null) {
        identifierResults = new LinkedHashMap<JavaType, List<Identifier>>();
        reverseEngineer(database);
    }
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) JavaType(org.springframework.roo.model.JavaType) Database(org.springframework.roo.addon.dbre.addon.model.Database) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with Database

use of org.springframework.roo.addon.dbre.addon.model.Database in project spring-roo by spring-projects.

the class DbreMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // We need to parse the annotation, which we expect to be present
    final DbManagedAnnotationValues annotationValues = new DbManagedAnnotationValues(governorPhysicalTypeMetadata);
    if (!annotationValues.isAnnotationFound()) {
        return null;
    }
    // Abort if the database couldn't be deserialized. This can occur if the
    // DBRE XML file has been deleted or is empty.
    final Database database = getDbreModelService().getDatabase(false);
    if (database == null) {
        return null;
    }
    // We know governor type details are non-null and can be safely cast
    final JavaType javaType = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getName();
    final IdentifierHolder identifierHolder = getIdentifierHolder(javaType);
    if (identifierHolder == null) {
        return null;
    }
    final FieldMetadata versionField = getVersionField(javaType, metadataIdentificationString);
    // Search for database-managed entities
    final Iterable<ClassOrInterfaceTypeDetails> managedEntities = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(ROO_DB_MANAGED);
    boolean found = false;
    for (final ClassOrInterfaceTypeDetails managedEntity : managedEntities) {
        if (managedEntity.getName().equals(javaType)) {
            found = true;
            break;
        }
    }
    if (!found) {
        final String mid = getTypeLocationService().getPhysicalTypeIdentifier(javaType);
        getMetadataDependencyRegistry().registerDependency(mid, metadataIdentificationString);
        return null;
    }
    final DbreMetadata dbreMetadata = new DbreMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, identifierHolder, versionField, managedEntities, database);
    final ClassOrInterfaceTypeDetails updatedGovernor = dbreMetadata.getUpdatedGovernor();
    if (updatedGovernor != null) {
        getTypeManagementService().createOrUpdateTypeOnDisk(updatedGovernor);
    }
    return dbreMetadata;
}
Also used : JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) Database(org.springframework.roo.addon.dbre.addon.model.Database) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Example 3 with Database

use of org.springframework.roo.addon.dbre.addon.model.Database in project spring-roo by spring-projects.

the class DbreOperationsImpl method displayDatabaseMetadata.

public void displayDatabaseMetadata(final Set<Schema> schemas, final File file, final boolean view) {
    Validate.notNull(schemas, "Schemas required");
    // Force it to refresh the database from the actual JDBC connection
    final Database database = dbreModelService.refreshDatabase(schemas, view, Collections.<String>emptySet(), Collections.<String>emptySet());
    database.setIncludeNonPortableAttributes(true);
    database.setDisableVersionFields(true);
    database.setDisableGeneratedIdentifiers(true);
    outputSchemaXml(database, schemas, file, true);
}
Also used : Database(org.springframework.roo.addon.dbre.addon.model.Database)

Example 4 with Database

use of org.springframework.roo.addon.dbre.addon.model.Database in project spring-roo by spring-projects.

the class DbreOperationsImpl method reverseEngineerDatabase.

public void reverseEngineerDatabase(final Set<Schema> schemas, final JavaPackage destinationPackage, final boolean testAutomatically, final boolean view, final Set<String> includeTables, final Set<String> excludeTables, final boolean includeNonPortableAttributes, final boolean disableVersionFields, final boolean disableGeneratedIdentifiers, final boolean repository, final boolean service) {
    // Force it to refresh the database from the actual JDBC connection
    final Database database = dbreModelService.refreshDatabase(schemas, view, includeTables, excludeTables);
    database.setModuleName(projectOperations.getFocusedModuleName());
    database.setRepository(repository);
    database.setService(service);
    database.setDestinationPackage(destinationPackage);
    database.setIncludeNonPortableAttributes(includeNonPortableAttributes);
    database.setDisableVersionFields(disableVersionFields);
    database.setDisableGeneratedIdentifiers(disableGeneratedIdentifiers);
    database.setTestAutomatically(testAutomatically);
    outputSchemaXml(database, schemas, null, false);
    // Update the pom.xml to add an exclusion for the DBRE XML file in the
    // maven-war-plugin
    updatePom();
    // Change the persistence.xml file to prevent tables being created and
    // dropped.
    updatePersistenceXml(includeNonPortableAttributes);
}
Also used : Database(org.springframework.roo.addon.dbre.addon.model.Database)

Aggregations

Database (org.springframework.roo.addon.dbre.addon.model.Database)4 JavaType (org.springframework.roo.model.JavaType)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)1 JdkJavaType (org.springframework.roo.model.JdkJavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1