游泳

SQL和PL-SQL中模拟Java对象状态持久性_a

2020-01-20 01:10:58来源:励志吧0次阅读

Java存储程序和RAW数据RAW数据类型是二进制8位的数据。当与Java存储程序参数相互映射时,Oracle数据库将自动地将字节数组转换为RAW列,并将转换值返回到SQL或者PL/SQP。

所以,为了能在SQL或者PL/SQL中使用我们的类,我们必须编写一个Java类,这一类能够系列化一个对象,并通过一个静态方法有选择地在调用函数中反系列化这一对象。

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

public class JSerialPoint

{

private static Point from_raw(byte[] p_raw)

throws ClassNotFoundException,IOException

{

ByteArrayInputStream bytes = new ByteArrayInputStream(p_raw);

ObjectInputStream in = new ObjectInputStream(bytes);

return (Point)in.readObject();

}

private static byte[] to_raw(Point p_point) throws IOException

{

ByteArrayOutputStream bytes = new ByteArrayOutputStream();

ObjectOutputStream out = new ObjectOutputStream(bytes);

out.writeObject(p_point);

out.close();

return bytes.toByteArray();

}

private static void copy_raw(Point p_point,byte[] p_raw) throws IOException

{

byte[] l_raw = to_raw(p_point);

System.arraycopy(l_raw,0,p_raw,0,l_raw.length);

}

// construct a point

public static byte[] new_point(intx,int y) throws IOException

{

Point p = new Point(x,y);

return to_raw(p);

}

public static intget_x(byte[] p_point)

throws ClassNotFoundException,IOException

{

return from_raw(p_point).get_x();

}

public static byte[] set_x(byte[] p_point,intp_x)

throws ClassNotFoundException,IOException

{

Point p = from_raw(p_point);

p.set_x(p_x);

return to_raw(p);

}

public static intget_y(byte[] p_point)

throws ClassNotFoundException,IOException

{

return from_raw(p_point).get_y();

}

public static byte[] set_y(byte[] p_point,intp_y)

throws ClassNotFoundException,IOException

{

Point p = from_raw(p_point);

p.set_y(p_y);

return to_raw(p);

}

public static byte[] move(byte[] p_point,intx,int y)

throws ClassNotFoundException,IOException

{

Point p = from_raw(p_point);

p.move(x,y);

return to_raw(p);

}

public static String to_string(byte[] p_point)

throws ClassNotFoundException,IOException

{

Point p = from_raw(p_point);

return p.toString();

}

}

跌打损伤吃什么消肿快
治脑梗哪好
薏芽健脾凝胶吃法
孩子早上咳嗽有痰咳不出怎么办
分享到: