Search in sources :

Example 6 with MySQLInnoDBDialect

use of org.alfresco.repo.domain.dialect.MySQLInnoDBDialect in project alfresco-repository by Alfresco.

the class SchemaBootstrap method checkDialect.

/**
 * Performs dialect-specific checking.  This includes checking for InnoDB, dumping the dialect being used
 * as well as setting any runtime, dialect-specific properties.
 */
private void checkDialect(Dialect dialect) {
    Class<?> dialectClazz = dialect.getClass();
    LogUtil.info(logger, MSG_DIALECT_USED, dialectClazz.getName());
    // if (dialectClazz.equals(MySQLDialect.class) || dialectClazz.equals(MySQL5Dialect.class))
    // {
    // LogUtil.error(logger, ERR_DIALECT_SHOULD_USE, dialectClazz.getName(), MySQLInnoDBDialect.class.getName());
    // throw AlfrescoRuntimeException.create(WARN_DIALECT_UNSUPPORTED, dialectClazz.getName());
    // }
    // else if (dialectClazz.equals(HSQLDialect.class))
    // {
    // LogUtil.info(logger, WARN_DIALECT_HSQL);
    // }
    // else if (dialectClazz.equals(DerbyDialect.class))
    // {
    // LogUtil.info(logger, WARN_DIALECT_DERBY);
    // }
    // else if (dialectClazz.equals(Oracle9iDialect.class) || dialectClazz.equals(Oracle10gDialect.class))
    // {
    // LogUtil.error(logger, ERR_DIALECT_SHOULD_USE, dialectClazz.getName(), Oracle9Dialect.class.getName());
    // throw AlfrescoRuntimeException.create(WARN_DIALECT_UNSUPPORTED, dialectClazz.getName());
    // }
    // else if (dialectClazz.equals(OracleDialect.class) || dialectClazz.equals(Oracle9Dialect.class))
    // {
    // LogUtil.error(logger, ERR_DIALECT_SHOULD_USE, dialectClazz.getName(), Oracle9Dialect.class.getName());
    // throw AlfrescoRuntimeException.create(WARN_DIALECT_UNSUPPORTED, dialectClazz.getName());
    // }
    int maxStringLength = SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH;
    int serializableType = SerializableTypeHandler.getSerializableType();
    // Adjust the maximum allowable String length according to the dialect
    if (dialect instanceof SQLServerDialect) {
        // string_value nvarchar(1024) null,
        // serializable_value image null,
        maxStringLength = SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH;
    } else if (dialect instanceof MySQLClusterNDBDialect) {
        // string_value varchar(400),
        // serializable_value blob,
        maxStringLength = SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH_NDB;
    } else if (dialect instanceof MySQLInnoDBDialect) {
        // string_value text,
        // serializable_value blob,
        maxStringLength = Integer.MAX_VALUE;
    } else if (dialect instanceof Oracle9Dialect) {
        // string_value varchar2(1024 char),
        // serializable_value blob,
        maxStringLength = SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH;
    } else if (dialect instanceof PostgreSQLDialect) {
        // string_value varchar(1024),
        // serializable_value bytea,
        maxStringLength = SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH;
    }
    SchemaBootstrap.setMaxStringLength(maxStringLength, dialect);
    SerializableTypeHandler.setSerializableType(serializableType);
    // Now override the maximum string length if it was set directly
    if (maximumStringLength > 0) {
        SchemaBootstrap.setMaxStringLength(maximumStringLength, dialect);
    }
}
Also used : MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) PostgreSQLDialect(org.alfresco.repo.domain.dialect.PostgreSQLDialect) SQLServerDialect(org.alfresco.repo.domain.dialect.SQLServerDialect) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) Oracle9Dialect(org.alfresco.repo.domain.dialect.Oracle9Dialect) Savepoint(java.sql.Savepoint)

Example 7 with MySQLInnoDBDialect

use of org.alfresco.repo.domain.dialect.MySQLInnoDBDialect in project alfresco-repository by Alfresco.

the class DbNodeServiceImplTest method testMySQLInnoDBNodeStringLengthWorker.

/**
 * Check that the maximum string lengths can be adjusted up and down.
 * Note that this test ONLY works for MySQL because the other databases cannot support more than 1024 characters
 * in the string_value column and the value may not be set to less than 1024.
 *
 * @see SchemaBootstrap#DEFAULT_MAX_STRING_LENGTH
 */
