Project

General

Profile

Revision 15bf6961

ID15bf696109190b07423d46102a676eedc97d4f33
Parent 9e1278e0
Child 88d9400d

Added by Andreas Müller over 1 year ago

fix #9058 fix failing index creation for ordinary MySQL key indexes and remove combined unique key for AuthorityBase

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/permission/AuthorityBase.java
12 12
import javax.persistence.Inheritance;
13 13
import javax.persistence.InheritanceType;
14 14
import javax.persistence.Table;
15
import javax.persistence.UniqueConstraint;
16 15
import javax.xml.bind.annotation.XmlAccessType;
17 16
import javax.xml.bind.annotation.XmlAccessorType;
18 17
import javax.xml.bind.annotation.XmlRootElement;
......
35 34
@XmlRootElement(name = "Authority")
36 35
@Table(name="Authority"
37 36
   //for some reason this does not work, see comment #8464#note-6
38
   ,uniqueConstraints=@UniqueConstraint(columnNames={"property","permissionClass","targetUuid","operations"})
37
 //  ,uniqueConstraints=@UniqueConstraint(columnNames={"property","permissionClass","targetUuid","operations"})
39 38
)
40 39
@Entity
41 40
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
cdmlib-persistence/src/main/java/org/hibernate/dialect/MySQL5MyISAMUtf8Dialect.java
11 11

  
12 12
import java.sql.Types;
13 13

  
14
import org.hibernate.mapping.Index;
15
import org.hibernate.tool.schema.spi.Exporter;
16

  
14 17

  
15 18

  
16 19
/**
......
20 23
 */
21 24
public class MySQL5MyISAMUtf8Dialect extends MySQL5Dialect {
22 25

  
26
    private MySqlIsamIndexExporter mySqlIsamIndexExporter = new MySqlIsamIndexExporter( this );
27

  
28

  
23 29
	public MySQL5MyISAMUtf8Dialect(){
24 30
		super();
25 31
		//see http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
......
30 36
	public String getTableTypeString() {
31 37
        return " ENGINE=MYISAM DEFAULT CHARSET=utf8";
32 38
    }
33
    
34
    
39

  
40
    @Override
41
    public Exporter<Index> getIndexExporter() {
42
        return mySqlIsamIndexExporter;
43
    }
44

  
45

  
35 46
	// compare org.hibernate.dialect.MySQLMyISAMDialect
36 47
    @Override
37 48
	public boolean dropConstraints() {
cdmlib-persistence/src/main/java/org/hibernate/dialect/MySqlIsamIndexExporter.java
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package org.hibernate.dialect;
10

  
11
import java.util.Iterator;
12

  
13
import org.hibernate.boot.Metadata;
14
import org.hibernate.boot.model.relational.QualifiedNameImpl;
15
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
16
import org.hibernate.mapping.Column;
17
import org.hibernate.mapping.Index;
18
import org.hibernate.tool.schema.internal.StandardIndexExporter;
19

  
20
/**
21
 * This index exporter extends the {@link StandardIndexExporter}
22
 * by using a maximum size of 255 for text based indexes.
23
 *
24
 * @author a.mueller
25
 * @since 09.06.2020
26
 */
27
public class MySqlIsamIndexExporter extends StandardIndexExporter {
28

  
29
    private final Dialect dialect;
30

  
31
    public MySqlIsamIndexExporter(Dialect dialect) {
32
        super(dialect);
33
        this.dialect = dialect;
34
    }
35

  
36
    /*
37
     * This is a copy from StandardIndexExported. The changes
38
     * are marked as such
39
     */
40
    @Override
41
    public String[] getSqlCreateStrings(Index index, Metadata metadata) {
42
        final JdbcEnvironment jdbcEnvironment = metadata.getDatabase().getJdbcEnvironment();
43
        final String tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
44
                index.getTable().getQualifiedTableName(),
45
                dialect
46
        );
47

  
48
        final String indexNameForCreation;
49
        if ( dialect.qualifyIndexName() ) {
50
            indexNameForCreation = jdbcEnvironment.getQualifiedObjectNameFormatter().format(
51
                    new QualifiedNameImpl(
52
                            index.getTable().getQualifiedTableName().getCatalogName(),
53
                            index.getTable().getQualifiedTableName().getSchemaName(),
54
                            jdbcEnvironment.getIdentifierHelper().toIdentifier( index.getName() )
55
                    ),
56
                    jdbcEnvironment.getDialect()
57
            );
58
        }
59
        else {
60
            indexNameForCreation = index.getName();
61
        }
62
        final StringBuilder buf = new StringBuilder()
63
                .append( "create index " )
64
                .append( indexNameForCreation )
65
                .append( " on " )
66
                .append( tableName )
67
                .append( " (" );
68

  
69
        boolean first = true;
70
        int colCount = index.getColumnSpan();
71
        Iterator<Column> columnItr = index.getColumnIterator();
72
        while ( columnItr.hasNext() ) {
73
            final Column column = columnItr.next();
74
            if ( first ) {
75
                first = false;
76
            }
77
            else {
78
                buf.append( ", " );
79
            }
80
            //*** CHANGED *******/
81
            String length = column.getLength()>254?"(255)":"";  //for some reason column.getLength() return 255 even if the column is defined with length 800
82
            buf.append( ( column.getQuotedName( dialect )+length) );
83
            //*** DEGNAHC *******/
84
        }
85
        buf.append( ")" );
86
        return new String[] { buf.toString() };
87
    }
88
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)