Search in sources :

Example 6 with DbKeyGenerator

use of org.apache.cayenne.map.DbKeyGenerator in project cayenne by apache.

the class JdbcAdapterIT method testCreateTableQuoteSqlIdentifiers.

@Test
public void testCreateTableQuoteSqlIdentifiers() {
    if (dbAdapter instanceof MySQLAdapter) {
        DbEntity entity = new DbEntity();
        DbAttribute attr = new DbAttribute();
        attr.setName("name column");
        attr.setType(1);
        entity.addAttribute(attr);
        DbKeyGenerator id = new DbKeyGenerator();
        entity.setPrimaryKeyGenerator(id);
        DataMap dm = new DataMap();
        dm.setQuotingSQLIdentifiers(true);
        entity.setDataMap(dm);
        entity.setName("name table");
        MySQLAdapter adaptMySQL = (MySQLAdapter) dbAdapter;
        String str = "CREATE TABLE `name table` (`name column` CHAR NULL) ENGINE=InnoDB";
        assertEquals(str, adaptMySQL.createTable(entity));
    }
}
Also used : MySQLAdapter(org.apache.cayenne.dba.mysql.MySQLAdapter) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) DbKeyGenerator(org.apache.cayenne.map.DbKeyGenerator) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 7 with DbKeyGenerator

use of org.apache.cayenne.map.DbKeyGenerator in project cayenne by apache.

the class OraclePkGeneratorIT method testSequenceNameCustom2.

@Test
public void testSequenceNameCustom2() throws Exception {
    DbEntity entity = new DbEntity("TEST_ENTITY");
    DbKeyGenerator customGenerator = new DbKeyGenerator();
    customGenerator.setGeneratorType(DbKeyGenerator.NAMED_SEQUENCE_TABLE_TYPE);
    customGenerator.setGeneratorName("CUSTOM_GENERATOR");
    assertEquals("pk_test_entity", pkGenerator.sequenceName(entity));
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbKeyGenerator(org.apache.cayenne.map.DbKeyGenerator) Test(org.junit.Test)

Example 8 with DbKeyGenerator

use of org.apache.cayenne.map.DbKeyGenerator in project cayenne by apache.

the class DbKeyGeneratorHandler method setDbGeneratorType.

private void setDbGeneratorType(String type) {
    if (entity == null) {
        return;
    }
    DbKeyGenerator pkGenerator = entity.getPrimaryKeyGenerator();
    pkGenerator.setGeneratorType(type);
    if (pkGenerator.getGeneratorType() == null) {
        entity.setPrimaryKeyGenerator(null);
    }
}
Also used : DbKeyGenerator(org.apache.cayenne.map.DbKeyGenerator)

Example 9 with DbKeyGenerator

use of org.apache.cayenne.map.DbKeyGenerator in project cayenne by apache.

the class DbKeyGeneratorHandler method setDbGeneratorName.

private void setDbGeneratorName(String name) {
    if (entity == null) {
        return;
    }
    DbKeyGenerator pkGenerator = entity.getPrimaryKeyGenerator();
    if (pkGenerator == null) {
        return;
    }
    pkGenerator.setGeneratorName(name);
}
Also used : DbKeyGenerator(org.apache.cayenne.map.DbKeyGenerator)

Example 10 with DbKeyGenerator

use of org.apache.cayenne.map.DbKeyGenerator in project cayenne by apache.

the class PKCustomSequenceGeneratorPanel method setPKName.

protected void setPKName(String text) {
    if (mediator.getCurrentDbEntity() == null || mediator.getCurrentDbEntity().getPrimaryKeyGenerator() == null) {
        return;
    }
    if (text != null && text.trim().length() == 0) {
        text = null;
    }
    DbKeyGenerator generator = mediator.getCurrentDbEntity().getPrimaryKeyGenerator();
    if (!Util.nullSafeEquals(text, generator.getName())) {
        generator.setGeneratorName(text);
        mediator.fireDbEntityEvent(new EntityEvent(this, generator.getDbEntity()));
    }
}
Also used : EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbKeyGenerator(org.apache.cayenne.map.DbKeyGenerator)

Aggregations

DbKeyGenerator (org.apache.cayenne.map.DbKeyGenerator)11 DbEntity (org.apache.cayenne.map.DbEntity)4 Test (org.junit.Test)3 EntityEvent (org.apache.cayenne.map.event.EntityEvent)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 MySQLAdapter (org.apache.cayenne.dba.mysql.MySQLAdapter)1 DataMap (org.apache.cayenne.map.DataMap)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 ValidationException (org.apache.cayenne.validation.ValidationException)1