Search in sources :

Example 11 with DbKeyGenerator

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

the class PKCustomSequenceGeneratorPanel method setPKSize.

protected void setPKSize(String text) {
    if (mediator.getCurrentDbEntity() == null || mediator.getCurrentDbEntity().getPrimaryKeyGenerator() == null) {
        return;
    }
    int cacheSize = 0;
    if (text != null && text.trim().length() > 0) {
        try {
            cacheSize = Integer.parseInt(text);
        } catch (NumberFormatException nfex) {
            throw new ValidationException("Invalid number");
        }
    }
    DbKeyGenerator generator = mediator.getCurrentDbEntity().getPrimaryKeyGenerator();
    if (!Util.nullSafeEquals(generator.getKeyCacheSize(), new Integer(cacheSize))) {
        generator.setKeyCacheSize(new Integer(cacheSize));
        mediator.fireDbEntityEvent(new EntityEvent(this, generator.getDbEntity()));
    }
}
Also used : ValidationException(org.apache.cayenne.validation.ValidationException) 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