@Override public String valueToString(Object value) { throw new ActiveObjectsException("Cannot convert BLOB value to string"); } }
@Override public String valueToString(Object value) { throw new ActiveObjectsException("Cannot convert BLOB value to string"); } }
public static Date checkAgainstMaxDate(Date date) { if (date.compareTo(MAX_DATE) > 0) { throw new ActiveObjectsException("Default date value must be strictly before " + MAX_DATE); } return date; }
public static Date checkAgainstMaxDate(Date date) { if (date.compareTo(MAX_DATE) > 0) { throw new ActiveObjectsException("Default date value must be strictly before " + MAX_DATE); } return date; }
public static Double checkDouble(Double d) { if (d.compareTo(MAX_VALUE) > 0) { throw new ActiveObjectsException("The max value of double allowed with Active Objects is " + MAX_VALUE + ", checked double is " + d); } if (d.compareTo(MIN_VALUE) < 0) { throw new ActiveObjectsException("The min value of double allowed with Active Objects is " + MIN_VALUE + ", checked double is " + d); } return d; } }
public static Double checkDouble(Double d) { if (d.compareTo(MAX_VALUE) > 0) { throw new ActiveObjectsException("The max value of double allowed with Active Objects is " + MAX_VALUE + ", checked double is " + d); } if (d.compareTo(MIN_VALUE) < 0) { throw new ActiveObjectsException("The min value of double allowed with Active Objects is " + MIN_VALUE + ", checked double is " + d); } return d; } }
public Query alias(Class<? extends RawEntity<?>> table, String alias) { if (aliases.containsValue(alias)) { throw new ActiveObjectsException("There is already a table aliased '" + alias + "' for this query!"); } aliases.put(table, alias); return this; }
public Query alias(Class<? extends RawEntity<?>> table, String alias) { if (aliases.containsValue(alias)) { throw new ActiveObjectsException("There is already a table aliased '" + alias + "' for this query!"); } aliases.put(table, alias); return this; }
public DisposableDataSource getDataSource(Class<? extends Driver> driverClass, String url, String username, String password) { Objects.requireNonNull(dataSourceFactoryClass, "dataSourceFactoryClass can't be null"); try { return dataSourceFactoryClass.newInstance().getDataSource(driverClass, url, username, password); } catch (InstantiationException | IllegalAccessException e) { throw new ActiveObjectsException("Could not create an instance of <" + dataSourceFactoryClass + ">, have you called isAvailable before hand?", e); } }
@Override public T invoke(K k) throws SQLException { final T[] ts = find(type, primaryKeyField + " = ?", k); if (ts.length == 1) { return ts[0]; } else if (ts.length == 0) { return null; } else { throw new ActiveObjectsException("Found more that one object of type '" + type.getName() + "' for key '" + k + "'"); } } };
public <T> T doInTransaction(final TransactionCallback<T> callback) { try { return new Transaction<T>(entityManager) { public T run() { return callback.doInTransaction(); } }.execute(); } catch (SQLException e) { throw new ActiveObjectsException(e); } } }, findDatabaseType(entityManager));
@Override public T invoke(K k) throws SQLException { final T[] ts = find(type, primaryKeyField + " = ?", k); if (ts.length == 1) { return ts[0]; } else if (ts.length == 0) { return null; } else { throw new ActiveObjectsException("Found more that one object of type '" + type.getName() + "' for key '" + k + "'"); } } };
static String checkLength(String name, String errorMsg) { if (enforceLength() && name != null && name.length() > MAX_LENGTH) { throw new ActiveObjectsException(errorMsg); } return name; }
static String checkLength(String name, String errorMsg) { if (enforceLength() && name != null && name.length() > MAX_LENGTH) { throw new ActiveObjectsException(errorMsg); } return name; }
@SuppressWarnings("unchecked") @Override public Enum<?> pullFromDatabase(EntityManager manager, ResultSet res, Class<Enum<?>> type, String columnName) throws SQLException { final String dbValue = res.getString(columnName); if (StringUtils.isBlank(dbValue)) { return null; } try { return Enum.valueOf((Class<? extends Enum>) type, dbValue); } catch (IllegalArgumentException e) { throw new ActiveObjectsException("Could not find enum value for '" + type + "' corresponding to database value '" + dbValue + "'"); } }
@SuppressWarnings("unchecked") @Override public Enum<?> pullFromDatabase(EntityManager manager, ResultSet res, Class<Enum<?>> type, String columnName) throws SQLException { final String dbValue = res.getString(columnName); if (StringUtils.isBlank(dbValue)) { return null; } try { return Enum.valueOf((Class<? extends Enum>) type, dbValue); } catch (IllegalArgumentException e) { throw new ActiveObjectsException("Could not find enum value for '" + type + "' corresponding to database value '" + dbValue + "'"); } }
static SupportedDatabase fromUri(String uri) { for (SupportedDatabase supported : values()) { if (supported.accept(uri)) { return supported; } } throw new ActiveObjectsException("Could not resolve database for database connection URI <" + uri + ">, are you sure this database is supported"); }
private EntityManagerBuilderWithDatabaseProperties getEntityManagerBuilderWithDatabaseProperties(ConnectionPool pool) { if (pool.isAvailable()) { logger.debug("Entity manager will be using connection pool '{}'.", pool); return new EntityManagerBuilderWithDatabaseProperties(getDatabaseProperties(pool)); } else { throw new ActiveObjectsException("Connection pool " + pool + " is not available on the classpath"); } }
public static <K> void validatePrimaryKey(FieldInfo<K> primaryKeyInfo, Object value) { if (null == value) { throw new IllegalArgumentException("Cannot set primary key to NULL"); } TypeInfo<K> typeInfo = primaryKeyInfo.getTypeInfo(); Class<K> javaTypeClass = primaryKeyInfo.getJavaType(); if (!typeInfo.isAllowedAsPrimaryKey()) { throw new ActiveObjectsException(javaTypeClass.getName() + " cannot be used as a primary key!"); } typeInfo.getLogicalType().validate(value); if ((value instanceof String) && StringUtils.isBlank((String) value)) { throw new ActiveObjectsException("Cannot set primary key to blank String"); } }
public EntityManagerBuilderWithDatabaseProperties auto() { for (ConnectionPool pool : ConnectionPool.values()) { if (pool.isAvailable()) { return getEntityManagerBuilderWithDatabaseProperties(pool); } } throw new ActiveObjectsException("Could not find any connection pool! Impossible, " + ConnectionPool.NONE + " should always be an option..."); }