本文整理汇总了Java中org.eclipse.persistence.exceptions.DatabaseException类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseException类的具体用法?Java DatabaseException怎么用?Java DatabaseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseException类属于org.eclipse.persistence.exceptions包,在下文中一共展示了DatabaseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loginAction
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
/**
*
* @param auth
* @return
*/
@RequestMapping(path = "/login", method = RequestMethod.POST,
consumes = {"application/json"})
public ResponseEntity<String> loginAction(@RequestBody LoginDTO auth) {
boolean isLoginSuccessful;
try {
isLoginSuccessful = authenticationService.login(auth.getLogin(), auth.getPassword());
if(isLoginSuccessful) {
AppUser appUser = authenticationService.getLoggedUser();
UUID token = UUID.randomUUID();
UserDTO userDTO = new UserDTO(appUser.getId(), appUser.getEmail(), appUser.getFirstName(), appUser.getLastName(), token.toString());
authTokenCache.addAuthToken(token, appUser);
return ResponseEntity.ok(gson.toJsonTree(userDTO).toString());
}
} catch(CannotCreateTransactionException | PersistenceException | DatabaseException e) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
}
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
}
示例2: replaceDefaultTables
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
/**
* Drop and recreate the default table schema for the project this session
* associated with.
*/
public void replaceDefaultTables(boolean createSequenceTables, boolean createSequences, boolean generateFKConstraints) throws EclipseLinkException {
boolean shouldLogExceptionStackTrace = getSession().getSessionLog().shouldLogExceptionStackTrace();
this.session.getSessionLog().setShouldLogExceptionStackTrace(false);
try {
JPAMTableCreator tableCreator = getDefaultTableCreator(generateFKConstraints);
tableCreator.replaceTables(this.session, this, createSequenceTables, createSequences);
// Drop all the database schemas now if set to do so. This must be
// called after all the constraints, tables etc. are dropped.
dropDatabaseSchemas();
} catch (DatabaseException exception) {
// Ignore error
} finally {
this.session.getSessionLog().setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace);
}
// Reset database change events to new tables.
if (this.session.getDatabaseEventListener() != null) {
this.session.getDatabaseEventListener().remove(this.session);
this.session.getDatabaseEventListener().register(this.session);
}
}
示例3: persist
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
public void persist(VO vo) throws DatabaseException {
EntityTransaction tx = null;
try {
tx = em.getTransaction();
tx.begin();
service.persist(vo, em);
tx.commit();
} catch (Exception e) {
if (em != null && tx != null) {
tx.rollback();
}
throw new PersistException(e.getMessage());
} finally {
if (em != null) {
em.clear();
em.close();
}
}
}
示例4: handlePersistenceException
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
static private void handlePersistenceException(Exception e)
{
if (e.getCause() instanceof PersistenceException)
{
String tmp = e.getMessage();
PersistenceException pex = (PersistenceException) e.getCause();
if (pex.getCause() instanceof DatabaseException)
{
DatabaseException dex = (DatabaseException) pex.getCause();
tmp = dex.getMessage();
if (tmp.indexOf("Query being") > 0)
{
// strip of the query
tmp = tmp.substring(0, tmp.indexOf("Query being"));
if (tmp.contains("MySQL"))
{
tmp = tmp.substring(tmp.indexOf("MySQL") + 5);
}
}
}
logger.error(e, e);
throw new RuntimeException(tmp);
}
}
示例5: registerAction
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
/**
*
* @param registration
* @return
*/
@RequestMapping(path = "/register", method = RequestMethod.POST,
consumes = {"application/json"})
public ResponseEntity<String> registerAction(@RequestBody RegistrationDTO registration) {
try {
registrationService.register(registration);
AppUser appUser = authenticationService.getLoggedUser();
UUID token = UUID.randomUUID();
UserDTO userDTO = new UserDTO(appUser.getId(), appUser.getEmail(), appUser.getFirstName(), appUser.getLastName(), token.toString());
authTokenCache.addAuthToken(token, appUser);
return ResponseEntity.ok(gson.toJsonTree(userDTO).toString());
} catch(CannotCreateTransactionException | PersistenceException | DatabaseException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("MUJ POKUS");
}
}
示例6: UserResource
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
public UserResource() {
try {
dao.createUserTable();
} catch (DatabaseException e) {
logger.info("Table already here !",e);
}
}
示例7: connectToDataSource
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
/**
* Connect with the specified properties and return the Connection.
*/
public Connection connectToDataSource(EISAccessor accessor, Properties properties) throws DatabaseException, ValidationException {
if (this.connectionFactory == null && this.name == null) {
this.connectionFactory = new DemoConnectionFactory();
}
if (!properties.isEmpty()) {
if (this.connectionSpec == null) {
this.connectionSpec = new DemoJCAConnectionSpec();
}
}
return super.connectToDataSource(accessor, properties);
}
示例8: testDisableVersioning
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
@Test
public void testDisableVersioning() {
// get a random value for our id
String rndId = getRandomId();
String property = "testPropertyValue";
// persist to the datasource
KRADServiceLocator.getDataObjectService().save(createDisableVersion(rndId, property));
// retrieve the object back from the datasource
DisableVersion resultDV = KRADServiceLocator.getDataObjectService().find(DisableVersion.class, rndId);
// validate
assertNotNull("DisableVersion is null", resultDV);
assertEquals("DisableVersion id does not match given value", rndId, resultDV.getId());
assertEquals("DisableVersion property does not match given value", property, resultDV.getProperty());
assertEquals(new Long(0), resultDV.getVersionNumber());
// now set the version number to a value and make sure it persists properly
resultDV.setVersionNumber(new Long(50));
resultDV = KRADServiceLocator.getDataObjectService().save(resultDV);
assertEquals(new Long(50), resultDV.getVersionNumber());
// now, since DisableNoVersion has no version number column, it should throw an exception when we attempt to
// persist it since there is no ver_nbr column in the database
try {
KRADServiceLocator.getDataObjectService().save(createDisableNoVersion(rndId, property));
fail("Database exception should have been thrown when saving with no version number column");
} catch (DatabaseException e) {}
// DisableVersionRemoveMapping *should* work though because we are removing the VER_NBR column mapping which
// should help because we have no such column in the database
KRADServiceLocator.getDataObjectService().save(createDisableNoVersionRemoveMapping(rndId, property));
// retrieve the object back from the datasource
DisableNoVersionRemoveMapping resultDNV = KRADServiceLocator.getDataObjectService().find(DisableNoVersionRemoveMapping.class, rndId);
// validate
assertNotNull("DisableNoVersionRemoveMapping is null", resultDNV);
assertEquals("DisableNoVersionRemoveMapping id does not match given value", rndId, resultDNV.getId());
assertEquals("DisableNoVersionRemoveMapping property does not match given value", property, resultDNV.getProperty());
}
示例9: handleException
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
public Object handleException(RuntimeException exception) {
if (exception instanceof DatabaseException && exception.getCause() instanceof SQLException) {
final SQLException sqlEx = (SQLException) exception.getCause();
switch (sqlEx.getSQLState()) {
case "23505":
throw new DuplicateKeyException(exception.getMessage(), exception);
case "23503":
throw new IntegrityConstraintViolationException(exception.getMessage(), exception);
}
}
throw exception;
}
示例10: handleException
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
public Object handleException(RuntimeException exception) {
if (exception instanceof DatabaseException && exception.getCause() instanceof SQLException) {
final SQLException sqlEx = (SQLException) exception.getCause();
switch (sqlEx.getErrorCode()) {
case 23505:
throw new DuplicateKeyException(exception.getMessage(), exception);
case 23506:
throw new IntegrityConstraintViolationException(exception.getMessage(), exception);
}
}
throw exception;
}
示例11: dropConstraints
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
/**
* Drop the table constraints from the database.
*/
public void dropConstraints(DatabaseSession session, JPAMSchemaManager schemaManager, boolean build) {
buildConstraints(schemaManager, build);
for (JPAMTableDefinition table : getTableDefinitions()) {
try {
schemaManager.dropConstraints(table);
} catch (DatabaseException exception) {
//ignore
}
}
}
示例12: createUniqueConstraintsOnDatabase
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
@Override
void createUniqueConstraintsOnDatabase(final AbstractSession session) throws ValidationException, DatabaseException {
if ((!session.getPlatform().supportsUniqueKeyConstraints())
|| getUniqueKeys().isEmpty()
|| session.getPlatform().requiresUniqueConstraintCreationOnTableCreate()) {
return;
}
for (UniqueKeyConstraint uniqueKey : getUniqueKeys()) {
session.priviledgedExecuteNonSelectingCall(new org.eclipse.persistence.queries.SQLCall(buildUniqueConstraintCreationWriter(session, uniqueKey, new StringWriter()).toString()));
}
}
示例13: createForeignConstraintsOnDatabase
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
@Override
void createForeignConstraintsOnDatabase(final AbstractSession session) throws ValidationException, DatabaseException {
if ((!session.getPlatform().supportsForeignKeyConstraints()) || getForeignKeyMap().isEmpty()) {
return;
}
for (ForeignKeyConstraint foreignKey : getForeignKeyMap().values()) {
if (!foreignKey.disableForeignKey()) {
session.priviledgedExecuteNonSelectingCall(new SQLCall(buildConstraintCreationWriter(session, foreignKey, new StringWriter()).toString()));
}
}
}
示例14: replaceObject
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
/**
* Use the definition object to drop and recreate the schema entity on the
* database. This is used for dropping tables, views, procedures ... etc ...
* This handles and ignore any database error while dropping in case the
* object did not previously exist.
*/
public void replaceObject(DatabaseObjectDefinition databaseDefinition) throws EclipseLinkException {
// PERF: Allow a special "fast" flag to be set on the session causes a delete from the table instead of a replace.
boolean fast = FAST_TABLE_CREATOR;
if (fast && (databaseDefinition instanceof TableDefinition)) {
session.executeNonSelectingSQL("DELETE FROM " + databaseDefinition.getName());
} else if (fast && (databaseDefinition instanceof StoredProcedureDefinition)) {
// do nothing
} else {
// CR 3870467, do not log stack
boolean shouldLogExceptionStackTrace = getSession().getSessionLog().shouldLogExceptionStackTrace();
if (shouldLogExceptionStackTrace) {
getSession().getSessionLog().setShouldLogExceptionStackTrace(false);
}
try {
dropObject(databaseDefinition);
} catch (DatabaseException exception) {
// Ignore error
} finally {
if (shouldLogExceptionStackTrace) {
getSession().getSessionLog().setShouldLogExceptionStackTrace(true);
}
}
String query = createObject(databaseDefinition);
getDBMapping().putCreateQuery(databaseDefinition.getName(), query);
}
}
示例15: dropDefaultTables
import org.eclipse.persistence.exceptions.DatabaseException; //导入依赖的package包/类
/**
* Create the default table schema for the project this session associated
* with.
*/
public void dropDefaultTables() {
// Drop each table w/o throwing exception and/or exit if some don't exist.
boolean shouldLogExceptionStackTrace = getSession().getSessionLog().shouldLogExceptionStackTrace();
getSession().getSessionLog().setShouldLogExceptionStackTrace(false);
try {
// Drop the tables.
JPAMTableCreator tableCreator = getDefaultTableCreator(true);
tableCreator.dropTables(this.session, this);
// Drop the sequences.
dropSequences();
// Drop all the database schemas now if set to do so. This must be
// called after all the constraints, tables etc. are dropped.
dropDatabaseSchemas();
} catch (DatabaseException ex) {
// Ignore error
} finally {
getSession().getSessionLog().setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace);
}
// Reset database change events to new tables.
if (this.session.getDatabaseEventListener() != null) {
this.session.getDatabaseEventListener().remove(this.session);
this.session.getDatabaseEventListener().register(this.session);
}
}