Showing posts with label custom properties. Show all posts
Showing posts with label custom properties. Show all posts

Monday, February 8, 2010

Handle Soft Delete using Custom Properties (Jdev11g ADF)

I read Generic Handle softdelete At husain dalal's blog and I would like to show another way to handle soft delete using custom property for DeletedFlag attribute using custom properties,
You will notice that DeletedFlag attribute type is Date where it will be entered as new Date("0001-01-01") in Insert operation and will set as system date in delete operation where it will be more better to know the date of delete operation


Now,
1. Create a new Fusion ADF Application and add a new java class that extends oracle.jbo.server.EntityImpl
2. In the CustomEntityImpl override the following methods:
a. remove() - To set the value of column with custom property(DeletedFlag,”YES”) to deleted value.
b. doDML() - During delete, to force an entity object to be updated instead of deleted. And during insert to default the value of column with custom property(DeletedFlag,”YES”) to new Date("0001-01-01").
public int getSoftDeletedColumn() {
int colIndex = -1;
for (AttributeDef def : getEntityDef().getAttributeDefs()) {
if (((AttributeDefImpl)def).getProperty("DeletedFlag") == "YES") {

colIndex = def.getIndex();
}

}
return colIndex;

}

@Override
public void remove() {
int deleteCol = getSoftDeletedColumn();
if (deleteCol != -1) {
setAttribute(deleteCol,
new Date(new Timestamp(System.currentTimeMillis())));
}

super.remove();
}

@Override
protected void doDML(int operation, TransactionEvent transactionEvent) {
int deleteCol = getSoftDeletedColumn();
if (EntityImpl.DML_DELETE == operation && deleteCol != -1) {
operation = DML_UPDATE;
}
if (EntityImpl.DML_INSERT == operation && deleteCol != -1) {

setAttribute(deleteCol, new Date("0001-01-01"));
}
super.doDML(operation, transactionEvent);

}
3. In the Application Navigator, double-click the entity you want to edit.
4. In the overview editor, click the Attributes navigation tab, and double-click the attribute you want to edit.
5. In the Edit Attribute dialog, then click the Custom Properties node add new property of
Name=DeletedFlag, value =YES then add



Download workspace from here but don't forget to generate example table

Wednesday, January 27, 2010

Assigning the Primary Key Value Using an Oracle Sequence and Custom Properties for multiple entitys

This is practice of using custom properties where you can assign the value to a primary key when creating a new row using an Oracle sequence. by single Java file that can be reused by multiple entity objects.
CustomEntityImpl framework extension class on which the entity objects are based. Its overridden create() method tests for the presence of a custom attribute-level metadata property named SequenceName and if detected, populates the attribute's default value from the next number in that sequence.

To assign the primary key value using an Oracle sequence:
1. Create the CustomEntityImpl.java file in your project, and insert the code
package eg.alex.karim.model.frameworkExten;
import oracle.jbo.AttributeDef;
import oracle.jbo.AttributeList;
import oracle.jbo.server.EntityImpl;
import oracle.jbo.server.SequenceImpl;

public class CustomEntityImpl extends EntityImpl {
protected void create(AttributeList attributeList) {
super.create(attributeList);
for (AttributeDef def : getEntityDef().getAttributeDefs()) {
String sequenceName = (String)def.getProperty("SequenceName");
if (sequenceName != null) {
SequenceImpl s = new SequenceImpl(sequenceName,getDBTransaction());
setAttribute(def.getIndex(),s.getSequenceNumber());
}
}
}
}
2. In the Application Navigator, double-click the entity you want to edit.
3. In the overview editor, click the Attributes navigation tab, and double-click the attribute you want to edit.
4. In the Edit Attribute dialog, set the attribute Type from DBSequance to Number, and then click the Custom Properties node.

5.enable the generation of custom Java classes for an entity object and let it extend CustomEntityImpl.java.

you can download workspace from Here
Summary
by using custom properties you may categorize some attriutes which shared in it's behavior