├── .gitignore ├── CONTRIBUTING.md ├── README.md ├── build.gradle ├── build.gradle-4 ├── build.properties.dist ├── changelog.txt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lgpl.txt ├── libraries.gradle └── src ├── docbook └── reference │ ├── .cvsignore │ ├── README │ ├── build.xml │ ├── en │ ├── images │ │ └── hibernate_logo_a.png │ ├── master.xml │ ├── modules │ │ ├── architecture.xml │ │ ├── configuration.xml │ │ ├── limitations.xml │ │ ├── querying.xml │ │ ├── resharding.xml │ │ └── shardstrategy.xml │ └── styles │ │ ├── fopdf.xsl │ │ ├── html.css │ │ ├── html.xsl │ │ └── html_chunk.xsl │ └── fr │ ├── images │ └── hibernate_logo_a.png │ ├── master.xml │ ├── modules │ ├── architecture.xml │ ├── configuration.xml │ ├── limitations.xml │ ├── querying.xml │ ├── resharding.xml │ └── shardstrategy.xml │ └── styles │ ├── fopdf.xsl │ ├── html.css │ ├── html.xsl │ └── html_chunk.xsl ├── main └── java │ └── org │ └── hibernate │ └── shards │ ├── BaseHasShardIdList.java │ ├── CrossShardAssociationException.java │ ├── HasShardIdList.java │ ├── Shard.java │ ├── ShardId.java │ ├── ShardImpl.java │ ├── ShardOperation.java │ ├── ShardedConfiguration.java │ ├── ShardedTransaction.java │ ├── cfg │ ├── ConfigurationToShardConfigurationAdapter.java │ ├── ShardConfiguration.java │ └── ShardedEnvironment.java │ ├── criteria │ ├── AddCriterionEvent.java │ ├── AddOrderEvent.java │ ├── CreateAliasEvent.java │ ├── CreateSubcriteriaEvent.java │ ├── CriteriaEvent.java │ ├── CriteriaFactory.java │ ├── CriteriaFactoryImpl.java │ ├── CriteriaId.java │ ├── ExitOperationsCriteriaCollector.java │ ├── InMemoryOrderBy.java │ ├── SetCacheModeEvent.java │ ├── SetCacheRegionEvent.java │ ├── SetCacheableEvent.java │ ├── SetCommentEvent.java │ ├── SetFetchModeEvent.java │ ├── SetFetchSizeEvent.java │ ├── SetFirstResultEvent.java │ ├── SetFlushModeEvent.java │ ├── SetLockModeEvent.java │ ├── SetMaxResultsEvent.java │ ├── SetProjectionEvent.java │ ├── SetReadOnlyEvent.java │ ├── SetResultTransformerEvent.java │ ├── SetTimeoutEvent.java │ ├── ShardedCriteria.java │ ├── ShardedCriteriaImpl.java │ ├── ShardedSubcriteria.java │ ├── ShardedSubcriteriaImpl.java │ ├── SubcriteriaFactory.java │ └── SubcriteriaFactoryImpl.java │ ├── engine │ ├── ShardedSessionFactoryImplementor.java │ └── ShardedSessionImplementor.java │ ├── id │ ├── GeneratorRequiringControlSessionProvider.java │ ├── ShardEncodingIdentifierGenerator.java │ ├── ShardedTableHiLoGenerator.java │ └── ShardedUUIDGenerator.java │ ├── loadbalance │ ├── BaseShardLoadBalancer.java │ ├── RandomShardLoadBalancer.java │ ├── RoundRobinShardLoadBalancer.java │ └── ShardLoadBalancer.java │ ├── package-info.java │ ├── query │ ├── AdHocQueryFactoryImpl.java │ ├── ExitOperationsQueryCollector.java │ ├── NamedQueryFactoryImpl.java │ ├── QueryEvent.java │ ├── QueryFactory.java │ ├── QueryId.java │ ├── QueryResult.java │ ├── SetBigDecimalEvent.java │ ├── SetBigIntegerEvent.java │ ├── SetBinaryEvent.java │ ├── SetBooleanEvent.java │ ├── SetByteEvent.java │ ├── SetCacheModeEvent.java │ ├── SetCacheRegionEvent.java │ ├── SetCacheableEvent.java │ ├── SetCalendarDateEvent.java │ ├── SetCalendarEvent.java │ ├── SetCharacterEvent.java │ ├── SetCommentEvent.java │ ├── SetDateEvent.java │ ├── SetDoubleEvent.java │ ├── SetEntityEvent.java │ ├── SetFetchSizeEvent.java │ ├── SetFirstResultEvent.java │ ├── SetFloatEvent.java │ ├── SetFlushModeEvent.java │ ├── SetIntegerEvent.java │ ├── SetLocaleEvent.java │ ├── SetLockModeEvent.java │ ├── SetLockOptionsEvent.java │ ├── SetLongEvent.java │ ├── SetMaxResultsEvent.java │ ├── SetParameterEvent.java │ ├── SetParameterListEvent.java │ ├── SetParametersEvent.java │ ├── SetPropertiesEvent.java │ ├── SetReadOnlyEvent.java │ ├── SetResultTransformerEvent.java │ ├── SetSerializableEvent.java │ ├── SetShortEvent.java │ ├── SetStringEvent.java │ ├── SetTextEvent.java │ ├── SetTimeEvent.java │ ├── SetTimeoutEvent.java │ ├── SetTimestampEvent.java │ ├── ShardedQuery.java │ ├── ShardedQueryImpl.java │ ├── ShardedSQLQuery.java │ └── ShardedSQLQueryImpl.java │ ├── session │ ├── BaseStatefulInterceptorFactory.java │ ├── ControlSessionProvider.java │ ├── CrossShardRelationshipDetectingInterceptor.java │ ├── CrossShardRelationshipDetectingInterceptorDecorator.java │ ├── DeleteOperation.java │ ├── DisableFetchProfileOpenSessionEvent.java │ ├── DisableFilterOpenSessionEvent.java │ ├── EnableFetchProfileOpenSessionEvent.java │ ├── EnableFilterOpenSessionEvent.java │ ├── OpenSessionEvent.java │ ├── RefreshOperation.java │ ├── RequiresSession.java │ ├── SaveOrUpdateOperation.java │ ├── SetCacheModeOpenSessionEvent.java │ ├── SetDefaultReadOnlyOpenSessionEvent.java │ ├── SetFlushModeOpenSessionEvent.java │ ├── SetReadOnlyOpenSessionEvent.java │ ├── SetSessionOnRequiresSessionEvent.java │ ├── SetupTransactionOpenSessionEvent.java │ ├── ShardAware.java │ ├── ShardAwareInterceptor.java │ ├── ShardIdResolver.java │ ├── ShardedSession.java │ ├── ShardedSessionException.java │ ├── ShardedSessionFactory.java │ ├── ShardedSessionFactoryImpl.java │ ├── ShardedSessionImpl.java │ ├── StatefulInterceptorFactory.java │ ├── SubsetShardedSessionFactoryImpl.java │ └── UpdateOperation.java │ ├── stat │ └── ShardedSessionStatistics.java │ ├── strategy │ ├── ShardStrategy.java │ ├── ShardStrategyFactory.java │ ├── ShardStrategyImpl.java │ ├── access │ │ ├── LoadBalancedSequentialShardAccessStrategy.java │ │ ├── ParallelShardAccessStrategy.java │ │ ├── ParallelShardOperationCallable.java │ │ ├── SequentialShardAccessStrategy.java │ │ ├── ShardAccessStrategy.java │ │ └── StartAwareFutureTask.java │ ├── exit │ │ ├── AggregateExitOperation.java │ │ ├── AvgResultsExitOperation.java │ │ ├── ConcatenateListsExitStrategy.java │ │ ├── CountExitOperation.java │ │ ├── DistinctExitOperation.java │ │ ├── ExitOperation.java │ │ ├── ExitOperationUtils.java │ │ ├── ExitOperationsCollector.java │ │ ├── ExitStrategy.java │ │ ├── FirstNonNullResultExitStrategy.java │ │ ├── FirstResultExitOperation.java │ │ ├── MaxResultsExitOperation.java │ │ ├── OrderExitOperation.java │ │ ├── ProjectionExitOperation.java │ │ ├── ProjectionExitOperationFactory.java │ │ ├── RowCountExitOperation.java │ │ └── ShardedAvgExitOperation.java │ ├── resolution │ │ ├── AllShardsShardResolutionStrategy.java │ │ ├── BaseShardResolutionStrategy.java │ │ └── ShardResolutionStrategy.java │ └── selection │ │ ├── BaseShardSelectionStrategy.java │ │ ├── LoadBalancedShardSelectionStrategy.java │ │ ├── RoundRobinShardSelectionStrategy.java │ │ ├── ShardResolutionStrategyData.java │ │ ├── ShardResolutionStrategyDataImpl.java │ │ └── ShardSelectionStrategy.java │ ├── transaction │ └── ShardedTransactionImpl.java │ └── util │ ├── InterceptorDecorator.java │ ├── InterceptorList.java │ ├── Iterables.java │ ├── Lists.java │ ├── Maps.java │ ├── Pair.java │ ├── Preconditions.java │ ├── Sets.java │ └── StringUtil.java └── test ├── java └── org │ └── hibernate │ └── shards │ ├── BaseHasShardIdListTest.java │ ├── InstanceShardStrategyImplTest.java │ ├── PermutationHelper.java │ ├── ShardDefaultMock.java │ ├── ShardImplTest.java │ ├── ShardOperationDefaultMock.java │ ├── ShardedConfigurationTest.java │ ├── ShardedSessionFactoryDefaultMock.java │ ├── ShardedTransactionDefaultMock.java │ ├── criteria │ ├── AddCriterionEventTest.java │ ├── AddOrderEventTest.java │ ├── CreateAliasEventTest.java │ ├── CreateSubcriteriaEventTest.java │ ├── CriteriaEventDefaultMock.java │ ├── CriteriaFactoryDefaultMock.java │ ├── CriteriaFactoryImplTest.java │ ├── InMemoryOrderByTest.java │ ├── SetCacheModeEventTest.java │ ├── SetCacheRegionEventTest.java │ ├── SetCacheableEventTest.java │ ├── SetCommentEventTest.java │ ├── SetFetchModeEventTest.java │ ├── SetFetchSizeEventTest.java │ ├── SetFirstResultEventTest.java │ ├── SetFlushModeEventTest.java │ ├── SetLockModeEventTest.java │ ├── SetMaxResultsEventTest.java │ ├── SetProjectionEventTest.java │ ├── SetResultTransformerEventTest.java │ ├── SetTimeoutEventTest.java │ ├── ShardedCriteriaDefaultMock.java │ ├── ShardedCriteriaImplTest.java │ ├── ShardedSubcriteriaImplTest.java │ ├── SubcriteriaFactoryDefaultMock.java │ └── SubcriteriaFactoryImplTest.java │ ├── defaultmock │ ├── ClassMetadataDefaultMock.java │ ├── CriteriaDefaultMock.java │ ├── EntityPersisterDefaultMock.java │ ├── InterceptorDefaultMock.java │ ├── QueryDefaultMock.java │ ├── SessionDefaultMock.java │ ├── SessionFactoryDefaultMock.java │ ├── SessionImplementorDefaultMock.java │ ├── ShardConfigurationDefaultMock.java │ └── TypeDefaultMock.java │ ├── engine │ └── ShardedSessionImplementorDefaultMock.java │ ├── example │ ├── WeatherReport.java │ └── WeatherReportApp.java │ ├── id │ ├── ShardedTableHiLoGeneratorTest.java │ ├── ShardedUUIDGeneratorTest.java │ └── UUIDBigIntGenerator.java │ ├── integration │ ├── BaseShardingIntegrationTestCase.java │ ├── BaseShardingIntegrationTestCasePermutedIntegrationTest.java │ ├── ConfigPermutedIntegrationTest.java │ ├── DbAccessPermutedIntegrationTest.java │ ├── IdGenType.java │ ├── Permutation.java │ ├── ShardAccessStrategyType.java │ ├── id │ │ └── IdGeneratorPermutedIntegrationTest.java │ ├── model │ │ ├── InterceptorBehaviorPermutedIntegrationTest.java │ │ ├── MemoryLeakTest.java │ │ ├── ModelCriteriaPermutedIntegrationTest.java │ │ ├── ModelDataFactory.java │ │ ├── ModelIntegrationTest.java │ │ ├── ModelPermutedIntegrationTest.java │ │ └── ModelQueryPermutedIntegrationTest.java │ ├── package-info.java │ └── platform │ │ ├── BaseDatabasePlatform.java │ │ ├── DatabasePlatform.java │ │ ├── DatabasePlatformFactory.java │ │ ├── hsql │ │ └── HSQLDatabasePlatform.java │ │ └── mysql │ │ └── MySQLDatabasePlatform.java │ ├── loadbalance │ ├── RoundRobinShardLoadBalancerTest.java │ └── ShardLoadBalancerDefaultMock.java │ ├── model │ ├── Building.java │ ├── Elevator.java │ ├── Escalator.java │ ├── Floor.java │ ├── IdIsBaseType.java │ ├── Office.java │ ├── Person.java │ ├── Tenant.java │ └── Window.java │ ├── query │ ├── QueryEventDefaultMock.java │ ├── QueryFactoryDefaultMock.java │ ├── SetBigDecimalEventTest.java │ ├── SetBigIntegerEventTest.java │ ├── SetBinaryEventTest.java │ ├── SetBooleanEventTest.java │ ├── SetByteEventTest.java │ ├── SetCacheModeEventTest.java │ ├── SetCacheRegionEventTest.java │ ├── SetCacheableEventTest.java │ ├── SetCalendarDateEventTest.java │ ├── SetCalendarEventTest.java │ ├── SetCharacterEventTest.java │ ├── SetCommentEventTest.java │ ├── SetDateEventTest.java │ ├── SetDoubleEventTest.java │ ├── SetEntityEventTest.java │ ├── SetFetchSizeEventTest.java │ ├── SetFirstResultEventTest.java │ ├── SetFloatEventTest.java │ ├── SetFlushModeEventTest.java │ ├── SetIntegerEventTest.java │ ├── SetLocaleEventTest.java │ ├── SetLockModeEventTest.java │ ├── SetLongEventTest.java │ ├── SetMaxResultsEventTest.java │ ├── SetParameterEventTest.java │ ├── SetParameterListEventTest.java │ ├── SetParametersEventTest.java │ ├── SetPropertiesEventTest.java │ ├── SetReadOnlyEventTest.java │ ├── SetResultTransformerEventTest.java │ ├── SetSerializableEventTest.java │ ├── SetShortEventTest.java │ ├── SetStringEventTest.java │ ├── SetTextEventTest.java │ ├── SetTimeEventTest.java │ ├── SetTimeoutEventTest.java │ ├── SetTimestampEventTest.java │ └── ShardedQueryDefaultMock.java │ ├── session │ ├── CrossShardRelationshipDetectingInterceptorDecoratorTest.java │ ├── CrossShardRelationshipDetectingInterceptorTest.java │ ├── DisableFilterOpenSessionEventTest.java │ ├── EnableFilterOpenSessionEventTest.java │ ├── OpenSessionEventDefaultMock.java │ ├── SetCacheModeOpenSessionEventTest.java │ ├── SetFlushModeOpenSessionEventTest.java │ ├── SetReadOnlyOpenSessionEventTest.java │ ├── SetSessionOnRequiresSessionEventTest.java │ ├── ShardAwareInterceptorTest.java │ ├── ShardIdResolverDefaultMock.java │ ├── ShardedSessionFactoryImplTest.java │ └── ShardedSessionImplTest.java │ ├── strategy │ ├── ShardStrategyDefaultMock.java │ ├── ShardStrategyFactoryDefaultMock.java │ ├── access │ │ ├── ParallelShardAccessStrategyTest.java │ │ ├── ParallelShardOperationCallableTest.java │ │ ├── ShardAccessStrategyDefaultMock.java │ │ └── StartAwareFutureTaskTest.java │ ├── exit │ │ ├── AggregateExitOperationTest.java │ │ ├── AvgResultsExitOperationTest.java │ │ ├── ExitOperationUtilsTest.java │ │ ├── ExitStrategyDefaultMock.java │ │ ├── FirstNonNullResultExitStrategyTest.java │ │ ├── FirstResultExitOperationTest.java │ │ ├── MaxResultExitOperationTest.java │ │ ├── OrderExitOperationTest.java │ │ ├── ProjectionExitOperationFactoryTest.java │ │ └── RowCountExitOperationTest.java │ ├── resolution │ │ ├── ShardResolutionStrategyDataDefaultMock.java │ │ └── ShardResolutionStrategyDefaultMock.java │ └── selection │ │ ├── LoadBalancedShardSelectionStrategyTest.java │ │ └── ShardSelectionStrategyDefaultMock.java │ ├── transaction │ └── ShardedTransactionImplTest.java │ └── util │ ├── DatabaseUtils.java │ ├── JdbcStrategy.java │ └── JdbcUtil.java └── resources ├── log4j.properties └── org └── hibernate └── shards ├── example ├── hibernate0.cfg.xml ├── hibernate1.cfg.xml ├── hibernate2.cfg.xml └── weather.hbm.xml └── integration └── platform ├── hsql └── config │ ├── mappings-shardedTableHiLo.hbm.xml │ ├── mappings-shardedUUID.hbm.xml │ ├── mappings.hbm.xml │ ├── shard0.hibernate.cfg.xml │ ├── shard1.hibernate.cfg.xml │ └── shard2.hibernate.cfg.xml └── mysql └── config ├── mappings-shardedTableHiLo.hbm.xml ├── mappings-shardedUUID.hbm.xml ├── mappings.hbm.xml ├── shard0.hibernate.cfg.xml ├── shard1.hibernate.cfg.xml └── shard2.hibernate.cfg.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Typically *NIX text editors, by default, append '~' to files on saving to make backups 2 | *~ 3 | 4 | # Gradle work directory 5 | .gradle 6 | 7 | # Build output directies 8 | /target 9 | */target 10 | /build 11 | */build 12 | testdb 13 | 14 | # IntelliJ specific files/directories 15 | out 16 | .idea 17 | *.ipr 18 | *.iws 19 | *.iml 20 | atlassian-ide-plugin.xml 21 | 22 | # Eclipse specific files/directories 23 | .classpath 24 | .project 25 | .settings 26 | .metadata 27 | bin 28 | 29 | # NetBeans specific files/directories 30 | .nbattrs 31 | 32 | # Miscellaneous 33 | *.log 34 | .clover 35 | 36 | # JBoss Transactions 37 | ObjectStore 38 | 39 | # Profiler and heap dumps 40 | *.jps 41 | *.hprof 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repo holds the Hibernate Shards project which is no longer supported and therefore has been archived 2 | -------------------------------------------------------------------------------- /build.properties.dist: -------------------------------------------------------------------------------- 1 | common.dir=. 2 | src.dir=src 3 | test.dir=test 4 | hibernate-core.home=../hibernate-3.2 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibernate/hibernate-shards/487d9e672b1b388fdace42e55a9dce4f41574eb1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Sep 01 02:41:24 CST 2011 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.1-bin.zip 7 | -------------------------------------------------------------------------------- /src/docbook/reference/.cvsignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /src/docbook/reference/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/docbook/reference/en/images/hibernate_logo_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibernate/hibernate-shards/487d9e672b1b388fdace42e55a9dce4f41574eb1/src/docbook/reference/en/images/hibernate_logo_a.png -------------------------------------------------------------------------------- /src/docbook/reference/fr/images/hibernate_logo_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibernate/hibernate-shards/487d9e672b1b388fdace42e55a9dce4f41574eb1/src/docbook/reference/fr/images/hibernate_logo_a.png -------------------------------------------------------------------------------- /src/docbook/reference/fr/master.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibernate/hibernate-shards/487d9e672b1b388fdace42e55a9dce4f41574eb1/src/docbook/reference/fr/master.xml -------------------------------------------------------------------------------- /src/docbook/reference/fr/modules/architecture.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibernate/hibernate-shards/487d9e672b1b388fdace42e55a9dce4f41574eb1/src/docbook/reference/fr/modules/architecture.xml -------------------------------------------------------------------------------- /src/docbook/reference/fr/modules/querying.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibernate/hibernate-shards/487d9e672b1b388fdace42e55a9dce4f41574eb1/src/docbook/reference/fr/modules/querying.xml -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/HasShardIdList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * Interface for objects that can provide a List of ShardIds. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public interface HasShardIdList { 29 | 30 | /** 31 | * @return an unmodifiable list of {@link ShardId}s 32 | */ 33 | List getShardIds(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/ShardOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards; 20 | 21 | /** 22 | * Simple interface used to reference something we can do against a {@link Shard}. 23 | * 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public interface ShardOperation { 27 | 28 | /** 29 | * @param shard the shard to execute against 30 | * @return the result of the operation 31 | */ 32 | T execute(Shard shard); 33 | 34 | /** 35 | * @return the name of the operation (useful for logging and debugging) 36 | */ 37 | String getOperationName(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/ShardedTransaction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards; 20 | 21 | import org.hibernate.Session; 22 | import org.hibernate.Transaction; 23 | 24 | /** 25 | * Simple interface to represent a shard-aware {@link Transaction}. 26 | * 27 | * @author Tomislav Nad 28 | */ 29 | public interface ShardedTransaction extends Transaction { 30 | 31 | /** 32 | * If a new Session is opened while ShardedTransaction exists, this method is 33 | * called with the Session as argument. Implementations should set up a 34 | * transaction for this session and sync it with ShardedTransaction 35 | * 36 | * @param session the Session on which the Transaction should be setup 37 | */ 38 | void setupTransaction(Session session); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/AddCriterionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.criterion.Criterion; 23 | 24 | /** 25 | * Event that allows a Criterion to be lazily added to a Criteria. 26 | * @see Criteria#add(Criterion) 27 | * 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | class AddCriterionEvent implements CriteriaEvent { 31 | 32 | // the Criterion we're going to add when the event fires 33 | private final Criterion criterion; 34 | 35 | public AddCriterionEvent(Criterion criterion) { 36 | this.criterion = criterion; 37 | } 38 | 39 | 40 | public void onEvent(Criteria criteria) { 41 | criteria.add(criterion); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/AddOrderEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.criterion.Order; 23 | 24 | /** 25 | * Event that allows an Order to be lazily added to a Criteria. 26 | * @see Criteria#addOrder(Order) 27 | * 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | class AddOrderEvent implements CriteriaEvent { 31 | 32 | // the Order we're going to add when the event fires 33 | private final Order order; 34 | 35 | /** 36 | * Construct an AddOrderEvent 37 | * 38 | * @param order the Order we'll add when the event fires 39 | */ 40 | public AddOrderEvent(Order order) { 41 | this.order = order; 42 | } 43 | 44 | public void onEvent(Criteria criteria) { 45 | criteria.addOrder(order); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/CreateSubcriteriaEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Event that allows a Subcriteria to be lazily added to a Criteria. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class CreateSubcriteriaEvent implements CriteriaEvent { 29 | 30 | private final SubcriteriaFactory subcriteriaFactory; 31 | private final ShardedSubcriteriaImpl.SubcriteriaRegistrar subcriteriaRegistrar; 32 | 33 | public CreateSubcriteriaEvent(SubcriteriaFactory subcriteriaFactory, ShardedSubcriteriaImpl.SubcriteriaRegistrar subcriteriaRegistrar) { 34 | this.subcriteriaFactory = subcriteriaFactory; 35 | this.subcriteriaRegistrar = subcriteriaRegistrar; 36 | } 37 | 38 | public void onEvent(Criteria criteria) { 39 | subcriteriaRegistrar.establishSubcriteria(criteria, subcriteriaFactory); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/CriteriaEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Interface for events that can be laziliy applied to a 25 | * {@link org.hibernate.Criteria}. Useful because we don't allocate a 26 | * {@link org.hibernate.Criteria} until we actually need it, and programmers 27 | * might be calling a variety of methods against the 28 | * {@link org.hibernate.shards.criteria.ShardedCriteria} 29 | * which need to be applied to the actual {@link org.hibernate.Criteria} once 30 | * the actual {@link org.hibernate.Criteria} when it is allocated. 31 | * 32 | * @author maxr@google.com (Max Ross) 33 | */ 34 | public interface CriteriaEvent { 35 | 36 | /** 37 | * Apply the event 38 | * 39 | * @param criteria the Criteria to apply the event to 40 | */ 41 | void onEvent(Criteria criteria); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/CriteriaFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.Session; 23 | 24 | /** 25 | * Factory that knows how to create a {@link Criteria} for a given {@link Session} 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public interface CriteriaFactory { 30 | 31 | /** 32 | * Create a {@link Criteria} for the given {@link Session} 33 | * 34 | * @param session the {@link Session} to be used when creating the {@link Criteria} 35 | * @return a {@link Criteria} associated with the given {@link Session} 36 | */ 37 | Criteria createCriteria(Session session); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SetCacheRegionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Event that allows the cache region of a {@link Criteria} to be set lazily. 25 | * @see Criteria#setCacheRegion(String) 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetCacheRegionEvent implements CriteriaEvent { 30 | 31 | // the cache region that we'll set on the Criteria when the event fires 32 | private final String cacheRegion; 33 | 34 | /** 35 | * Construct a CacheRegionEvent 36 | * 37 | * @param cacheRegion the cache region we'll set on the {@link Criteria} 38 | * when the event fires. 39 | */ 40 | public SetCacheRegionEvent(String cacheRegion) { 41 | this.cacheRegion = cacheRegion; 42 | } 43 | 44 | public void onEvent(Criteria criteria) { 45 | criteria.setCacheRegion(cacheRegion); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SetCacheableEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Event that allows the cacheability of a {@link Criteria} to be set lazily. 25 | * @see Criteria#setCacheable(boolean) 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetCacheableEvent implements CriteriaEvent { 30 | 31 | // the value to which we're going to set the cacheability of the Criteria 32 | // when the event fires 33 | private boolean cacheable; 34 | 35 | /** 36 | * Construct a SetCacheableEvent 37 | * 38 | * @param cacheable the value to which we'll set the cacheability when the event 39 | * fires 40 | */ 41 | public SetCacheableEvent(boolean cacheable) { 42 | this.cacheable = cacheable; 43 | } 44 | 45 | public void onEvent(Criteria criteria) { 46 | criteria.setCacheable(cacheable); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SetCommentEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Event that allows the comment of a {@link Criteria} to be set lazily. 25 | * @see Criteria#setComment(String) 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetCommentEvent implements CriteriaEvent { 30 | 31 | // the comment that we'll set on the Criteria when the event fires 32 | private final String comment; 33 | 34 | /** 35 | * Construct a SetCommentEvent 36 | * 37 | * @param comment the comment we'll set on the {@link Criteria} 38 | * when the event fires. 39 | */ 40 | public SetCommentEvent(String comment) { 41 | this.comment = comment; 42 | } 43 | 44 | public void onEvent(Criteria criteria) { 45 | criteria.setComment(comment); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SetFetchSizeEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Event that allows the fetch size of a {@link Criteria} to be set lazily. 25 | * @see Criteria#setFetchSize(int) 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetFetchSizeEvent implements CriteriaEvent { 30 | 31 | // the fetchSize we'll set on the Criteria when the event fires. 32 | private final int fetchSize; 33 | 34 | /** 35 | * Construct a SetFetchSizeEvent 36 | * 37 | * @param fetchSize the fetchSize that 38 | * we'll set on the {@link Criteria} when the event fires. 39 | */ 40 | public SetFetchSizeEvent(int fetchSize) { 41 | this.fetchSize = fetchSize; 42 | } 43 | 44 | public void onEvent(Criteria criteria) { 45 | criteria.setFetchSize(fetchSize); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SetFirstResultEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Event that allows the firstResult of a {@link Criteria} to be set lazily. 25 | * @see Criteria#setFirstResult(int) 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetFirstResultEvent implements CriteriaEvent { 30 | 31 | // the firstResult that we'll set on the Criteria when the event fires 32 | private final int firstResult; 33 | 34 | /** 35 | * Construct a SetFirstResultEvent 36 | * 37 | * @param firstResult the firstResult that 38 | * we'll set on the {@link Criteria} when the event fires. 39 | */ 40 | public SetFirstResultEvent(int firstResult) { 41 | this.firstResult = firstResult; 42 | } 43 | 44 | public void onEvent(Criteria criteria) { 45 | criteria.setFirstResult(firstResult); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SetReadOnlyEvent.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.criteria; 2 | 3 | import org.hibernate.Criteria; 4 | 5 | class SetReadOnlyEvent implements CriteriaEvent { 6 | 7 | private final boolean readOnly; 8 | 9 | public SetReadOnlyEvent(final boolean readOnly) { 10 | this.readOnly = readOnly; 11 | } 12 | 13 | @Override 14 | public void onEvent(final Criteria criteria) { 15 | criteria.setReadOnly(readOnly); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SetTimeoutEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Event that allows the timeout of a {@link Criteria} to be set lazily. 25 | * @see Criteria#setTimeout(int) 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetTimeoutEvent implements CriteriaEvent { 30 | 31 | // the timeout we'll set on the Criteria when the event fires. 32 | private final int timeout; 33 | 34 | /** 35 | * Constructs a SetTimeoutEvent 36 | * 37 | * @param timeout the timeout we'll set on the {@link Criteria} when the 38 | * event fires. 39 | */ 40 | public SetTimeoutEvent(int timeout) { 41 | this.timeout = timeout; 42 | } 43 | 44 | public void onEvent(Criteria criteria) { 45 | criteria.setTimeout(timeout); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/ShardedCriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Interface for a shard-aware {@link Criteria} implementation. 25 | * @see Criteria 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public interface ShardedCriteria extends Criteria { 30 | 31 | /** 32 | * @return the CriteriaId of this ShardedCriteria instance. 33 | */ 34 | CriteriaId getCriteriaId(); 35 | 36 | /** 37 | * 38 | * @return the CriteriaFactory of this ShardedCriteria instance. 39 | */ 40 | CriteriaFactory getCriteriaFactory(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/ShardedSubcriteria.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.impl.CriteriaImpl; 23 | 24 | /** 25 | * Interface describing a {@link CriteriaImpl.Subcriteria} 26 | * that is shard-aware. A ShardedSubcriteria must know how to provide 27 | * a reference to its parent {@link ShardedCriteria}. 28 | * 29 | * @author maxr@google.com (Max Ross) 30 | * @see CriteriaImpl.Subcriteria 31 | */ 32 | interface ShardedSubcriteria extends Criteria { 33 | 34 | /** 35 | * @return the owning ShardedCriteria 36 | */ 37 | ShardedCriteria getParentCriteria(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/criteria/SubcriteriaFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * Interface describing an object tha knows how to create {@link Criteria}. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public interface SubcriteriaFactory { 29 | 30 | /** 31 | * Create a sub {@link Criteria} with the given parent and events 32 | * 33 | * @param parent the parent 34 | * @param events the events to apply 35 | * @return a criteria with the given parent and events 36 | */ 37 | Criteria createSubcriteria(Criteria parent, Iterable events); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/engine/ShardedSessionFactoryImplementor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.engine; 20 | 21 | import org.hibernate.engine.SessionFactoryImplementor; 22 | import org.hibernate.shards.ShardId; 23 | import org.hibernate.shards.session.ShardedSessionFactory; 24 | 25 | import java.util.Map; 26 | import java.util.Set; 27 | 28 | /** 29 | * Internal interface for implementors of ShardedSessionFactory 30 | * 31 | * @author Tomislav Nad 32 | */ 33 | public interface ShardedSessionFactoryImplementor extends ShardedSessionFactory, SessionFactoryImplementor { 34 | 35 | Map> getSessionFactoryShardIdMap(); 36 | 37 | boolean containsFactory(SessionFactoryImplementor factory); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/engine/ShardedSessionImplementor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.engine; 20 | 21 | import org.hibernate.shards.Shard; 22 | import org.hibernate.shards.session.ShardedSession; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Defines the internal contract between the ShardedSession and other 28 | * parts of Hibernate Shards. 29 | * 30 | * @author Tomislav Nad 31 | * @see ShardedSession the interface to the application 32 | * @see org.hibernate.shards.session.ShardedSessionImpl the actual implementation 33 | */ 34 | public interface ShardedSessionImplementor { 35 | 36 | /** 37 | * Gets all the shards the ShardedSession is spanning. 38 | * 39 | * @return list of all shards the ShardedSession is associated with 40 | */ 41 | List getShards(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/id/GeneratorRequiringControlSessionProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.id; 20 | 21 | import org.hibernate.shards.session.ControlSessionProvider; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public interface GeneratorRequiringControlSessionProvider { 27 | 28 | void setControlSessionProvider(ControlSessionProvider provider); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/id/ShardEncodingIdentifierGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.id; 20 | 21 | import org.hibernate.id.IdentifierGenerator; 22 | import org.hibernate.shards.ShardId; 23 | 24 | import java.io.Serializable; 25 | 26 | /** 27 | * @author Tomislav Nad 28 | */ 29 | public interface ShardEncodingIdentifierGenerator extends IdentifierGenerator { 30 | 31 | ShardId extractShardId(Serializable identifier); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/loadbalance/ShardLoadBalancer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.loadbalance; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | /** 24 | * Describes a load balance for shards. 25 | * Implementations are expected to be threadsafe. 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public interface ShardLoadBalancer { 30 | 31 | /** 32 | * @return the next ShardId 33 | */ 34 | ShardId getNextShardId(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/AdHocQueryFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | import org.hibernate.SQLQuery; 23 | import org.hibernate.Session; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class AdHocQueryFactoryImpl implements QueryFactory { 29 | 30 | private final String queryString; 31 | 32 | public AdHocQueryFactoryImpl(final String queryString) { 33 | this.queryString = queryString; 34 | } 35 | 36 | @Override 37 | public Query createQuery(final Session session) { 38 | return session.createQuery(queryString); 39 | } 40 | 41 | @Override 42 | public SQLQuery createSQLQuery(final Session session) { 43 | return session.createSQLQuery(queryString); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/NamedQueryFactoryImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | import org.hibernate.SQLQuery; 23 | import org.hibernate.Session; 24 | 25 | /** 26 | * Facilitates use of named queries when using ShardedQuery. 27 | * 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | public class NamedQueryFactoryImpl implements QueryFactory { 31 | 32 | private final String queryName; 33 | 34 | public NamedQueryFactoryImpl(final String queryName) { 35 | this.queryName = queryName; 36 | } 37 | 38 | @Override 39 | public Query createQuery(final Session session) { 40 | return session.getNamedQuery(queryName); 41 | } 42 | 43 | @Override 44 | public SQLQuery createSQLQuery(final Session session) { 45 | throw new UnsupportedOperationException("no such thing as named SQLQuery"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/QueryEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | 23 | /** 24 | * Interface for events that can be lazily applied to a 25 | * {@link org.hibernate.Query}. Useful because we don't allocate a 26 | * {@link org.hibernate.Query} until we actually need it, and programmers 27 | * might be calling a variety of methods against 28 | * {@link org.hibernate.shards.query.ShardedQueryImpl} 29 | * which need to be applied to the actual {@link org.hibernate.Query} when 30 | * it is allocated. 31 | * 32 | * @author Maulik Shah 33 | */ 34 | 35 | public interface QueryEvent { 36 | 37 | /** 38 | * Apply the event 39 | * 40 | * @param query the Query to apply the event to 41 | */ 42 | void onEvent(Query query); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/QueryFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | import org.hibernate.SQLQuery; 23 | import org.hibernate.Session; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public interface QueryFactory { 29 | 30 | Query createQuery(Session session); 31 | 32 | SQLQuery createSQLQuery(Session session); 33 | } -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/QueryId.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | /** 22 | * @author Maulik Shah 23 | */ 24 | public class QueryId { 25 | 26 | private final int id; 27 | 28 | public QueryId(int id) { 29 | this.id = id; 30 | } 31 | 32 | public int getId() { 33 | return id; 34 | } 35 | 36 | public boolean equals(Object o) { 37 | if (this == o) { 38 | return true; 39 | } 40 | if (!(o instanceof QueryId)) { 41 | return false; 42 | } 43 | 44 | final QueryId queryId = (QueryId) o; 45 | 46 | if (id != queryId.id) { 47 | return false; 48 | } 49 | 50 | return true; 51 | } 52 | 53 | public int hashCode() { 54 | return id; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetCacheModeEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.CacheMode; 22 | import org.hibernate.Query; 23 | 24 | /** 25 | * @author Maulik Shah 26 | */ 27 | public class SetCacheModeEvent implements QueryEvent { 28 | 29 | private final CacheMode cacheMode; 30 | 31 | public SetCacheModeEvent(CacheMode cacheMode) { 32 | this.cacheMode = cacheMode; 33 | } 34 | 35 | public void onEvent(Query query) { 36 | query.setCacheMode(cacheMode); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetCacheRegionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | /** 23 | * @author Maulik Shah 24 | */ 25 | public class SetCacheRegionEvent implements QueryEvent { 26 | 27 | private final String cacheRegion; 28 | 29 | public SetCacheRegionEvent(String cacheRegion) { 30 | this.cacheRegion = cacheRegion; 31 | } 32 | 33 | public void onEvent(Query query) { 34 | query.setCacheRegion(cacheRegion); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetCacheableEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | /** 23 | * @author Maulik Shah 24 | */ 25 | public class SetCacheableEvent implements QueryEvent { 26 | 27 | private final boolean cacheable; 28 | 29 | public SetCacheableEvent(boolean cacheable) { 30 | this.cacheable = cacheable; 31 | } 32 | 33 | public void onEvent(Query query) { 34 | query.setCacheable(cacheable); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetCommentEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | /** 23 | * @author Maulik Shah 24 | */ 25 | public class SetCommentEvent implements QueryEvent { 26 | 27 | private final String comment; 28 | 29 | public SetCommentEvent(String comment) { 30 | this.comment = comment; 31 | } 32 | 33 | public void onEvent(Query query) { 34 | query.setComment(comment); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetFetchSizeEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | /** 23 | * @author Maulik Shah 24 | */ 25 | public class SetFetchSizeEvent implements QueryEvent { 26 | 27 | private final int fetchSize; 28 | 29 | public SetFetchSizeEvent(int fetchSize) { 30 | this.fetchSize = fetchSize; 31 | } 32 | 33 | public void onEvent(Query query) { 34 | query.setFetchSize(fetchSize); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetFirstResultEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | /** 23 | * @author Maulik Shah 24 | */ 25 | public class SetFirstResultEvent implements QueryEvent { 26 | 27 | private final int firstResult; 28 | 29 | public SetFirstResultEvent(int firstResult) { 30 | this.firstResult = firstResult; 31 | } 32 | 33 | public void onEvent(Query query) { 34 | query.setFirstResult(firstResult); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetFlushModeEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.FlushMode; 22 | import org.hibernate.Query; 23 | 24 | /** 25 | * @author Maulik Shah 26 | */ 27 | public class SetFlushModeEvent implements QueryEvent { 28 | 29 | private final FlushMode flushMode; 30 | 31 | public SetFlushModeEvent(FlushMode flushMode) { 32 | this.flushMode = flushMode; 33 | } 34 | 35 | public void onEvent(Query query) { 36 | query.setFlushMode(flushMode); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetLockModeEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.LockMode; 22 | import org.hibernate.Query; 23 | 24 | /** 25 | * @author Maulik Shah 26 | */ 27 | public class SetLockModeEvent implements QueryEvent { 28 | 29 | private final String alias; 30 | private final LockMode lockMode; 31 | 32 | public SetLockModeEvent(String alias, LockMode lockMode) { 33 | this.alias = alias; 34 | this.lockMode = lockMode; 35 | } 36 | 37 | public void onEvent(Query query) { 38 | query.setLockMode(alias, lockMode); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetLockOptionsEvent.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.query; 2 | 3 | import org.hibernate.LockOptions; 4 | import org.hibernate.Query; 5 | 6 | /** 7 | * @author Adriano Machado 8 | */ 9 | public class SetLockOptionsEvent implements QueryEvent { 10 | 11 | private final LockOptions lockOptions; 12 | 13 | public SetLockOptionsEvent(final LockOptions lockOptions) { 14 | this.lockOptions = lockOptions; 15 | } 16 | 17 | @Override 18 | public void onEvent(final Query query) { 19 | query.setLockOptions(lockOptions); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetMaxResultsEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | 23 | /** 24 | * @author Maulik Shah 25 | */ 26 | 27 | public class SetMaxResultsEvent implements QueryEvent { 28 | private final int maxResults; 29 | 30 | public SetMaxResultsEvent(int maxResults) { 31 | this.maxResults = maxResults; 32 | } 33 | 34 | public void onEvent(Query query) { 35 | query.setMaxResults(maxResults); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetParametersEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | import org.hibernate.type.Type; 23 | 24 | /** 25 | * @author Maulik Shah 26 | */ 27 | public class SetParametersEvent implements QueryEvent { 28 | 29 | private final Object[] values; 30 | private final Type[] types; 31 | 32 | public SetParametersEvent(Object[] values, Type[] types) { 33 | this.values = values; 34 | this.types = types; 35 | } 36 | 37 | public void onEvent(Query query) { 38 | query.setParameters(values, types); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetReadOnlyEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | /** 23 | * @author Maulik Shah 24 | */ 25 | public class SetReadOnlyEvent implements QueryEvent { 26 | 27 | private final boolean readOnly; 28 | 29 | public SetReadOnlyEvent(boolean readOnly) { 30 | this.readOnly = readOnly; 31 | } 32 | 33 | public void onEvent(Query query) { 34 | query.setReadOnly(readOnly); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetResultTransformerEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | import org.hibernate.transform.ResultTransformer; 23 | 24 | /** 25 | * @author Maulik Shah 26 | */ 27 | public class SetResultTransformerEvent implements QueryEvent { 28 | 29 | private final ResultTransformer transformer; 30 | 31 | public SetResultTransformerEvent(ResultTransformer transformer) { 32 | this.transformer = transformer; 33 | } 34 | 35 | public void onEvent(Query query) { 36 | query.setResultTransformer(transformer); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/SetTimeoutEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | /** 23 | * @author Maulik Shah 24 | */ 25 | public class SetTimeoutEvent implements QueryEvent { 26 | 27 | private final int timeout; 28 | 29 | public SetTimeoutEvent(int timeout) { 30 | this.timeout = timeout; 31 | } 32 | 33 | public void onEvent(Query query) { 34 | query.setTimeout(timeout); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/ShardedQuery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | 23 | /** 24 | * ShardedQuery extends the Query interface to provide the ability to query 25 | * across shards. 26 | * 27 | * @author Maulik Shah 28 | * @see org.hibernate.Query 29 | */ 30 | 31 | public interface ShardedQuery extends Query { 32 | 33 | QueryId getQueryId(); 34 | 35 | QueryFactory getQueryFactory(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/query/ShardedSQLQuery.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.SQLQuery; 22 | 23 | /** 24 | * @author aviadl@sentrigo.com (Aviad Lichtenstadt) 25 | */ 26 | public interface ShardedSQLQuery extends ShardedQuery, SQLQuery { 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/BaseStatefulInterceptorFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.EmptyInterceptor; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public abstract class BaseStatefulInterceptorFactory extends EmptyInterceptor implements StatefulInterceptorFactory { 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/ControlSessionProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.engine.SessionImplementor; 22 | 23 | /** 24 | * Interface for any entity that can provide the control session. 25 | * Control session is used to access control (meta)data which usually lives on 26 | * only one shard. 27 | * 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | public interface ControlSessionProvider { 31 | 32 | /** 33 | * Opens control session. 34 | * 35 | * @return control session 36 | */ 37 | SessionImplementor openControlSession(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/DeleteOperation.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.session; 2 | 3 | import org.hibernate.shards.Shard; 4 | 5 | interface DeleteOperation { 6 | void delete(Shard shard, Object object); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/DisableFetchProfileOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.session; 2 | 3 | import org.hibernate.Session; 4 | import org.hibernate.UnknownProfileException; 5 | 6 | /** 7 | * OpenSessionEvent which disables specified fetch profile. 8 | * 9 | * @author maxr@google.com (Max Ross) 10 | */ 11 | class DisableFetchProfileOpenSessionEvent implements OpenSessionEvent { 12 | 13 | private final String name; 14 | 15 | public DisableFetchProfileOpenSessionEvent(final String name) { 16 | this.name = name; 17 | } 18 | 19 | @Override 20 | public void onOpenSession(final Session session) { 21 | try { 22 | session.disableFetchProfile(name); 23 | } catch(UnknownProfileException e) { 24 | throw new UnsupportedOperationException("fetch profile " + name + " is unknown to one session", e); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/DisableFilterOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * OpenSessionEvent which disables specified filter. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | class DisableFilterOpenSessionEvent implements OpenSessionEvent { 29 | 30 | private final String filterName; 31 | 32 | public DisableFilterOpenSessionEvent(final String filterName) { 33 | this.filterName = filterName; 34 | } 35 | 36 | @Override 37 | public void onOpenSession(final Session session) { 38 | session.disableFilter(filterName); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/EnableFetchProfileOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.session; 2 | 3 | import org.hibernate.Session; 4 | import org.hibernate.UnknownProfileException; 5 | 6 | class EnableFetchProfileOpenSessionEvent implements OpenSessionEvent { 7 | 8 | private final String name; 9 | 10 | public EnableFetchProfileOpenSessionEvent(final String name) { 11 | this.name = name; 12 | } 13 | 14 | @Override 15 | public void onOpenSession(final Session session) { 16 | try { 17 | session.enableFetchProfile(name); 18 | } catch(UnknownProfileException e) { 19 | throw new UnsupportedOperationException("fetch profile " + name + " is unknown to one session", e); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/EnableFilterOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * OpenSessionEvent which enables specified filter. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | class EnableFilterOpenSessionEvent implements OpenSessionEvent { 29 | 30 | private final String filterName; 31 | 32 | public EnableFilterOpenSessionEvent(final String filterName) { 33 | this.filterName = filterName; 34 | } 35 | 36 | @Override 37 | public void onOpenSession(final Session session) { 38 | session.enableFilter(filterName); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/OpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * Interface for events that can be laziliy applied to a {@link org.hibernate.Session}. 25 | * Useful because we don't allocate a {@link org.hibernate.Session} until we actually need it, 26 | * and programmers might be calling a variety of methods against the 27 | * {@link ShardedSession} which 28 | * need to be applied to the actual {@link org.hibernate.Session} 29 | * once the actual {@link org.hibernate.Session} is allocated. 30 | * 31 | * @author maxr@google.com (Max Ross) 32 | */ 33 | public interface OpenSessionEvent { 34 | 35 | /** 36 | * Invokes any actions that have to occur when a session is opened. 37 | * 38 | * @param session Session which is being opened 39 | */ 40 | void onOpenSession(Session session); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/RefreshOperation.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.session; 2 | 3 | import org.hibernate.shards.Shard; 4 | 5 | interface RefreshOperation { 6 | void refresh(Shard shard, Object object); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/RequiresSession.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * Interface describing an object that can have a Session set on it. This 25 | * is designed to be used in conjunction with stateful interceptors. 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | * @see StatefulInterceptorFactory 29 | */ 30 | public interface RequiresSession { 31 | void setSession(Session session); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/SaveOrUpdateOperation.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.session; 2 | 3 | import org.hibernate.shards.Shard; 4 | 5 | interface SaveOrUpdateOperation { 6 | 7 | void saveOrUpdate(Shard shard, Object object); 8 | 9 | void merge(Shard shard, Object object); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/SetCacheModeOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.CacheMode; 22 | import org.hibernate.Session; 23 | 24 | /** 25 | * OpenSessionEvent which sets the CacheMode. 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetCacheModeOpenSessionEvent implements OpenSessionEvent { 30 | 31 | private final CacheMode cacheMode; 32 | 33 | public SetCacheModeOpenSessionEvent(CacheMode cacheMode) { 34 | this.cacheMode = cacheMode; 35 | } 36 | 37 | public void onOpenSession(Session session) { 38 | session.setCacheMode(cacheMode); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/SetDefaultReadOnlyOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * OpenSessionEvent which sets specified entity's readOnly flag. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | class SetDefaultReadOnlyOpenSessionEvent implements OpenSessionEvent { 29 | 30 | private final boolean readOnly; 31 | 32 | public SetDefaultReadOnlyOpenSessionEvent(boolean readOnly) { 33 | this.readOnly = readOnly; 34 | } 35 | 36 | @Override 37 | public void onOpenSession(Session session) { 38 | session.setDefaultReadOnly(readOnly); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/SetFlushModeOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.FlushMode; 22 | import org.hibernate.Session; 23 | 24 | /** 25 | * OpenSessionEvent which sets the FlushMode. 26 | * 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | class SetFlushModeOpenSessionEvent implements OpenSessionEvent { 30 | 31 | private final FlushMode flushMode; 32 | 33 | public SetFlushModeOpenSessionEvent(FlushMode flushMode) { 34 | this.flushMode = flushMode; 35 | } 36 | 37 | public void onOpenSession(Session session) { 38 | session.setFlushMode(flushMode); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/SetReadOnlyOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * OpenSessionEvent which sets specified entity's readOnly flag. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | class SetReadOnlyOpenSessionEvent implements OpenSessionEvent { 29 | 30 | private final Object entity; 31 | 32 | private final boolean readOnly; 33 | 34 | public SetReadOnlyOpenSessionEvent(Object entity, boolean readOnly) { 35 | this.entity = entity; 36 | this.readOnly = readOnly; 37 | } 38 | 39 | public void onOpenSession(Session session) { 40 | session.setReadOnly(entity, readOnly); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/SetSessionOnRequiresSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * OpenSessionEvent which sets the provided Session on a RequiresSession. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class SetSessionOnRequiresSessionEvent implements OpenSessionEvent { 29 | 30 | private final RequiresSession requiresSession; 31 | 32 | 33 | public SetSessionOnRequiresSessionEvent(RequiresSession requiresSession) { 34 | this.requiresSession = requiresSession; 35 | } 36 | 37 | public void onOpenSession(Session session) { 38 | requiresSession.setSession(session); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/SetupTransactionOpenSessionEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | import org.hibernate.shards.ShardedTransaction; 23 | 24 | /** 25 | * OpenSessionEvent which adds newly opened session to the specified 26 | * ShardedTransaction. 27 | * 28 | * @author Tomislav Nad 29 | */ 30 | public class SetupTransactionOpenSessionEvent implements OpenSessionEvent { 31 | 32 | private final ShardedTransaction shardedTransaction; 33 | 34 | public SetupTransactionOpenSessionEvent(ShardedTransaction shardedTtransaction) { 35 | this.shardedTransaction = shardedTtransaction; 36 | } 37 | 38 | public void onOpenSession(Session session) { 39 | shardedTransaction.setupTransaction(session); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/ShardAware.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.session; 2 | 3 | import org.hibernate.shards.ShardId; 4 | 5 | /** 6 | * Copyright (C) 2007 Google Inc. 7 | * 8 | * This library is free software; you can redistribute it and/or modify it under 9 | * the terms of the GNU Lesser General Public License as published by the Free 10 | * Software Foundation; either version 2.1 of the License, or (at your option) 11 | * any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, but WITHOUT 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 16 | * details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this library; if not, write to the Free Software Foundation, Inc., 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 21 | */ 22 | 23 | /** 24 | * Describes an object that knows the id of the shard on which it lives. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public interface ShardAware { 29 | 30 | void setShardId(ShardId shardId); 31 | 32 | ShardId getShardId(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/ShardIdResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | /** 24 | * Interface for objects that are able to resolve shard of objects. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | interface ShardIdResolver { 29 | 30 | /** 31 | * Gets ShardId of the shard given object lives on. 32 | * 33 | * @param obj Object whose Shard should be resolved 34 | * @return ShardId of the shard the object lives on; null if shard could not be resolved 35 | */ 36 | /*@Nullable*/ ShardId getShardIdForObject(Object obj); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/ShardedSessionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | /** 22 | * Main exception used in Hibernate Shards. 23 | * 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public class ShardedSessionException extends RuntimeException { 27 | 28 | public ShardedSessionException() { 29 | } 30 | 31 | public ShardedSessionException(String message) { 32 | super(message); 33 | } 34 | 35 | public ShardedSessionException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | 39 | public ShardedSessionException(Throwable cause) { 40 | super(cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/StatefulInterceptorFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Interceptor; 22 | 23 | /** 24 | * Interface describing an object that knows how to create Interceptors. 25 | * Technically this is just an interceptor factory, but it is designed 26 | * to be used by clients who want to use stateful interceptors in conjunction 27 | * with sharded sessions. Clients should make sure their Interceptor 28 | * implementation implements this interface. Furthermore, if the 29 | * Interceptor implementation requires a reference to the Session, the 30 | * Interceptor returned by newInstance() should implement the {@link RequiresSession} 31 | * interface. 32 | * 33 | * @author maxr@google.com (Max Ross) 34 | */ 35 | public interface StatefulInterceptorFactory { 36 | Interceptor newInstance(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/session/UpdateOperation.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards.session; 2 | 3 | import org.hibernate.shards.Shard; 4 | 5 | interface UpdateOperation { 6 | 7 | void update(Shard shard, Object object); 8 | 9 | void merge(Shard shard, Object object); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/ShardStrategyFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public interface ShardStrategyFactory { 29 | ShardStrategy newShardStrategy(List shardIds); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/access/ShardAccessStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.access; 20 | 21 | import org.hibernate.shards.Shard; 22 | import org.hibernate.shards.ShardOperation; 23 | import org.hibernate.shards.strategy.exit.ExitOperationsCollector; 24 | import org.hibernate.shards.strategy.exit.ExitStrategy; 25 | 26 | import java.util.List; 27 | 28 | public interface ShardAccessStrategy { 29 | T apply(List shards, ShardOperation operation, ExitStrategy exitStrategy, ExitOperationsCollector exitOperationsCollector); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/ConcatenateListsExitStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import org.hibernate.shards.Shard; 22 | import org.hibernate.shards.util.Lists; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Threadsafe ExistStrategy that concatenates all the lists that are added. 28 | * 29 | * @author maxr@google.com (Max Ross) 30 | */ 31 | public class ConcatenateListsExitStrategy implements ExitStrategy> { 32 | 33 | private final List result = Lists.newArrayList(); 34 | 35 | public synchronized boolean addResult(List oneResult, Shard shard) { 36 | result.addAll(oneResult); 37 | return false; 38 | } 39 | 40 | public List compileResults(ExitOperationsCollector exitOperationsCollector) { 41 | return exitOperationsCollector.apply(result); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/ExitOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Maulik Shah 25 | */ 26 | public interface ExitOperation { 27 | 28 | List apply(List results); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/ExitOperationsCollector.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import org.hibernate.engine.SessionFactoryImplementor; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Classes that implement this interface are designed to manage the results 27 | * of a incomplete execution of a query/critieria. For example, with averages 28 | * the result of each query/critieria should be a list objects on which to 29 | * calculate the average, rather than the avgerages on each shard. Or the 30 | * the sum of maxResults(200) should be the sum of only 200 results, not the 31 | * sum of the sums of 200 results per shard. 32 | * 33 | * @author Maulik Shah 34 | */ 35 | public interface ExitOperationsCollector { 36 | 37 | List apply(List result); 38 | 39 | void setSessionFactory(SessionFactoryImplementor sessionFactoryImplementor); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/ExitStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import org.hibernate.shards.Shard; 22 | 23 | /** 24 | * Classes implementing this interface gather results from operations that are 25 | * executed across shards. If you intend to use a specific implementation 26 | * in conjunction with ParallelShardAccessStrategy that implementation must 27 | * be threadsafe. 28 | * 29 | * @author maxr@google.com (Max Ross) 30 | */ 31 | public interface ExitStrategy { 32 | 33 | /** 34 | * Add the provided result and return whether or not the caller can halt 35 | * processing. 36 | * @param result The result to add 37 | * @return Whether or not the caller can halt processing 38 | */ 39 | boolean addResult(T result, Shard shard); 40 | 41 | T compileResults(ExitOperationsCollector exitOperationsCollector); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/FirstResultExitOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import java.util.Collections; 22 | import java.util.List; 23 | 24 | /** 25 | * @author Maulik Shah 26 | */ 27 | public class FirstResultExitOperation implements ExitOperation { 28 | 29 | private final int firstResult; 30 | 31 | public FirstResultExitOperation(int firstResult) { 32 | this.firstResult = firstResult; 33 | } 34 | 35 | public List apply(List results) { 36 | List nonNullResults = ExitOperationUtils.getNonNullList(results); 37 | if(nonNullResults.size() <= firstResult) { 38 | return Collections.emptyList(); 39 | } 40 | return nonNullResults.subList(firstResult, nonNullResults.size()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/MaxResultsExitOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Maulik Shah 25 | */ 26 | public class MaxResultsExitOperation implements ExitOperation { 27 | 28 | private final int maxResults; 29 | 30 | public MaxResultsExitOperation(int maxResults) { 31 | this.maxResults = maxResults; 32 | } 33 | 34 | public List apply(List results) { 35 | List nonNullResults = ExitOperationUtils.getNonNullList(results); 36 | return nonNullResults.subList(0, Math.min(nonNullResults.size(), maxResults)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/ProjectionExitOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author Maulik Shah 25 | */ 26 | public interface ProjectionExitOperation extends ExitOperation{ 27 | List apply(List results); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/exit/RowCountExitOperation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import org.hibernate.criterion.Projection; 22 | import org.hibernate.criterion.RowCountProjection; 23 | import org.hibernate.shards.util.Preconditions; 24 | 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Maulik Shah 30 | */ 31 | public class RowCountExitOperation implements ProjectionExitOperation { 32 | 33 | public RowCountExitOperation(Projection projection) { 34 | Preconditions.checkState(projection instanceof RowCountProjection); 35 | } 36 | 37 | public List apply(List results) { 38 | List nonNullResults = ExitOperationUtils.getNonNullList(results); 39 | return Collections.singletonList((Object) nonNullResults.size()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/resolution/AllShardsShardResolutionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.resolution; 20 | 21 | import org.hibernate.shards.ShardId; 22 | import org.hibernate.shards.strategy.selection.ShardResolutionStrategyData; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class AllShardsShardResolutionStrategy extends BaseShardResolutionStrategy { 30 | 31 | public AllShardsShardResolutionStrategy(final List shardIds) { 32 | super(shardIds); 33 | } 34 | 35 | @Override 36 | public List selectShardIdsFromShardResolutionStrategyData( 37 | final ShardResolutionStrategyData shardResolutionStrategyData) { 38 | return shardIds; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/resolution/BaseShardResolutionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.resolution; 20 | 21 | import org.hibernate.shards.BaseHasShardIdList; 22 | import org.hibernate.shards.ShardId; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public abstract class BaseShardResolutionStrategy extends BaseHasShardIdList implements ShardResolutionStrategy { 30 | 31 | public BaseShardResolutionStrategy(final List shardIds) { 32 | super(shardIds); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/resolution/ShardResolutionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.resolution; 20 | 21 | import org.hibernate.shards.ShardId; 22 | import org.hibernate.shards.strategy.selection.ShardResolutionStrategyData; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public interface ShardResolutionStrategy { 30 | /** 31 | * Determine the shards on which an object might live 32 | * 33 | * @param shardResolutionStrategyData information we can use to select shards 34 | * @return the ids of the shards on which the object described by the ShardSelectionStrategyData might reside 35 | */ 36 | List selectShardIdsFromShardResolutionStrategyData( 37 | ShardResolutionStrategyData shardResolutionStrategyData); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/selection/BaseShardSelectionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.selection; 20 | 21 | import org.hibernate.shards.BaseHasShardIdList; 22 | import org.hibernate.shards.ShardId; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public abstract class BaseShardSelectionStrategy extends BaseHasShardIdList implements ShardSelectionStrategy { 30 | 31 | protected BaseShardSelectionStrategy(final List shardIds) { 32 | super(shardIds); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/selection/LoadBalancedShardSelectionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.selection; 20 | 21 | import org.hibernate.shards.ShardId; 22 | import org.hibernate.shards.loadbalance.ShardLoadBalancer; 23 | 24 | /** 25 | * @author maxr@google.com (Max Ross) 26 | */ 27 | public class LoadBalancedShardSelectionStrategy implements ShardSelectionStrategy { 28 | 29 | private final ShardLoadBalancer shardLoadBalancer; 30 | 31 | public LoadBalancedShardSelectionStrategy(final ShardLoadBalancer shardLoadBalancer) { 32 | this.shardLoadBalancer = shardLoadBalancer; 33 | } 34 | 35 | @Override 36 | public ShardId selectShardIdForNewObject(Object obj) { 37 | return shardLoadBalancer.getNextShardId(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/selection/RoundRobinShardSelectionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.selection; 20 | 21 | import org.hibernate.shards.ShardId; 22 | import org.hibernate.shards.loadbalance.RoundRobinShardLoadBalancer; 23 | 24 | /** 25 | * @author maxr@google.com (Max Ross) 26 | */ 27 | public class RoundRobinShardSelectionStrategy implements ShardSelectionStrategy { 28 | 29 | private final RoundRobinShardLoadBalancer loadBalancer; 30 | 31 | public RoundRobinShardSelectionStrategy(final RoundRobinShardLoadBalancer loadBalancer) { 32 | this.loadBalancer = loadBalancer; 33 | } 34 | 35 | public ShardId selectShardIdForNewObject(final Object obj) { 36 | return loadBalancer.getNextShardId(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/selection/ShardResolutionStrategyData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.selection; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public interface ShardResolutionStrategyData { 27 | 28 | String getEntityName(); 29 | 30 | Serializable getId(); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/strategy/selection/ShardSelectionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.selection; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public interface ShardSelectionStrategy { 27 | 28 | /** 29 | * Determine the specific shard on which this object should reside 30 | * 31 | * @param obj the new object for which we are selecting a shard 32 | * @return the id of the shard on which this object should live 33 | */ 34 | ShardId selectShardIdForNewObject(Object obj); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/hibernate/shards/util/Maps.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.util; 20 | 21 | import java.util.HashMap; 22 | import java.util.LinkedHashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * Helper methods related to {@link Map}s. 27 | * 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | public class Maps { 31 | 32 | private Maps() { 33 | } 34 | 35 | /** 36 | * Construct a new {@link HashMap}, taking advantage of type inference to 37 | * avoid specifying the type on the rhs. 38 | */ 39 | public static HashMap newHashMap() { 40 | return new HashMap(); 41 | } 42 | 43 | /** 44 | * Construct a new {@link LinkedHashMap}, taking advantage of type inference to 45 | * avoid specifying the type on the rhs. 46 | */ 47 | public static LinkedHashMap newLinkedHashMap() { 48 | return new LinkedHashMap(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/PermutationHelper.java: -------------------------------------------------------------------------------- 1 | package org.hibernate.shards; 2 | 3 | import org.hibernate.shards.integration.IdGenType; 4 | import org.hibernate.shards.integration.Permutation; 5 | import org.hibernate.shards.integration.ShardAccessStrategyType; 6 | import org.hibernate.shards.util.Lists; 7 | import org.junit.runners.Parameterized; 8 | 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | public class PermutationHelper { 13 | 14 | private static final int MIN_SHARDS = 1; 15 | private static final int MAX_SHARDS = 3; 16 | 17 | public static Iterable data() { 18 | 19 | final List parameters = Lists.newArrayList(); 20 | 21 | for (final Permutation permutation : buildPermutationList()) { 22 | parameters.add(new Object[]{permutation}); 23 | } 24 | 25 | return parameters; 26 | } 27 | 28 | private static List buildPermutationList() { 29 | final List list = Lists.newArrayList(); 30 | for (final IdGenType idGenType : IdGenType.values()) { 31 | for (final ShardAccessStrategyType sast : ShardAccessStrategyType.values()) { 32 | for (int i = MIN_SHARDS; i <= MAX_SHARDS; i++) { 33 | list.add(new Permutation(idGenType, sast, i)); 34 | if (idGenType.getSupportsVirtualSharding()) { 35 | list.add(new Permutation(idGenType, sast, i, 9, true)); 36 | list.add(new Permutation(idGenType, sast, i, i, true)); 37 | } 38 | } 39 | } 40 | } 41 | return list; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/ShardOperationDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards; 20 | 21 | /** 22 | * @author maxr@google.com (Max Ross) 23 | */ 24 | public class ShardOperationDefaultMock implements ShardOperation { 25 | 26 | public T execute(Shard shard) { 27 | throw new UnsupportedOperationException(); 28 | } 29 | 30 | public String getOperationName() { 31 | throw new UnsupportedOperationException(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/AddCriterionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.criterion.Criterion; 23 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | 27 | /** 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | public class AddCriterionEventTest { 31 | 32 | @Test 33 | public void testOnOpenSession() { 34 | AddCriterionEvent event = new AddCriterionEvent(null); 35 | final boolean[] called = {false}; 36 | Criteria crit = new CriteriaDefaultMock() { 37 | @Override 38 | public Criteria add(Criterion criterion) { 39 | called[0] = true; 40 | return null; 41 | } 42 | }; 43 | event.onEvent(crit); 44 | Assert.assertTrue(called[0]); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/AddOrderEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.criterion.Order; 23 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 24 | 25 | import org.junit.Assert; 26 | import org.junit.Test; 27 | 28 | /** 29 | * @author maxr@google.com (Max Ross) 30 | */ 31 | public class AddOrderEventTest { 32 | 33 | @Test 34 | public void testOnOpenSession() { 35 | AddOrderEvent event = new AddOrderEvent(null); 36 | final boolean[] called = {false}; 37 | Criteria crit = new CriteriaDefaultMock() { 38 | @Override 39 | public Criteria addOrder(Order order) { 40 | called[0] = true; 41 | return null; 42 | } 43 | }; 44 | event.onEvent(crit); 45 | Assert.assertTrue(called[0]); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/CriteriaEventDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public class CriteriaEventDefaultMock implements CriteriaEvent { 27 | 28 | public void onEvent(Criteria criteria) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/CriteriaFactoryDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.Session; 23 | 24 | /** 25 | * @author maxr@google.com (Max Ross) 26 | */ 27 | public class CriteriaFactoryDefaultMock implements CriteriaFactory { 28 | 29 | public Criteria createCriteria(Session session) { 30 | throw new UnsupportedOperationException(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetCacheModeEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.CacheMode; 22 | import org.hibernate.Criteria; 23 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | 27 | /** 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | public class SetCacheModeEventTest { 31 | 32 | @Test 33 | public void testOnOpenSession() { 34 | SetCacheModeEvent event = new SetCacheModeEvent(CacheMode.GET); 35 | final boolean[] called = {false}; 36 | Criteria crit = new CriteriaDefaultMock() { 37 | @Override 38 | public Criteria setCacheMode(CacheMode cacheMode) { 39 | called[0] = true; 40 | return null; 41 | } 42 | }; 43 | event.onEvent(crit); 44 | Assert.assertTrue(called[0]); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetCacheRegionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetCacheRegionEventTest { 30 | 31 | @Test 32 | public void testOnOpenSession() { 33 | SetCacheRegionEvent event = new SetCacheRegionEvent(null); 34 | final boolean[] called = {false}; 35 | Criteria crit = new CriteriaDefaultMock() { 36 | @Override 37 | public Criteria setCacheRegion(String cacheRegion) { 38 | called[0] = true; 39 | return null; 40 | } 41 | }; 42 | event.onEvent(crit); 43 | Assert.assertTrue(called[0]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetCacheableEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetCacheableEventTest { 30 | 31 | @Test 32 | public void testOnOpenSession() { 33 | SetCacheableEvent event = new SetCacheableEvent(true); 34 | final boolean[] called = {false}; 35 | Criteria crit = new CriteriaDefaultMock() { 36 | @Override 37 | public Criteria setCacheable(boolean cacheable) { 38 | called[0] = true; 39 | return null; 40 | } 41 | }; 42 | event.onEvent(crit); 43 | Assert.assertTrue(called[0]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetCommentEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetCommentEventTest { 30 | 31 | @Test 32 | public void testOnOpenSession() { 33 | SetCommentEvent event = new SetCommentEvent(null); 34 | final boolean[] called = {false}; 35 | Criteria crit = new CriteriaDefaultMock() { 36 | @Override 37 | public Criteria setComment(String comment) { 38 | called[0] = true; 39 | return null; 40 | } 41 | }; 42 | event.onEvent(crit); 43 | Assert.assertTrue(called[0]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetFetchSizeEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetFetchSizeEventTest { 30 | 31 | @Test 32 | public void testOnOpenSession() { 33 | SetFetchSizeEvent event = new SetFetchSizeEvent(33); 34 | final boolean[] called = {false}; 35 | Criteria crit = new CriteriaDefaultMock() { 36 | @Override 37 | public Criteria setFetchSize(int fetchSize) { 38 | called[0] = true; 39 | return null; 40 | } 41 | }; 42 | event.onEvent(crit); 43 | Assert.assertTrue(called[0]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetFirstResultEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetFirstResultEventTest { 30 | 31 | @Test 32 | public void testOnOpenSession() { 33 | SetFirstResultEvent event = new SetFirstResultEvent(33); 34 | final boolean[] called = {false}; 35 | Criteria crit = new CriteriaDefaultMock() { 36 | @Override 37 | public Criteria setFirstResult(int firstResult) { 38 | called[0] = true; 39 | return null; 40 | } 41 | }; 42 | event.onEvent(crit); 43 | Assert.assertTrue(called[0]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetMaxResultsEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetMaxResultsEventTest { 30 | 31 | @Test 32 | public void testOnOpenSession() { 33 | SetMaxResultsEvent event = new SetMaxResultsEvent(22); 34 | final boolean[] called = {false}; 35 | Criteria crit = new CriteriaDefaultMock() { 36 | @Override 37 | public Criteria setMaxResults(int maxResults) { 38 | called[0] = true; 39 | return null; 40 | } 41 | }; 42 | event.onEvent(crit); 43 | Assert.assertTrue(called[0]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SetTimeoutEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | import org.hibernate.shards.defaultmock.CriteriaDefaultMock; 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetTimeoutEventTest { 30 | 31 | @Test 32 | public void testOnOpenSession() { 33 | SetTimeoutEvent event = new SetTimeoutEvent(23); 34 | final boolean[] called = {false}; 35 | Criteria crit = new CriteriaDefaultMock() { 36 | @Override 37 | public Criteria setTimeout(int timeout) { 38 | called[0] = true; 39 | return null; 40 | } 41 | }; 42 | event.onEvent(crit); 43 | Assert.assertTrue(called[0]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/criteria/SubcriteriaFactoryDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.criteria; 20 | 21 | import org.hibernate.Criteria; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public class SubcriteriaFactoryDefaultMock implements SubcriteriaFactory { 27 | 28 | public Criteria createSubcriteria(Criteria parent, 29 | Iterable events) { 30 | throw new UnsupportedOperationException(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/id/UUIDBigIntGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.id; 20 | 21 | import org.hibernate.engine.SessionImplementor; 22 | import org.hibernate.id.UUIDHexGenerator; 23 | 24 | import java.math.BigInteger; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class UUIDBigIntGenerator extends UUIDHexGenerator { 30 | 31 | @Override 32 | public BigInteger generate(SessionImplementor session, Object obj) { 33 | 34 | final String str = new StringBuilder(32) 35 | .append(format((short) 0)) 36 | .append(format(getIP())) 37 | .append(format((short) (getJVM() >>> 16))) 38 | .append(format(getHiTime())) 39 | .append(format(getLoTime())) 40 | .append(format(getCount())) 41 | .toString(); 42 | 43 | return new BigInteger(str, 16); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/integration/IdGenType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.integration; 20 | 21 | /** 22 | * @author maxr@google.com (Max Ross) 23 | */ 24 | public enum IdGenType { 25 | SIMPLE("mappings.hbm.xml", false), 26 | SHARD_HI_LO("mappings-shardedTableHiLo.hbm.xml", false), 27 | SHARD_UUID("mappings-shardedUUID.hbm.xml", true); 28 | 29 | private final String mappingFile; 30 | private final boolean supportsVirtualSharding; 31 | 32 | private IdGenType(String mappingFile, boolean supportsVirtualSharding) { 33 | this.mappingFile = mappingFile; 34 | this.supportsVirtualSharding = supportsVirtualSharding; 35 | } 36 | 37 | public String getMappingFile() { 38 | return mappingFile; 39 | } 40 | 41 | public boolean getSupportsVirtualSharding() { 42 | return supportsVirtualSharding; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/integration/ShardAccessStrategyType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.integration; 20 | 21 | /** 22 | * @author maxr@google.com (Max Ross) 23 | */ 24 | public enum ShardAccessStrategyType { 25 | SEQUENTIAL, PARALLEL 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/integration/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.integration; 20 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/integration/platform/BaseDatabasePlatform.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.integration.platform; 20 | 21 | /** 22 | * @author maxr@google.com (Max Ross) 23 | */ 24 | public abstract class BaseDatabasePlatform implements DatabasePlatform { 25 | 26 | protected BaseDatabasePlatform() { 27 | try { 28 | Class.forName(getDriverClass()); 29 | } catch (ClassNotFoundException e) { 30 | throw new RuntimeException(e); 31 | } 32 | } 33 | 34 | protected abstract String getDriverClass(); 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/integration/platform/DatabasePlatform.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.integration.platform; 20 | 21 | import org.hibernate.shards.integration.IdGenType; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public interface DatabasePlatform { 27 | 28 | String getName(); 29 | 30 | Iterable getCreateTableStatements(IdGenType idGenType); 31 | 32 | Iterable getDropTableStatements(IdGenType idGenType); 33 | 34 | String getUrl(int index); 35 | 36 | String getUser(); 37 | 38 | String getPassword(); 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/loadbalance/RoundRobinShardLoadBalancerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.loadbalance; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.shards.ShardId; 23 | import org.hibernate.shards.util.Lists; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * @author maxr@google.com (Max Ross) 29 | */ 30 | public class RoundRobinShardLoadBalancerTest extends TestCase { 31 | 32 | public void testBalancer() { 33 | List shardIds = Lists.newArrayList(new ShardId(1), new ShardId(2)); 34 | RoundRobinShardLoadBalancer balancer = new RoundRobinShardLoadBalancer(shardIds); 35 | assertEquals(0, balancer.getNextIndex()); 36 | assertEquals(1, balancer.getNextIndex()); 37 | assertEquals(0, balancer.getNextIndex()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/loadbalance/ShardLoadBalancerDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.loadbalance; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class ShardLoadBalancerDefaultMock implements org.hibernate.shards.loadbalance.ShardLoadBalancer { 29 | 30 | public ShardId getNextShardId() { 31 | throw new UnsupportedOperationException(); 32 | } 33 | 34 | public List getAllShardIds() { 35 | throw new UnsupportedOperationException(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/model/IdIsBaseType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | package org.hibernate.shards.model; 19 | 20 | import java.math.BigInteger; 21 | 22 | /** 23 | * Test class used for tests that illustrate we can handle objects with 24 | * ids that are base types. 25 | * 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class IdIsBaseType { 29 | 30 | private BigInteger idIsBaseTypeId; 31 | private String value; 32 | 33 | public BigInteger getIdIsBaseTypeId() { 34 | return idIsBaseTypeId; 35 | } 36 | 37 | public void setIdIsBaseTypeId(BigInteger hasLongId) { 38 | this.idIsBaseTypeId = hasLongId; 39 | } 40 | 41 | public String getValue() { 42 | return value; 43 | } 44 | 45 | public void setValue(String value) { 46 | this.value = value; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/QueryEventDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | 23 | /** 24 | * @author Maulik Shah 25 | */ 26 | public class QueryEventDefaultMock implements QueryEvent { 27 | 28 | public void onEvent(Query query) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/QueryFactoryDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import org.hibernate.Query; 22 | import org.hibernate.SQLQuery; 23 | import org.hibernate.Session; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class QueryFactoryDefaultMock implements QueryFactory { 29 | 30 | @Override 31 | public Query createQuery(Session session) { 32 | throw new UnsupportedOperationException(); 33 | } 34 | 35 | @Override 36 | public SQLQuery createSQLQuery(Session session) { 37 | throw new UnsupportedOperationException(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetCacheModeEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.CacheMode; 23 | import org.hibernate.Query; 24 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 25 | 26 | /** 27 | * @author Maulik Shah 28 | */ 29 | public class SetCacheModeEventTest extends TestCase { 30 | 31 | public void testSetCacheModeEventCachemode() { 32 | SetCacheModeEvent event = new SetCacheModeEvent(null); 33 | final boolean[] called = {false}; 34 | Query query = new QueryDefaultMock() { 35 | @Override 36 | public Query setCacheMode(CacheMode cacheMode) { 37 | called[0] = true; 38 | return null; 39 | } 40 | }; 41 | event.onEvent(query); 42 | assertTrue(called[0]); 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetCacheRegionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetCacheRegionEventTest extends TestCase { 29 | 30 | public void testSetCacheRegionEventCacheregion() { 31 | SetCacheRegionEvent event = new SetCacheRegionEvent(null); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setCacheRegion(String cacheRegion) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetCacheableEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetCacheableEventTest extends TestCase { 29 | 30 | public void testSetCacheableEventCacheable() { 31 | SetCacheableEvent event = new SetCacheableEvent(false); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setCacheable(boolean cacheable) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetCommentEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetCommentEventTest extends TestCase { 29 | 30 | public void testSetCommentEventComment() { 31 | SetCommentEvent event = new SetCommentEvent(null); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setComment(String comment) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetFetchSizeEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetFetchSizeEventTest extends TestCase { 29 | 30 | public void testSetFetchSizeEventFetchsize() { 31 | SetFetchSizeEvent event = new SetFetchSizeEvent(-1); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setFetchSize(int fetchSize) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetFirstResultEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetFirstResultEventTest extends TestCase { 29 | 30 | public void testSetFirstResultEventFirstresult() { 31 | SetFirstResultEvent event = new SetFirstResultEvent(-1); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setFirstResult(int firstResult) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetFlushModeEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.FlushMode; 23 | import org.hibernate.Query; 24 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 25 | 26 | /** 27 | * @author Maulik Shah 28 | */ 29 | public class SetFlushModeEventTest extends TestCase { 30 | 31 | public void testSetFlushModeEventFlushmode() { 32 | SetFlushModeEvent event = new SetFlushModeEvent(null); 33 | final boolean[] called = {false}; 34 | Query query = new QueryDefaultMock() { 35 | @Override 36 | public Query setFlushMode(FlushMode flushMode) { 37 | called[0] = true; 38 | return null; 39 | } 40 | }; 41 | event.onEvent(query); 42 | assertTrue(called[0]); 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetLockModeEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.LockMode; 23 | import org.hibernate.Query; 24 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 25 | 26 | /** 27 | * @author Maulik Shah 28 | */ 29 | public class SetLockModeEventTest extends TestCase { 30 | 31 | public void testSetLockModeEventAliasLockmode() { 32 | SetLockModeEvent event = new SetLockModeEvent(null, null); 33 | final boolean[] called = {false}; 34 | Query query = new QueryDefaultMock() { 35 | @Override 36 | public Query setLockMode(String alias, LockMode lockMode) { 37 | called[0] = true; 38 | return null; 39 | } 40 | }; 41 | event.onEvent(query); 42 | assertTrue(called[0]); 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetMaxResultsEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetMaxResultsEventTest extends TestCase { 29 | 30 | public void testSetMaxResultsEventMaxresults() { 31 | SetMaxResultsEvent event = new SetMaxResultsEvent(-1); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setMaxResults(int maxResults) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetParametersEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | import org.hibernate.type.Type; 25 | 26 | /** 27 | * @author Maulik Shah 28 | */ 29 | public class SetParametersEventTest extends TestCase { 30 | 31 | public void testSetParametersEventValuesTypes() { 32 | SetParametersEvent event = new SetParametersEvent(null, null); 33 | final boolean[] called = {false}; 34 | Query query = new QueryDefaultMock() { 35 | @Override 36 | public Query setParameters(Object[] values, Type[] types) { 37 | called[0] = true; 38 | return null; 39 | } 40 | }; 41 | event.onEvent(query); 42 | assertTrue(called[0]); 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetReadOnlyEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetReadOnlyEventTest extends TestCase { 29 | 30 | public void testSetReadOnlyEventReadonly() { 31 | SetReadOnlyEvent event = new SetReadOnlyEvent(false); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setReadOnly(boolean readOnly) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetResultTransformerEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | import org.hibernate.transform.ResultTransformer; 25 | 26 | /** 27 | * @author Maulik Shah 28 | */ 29 | public class SetResultTransformerEventTest extends TestCase { 30 | 31 | public void testSetResultTransformerEventTransformer() { 32 | SetResultTransformerEvent event = new SetResultTransformerEvent(null); 33 | final boolean[] called = {false}; 34 | Query query = new QueryDefaultMock() { 35 | @Override 36 | public Query setResultTransformer(ResultTransformer transformer) { 37 | called[0] = true; 38 | return null; 39 | } 40 | }; 41 | event.onEvent(query); 42 | assertTrue(called[0]); 43 | } 44 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/query/SetTimeoutEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.query; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Query; 23 | import org.hibernate.shards.defaultmock.QueryDefaultMock; 24 | 25 | /** 26 | * @author Maulik Shah 27 | */ 28 | public class SetTimeoutEventTest extends TestCase { 29 | 30 | public void testSetTimeoutEventTimeout() { 31 | SetTimeoutEvent event = new SetTimeoutEvent(-1); 32 | final boolean[] called = {false}; 33 | Query query = new QueryDefaultMock() { 34 | @Override 35 | public Query setTimeout(int timeout) { 36 | called[0] = true; 37 | return null; 38 | } 39 | }; 40 | event.onEvent(query); 41 | assertTrue(called[0]); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/session/DisableFilterOpenSessionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Session; 23 | import org.hibernate.shards.defaultmock.SessionDefaultMock; 24 | 25 | /** 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class DisableFilterOpenSessionEventTest extends TestCase { 29 | 30 | public void testOnOpenSession() { 31 | DisableFilterOpenSessionEvent event = new DisableFilterOpenSessionEvent("yam"); 32 | final boolean[] called = {false}; 33 | Session session = new SessionDefaultMock() { 34 | @Override 35 | public void disableFilter(String filterName) { 36 | called[0] = true; 37 | } 38 | }; 39 | event.onOpenSession(session); 40 | assertTrue(called[0]); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/session/EnableFilterOpenSessionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Filter; 23 | import org.hibernate.Session; 24 | import org.hibernate.shards.defaultmock.SessionDefaultMock; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class EnableFilterOpenSessionEventTest extends TestCase { 30 | 31 | public void testOnOpenSession() { 32 | EnableFilterOpenSessionEvent event = new EnableFilterOpenSessionEvent("yam"); 33 | final boolean[] called = {false}; 34 | Session session = new SessionDefaultMock() { 35 | @Override 36 | public Filter enableFilter(String filterName) { 37 | called[0] = true; 38 | return null; 39 | } 40 | }; 41 | event.onOpenSession(session); 42 | assertTrue(called[0]); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/session/OpenSessionEventDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.Session; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public class OpenSessionEventDefaultMock implements OpenSessionEvent { 27 | 28 | public void onOpenSession(Session session) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/session/SetCacheModeOpenSessionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.CacheMode; 23 | import org.hibernate.Session; 24 | import org.hibernate.shards.defaultmock.SessionDefaultMock; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetCacheModeOpenSessionEventTest extends TestCase { 30 | 31 | public void testOnOpenSession() { 32 | SetCacheModeOpenSessionEvent event = new SetCacheModeOpenSessionEvent(CacheMode.IGNORE); 33 | final boolean[] called = {false}; 34 | Session session = new SessionDefaultMock() { 35 | @Override 36 | public void setCacheMode(CacheMode cacheMode) { 37 | called[0] = true; 38 | } 39 | }; 40 | event.onOpenSession(session); 41 | assertTrue(called[0]); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/session/SetFlushModeOpenSessionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.FlushMode; 23 | import org.hibernate.Session; 24 | import org.hibernate.shards.defaultmock.SessionDefaultMock; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class SetFlushModeOpenSessionEventTest extends TestCase { 30 | public void testOnOpenSession() { 31 | SetFlushModeOpenSessionEvent event = new SetFlushModeOpenSessionEvent(FlushMode.ALWAYS); 32 | final boolean[] called = {false}; 33 | Session session = new SessionDefaultMock() { 34 | @Override 35 | public void setFlushMode(FlushMode flushMode) { 36 | called[0] = true; 37 | } 38 | }; 39 | event.onOpenSession(session); 40 | assertTrue(called[0]); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/session/SetReadOnlyOpenSessionEventTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.Session; 23 | import org.hibernate.shards.defaultmock.SessionDefaultMock; 24 | 25 | /** 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class SetReadOnlyOpenSessionEventTest extends TestCase { 29 | 30 | public void testOnOpenSession() { 31 | SetReadOnlyOpenSessionEvent event = new SetReadOnlyOpenSessionEvent(null, false); 32 | final boolean[] called = {false}; 33 | Session session = new SessionDefaultMock() { 34 | @Override 35 | public void setReadOnly(Object entity, boolean readOnly) { 36 | called[0] = true; 37 | } 38 | }; 39 | event.onOpenSession(session); 40 | assertTrue(called[0]); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/session/ShardIdResolverDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.session; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | class ShardIdResolverDefaultMock implements ShardIdResolver { 27 | 28 | public ShardId getShardIdForObject(Object obj) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/ShardStrategyDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy; 20 | 21 | import org.hibernate.shards.strategy.access.ShardAccessStrategy; 22 | import org.hibernate.shards.strategy.resolution.ShardResolutionStrategy; 23 | import org.hibernate.shards.strategy.selection.ShardSelectionStrategy; 24 | 25 | /** 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class ShardStrategyDefaultMock implements ShardStrategy { 29 | 30 | public ShardSelectionStrategy getShardSelectionStrategy() { 31 | throw new UnsupportedOperationException(); 32 | } 33 | 34 | public ShardAccessStrategy getShardAccessStrategy() { 35 | throw new UnsupportedOperationException(); 36 | } 37 | 38 | public ShardResolutionStrategy getShardResolutionStrategy() { 39 | throw new UnsupportedOperationException(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/ShardStrategyFactoryDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class ShardStrategyFactoryDefaultMock implements ShardStrategyFactory { 29 | 30 | public ShardStrategy newShardStrategy(List shardIds) { 31 | throw new UnsupportedOperationException(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/access/ParallelShardAccessStrategyTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.access; 20 | 21 | import org.junit.Test; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public class ParallelShardAccessStrategyTest { 27 | 28 | @Test(expected = NullPointerException.class) 29 | public void testCtor() { 30 | new ParallelShardAccessStrategy(null); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/access/ShardAccessStrategyDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.access; 20 | 21 | import org.hibernate.shards.Shard; 22 | import org.hibernate.shards.ShardOperation; 23 | import org.hibernate.shards.strategy.exit.ExitOperationsCollector; 24 | import org.hibernate.shards.strategy.exit.ExitStrategy; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * @author maxr@google.com (Max Ross) 30 | */ 31 | public class ShardAccessStrategyDefaultMock implements ShardAccessStrategy { 32 | 33 | public T apply(List shards, ShardOperation operation, 34 | ExitStrategy exitStrategy, ExitOperationsCollector exitOperationsCollector) { 35 | throw new UnsupportedOperationException(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/exit/ExitStrategyDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import org.hibernate.shards.Shard; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public class ExitStrategyDefaultMock implements ExitStrategy { 27 | 28 | public boolean addResult(T result, Shard shard) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | 32 | public T compileResults(ExitOperationsCollector exitOperationsCollector) { 33 | throw new UnsupportedOperationException(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/exit/RowCountExitOperationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.exit; 20 | 21 | import junit.framework.TestCase; 22 | import org.hibernate.criterion.Projections; 23 | import org.hibernate.shards.util.Lists; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * @author Maulik Shah 29 | */ 30 | public class RowCountExitOperationTest extends TestCase { 31 | public void testCtor() throws Exception { 32 | try { 33 | new RowCountExitOperation(Projections.avg("foo")); 34 | fail(); 35 | } catch (IllegalStateException e) { 36 | //good 37 | } 38 | } 39 | 40 | public void testApplyCount() throws Exception { 41 | RowCountExitOperation exitOp = new RowCountExitOperation(Projections.rowCount()); 42 | 43 | List list = Lists.newArrayList(1,2,null,3); 44 | assertEquals(3, (int)(Integer)exitOp.apply(list).get(0)); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/resolution/ShardResolutionStrategyDataDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.resolution; 20 | 21 | import org.hibernate.shards.strategy.selection.ShardResolutionStrategyData; 22 | 23 | import java.io.Serializable; 24 | 25 | /** 26 | * @author maxr@google.com (Max Ross) 27 | */ 28 | public class ShardResolutionStrategyDataDefaultMock implements ShardResolutionStrategyData { 29 | 30 | public String getEntityName() { 31 | throw new UnsupportedOperationException(); 32 | } 33 | 34 | public Serializable getId() { 35 | throw new UnsupportedOperationException(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/resolution/ShardResolutionStrategyDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.resolution; 20 | 21 | import org.hibernate.shards.ShardId; 22 | import org.hibernate.shards.strategy.selection.ShardResolutionStrategyData; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * @author maxr@google.com (Max Ross) 28 | */ 29 | public class ShardResolutionStrategyDefaultMock implements ShardResolutionStrategy { 30 | 31 | public List selectShardIdsFromShardResolutionStrategyData( 32 | ShardResolutionStrategyData shardResolutionStrategyData) { 33 | throw new UnsupportedOperationException(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/strategy/selection/ShardSelectionStrategyDefaultMock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.strategy.selection; 20 | 21 | import org.hibernate.shards.ShardId; 22 | 23 | /** 24 | * @author maxr@google.com (Max Ross) 25 | */ 26 | public class ShardSelectionStrategyDefaultMock implements ShardSelectionStrategy { 27 | 28 | public ShardId selectShardIdForNewObject(Object obj) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/hibernate/shards/util/JdbcStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2007 Google Inc. 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 | */ 18 | 19 | package org.hibernate.shards.util; 20 | 21 | import java.sql.ResultSet; 22 | import java.sql.SQLException; 23 | 24 | public interface JdbcStrategy { 25 | void extractData(ResultSet rs) throws SQLException; 26 | } 27 | -------------------------------------------------------------------------------- /src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 2 | log4j.appender.stdout.Target=System.out 3 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 4 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n 5 | 6 | 7 | log4j.rootLogger=info, stdout 8 | 9 | log4j.logger.org.hibernate.tool.hbm2ddl=trace 10 | log4j.logger.org.hibernate.testing.cache=debug 11 | 12 | # SQL Logging - HHH-6833 13 | log4j.logger.org.hibernate.SQL=debug 14 | 15 | log4j.logger.org.hibernate.hql.internal.ast=debug 16 | 17 | log4j.logger.org.hibernate.sql.ordering.antlr=debug -------------------------------------------------------------------------------- /src/test/resources/org/hibernate/shards/example/hibernate0.cfg.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | org.hibernate.dialect.HSQLDialect 7 | org.hsqldb.jdbcDriver 8 | jdbc:hsqldb:mem:shard0 9 | sa 10 | 11 | 0 12 | 13 | true 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/org/hibernate/shards/example/hibernate1.cfg.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | org.hibernate.dialect.HSQLDialect 7 | org.hsqldb.jdbcDriver 8 | jdbc:hsqldb:mem:shard1 9 | sa 10 | 11 | 1 12 | 13 | true 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/org/hibernate/shards/example/hibernate2.cfg.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | org.hibernate.dialect.HSQLDialect 7 | org.hsqldb.jdbcDriver 8 | jdbc:hsqldb:mem:shard2 9 | sa 10 | 11 | 2 12 | 13 | true 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/org/hibernate/shards/example/weather.hbm.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------