Next Steps
In the example above the Oracle10Plugin is being used. Ebean tries to detect the
specific database based on the jdbc driver. If it can not, then the BasePlugin will
be used instead and you may need to configure it for the specific database.
If you are using Ebean in a Servlet Container refer to webapp_readme.txt
I recommend playing around with Ebean in just a normal application first.
3. Database Dictionary
Ebean makes significant use of the Database Meta data. This can normally be
very slow with some databases. Ebean speeds this up by serializing the
Database Meta data in a file.
If you change your schema you should delete this file forcing Ebean to rebuild it.
You will see INFO: DictionaryInfo deserialized from file... on startup when the
Database Meta data is being read from the file. Also note that this file grows
as more Meta Data is needed automatically. Aka it generally does not read your
entire database meta data but automatically gets more when it needs it.
INFO: DictionaryInfo deserialized from file -
[C:/devjava/project/appzsite/webapp/WEB-INF/data\primarydatabase.dictionary]
4. Log Files
Ebean will create transaction log files as well as the general avajeXXX.log.
The transaction logs can contain all the SQL, binding and summary information
and you can control this with system.properties.
The transaction logs will be a good place to look to see what Ebean is doing.
Implicit transactions are ones without any explicit beginTransaction() commitTransaction().
// Example: Implicit Transaction
Ebean.find(Topic.class, 1);
// Example: Explicit Transaction
Ebean.beginTransaction();
try {
Ebean.find(Topic.class,1);
Ebean.commitTransaction();
} finally {
Ebean.endTransaction();
}
Implicit transactions by default go into a shared log file as there is generally
only one find/save/delete statement.
Explicit transactions by default go into their own separate file as generally
there will be many statements and generally you wish to see them together and
without all the other transactions intermingled.
Initially this may be confusing and you can change the configuration so that all
the statements go into a single file.
To do this change system.properties...
ebean.transactionlogging.share=2
You can start creating your own annotated Entity Beans or use the Code Generator
to build them from your database schema. codegenerator_readme.txt
Without any Annotated Entity Beans you can still use FindByNative, UpdateSql,
CallableSql and also MapBeans.
You can run a query or an update using MapBeans like the ones below.
In this example there is a table in my database called "b_bug".
package test;
import java.util.List;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.FindByPredicates;
import com.avaje.ebean.MapBean;
public class TestQuery {
public static void main(String[] args) {
FindByPredicates find = new FindByPredicates();
find.setTableName("b_bug");
List list = Ebean.findList(find);
for (int i = 0; i < list.size(); i++) {
MapBean mp = (MapBean)list.get(i);
System.out.println(mp);
}
}
}
Update using a MapBean
package test;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.FindById;
import com.avaje.ebean.MapBean;
public class TestUpdate {
public static void main(String[] args) {
FindById find = new FindById();
find.setTableName("b_bug");
find.setId(1);
MapBean mb = (MapBean)Ebean.find(find);
mb.set("priority_code", "LOW");
Ebean.save(mb);
}
}
|