Search in sources :

Example 1 with DatabaseTable

use of org.eclipse.persistence.internal.helper.DatabaseTable in project tomee by apache.

the class PrefixSessionCustomizer method customize.

@Override
public void customize(final Session session) throws Exception {
    if (JPAThreadContext.infos.containsKey("properties")) {
        final String prefix = ((Properties) JPAThreadContext.infos.get("properties")).getProperty("openejb.jpa.table_prefix");
        final List<DatabaseTable> tables = new ArrayList<DatabaseTable>();
        for (final ClassDescriptor cd : session.getDescriptors().values()) {
            for (final DatabaseTable table : cd.getTables()) {
                update(prefix, tables, table);
            }
            for (final DatabaseMapping mapping : cd.getMappings()) {
                if (mapping instanceof ManyToManyMapping) {
                    update(prefix, tables, ((ManyToManyMapping) mapping).getRelationTable());
                } else if (mapping instanceof DirectCollectionMapping) {
                    update(prefix, tables, ((DirectCollectionMapping) mapping).getReferenceTable());
                }
            // TODO: else check we need to update something
            }
        }
        final Sequence sequence = session.getDatasourcePlatform().getDefaultSequence();
        if (sequence instanceof TableSequence) {
            final TableSequence ts = ((TableSequence) sequence);
            ts.setName(prefix + ts.getName());
        }
    }
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ArrayList(java.util.ArrayList) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) TableSequence(org.eclipse.persistence.sequencing.TableSequence) Sequence(org.eclipse.persistence.sequencing.Sequence) Properties(java.util.Properties) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping) TableSequence(org.eclipse.persistence.sequencing.TableSequence)

Aggregations

ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)1 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)1 Sequence (org.eclipse.persistence.sequencing.Sequence)1 TableSequence (org.eclipse.persistence.sequencing.TableSequence)1