기업 사용자 가입 문제 처리
This commit is contained in:
@@ -1,35 +1,60 @@
|
|||||||
package com.eactive.apim.portal.portalorg.entity;
|
package com.eactive.apim.portal.portalorg.entity;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
import org.hibernate.tuple.ValueGenerator;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import org.hibernate.HibernateException;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
|
||||||
import org.hibernate.tuple.ValueGenerator;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class OrgCodeGenerator implements ValueGenerator<String> {
|
public class OrgCodeGenerator implements ValueGenerator<String> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(OrgCodeGenerator.class);
|
|
||||||
private static final String TABLE_NAME = "PTL_ID";
|
private static final String TABLE_NAME = "PTL_ID";
|
||||||
private static final String SELECT_SQL =
|
private final String CHECK_EXISTS_SQL;
|
||||||
"SELECT NEXT_ID FROM " + TABLE_NAME +
|
private final String INSERT_SQL;
|
||||||
" WHERE TABLE_NAME = 'PTL_ORG' FOR UPDATE";
|
private final String SELECT_SQL;
|
||||||
private static final String UPDATE_SQL =
|
private final String UPDATE_SQL;
|
||||||
"UPDATE " + TABLE_NAME +
|
|
||||||
" SET NEXT_ID = ? WHERE TABLE_NAME = 'PTL_ORG'";
|
|
||||||
|
|
||||||
private static final String CHECK_EXISTS_SQL =
|
|
||||||
"SELECT COUNT(*) FROM " + TABLE_NAME +
|
|
||||||
" WHERE TABLE_NAME = 'PTL_ORG'";
|
|
||||||
|
|
||||||
private static final String INSERT_SQL =
|
|
||||||
"INSERT INTO " + TABLE_NAME +
|
|
||||||
" (TABLE_NAME, NEXT_ID) VALUES ('PTL_ORG', ?)";
|
|
||||||
private static final long INITIAL_VALUE = 1000000000L;
|
private static final long INITIAL_VALUE = 1000000000L;
|
||||||
|
|
||||||
|
|
||||||
|
private OrgCodeGenerator() {
|
||||||
|
// private static final String SELECT_SQL =
|
||||||
|
// "SELECT NEXT_ID FROM " + TABLE_NAME +
|
||||||
|
// " WHERE TABLE_NAME = 'PTL_ORG' FOR UPDATE";
|
||||||
|
// private static final String UPDATE_SQL =
|
||||||
|
// "UPDATE " + TABLE_NAME +
|
||||||
|
// " SET NEXT_ID = ? WHERE TABLE_NAME = 'PTL_ORG'";
|
||||||
|
//
|
||||||
|
// private static final String CHECK_EXISTS_SQL =
|
||||||
|
// "SELECT COUNT(*) FROM " + TABLE_NAME +
|
||||||
|
// " WHERE TABLE_NAME = 'PTL_ORG'";
|
||||||
|
//
|
||||||
|
// private static final String INSERT_SQL =
|
||||||
|
// "INSERT INTO " + TABLE_NAME +
|
||||||
|
// " (TABLE_NAME, NEXT_ID) VALUES ('PTL_ORG', ?)";
|
||||||
|
// private static final long INITIAL_VALUE = 1000000000L;
|
||||||
|
|
||||||
|
|
||||||
|
String schema = System.getProperty("ems.schema", "");
|
||||||
|
|
||||||
|
if (schema.isEmpty()) {
|
||||||
|
log.error("ems.schema is empty.");
|
||||||
|
throw new IllegalStateException("System property 'ems.schema' is not set. Please configure 'ems.datasource.schema'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
String TABLE_NAME_WITH_SCHEMA = System.getProperty("ems.schema", "") + "." + TABLE_NAME;
|
||||||
|
|
||||||
|
this.CHECK_EXISTS_SQL = "SELECT COUNT(*) FROM " + TABLE_NAME_WITH_SCHEMA + " WHERE TABLE_NAME = 'PTL_ORG'";
|
||||||
|
this.INSERT_SQL = "INSERT INTO " + TABLE_NAME_WITH_SCHEMA + " (TABLE_NAME, NEXT_ID) VALUES ('PTL_ORG', ?)";
|
||||||
|
this.SELECT_SQL = "SELECT NEXT_ID FROM " + TABLE_NAME_WITH_SCHEMA + " WHERE TABLE_NAME = 'PTL_ORG' FOR UPDATE";
|
||||||
|
this.UPDATE_SQL = "UPDATE " + TABLE_NAME_WITH_SCHEMA + " SET NEXT_ID = ? WHERE TABLE_NAME = 'PTL_ORG'";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateValue(Session session, Object owner) {
|
public String generateValue(Session session, Object owner) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user