📄 hlidgenerator.java
字号:
/* * HLIDGenerator.java * * Created on 2005年6月9日, 下午11:03 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package oid;import java.sql.*;import javax.sql.*;import java.util.*;import common.*;/** * * @author kevin */public class HLIDGenerator { private static Map idMap = new HashMap(); private static long personId = 1; private static long studentId = 1; private static long bachelorId = 1; private static long masterId = 1; private static long workerId = 1; private static long driverId = 1; private static long engineerId = 1; public synchronized static String nextPerson() { String id = (String) idMap.get("PERSON"); if (id == null) { id = String.valueOf(nextId()); idMap.put("PERSON", id); } return id + (personId++); } public synchronized static String nextStudent() { String id = (String) idMap.get("STUDENT"); if (id == null) { id = String.valueOf(nextId()); idMap.put("STUDENT", id); } return id + (studentId++); } public synchronized static String nextBachelor() { String id = (String) idMap.get("BACHELOR"); if (id == null) { id = String.valueOf(nextId()); idMap.put("BACHELOR", id); } return id + (bachelorId++); } public synchronized static String nextMaster() { String id = (String) idMap.get("MASTER"); if (id == null) { id = String.valueOf(nextId()); idMap.put("MASTER", id); } return id + (masterId++); } public synchronized static String nextWorker() { String id = (String) idMap.get("WORKER"); if (id == null) { id = String.valueOf(nextId()); idMap.put("WORKER", id); } return id + (workerId++); } public synchronized static String nextDriver() { String id = (String) idMap.get("DRIVER"); if (id == null) { id = String.valueOf(nextId()); idMap.put("DRIVER", id); } return id + (driverId++); } public synchronized static String nextEngineer() { String id = (String) idMap.get("ENGINEER"); if (id == null) { id = String.valueOf(nextId()); idMap.put("ENGINEER", id); } return id + (engineerId++); } public static long nextId() { long id = -1; Connection con = null; Statement st = null; ResultSet rs = null; try { ConnectionFactory factory = ConnectionFactory.getConnectionFactory(); con = factory.getConnection(); st = con.createStatement(); rs = st.executeQuery("SELECT nextval FROM oid_hl_tbl"); rs.next(); id = rs.getLong(1); st.execute("UPDATE oid_hl_tbl SET nextval = nextval + 1"); } catch (Exception e) { id = -1; e.printStackTrace(); } finally { DBUtils.close(rs, st, con); } return id; } public static void main(String[] aregs){ for(int i = 1; i< 12; i++) System.out.println(HLIDGenerator.nextDriver()); System.out.println("****************************"); for(int i = 1; i< 12; i++) System.out.println(HLIDGenerator.nextEngineer()); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -