COMPLEX TYPE OBJECTS -> JAVA MAPPING
COMPLEX TYPE OBJECTS -> JAVA MAPPING
PROCEDURE link_user_cards(p_cards IN t_product_card_coll) IS
BEGIN
CORE_PRODUCT.map_cards(p_cards);
END;
CREATE OR REPLACE TYPE T_PRODUCT_CARD_COLL IS TABLE OF T_PRODUCT_CARD
CREATE OR REPLACE TYPE T_PRODUCT_CARD UNDER T_PRODUCT (
PAN_MASK VARCHAR2(32),
LIMIT_ID NUMBER,
IS_SMS_ENABLED NUMBER,
USE_3D_SECURE NUMBER,
MBR INTEGER,
CARD_TYPE INTEGER,
ACCOUNTS T_PRODUCT_ACCOUNT_COLL
)
CREATE OR REPLACE TYPE T_PRODUCT IS OBJECT(
ID VARCHAR2(100 CHAR),
NAME VARCHAR2(100 CHAR),
TYPE INTEGER,
SYSTEM VARCHAR2(10 CHAR),
STATUS INTEGER
) NOT FINAL
alter type T_PRODUCT add attribute AMOUNT NUMBER cascade
-----JAVA SIDE----
@Override
public void loadUserCardsOnAccount(List<CardType> card) throws SQLException {
try {
loadContext();
ocstmt = prepareCallProcedure(Env.getDBApiScheme(), "api_product.link_user_cards(?)");
setArray(1, ProductMapping.getCardArray(oconn, card), ConstTypes.CARD_COLL);
ocstmt.execute();
} finally {
releaseAllResources();
}
}
public static Array getCardArray(OracleConnection connection, List<CardType> cards) throws SQLException {
if (CommonUtils.isListEmptyOrNull(cards))
return null;
Struct[] structs = new Struct[cards.size()];
int idx = 0;
for(CardType card : cards) {
structs[idx++] = getCardStruct(connection, card);
}
return connection.createOracleArray(ConstTypes.CARD_COLL, structs);
}
private static Struct getCardStruct(OracleConnection connection, CardType card) throws SQLException {
Object[] structs = getCardStructFields(connection, card);
return connection.createStruct(ConstTypes.CARD, structs);
}
private static Object[] getCardStructFields(OracleConnection connection, CardType card) throws SQLException {
return new Object[] {
card.getId(),
card.getName(),
card.getType(),
card.getSystem(),
card.getStatus(),
card.getAmount(),
card.getPan(),
card.getLimitId(),
card.getSmsEnabled(),
card.getUse3DSecure(),
card.getMbr(),
card.getCardType(),
getAccountArray(connection, card.getAccounts())
};
}
public static Array getAccountArray(OracleConnection connection, List<AccountType> accounts) throws SQLException {
if (CommonUtils.isListEmptyOrNull(accounts))
return null;
Struct[] structs = new Struct[accounts.size()];
int idx = 0;
for(AccountType account : accounts) {
structs[idx++] = getAccountStruct(connection, account);
}
return connection.createOracleArray(ConstTypes.ACCOUNT_COLL, structs);
}
public static Struct getAccountStruct(OracleConnection connection, AccountType account) throws SQLException {
return connection.createStruct(ConstTypes.ACCOUNT, getAccountStructFields(account));
}
private static Object[] getAccountStructFields(AccountType product) {
return new Object[] {
product.getId(),
product.getName(),
product.getType(),
product.getSystem(),
product.getStatus(),
product.getAmount(),
product.getAccount(),
product.getOverdraft(),
product.getCurrency()
};
}
Yorumlar
Yorum Gönder