Fix for #135 Make Model abstract, change db() and db(server) to be

static methods.
This commit is contained in:
Rob Bygrave
2014-05-30 01:30:57 +12:00
parent f4dceb97b0
commit b1de821817
2 changed files with 36 additions and 4 deletions
+31 -4
View File
@@ -29,7 +29,7 @@ import javax.persistence.MappedSuperclass;
* relatively nice clean way to write queries.
*/
@MappedSuperclass
public class Model {
public abstract class Model {
/**
* Return the underlying 'default' EbeanServer.
@@ -38,9 +38,36 @@ public class Model {
* This provides full access to the API such as explicit transaction demarcation etc.
*
* <p>
* TODO: Transaction example
* Example:
* <pre class="code">
* Transaction transaction = Customer.db().beginTransaction();
* try {
*
* // turn off cascade persist for this transaction
* transaction.setPersistCascade(false);
*
* // extra control over jdbc batching for this transaction
* transaction.setBatchGetGeneratedKeys(false);
* transaction.setBatchMode(true);
* transaction.setBatchSize(20);
*
* Customer customer = new Customer();
* customer.setName(&quot;Roberto&quot;);
* customer.save();
*
* Customer otherCustomer = new Customer();
* otherCustomer.setName(&quot;Franko&quot;);
* otherCustomer.save();
*
* transaction.commit();
*
* } finally {
* transaction.end();
* }
*
* </pre>
*/
public EbeanServer db() {
public static EbeanServer db() {
return Ebean.getServer(null);
}
@@ -54,7 +81,7 @@ public class Model {
* @param server
* The name of the EbeanServer. If this is null then the default EbeanServer is returned.
*/
public EbeanServer db(String server) {
public static EbeanServer db(String server) {
return Ebean.getServer(server);
}
@@ -18,6 +18,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.avaje.ebean.BackgroundExecutor;
import com.avaje.ebean.Model;
import com.avaje.ebean.RawSql;
import com.avaje.ebean.RawSqlBuilder;
import com.avaje.ebean.annotation.ConcurrencyMode;
@@ -1411,6 +1412,10 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
// we got to the top of the inheritance
return;
}
if (Model.class.equals(superclass)) {
// top of the inheritance. Not enhancing Model at this stage
return;
}
if (!EntityBean.class.isAssignableFrom(superclass)) {
throw new IllegalStateException("Super type "+superclass+" is not enhanced?");
}