@SuppressWarnings("deprecation")
public void testMySQLInnoDBNodeStringLengthWorker() throws Exception {
    TestTransaction.flagForCommit();
    TestTransaction.end();
    // Skip of the dialect if not MySQL (also skip for MySQL Cluster NDB)
    Dialect dialect = (Dialect) applicationContext.getBean("dialect");
    if ((dialect instanceof MySQLClusterNDBDialect) || (!(dialect instanceof MySQLInnoDBDialect))) {
        return;
    }
    SchemaBootstrap schemaBootstrap = (SchemaBootstrap) applicationContext.getBean("schemaBootstrap");
    assertEquals("Expected max string length to be MAX", Integer.MAX_VALUE, SchemaBootstrap.getMaxStringLength());
    NodeStringLengthWorker worker = (NodeStringLengthWorker) applicationContext.getBean("nodeStringLengthWorker");
    // If we run this worker just to get everything into the correct starting state.
    // If it does not work, then that will be detected later anyway
    NodeStringLengthWorkResult result = worker.execute();
    assertTrue(result.getPropertiesProcessed() > 0);
    assertEquals(0, result.getErrors());
    // Now set the max string length to DEFAULT_MAX_STRING_LENGTH characters
    schemaBootstrap.setMaximumStringLength(SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    // Move any values persisted before the test
    result = worker.execute();
    int firstPassChanged = result.getPropertiesChanged();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH + 1; i++) {
        sb.append("A");
    }
    final String longString = sb.toString();
    // Persist the property using the default MAX_VALUE so that it goes into the string_value
    schemaBootstrap.setMaximumStringLength(Integer.MAX_VALUE);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    txnService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            nodeService.setProperty(rootNodeRef, PROP_QNAME_STRING_VALUE, longString);
            return null;
        }
    });
    // The worker should do nothing
    result = worker.execute();
    assertEquals(firstPassChanged, result.getPropertiesChanged());
    // Now bring the limit down to the match for other DBs
    schemaBootstrap.setMaximumStringLength(SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    result = worker.execute();
    assertEquals(firstPassChanged + 1, result.getPropertiesChanged());
    // Put the limit back to the MySQL default and all the large values should go back into MySQL's TEXT field
    schemaBootstrap.setMaximumStringLength(Integer.MAX_VALUE);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    result = worker.execute();
    assertEquals(firstPassChanged + 1, result.getPropertiesChanged());
    // Check that our string is still OK
    String checkLongString = txnService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {

        @Override
        public String execute() throws Throwable {
            return (String) nodeService.getProperty(rootNodeRef, PROP_QNAME_STRING_VALUE);
        }
    });
    assertEquals("String manipulation corrupted the long string value. ", longString, checkLongString);
}
Also used : MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) SchemaBootstrap(org.alfresco.repo.domain.schema.SchemaBootstrap) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) Dialect(org.alfresco.repo.domain.dialect.Dialect) NodeStringLengthWorkResult(org.alfresco.repo.node.db.NodeStringLengthWorker.NodeStringLengthWorkResult)

Aggregations

MySQLInnoDBDialect (org.alfresco.repo.domain.dialect.MySQLInnoDBDialect)7 MySQLClusterNDBDialect (org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect)4 Dialect (org.alfresco.repo.domain.dialect.Dialect)3 PostgreSQLDialect (org.alfresco.repo.domain.dialect.PostgreSQLDialect)3 Before (org.junit.Before)3 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Savepoint (java.sql.Savepoint)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Oracle9Dialect (org.alfresco.repo.domain.dialect.Oracle9Dialect)2 SQLServerDialect (org.alfresco.repo.domain.dialect.SQLServerDialect)2 BufferedInputStream (java.io.BufferedInputStream)1 SchemaBootstrap (org.alfresco.repo.domain.schema.SchemaBootstrap)1 NodeStringLengthWorkResult (org.alfresco.repo.node.db.NodeStringLengthWorker.NodeStringLengthWorkResult)1 Index (org.alfresco.util.schemacomp.model.Index)1 Schema (org.alfresco.util.schemacomp.model.Schema)1 Table (org.alfresco.util.schemacomp.model.Table)1