Oracle support
Oracle database has certain particularities. JFinal provides some additional support for these particularities to facilitate the majority of Oracle users. The following is a complete Oracle configuration example:
public void configPlugin(Plugins me) { C3p0Plugin cp = new C3p0Plugin(……);
// Configure Oracle driver
cp. setDriverClass("oracle.jdbc.driver.OracleDriver"); me.add(cp);
ActiveRecordPlugin arp = new ActiveRecordPlugin(cp); me.add(arp);
// Configure the Oracle dialect
arp.setDialect(new OracleDialect());
// Configure the attribute name (field name) case-insensitive container factory arp.setContainerFactory(new CaseInsensitiveContainerFactory()); arp.addMapping( "user", "user_id", User.class);
}
Because the Oracle database will automatically convert the attribute name (field name) into uppercase, you need to manually specify the primary key name in uppercase , such as: arp.addMaping(“user”, “ID”, User.class). If you want ActiveRecord to be case-insensitive to attribute names (field names), you can achieve this by setting CaseInsensitiveContainerFactory. With this setting, arp.addMaping("user", "ID", User.class ) is no longer needed.
In addition, Oracle does not directly support auto-incrementing primary keys, and JFinal provides a convenient solution for this. There are two main steps for Oracle to support automatic primary keys: one is to create a sequence, and the other is to use this sequence in the model. The specific method is as follows:
1: Create a sequence through the following method. In this example, the sequence is named :MY_SEQ
MINVALUE 1
MAXVALUE 9999999999999999
START WITH 1
CACHE 20;
2: Use the sequence created above in YourModel.set(...)
User user = new User().set("id", "MY_SEQ.nextval ").set("age", 18); user.save();
// Get the id value
Integer id = user.get("id");
The use of the sequence is very simple, you only need yourModel.set(primary key name, sequence name + “.nextval”). Special Note that the “.nextval” suffix here must be lowercase, OracleDialect is case sensitive to this value.