/** * Specifies the {@link PolymorphicTypeMapper} instance to use for all flag value conversion of polymorphic types. * The default type mapper is an empty {@link DefaultPolymorphicTypeMapper} instance (thus using the fully qualified * classname for all values). * * @see #getPolymorphicTypeMapper() */ public void setPolymorphicTypeMapper(PolymorphicTypeMapper typeMapper) { typeMapperLock.writeLock().lock(); try { this.typeMapper = typeMapper; if (typeMapper instanceof DefaultPolymorphicTypeMapper) { ((DefaultPolymorphicTypeMapper) typeMapper).resolveMappings(getTableNameConverter()); } } finally { typeMapperLock.writeLock().unlock(); } }
/** * Specifies the {@link PolymorphicTypeMapper} instance to use for all flag value conversion of polymorphic types. * The default type mapper is an empty {@link DefaultPolymorphicTypeMapper} instance (thus using the fully qualified * classname for all values). * * @see #getPolymorphicTypeMapper() */ public void setPolymorphicTypeMapper(PolymorphicTypeMapper typeMapper) { typeMapperLock.writeLock().lock(); try { this.typeMapper = typeMapper; if (typeMapper instanceof DefaultPolymorphicTypeMapper) { ((DefaultPolymorphicTypeMapper) typeMapper).resolveMappings(getTableNameConverter()); } } finally { typeMapperLock.writeLock().unlock(); } }
/** * Get the table name of the given class entity * * @param entityType the class of the entity * @param escape whether or not to escape the table name * @return the table name */ public static String getTableName(EntityManager em, Class<? extends RawEntity<?>> entityType, boolean escape) { final String tableName = em.getProvider().shorten(em.getTableNameConverter().getName(entityType)); return escape ? em.getProvider().withSchema(tableName) : tableName; }
/** * Counts all entities of the specified type matching the given {@link Query} instance. The SQL runs as a * <code>SELECT COUNT(*)</code> to ensure maximum performance. * * @param type The type of the entities which should be counted. * @param query The {@link Query} instance used to determine the result set which will be counted. * @return The number of entities of the given type which match the specified query. */ public <K> int count(Class<? extends RawEntity<K>> type, Query query) throws SQLException { EntityInfo entityInfo = resolveEntityInfo(type); Connection connection = null; PreparedStatement stmt = null; ResultSet res = null; try { connection = provider.getConnection(); final String sql = query.toSQL(entityInfo, provider, getTableNameConverter(), true); stmt = provider.preparedStatement(connection, sql); provider.setQueryStatementProperties(stmt, query); query.setParameters(this, stmt); res = stmt.executeQuery(); return res.next() ? res.getInt(1) : -1; } finally { closeQuietly(res); closeQuietly(stmt); closeQuietly(connection); } }
/** * Counts all entities of the specified type matching the given {@link Query} instance. The SQL runs as a * <code>SELECT COUNT(*)</code> to ensure maximum performance. * * @param type The type of the entities which should be counted. * @param query The {@link Query} instance used to determine the result set which will be counted. * @return The number of entities of the given type which match the specified query. */ public <K> int count(Class<? extends RawEntity<K>> type, Query query) throws SQLException { EntityInfo entityInfo = resolveEntityInfo(type); Connection connection = null; PreparedStatement stmt = null; ResultSet res = null; try { connection = provider.getConnection(); final String sql = query.toSQL(entityInfo, provider, getTableNameConverter(), true); stmt = provider.preparedStatement(connection, sql); provider.setQueryStatementProperties(stmt, query); query.setParameters(this, stmt); res = stmt.executeQuery(); return res.next() ? res.getInt(1) : -1; } finally { closeQuietly(res); closeQuietly(stmt); closeQuietly(connection); } }
try { conn = provider.getConnection(); final String sql = query.toSQL(entityInfo, provider, getTableNameConverter(), false);
try { conn = provider.getConnection(); final String sql = query.toSQL(entityInfo, provider, getTableNameConverter(), false);
try { conn = provider.getConnection(); final String sql = query.toSQL(entityInfo, provider, getTableNameConverter(), false);
try { conn = provider.getConnection(); final String sql = query.toSQL(entityInfo, provider, getTableNameConverter(), false);