Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

5.11 Oracle Support


May 14, 2021 JFinal manual



Oracle databases are specific, and JFinal provides some additional support for these particularities to facilitate a wide range of Oracle consumers. Here's a complete example of an Oracle configuration:

public class DemoConfig extends JFinalConfig {
public void configPlugin(Plugins me) { C3p0Plugin cp = new C3p0Plugin(......);
Configure Oracle Drive
Cp. s etDriverClass("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 property name (field name) case insensitive container factory arp.setContainerFactory ()); a rp.addMapping("user", "user_id", User. class );
}

Because oracle databases automatically convert property names (field names) to capitals, you need to manually specify the primary key name to capitalized, such as arp.addMaping ("user," "ID," User.class). If you want ActiveRecord to be less sensitive to the large, small write of the property name (field name) to be achieved by setting CaseInsensitiveContainerFactory, with this setting, arp.addMaping ("user", "ID", User.class) is no longer needed.


In addition, Oracle does not directly support self-added primary keys, and JFinal provides a convenient solution for this. There are two main steps to getting Oracle to hold an automatic primary key: to create a sequence, and to use it in a model, as follows:

1: Create a sequence by creating a sequence, in this case named: MY_SEQ

CREATE SEQUENCE MY_SEQ INCREMENT BY 1
MINVALUE 1
MAXVALUE 9999999999999999
START WITH 1
CACHE 20;

2: At YourModel.set (...) Use the sequence created above

Create a User and use the sequence
User user = new User().set("id", "MY_SEQ.nextval").set("age", 18); user.save();
Gets the id value
Integer id = user.get("id");

The use of sequences is simple, just yourModel.set (primary key name, sequence name , ".nextval"). b20> in particular that the ".nextval" suffix here must be small case, and OracleDialect is case sensitive to this value.